__construct() public method

Constructor.
public __construct ( array $config = [] ) : void
$config array Available options are: - `'autoConnect'` _boolean_: If `true`, a connection is made on initialization. Defaults to `true`.
return void
コード例 #1
0
ファイル: Http.php プロジェクト: WarToaster/HangOn
 /**
  * Constructor
  *
  * @param array $config
  */
 public function __construct(array $config = array())
 {
     $defaults = array('adapter' => null, 'persistent' => false, 'scheme' => 'http', 'host' => 'localhost', 'version' => '1.1', 'auth' => null, 'login' => '', 'password' => '', 'port' => 80, 'timeout' => 30, 'encoding' => 'UTF-8');
     $config = $config + $defaults;
     $config['username'] = $config['login'];
     parent::__construct($config);
 }
コード例 #2
0
ファイル: Http.php プロジェクト: kdambekalns/framework-benchs
 /**
  * Constructor
  *
  * @param array $config
  * @return void
  */
 public function __construct($config = array())
 {
     $defaults = array('classes' => array(), 'adapter' => null, 'persistent' => false, 'protocol' => 'tcp', 'host' => 'localhost', 'version' => '1.1', 'auth' => 'Basic', 'login' => 'root', 'password' => '', 'port' => 80, 'timeout' => 1, 'encoding' => 'UTF-8');
     $config = (array) $config + $defaults;
     $config['auth'] = array('method' => $config['auth'], 'username' => $config['login'], 'password' => $config['password']);
     $this->_classes = $config['classes'] + $this->_classes;
     parent::__construct($config);
 }
コード例 #3
0
ファイル: MongoDb.php プロジェクト: newmight2015/Blockchain-2
 /**
  * Instantiates the MongoDB adapter with the default connection information.
  *
  * @see lithium\data\Connections::add()
  * @see lithium\data\source\MongoDb::$_schema
  * @link http://php.net/manual/en/mongo.construct.php PHP Manual: Mongo::__construct()
  * @param array $config All information required to connect to the database, including:
  *        - `'database'` _string_: The name of the database to connect to. Defaults to `null`.
  *        - `'host'` _string_: The IP or machine name where Mongo is running, followed by a
  *           colon, and the port number. Defaults to `'localhost:27017'`.
  *        - `'persistent'` _mixed_: Determines a persistent connection to attach to. See the
  *           `$options` parameter of
  *            [`Mongo::__construct()`](http://www.php.net/manual/en/mongo.construct.php) for
  *            more information. Defaults to `false`, meaning no persistent connection is made.
  *        - `'timeout'` _integer_: The number of milliseconds a connection attempt will wait
  *          before timing out and throwing an exception. Defaults to `100`.
  *        - `'schema'` _closure_: A closure or anonymous function which returns the schema
  *          information for a model class. See the `$_schema` property for more information.
  *        - `'gridPrefix'` _string_: The default prefix for MongoDB's `chunks` and `files`
  *          collections. Defaults to `'fs'`.
  *        - `'replicaSet'` _string_: See the documentation for `Mongo::__construct()`. Defaults
  *          to `false`.
  *        - `'readPreference'` _mixed_: May either be a single value such as Mongo::RP_NEAREST,
  *          or an array containing a read preference and a tag set such as:
  *          array(Mongo::RP_SECONDARY_PREFERRED, array('dc' => 'east) See the documentation for
  *          `Mongo::setReadPreference()`. Defaults to null.
  *
  * Typically, these parameters are set in `Connections::add()`, when adding the adapter to the
  * list of active connections.
  */
 public function __construct(array $config = array())
 {
     $host = 'localhost:27017';
     $server = $this->_classes['server'];
     if (class_exists($server, false)) {
         $host = $server::DEFAULT_HOST . ':' . $server::DEFAULT_PORT;
     }
     $defaults = compact('host') + array('persistent' => false, 'login' => null, 'password' => null, 'database' => null, 'timeout' => 100, 'replicaSet' => false, 'schema' => null, 'gridPrefix' => 'fs', 'safe' => false, 'readPreference' => null);
     parent::__construct($config + $defaults);
 }
コード例 #4
0
 /**
  * Creates the database object and set default values for it.
  *
  * Options defined:
  *  - 'database' _string_ Name of the database to use. Defaults to 'lithium'.
  *  - '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 none.
  *  - 'persistent' _boolean_ If true a persistent connection will be attempted, provided the
  *    adapter supports it. Defaults to true.
  *
  * @param $config array Array of configuration options.
  * @return Database object.
  */
 public function __construct($config = array())
 {
     $defaults = array('persistent' => true, 'host' => 'localhost', 'login' => 'root', 'password' => '', 'database' => 'lithium');
     parent::__construct((array) $config + $defaults);
 }
