Back to Adapter class

Method setAdapter

public bool
setAdapter
(mixed $name, mixed &$adapter = null, mixed $options = array())
Set an adapter by name
Parameters
  • string $name Adapter name
  • object $adapter Adapter object
  • array $options Adapter options
Returns
  • bool True if successful
Since
  • 1.6
Class: Adapter
Project: Joomla

Method setAdapter - Source code

/**
 * Set an adapter by name
 *
 * @param   string  $name     Adapter name
 * @param   object  $adapter  Adapter object
 * @param   array   $options  Adapter options
 *
 * @return  boolean  True if successful
 *
 * @since   1.6
 */
public function setAdapter($name, &$adapter = null, $options = array())
{
    if (is_object($adapter)) {
        $this->_adapters[$name] =& $adapter;
        return true;
    }
    $class = rtrim($this->_classprefix, '\\') . '\\' . ucfirst($name);
    if (class_exists($class)) {
        $this->_adapters[$name] = new $class($this, $this->_db, $options);
        return true;
    }
    $class = rtrim($this->_classprefix, '\\') . '\\' . ucfirst($name) . 'Adapter';
    if (class_exists($class)) {
        $this->_adapters[$name] = new $class($this, $this->_db, $options);
        return true;
    }
    $fullpath = $this->_basepath . '/' . $this->_adapterfolder . '/' . strtolower($name) . '.php';
    if (!is_file($fullpath)) {
        return false;
    }
    // Try to load the adapter object
    $class = $this->_classprefix . ucfirst($name);
    \JLoader::register($class, $fullpath);
    if (!class_exists($class)) {
        return false;
    }
    $this->_adapters[$name] = new $class($this, $this->_db, $options);
    return true;
}