Cake\Database\Connection::driver PHP Метод

driver() публичный Метод

If no params are passed it will return the current driver instance.
public driver ( Cake\Database\Driver | string | null $driver = null, array $config = [] ) : Cake\Database\Driver
$driver Cake\Database\Driver | string | null The driver instance to use.
$config array Either config for a new driver or null.
Результат Cake\Database\Driver
    public function driver($driver = null, $config = [])
    {
        if ($driver === null) {
            return $this->_driver;
        }
        if (is_string($driver)) {
            $className = App::className($driver, 'Database/Driver');
            if (!$className || !class_exists($className)) {
                throw new MissingDriverException(['driver' => $driver]);
            }
            $driver = new $className($config);
        }
        if (!$driver->enabled()) {
            throw new MissingExtensionException(['driver' => get_class($driver)]);
        }
        return $this->_driver = $driver;
    }

Usage Example

Пример #1
4
 /**
  * Refresh the protected foreign keys variable.
  * All foreign keys are removed from the original constraints.
  *
  * @return void
  */
 protected function _extractForeignKeys(Connection $connection)
 {
     $dialect = $connection->driver()->schemaDialect();
     foreach ($this->_constraints as $name => $attrs) {
         if ($attrs['type'] === static::CONSTRAINT_FOREIGN) {
             $this->_foreignKeys[$name] = $attrs;
             $this->_foreignKeysSql[$name] = $dialect->constraintSql($this, $name);
             unset($this->_constraints[$name]);
         }
     }
 }
All Usage Examples Of Cake\Database\Connection::driver