コード例 #5
0
ファイル: Database.php プロジェクト: EHER/monopolis
 /**
  * Creates the database object and set default values for it.
  *
  * Options defined:
  *  - '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`.
  *
  * @param $config array Array of configuration options.
  * @return Database object.
  */
 public function __construct(array $config = array())
 {
     $defaults = array('persistent' => true, 'host' => 'localhost', 'login' => 'root', 'password' => '', 'database' => null);
     $this->_strings += array('read' => 'SELECT {:fields} FROM {:source} {:alias} {:joins} {:conditions} {:group} ' . '{:order} {:limit};{:comment}');
     parent::__construct($config + $defaults);
 }
コード例 #6
0
ファイル: Redis.php プロジェクト: bruensicke/li3_redis
 /**
  *
  */
 public function __construct(array $config = array())
 {
     $defaults = array('host' => 'localhost', 'port' => '6379', 'timeout' => 3, 'retry_interval' => 100, 'persistent' => false, 'persistent_id' => null, 'retries' => null, 'password' => null, 'database' => null, 'lazy_connect' => true);
     parent::__construct($config + $defaults);
 }
コード例 #7
0
ファイル: Database.php プロジェクト: shopblocks/lithium
 /**
  * Constructor.
  *
  * @param $config 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(array $config = array())
 {
     $defaults = array('persistent' => true, 'host' => 'localhost', 'login' => 'root', 'password' => '', 'database' => null, 'encoding' => null, 'dsn' => null, 'options' => array());
     parent::__construct($config + $defaults);
 }
コード例 #8
0
ファイル: MongoDb.php プロジェクト: EHER/chegamos
 /**
  * Instantiates the MongoDB adapter with the default connection information.
  *
  * @see lithium\data\Connections::add()
  * @see lithium\data\source\MongoDb::$_schema
  * @param array $config All information required to connect to the database, including:
  *        - `'database'` _string_: The name of the database to connect to. Defaults to `'app'`.
  *        - `'host'` _string_: The IP or machine name where Mongo is running, followed by a
  *           colon, and the port number. Defaults to `'localhost:27017'`.
  *        - `'persistent'` _boolean_: If a persistent connection (if available) should be made.
  *            Defaults to `true`.
  *        - `'port'`_mixed_: The port number Mongo is listening on. The default is '27017'.
  *        - `'timeout'` _integer_: The number of milliseconds a connection attempt will wait
  *          before timing out and throwing an exception. Defaults to `100`.
  *        - `'schema'` _closure_: A closure or anonymous function which returns the schema
  *          information for a model class. See the `$_schema` property for more information.
  *
  * Typically, these parameters are set in `Connections::add()`, when adding the adapter to the
  * list of active connections.
  * @return object The adapter instance.
  */
 public function __construct(array $config = array())
 {
     $defaults = array('persistent' => true, 'login' => null, 'password' => null, 'host' => 'localhost:27107', 'database' => 'app', 'timeout' => 100, 'schema' => null, 'gridPrefix' => 'fs');
     parent::__construct($config + $defaults);
 }
コード例 #9
0
 /**
  * Instantiates the MongoDB adapter with the default connection information.
  *
  * @param array $config All information required to connect to the database, including:
  *        - `'database'`: The name of the database to connect to. Defaults to 'lithium'.
  *        - `'host'`: The IP or machine name where Mongo is running. Defaults to 'localhost'.
  *        - `'persistent'`: If a persistent connection (if available) should be made. Defaults
  *            to true.
  *        - `'port'`: The port number Mongo is listening on. The default is '27017'.
  *
  * 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\Connections::add()
  */
 public function __construct($config = array())
 {
     $defaults = array('persistent' => true, 'host' => 'localhost', 'database' => 'lithium', 'port' => '27017');
     parent::__construct((array) $config + $defaults);
 }
