Author: Daniele Alessandri (suppakilla@gmail.com)
Inheritance: implements Predis\Connection\ParametersInterface
Esempio n. 1
0
 /**
  * Creates an instance of connection parameters.
  *
  * @param mixed $parameters Connection parameters.
  *
  * @return ParametersInterface
  */
 protected function createParameters($parameters)
 {
     if ($parameters instanceof ParametersInterface) {
         return $parameters;
     }
     return Parameters::create($parameters);
 }
    /**
     * {@inheritdoc}
     */
    public function register(Container $app)
    {
        $prefix = $this->prefix;

        $app["$prefix.default_parameters"] = array();
        $app["$prefix.default_options"] = array();

        $app["$prefix.uri_parser"] = $app->protect(function ($uri) {
            return Parameters::parse($uri);
        });

        $app["$prefix.client_constructor"] = $app->protect(function ($parameters, $options) {
            return new Client($parameters, $options);
        });

        $app["$prefix.client_initializer"] = $this->getClientInitializer($app, $prefix);
        $app["$prefix"] = $this->getProviderHandler($app, $prefix);
    }
Esempio n. 3
0
 /**
  * Creates a connection parameters instance from the supplied argument.
  *
  * @param mixed $parameters Original connection parameters.
  *
  * @return ParametersInterface
  */
 protected function createParameters($parameters)
 {
     return Parameters::create($parameters);
 }
 /**
  * @group disconnected
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage Invalid parameters URI: tcp://invalid:uri
  */
 public function testParsingURIThrowOnInvalidURI()
 {
     Parameters::parse('tcp://invalid:uri');
 }
Esempio n. 5
0
 /**
  * Creates a connection parameters instance from the supplied argument.
  *
  * @param mixed $parameters Original connection parameters.
  *
  * @return ParametersInterface
  */
 protected function createParameters($parameters)
 {
     if (is_string($parameters)) {
         $parameters = Parameters::parse($parameters);
     } else {
         $parameters = $parameters ?: array();
     }
     if ($this->defaults) {
         $parameters += $this->defaults;
     }
     return new Parameters($parameters);
 }
Esempio n. 6
0
 /**
  * Creates a new connection to a sentinel server.
  *
  * @return NodeConnectionInterface
  */
 protected function createSentinelConnection($parameters)
 {
     if ($parameters instanceof NodeConnectionInterface) {
         return $parameters;
     }
     if (is_string($parameters)) {
         $parameters = Parameters::parse($parameters);
     }
     if (is_array($parameters)) {
         // We explicitly set "database" and "password" to null,
         // so that no AUTH and SELECT command is send to the sentinels.
         $parameters['database'] = null;
         $parameters['password'] = null;
         if (!isset($parameters['timeout'])) {
             $parameters['timeout'] = $this->sentinelTimeout;
         }
     }
     $connection = $this->connectionFactory->create($parameters);
     return $connection;
 }
 /**
  * Returns a base mocked connection from Predis\Connection\NodeConnectionInterface.
  *
  * @param mixed $parameters Optional parameters.
  *
  * @return mixed
  */
 protected function getMockConnection($parameters = null)
 {
     $connection = $this->getMock('Predis\\Connection\\NodeConnectionInterface');
     if ($parameters) {
         $parameters = Connection\Parameters::create($parameters);
         $hash = "{$parameters->host}:{$parameters->port}";
         $connection->expects($this->any())->method('getParameters')->will($this->returnValue($parameters));
         $connection->expects($this->any())->method('__toString')->will($this->returnValue($hash));
     }
     return $connection;
 }