Elastica\Connection::create PHP Method

create() public static method

public static create ( Connection | array $params = [] ) : self
$params Connection | array Params to create a connection
return self
    public static function create($params = [])
    {
        if (is_array($params)) {
            return new self($params);
        }
        if ($params instanceof self) {
            return $params;
        }
        throw new InvalidException('Invalid data type');
    }

Usage Example

Beispiel #1
0
 /**
  * Inits the client connections
  */
 protected function _initConnections()
 {
     $connections = array();
     foreach ($this->getConfig('connections') as $connection) {
         $connections[] = Connection::create($this->_prepareConnectionParams($connection));
     }
     if (isset($this->_config['servers'])) {
         foreach ($this->getConfig('servers') as $server) {
             $connections[] = Connection::create($this->_prepareConnectionParams($server));
         }
     }
     // If no connections set, create default connection
     if (empty($connections)) {
         $connections[] = Connection::create($this->_prepareConnectionParams($this->getConfig()));
     }
     if (!isset($this->_config['connectionStrategy'])) {
         if ($this->getConfig('roundRobin') === true) {
             $this->setConfigValue('connectionStrategy', 'RoundRobin');
         } else {
             $this->setConfigValue('connectionStrategy', 'Simple');
         }
     }
     $strategy = Connection\Strategy\StrategyFactory::create($this->getConfig('connectionStrategy'));
     $this->_connectionPool = new Connection\ConnectionPool($connections, $strategy, $this->_callback);
 }
All Usage Examples Of Elastica\Connection::create