Constructor.
public __construct ( array $config = [] ) : void | ||
$config | array | array Available configuration options are: - `'database'` _string_: Name of the database to use. Defaults to `null`. - `'host'` _string_: Name/address of server to connect to. Defaults to `'localhost'`. - `'login'` _string_: Username to use when connecting to server. Defaults to `'root'`. - `'password'` _string_: Password to use when connecting to server. Defaults to `''`. - `'persistent'` _boolean_: If true a persistent connection will be attempted, provided the adapter supports it. Defaults to `true`. |
return | void |
/** * */ public function __construct($config = array()) { $defaults = array('proxy' => array('auto' => true, 'path' => LITHIUM_APP_PATH . '/resources/tmp/cache/Doctrine/Proxies', 'namespace' => 'Doctrine\\Proxies'), 'useModelDriver' => true, 'mapping' => array('class' => null, 'path' => LITHIUM_APP_PATH . '/models'), 'configuration' => null, 'eventManager' => null, 'utf-8' => true); $config = Set::merge($defaults, $config); $configuration = $config['configuration'] ?: new Configuration(); $eventManager = $config['eventManager'] ?: new EventManager(); $configuration->setProxyDir($config['proxy']['path']); $configuration->setProxyNamespace($config['proxy']['namespace']); $configuration->setAutoGenerateProxyClasses($config['proxy']['auto']); $configuration->setMetadataCacheImpl(new ArrayCache()); // Annotation Driver $driver = $configuration->newDefaultAnnotationDriver(array(LITHIUM_APP_PATH . '/models')); $configuration->setMetadataDriverImpl($driver); // TODO: Not sure if this is required or not! // if (!$config['useModelDriver']) { // $configuration->setMetadataDriverImpl(new ModelDriver()); // } $configuration->setSqlLogger(new SqlLogger()); $mapping = array('adapter' => 'driver', 'login' => 'user', 'database' => 'dbname'); foreach ($mapping as $source => $dest) { if (isset($config[$source]) && !isset($config[$dest])) { $config[$dest] = $config[$source]; unset($config[$source]); } } $this->_em = EntityManager::create($config, $configuration, $eventManager); $this->_sm = $this->_em->getConnection()->getSchemaManager(); if ($this->_em->getConnection()->getDriver() instanceof Driver\PDOMySql\Driver && $config['utf-8']) { $this->_em->getEventManager()->addEventSubscriber(new MysqlSessionInit('utf8', 'utf8_unicode_ci')); } parent::__construct($config); }
/** * Constructor. Constructs the PostgreSQL adapter and sets the default port to 5432. * * @see lithium\data\source\Database::__construct() * @see lithium\data\Source::__construct() * @see lithium\data\Connections::add() * @param array $config The available configuration options are the following. Further * options are inherited from the parent classes. Typically, these parameters are * set in `Connections::add()`, when adding the adapter to the list of active * connections. * - `'host'` _string_: Defaults to `'localhost:5432'`. * - `'schema'` _string_: The name of the database schema to use. Defaults to `'public'`. * - `'timezone'` _string_: The timezone to use. Defaults to `'null'` * @return void */ public function __construct(array $config = array()) { $defaults = array('host' => 'localhost:5432', 'schema' => 'public', 'timezone' => null); parent::__construct($config + $defaults); }
/** * Constructs the Sqlite adapter * * @see lithium\data\source\Database::__construct() * @see lithium\data\Source::__construct() * @see lithium\data\Connections::add() * @param array $config Configuration options for this class. For additional configuration, * see `lithium\data\source\Database` and `lithium\data\Source`. Available options * defined by this class: * - `'database'` _string_: database name. Defaults to none * - `'flags'` _integer_: Optional flags used to determine how to open the SQLite * database. By default, open uses SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE. * - `'key'` _string_: An optional encryption key used when encrypting and decrypting * an SQLite database. * * Typically, these parameters are set in `Connections::add()`, when adding the adapter to the * list of active connections. */ public function __construct(array $config = array()) { $defaults = array( 'database' => '', 'flags' => SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE, 'key' => null ); parent::__construct($config + $defaults); }
/** * Constructs the MySQL adapter and sets the default port to 3306. * * @see lithium\data\source\Database::__construct() * @see lithium\data\Source::__construct() * @see lithium\data\Connections::add() * @param array $config Configuration options for this class. For additional configuration, * see `lithium\data\source\Database` and `lithium\data\Source`. Available options * defined by this class: * - `'database'`: The name of the database to connect to. Defaults to 'lithium'. * - `'host'`: The IP or machine name where MySQL is running, followed by a colon, * followed by a port number or socket. Defaults to `'localhost:3306'`. * - `'persistent'`: If a persistent connection (if available) should be made. * Defaults to true. * * Typically, these parameters are set in `Connections::add()`, when adding the adapter to the * list of active connections. */ public function __construct(array $config = array()) { $defaults = array('host' => 'localhost:3306', 'encoding' => null); parent::__construct($config + $defaults); }
public function __construct(array $config = array()) { parent::__construct($config); $this->connection = $this; }
public function __construct($config = array()) { parent::__construct($config); }
/** * Constructs the Sqlite adapter * * @param array $config Configuration options for this class. For additional configuration, * see `lithium\data\source\Database` and `lithium\data\Source`. Available options * defined by this class: * - `'database'` _string_: database name. Defaults to none * - `'flags'` _integer_: Optional flags used to determine how to open the SQLite * database. By default, open uses SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE. * - `'key'` _string_: An optional encryption key used when encrypting and decrypting * an SQLite database. * * Typically, these parameters are set in `Connections::add()`, when adding the adapter to the * list of active connections. * @return The adapter instance. * * @see lithium\data\source\Database::__construct() * @see lithium\data\Source::__construct() * @see lithium\data\Connections::add() */ public function __construct($config = array()) { $defaults = array('database' => '', 'flags' => NULL, 'key' => NULL); parent::__construct((array) $config + $defaults); }
public function __construct(array $config = array()) { $defaults = array('records' => array(), 'columns' => array()); $config['autoConnect'] = false; parent::__construct((array) $config + $defaults); }
/** * Constructs the Sqlite adapter * * @see lithium\data\source\Database::__construct() * @see lithium\data\Source::__construct() * @see lithium\data\Connections::add() * @param array $config Configuration options for this class. For additional configuration, * see `lithium\data\source\Database` and `lithium\data\Source`. Available options * defined by this class: * - `'database'` _string_: database name. Defaults to none * - `'flags'` _integer_: Optional flags used to determine how to open the SQLite * database. By default, open uses SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE. * - `'key'` _string_: An optional encryption key used when encrypting and decrypting * an SQLite database. * * Typically, these parameters are set in `Connections::add()`, when adding the adapter to the * list of active connections. */ public function __construct(array $config = array()) { $defaults = array('database' => ':memory:', 'encoding' => null); parent::__construct($config + $defaults); }
/** * Constructs the MySQLi adapter and defaults the port to 3306. * * @param array $config Configuration options for this class. For additional configuration, * see `lithium\data\source\Database` and `lithium\data\Source`. * - `'database'`: The name of the database to connect to. Defaults to 'lithium'. * - `'host'`: The IP or machine name where MySQL is running. Defaults to 'localhost'. * - `'persistent'`: If supported, should a persistent connection be made. Defaults to true. * - `'port'`: The port number MySQL is listening on. The default is '3306'. * * Typically, these parameters are set in `Connections::add()`, when adding the adapter to the * list of active connections. * * @return object The adapter instance. * * @see lithium\data\source\Database::__construct() * @see lithium\data\Source::__construct() * @see lithium\data\Connections::add() */ public function __construct($config = array()) { $defaults = array('port' => '3306'); parent::__construct((array) $config + $defaults); }