Ejemplo n.º 1
0
 /**
  * Adds the snc_redis.clients configuration
  *
  * @param ArrayNodeDefinition $rootNode
  */
 private function addClientsSection(ArrayNodeDefinition $rootNode)
 {
     $rootNode->fixXmlConfig('client')->children()->arrayNode('clients')->isRequired()->requiresAtLeastOneElement()->useAttributeAsKey('alias', false)->prototype('array')->fixXmlConfig('dsn')->children()->scalarNode('type')->isRequired()->validate()->ifTrue(function ($v) {
         return !in_array($v, array('predis', 'phpredis'));
     })->thenInvalid('The redis client type %s is invalid.')->end()->end()->scalarNode('alias')->isRequired()->end()->booleanNode('logging')->defaultValue($this->debug)->end()->arrayNode('dsns')->isRequired()->performNoDeepMerging()->beforeNormalization()->ifString()->then(function ($v) {
         return (array) $v;
     })->end()->beforeNormalization()->always()->then(function ($v) {
         return array_map(function ($dsn) {
             $parsed = new RedisDsn($dsn);
             return $parsed->isValid() ? $parsed : $dsn;
         }, $v);
     })->end()->prototype('variable')->validate()->ifTrue(function ($v) {
         return is_string($v);
     })->thenInvalid('The redis DSN %s is invalid.')->end()->end()->end()->scalarNode('alias')->isRequired()->end()->arrayNode('options')->addDefaultsIfNotSet()->children()->booleanNode('connection_async')->defaultFalse()->end()->booleanNode('connection_persistent')->defaultFalse()->end()->scalarNode('connection_timeout')->defaultValue(5)->end()->scalarNode('read_write_timeout')->defaultNull()->end()->booleanNode('iterable_multibulk')->defaultFalse()->end()->booleanNode('throw_errors')->defaultTrue()->end()->scalarNode('profile')->defaultValue('2.4')->beforeNormalization()->ifTrue(function ($v) {
         return false === is_string($v);
     })->then(function ($v) {
         return sprintf('%.1F', $v);
     })->end()->end()->scalarNode('cluster')->defaultNull()->end()->scalarNode('prefix')->defaultNull()->end()->booleanNode('replication')->defaultFalse()->end()->end()->end()->end()->end()->end()->end();
 }
Ejemplo n.º 2
0
 /**
  * @param string $dsn    DSN
  * @param int    $weight Weight
  *
  * @dataProvider weightValues
  */
 public function testParameterValues($dsn, $weight)
 {
     $dsn = new RedisDsn($dsn);
     $this->assertSame($weight, $dsn->getWeight());
 }