コード例 #10
0
ファイル: MongoDb.php プロジェクト: niel/lithium
	/**
	 * Instantiates the MongoDB adapter with the default connection information.
	 *
	 * @see lithium\data\Connections::add()
	 * @see lithium\data\source\MongoDb::$_schema
	 * @link http://php.net/manual/en/mongo.construct.php PHP Manual: Mongo::__construct()
	 * @param array $config All information required to connect to the database, including:
	 *        - `'database'` _string_: The name of the database to connect to. Defaults to `null`.
	 *        - `'host'` _string_: The IP or machine name where Mongo is running, followed by a
	 *           colon, and the port number. Defaults to `'localhost:27017'`.
	 *        - `'persistent'` _mixed_: Determines a persistent connection to attach to. See the
	 *           `$options` parameter of
	 *            [`Mongo::__construct()`](http://www.php.net/manual/en/mongo.construct.php) for
	 *            more information. Defaults to `false`, meaning no persistent connection is made.
	 *        - `'timeout'` _integer_: The number of milliseconds a connection attempt will wait
	 *          before timing out and throwing an exception. Defaults to `100`.
	 *        - `'schema'` _closure_: A closure or anonymous function which returns the schema
	 *          information for a model class. See the `$_schema` property for more information.
	 *        - `'gridPrefix'` _string_: The default prefix for MongoDB's `chunks` and `files`
	 *          collections. Defaults to `'fs'`.
	 *        - `'replicaSet'` _boolean_: See the documentation for `Mongo::__construct()`. Defaults
	 *          to `false`.
	 *
	 * 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(
			'persistent' => false,
			'login'      => null,
			'password'   => null,
			'host'       => Mongo::DEFAULT_HOST . ':' . Mongo::DEFAULT_PORT,
			'database'   => null,
			'timeout'    => 100,
			'replicaSet' => false,
			'schema'     => null,
			'gridPrefix' => 'fs'
		);
		parent::__construct($config + $defaults);
	}
コード例 #11
0
ファイル: Doctrine.php プロジェクト: mariano/li3_doctrine2
 /**
  * Build data source
  *
  * @param array $config Configuration
  */
 public function __construct(array $config = [])
 {
     $defaults = ['models' => LITHIUM_APP_PATH . '/models', 'proxies' => LITHIUM_APP_PATH . '/models/proxies', 'proxyNamespace' => 'proxies', 'cache' => null];
     $this->connectionSettings = array_diff_key($config, array_merge($defaults, ['type' => null, 'adapter' => null, 'login' => null, 'filters' => null]));
     parent::__construct($config + $defaults);
 }
コード例 #12
0
 /**
  * Creates the database object and set default values for it.
  *
  * Options defined:
  *  - '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`.
  *
  * @param $config array Array of configuration options.
  * @return Database object.
  */
 public function __construct(array $config = array())
 {
     $defaults = array('persistent' => true, 'host' => 'localhost', 'login' => 'root', 'password' => '', 'database' => null, 'encoding' => null, 'dsn' => null, 'options' => array());
     $this->_strings += array('read' => 'SELECT {:fields} FROM {:source} {:alias} {:joins} {:conditions} {:group} ' . '{:having} {:order} {:limit};{:comment}');
     $this->_strategies += array('joined' => function ($self, $model, $context) {
         $with = $context->with();
         $strategy = function ($me, $model, $tree, $path, $from, &$deps) use($self, $context, $with) {
             foreach ($tree as $name => $childs) {
                 if (!($rel = $model::relations($name))) {
                     throw new QueryException("Model relationship `{$name}` not found.");
                 }
                 $constraints = array();
                 $alias = $name;
                 $relPath = $path ? $path . '.' . $name : $name;
                 if (isset($with[$relPath])) {
                     list($unallowed, $allowed) = Set::slice($with[$relPath], array('alias', 'constraints'));
                     if ($unallowed) {
                         $message = "Only `'alias'` and `'constraints'` are allowed in ";
                         $message .= "`'with'` using the `'joined'` strategy.";
                         throw new QueryException($message);
                     }
                     extract($with[$relPath]);
                 }
                 $to = $context->alias($alias, $relPath);
                 $deps[$to] = $deps[$from];
                 $deps[$to][] = $from;
                 if ($context->relationships($relPath) === null) {
                     $context->relationships($relPath, array('type' => $rel->type(), 'model' => $rel->to(), 'fieldName' => $rel->fieldName(), 'alias' => $to));
                     $self->join($context, $rel, $from, $to, $constraints);
                 }
                 if (!empty($childs)) {
                     $me($me, $rel->to(), $childs, $relPath, $to, $deps);
                 }
             }
         };
         $tree = Set::expand(Set::normalize(array_keys($with)));
         $alias = $context->alias();
         $deps = array($alias => array());
         $strategy($strategy, $model, $tree, '', $alias, $deps);
         $models = $context->models();
         foreach ($context->fields() as $field) {
             list($alias, $field) = $self->invokeMethod('_splitFieldname', array($field));
             $alias = $alias ?: $field;
             if ($alias && isset($models[$alias])) {
                 foreach ($deps[$alias] as $depAlias) {
                     $depModel = $models[$depAlias];
                     $context->fields(array($depAlias => (array) $depModel::meta('key')));
                 }
             }
         }
     }, 'nested' => function ($self, $model, $context) {
         throw new QueryException("This strategy is not yet implemented.");
     });
     parent::__construct($config + $defaults);
 }