/** * @param string $name * @return Connection */ public function getConnection($name = 'default') { if (!isset($this->config)) { throw ConnectionException::missingConnection($name, array_keys($this->config)); } if (!isset($this->connection)) { $this->connection = new Connection($this->config, $this->processor); } return $this->connection; }
/** * @param array $config */ public function __construct(array $config, SphinxDataProcessorInterface $processor) { $this->config = $config; $this->processor = $processor; switch ($config['driver']) { case self::DRIVER_PDO: $this->connection = new PdoConnection(); $this->connection->setParams(['host' => $this->config['host'], 'port' => $this->config['port']]); return; case self::DRIVER_MYSQLI: $this->connection = new PdoConnection(); $this->connection->setParams(['host' => $this->config['host'], 'port' => $this->config['port']]); return; } throw ConnectionException::unsupportedDriver($config['driver'], self::getSupportedDrivers()); }