Phalcon\Db\Adapter\Factory::load PHP Method

load() public static method

Load config from file extension dynamical
public static load ( array $config ) : Phalcon\Db\AdapterInterface
$config array Adapter config
return Phalcon\Db\AdapterInterface
    public static function load(array $config)
    {
        if (!isset($config['adapter']) || empty($config['adapter']) || !is_string($config['adapter'])) {
            throw new Exception("A database 'adapter' option is required and must be a nonempty string.");
        }
        $namespace = __NAMESPACE__ . '\\' . 'Pdo' . '\\';
        $adapter = ucfirst(strtolower($config['adapter']));
        $className = $namespace . $adapter;
        if (!class_exists($className)) {
            throw new Exception("Database adapter {$adapter} is not supported");
        }
        unset($config['adapter']);
        return new $className($config);
    }

Usage Example

Exemplo n.º 1
0
 /**
  * @expectedException \Phalcon\Db\Exception
  * @expectedExceptionMessage Database adapter Drizzle is not supported
  */
 public function testLoadUnsupportedAdapter()
 {
     $this->testable['adapter'] = 'drizzle';
     AdaptersFactory::load($this->testable);
 }
Factory