addDefaultsIfNotSet() public method

This method is applicable to concrete nodes only (not to prototype nodes). If this function has been called and the node is not set during the finalization phase, it's default value will be derived from its children default values.
public addDefaultsIfNotSet ( ) : ArrayNodeDefinition
return ArrayNodeDefinition
 /**
  * @test if transport is not set default (first) is used
  */
 public function defaultTransport()
 {
     $this->root1->addDefaultsIfNotSet()->children()->scalarNode('param1')->defaultValue('value1')->end()->scalarNode('param2')->defaultValue('value2')->end()->end();
     $config = $this->processSection(['sub1' => [], 'sub2' => []]);
     $transport = ['type' => 'transport1', 'parameters' => ['param1' => 'value1', 'param2' => 'value2']];
     $this->assertEquals($transport, $config['sub1']['transport']);
     $this->assertEquals($transport, $config['sub2']['transport']);
 }
Exemplo n.º 2
0
 private function getDefaultsSection()
 {
     $node = new ArrayNodeDefinition('defaults');
     $node->addDefaultsIfNotSet();
     $this->appendPrototypedConfiguration($node);
     return $node;
 }
Exemplo n.º 3
0
 /**
  * @param ArrayNodeDefinition $builder
  *
  * @return null
  */
 public function configure(ArrayNodeDefinition $builder)
 {
     $builder->addDefaultsIfNotSet()->children()->arrayNode('fixtures')->beforeNormalization()->ifTrue(function ($v) {
         return is_scalar($v);
     })->then(function ($v) {
         return array('default' => array('app'), 'key_paths' => array('app' => $v));
     })->end()->validate()->ifTrue(function ($v) {
         foreach ($v['default'] as $default) {
             if (!array_key_exists($default, $v['key_paths'])) {
                 return true;
             }
         }
     })->thenInvalid("You can't define a default which is not present in key_paths.")->end()->children()->arrayNode('default')->beforeNormalization()->ifTrue(function ($v) {
         return is_scalar($v);
     })->then(function ($v) {
         return array($v);
     })->end()->prototype('scalar')->end()->end()->arrayNode('key_paths')->useAttributeAsKey('key_path')->validate()->ifTrue(function ($v) {
         return array_key_exists(FixtureStack::DEFAULT_KEY, $v);
     })->thenInvalid('You cannot add a key_path with key “' . FixtureStack::DEFAULT_KEY . '“, this is a reserved word.')->end()->prototype('scalar')->end()->end()->end()->end()->scalarNode('lifetime')->end()->arrayNode('faker')->addDefaultsIfNotSet()->children()->scalarNode('locale')->defaultValue('en_US')->end()->arrayNode('providers')->beforeNormalization()->always(function ($v) {
         return array_map(function ($class) {
             return new $class();
         }, $v);
     })->end()->prototype('variable')->end()->end()->end()->end()->arrayNode('adapters')->addDefaultsIfNotSet()->children()->arrayNode('elastica')->children()->scalarNode('fixture_class')->defaultValue('Rezzza\\AliceExtension\\Fixture\\ElasticaFixture')->cannotBeEmpty()->end()->scalarNode('index_service')->cannotBeEmpty()->end()->arrayNode('mapping')->prototype('scalar')->end()->end()->end()->end()->arrayNode('orm')->addDefaultsIfNotSet()->children()->scalarNode('fixture_class')->defaultValue('Rezzza\\AliceExtension\\Fixture\\ORMFixture')->cannotBeEmpty()->end()->end()->end()->end()->end()->arrayNode('faker')->addDefaultsIfNotSet()->children()->scalarNode('locale')->defaultValue('en_US')->end()->arrayNode('providers')->beforeNormalization()->always(function ($v) {
         return array_map(function ($class) {
             return new $class();
         }, $v);
     })->end()->prototype('variable')->end()->end()->end()->end()->end();
 }
 public function addConfiguration(ArrayNodeDefinition $pluginNode)
 {
     $pluginNode->addDefaultsIfNotSet()->children()->scalarNode('template_engine')->defaultValue('twig')->cannotBeEmpty()->end()->end();
     $this->addFormSection($pluginNode);
     $this->addOptionSection($pluginNode);
     $this->addSecuritySection($pluginNode);
 }
 /**
  * {@inheritdoc}
  */
 public function configure(ArrayNodeDefinition $builder)
 {
     $boolFilter = function ($v) {
         $filtered = filter_var($v, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
         return null === $filtered ? $v : $filtered;
     };
     $builder->addDefaultsIfNotSet()->children()->arrayNode('kernel')->addDefaultsIfNotSet()->children()->scalarNode('bootstrap')->defaultValue('app/autoload.php')->end()->scalarNode('path')->defaultValue('app/Application.php')->end()->scalarNode('class')->defaultValue(null)->end()->scalarNode('env')->defaultValue('test')->end()->booleanNode('debug')->beforeNormalization()->ifString()->then($boolFilter)->end()->defaultTrue()->end()->booleanNode('testSession')->defaultTrue()->end()->end()->end()->end()->end();
 }
 /**
  * {@inheritdoc}
  */
 public function configure(ArrayNodeDefinition $builder)
 {
     $boolFilter = function ($v) {
         $filtered = filter_var($v, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
         return null === $filtered ? $v : $filtered;
     };
     $builder->addDefaultsIfNotSet()->children()->scalarNode('client')->defaultValue('Symfony\\Bundle\\FrameworkBundle\\Client')->end()->arrayNode('kernel')->addDefaultsIfNotSet()->children()->scalarNode('bootstrap')->defaultValue('app/autoload.php')->end()->scalarNode('path')->defaultValue('app/AppKernel.php')->end()->scalarNode('class')->defaultValue('AppKernel')->end()->scalarNode('env')->defaultValue('test')->end()->booleanNode('debug')->beforeNormalization()->ifString()->then($boolFilter)->end()->defaultTrue()->end()->end()->end()->arrayNode('context')->addDefaultsIfNotSet()->children()->scalarNode('path_suffix')->defaultValue('Features')->end()->scalarNode('class_suffix')->defaultValue('Features\\Context\\FeatureContext')->end()->end()->end()->end()->end();
 }
 /**
  * {@inheritdoc}
  */
 public function configure(ArrayNodeDefinition $builder)
 {
     $boolFilter = function ($v) {
         $filtered = filter_var($v, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
         return null === $filtered ? $v : $filtered;
     };
     $builder->addDefaultsIfNotSet()->children()->arrayNode('client')->addDefaultsIfNotSet()->children()->scalarNode('url')->defaultValue('http://localhost')->end()->scalarNode('port')->defaultValue('1080')->end()->end()->end()->booleanNode('purge_before_scenario')->beforeNormalization()->ifString()->then($boolFilter)->end()->defaultTrue()->end()->scalarNode('mailcatcher_client')->defaultValue(self::DEFAULT_CLIENT_ID)->end()->scalarNode('mailcatcher_connection')->defaultValue(self::CONNECTION_GUZZLE_ID)->end()->end()->end();
 }
 protected function setModelConfig(ArrayNodeDefinition $nodeDefinition, array $config, $defaultRepositoryClass = null)
 {
     $childrenNode = $nodeDefinition->addDefaultsIfNotSet()->children();
     $childrenNode->scalarNode('default_repository')->defaultValue($defaultRepositoryClass)->end();
     $classesNode = $childrenNode->arrayNode('classes');
     foreach ($config as $model => $modelProperties) {
         $classesNode->addDefaultsIfNotSet()->children()->arrayNode($model)->addDefaultsIfNotSet()->children()->scalarNode('default_model')->defaultValue(@$modelProperties['default_class'] ?: $modelProperties['class'])->end()->scalarNode('model')->defaultValue($modelProperties['class'])->end()->scalarNode('repository')->defaultValue(@$modelProperties['repository'])->end()->end()->end()->end();
     }
 }
Exemplo n.º 9
0
 protected function getCapabilitiesNode()
 {
     $node = new ArrayNodeDefinition('capabilities');
     $node->addDefaultsIfNotSet()->normalizeKeys(false)->children()->scalarNode('browserName')->defaultValue('firefox')->end()->scalarNode('version')->defaultValue('21')->end()->scalarNode('platform')->defaultValue('ANY')->end()->scalarNode('browserVersion')->defaultValue('9')->end()->scalarNode('browser')->defaultValue('firefox')->end()->scalarNode('ignoreZoomSetting')->defaultValue('false')->end()->scalarNode('name')->defaultValue('Behat feature suite')->end()->scalarNode('deviceOrientation')->defaultValue('portrait')->end()->scalarNode('deviceType')->defaultValue('tablet')->end()->booleanNode('javascriptEnabled')->end()->booleanNode('databaseEnabled')->end()->booleanNode('locationContextEnabled')->end()->booleanNode('applicationCacheEnabled')->end()->booleanNode('browserConnectionEnabled')->end()->booleanNode('webStorageEnabled')->end()->booleanNode('rotatable')->end()->booleanNode('acceptSslCerts')->end()->booleanNode('nativeEvents')->end()->arrayNode('proxy')->children()->scalarNode('proxyType')->end()->scalarNode('proxyAuthconfigUrl')->end()->scalarNode('ftpProxy')->end()->scalarNode('httpProxy')->end()->scalarNode('sslProxy')->end()->end()->validate()->ifTrue(function ($v) {
         return empty($v);
     })->thenUnset()->end()->end()->arrayNode('firefox')->children()->scalarNode('profile')->validate()->ifTrue(function ($v) {
         return !file_exists($v);
     })->thenInvalid('Cannot find profile zip file %s')->end()->end()->scalarNode('binary')->end()->end()->end()->arrayNode('chrome')->children()->arrayNode('switches')->prototype('scalar')->end()->end()->scalarNode('binary')->end()->arrayNode('extensions')->prototype('scalar')->end()->end()->end()->end()->arrayNode('extra_capabilities')->info('Custom capabilities merged with the known ones')->normalizeKeys(false)->useAttributeAsKey('name')->prototype('variable')->end()->end()->end();
     return $node;
 }
Exemplo n.º 10
0
 private function addRoles(ArrayNodeDefinition $node)
 {
     $node->addDefaultsIfNotSet()->children()->arrayNode('roles')->useAttributeAsKey('name')->prototype('array')->children()->booleanNode('is_default')->defaultFalse()->end()->arrayNode('handler')->canBeUnset()->children()->scalarNode('cart')->cannotBeEmpty()->end()->scalarNode('item')->cannotBeEmpty()->end()->end()->end()->arrayNode('controller')->children()->scalarNode('cart')->cannotBeEmpty()->end()->scalarNode('item')->cannotBeEmpty()->end()->end()->end()->scalarNode('form')->end()->scalarNode('strategy')->end()->scalarNode('fallback_strategy')->end()->end()->validate()->ifTrue(function ($v) {
         return !isset($v['form']) && !isset($v['handler']['cart']);
     })->thenInvalid('You need to specify or the form or the cart handler.')->end()->end()->isRequired()->cannotBeEmpty()->validate()->ifTrue(function ($v) {
         return count($v) < 1;
     })->thenInvalid('You need to specify at least one role.')->end()->validate()->ifTrue(function ($roles) {
         $counter = 0;
         foreach ($roles as $role) {
             $counter += isset($role['is_default']) && $role['is_default'] ? 1 : 0;
         }
         return $counter > 1;
     })->thenInvalid('Multiple `is_default` defined.')->end()->end();
 }
Exemplo n.º 11
0
 private function configureRouter(ArrayNodeDefinition $root)
 {
     $root->addDefaultsIfNotSet();
     $root->treatNullLike(['endpoints' => []]);
     /** @var ArrayNodeDefinition $proto */
     $endpoints = $root->children()->arrayNode('endpoints');
     $proto = $endpoints->prototype('array');
     $proto->append((new ScalarNodeDefinition('path'))->isRequired()->example('/')->cannotBeEmpty()->info('Endpoint URI'));
     $proto->append((new ArrayNodeDefinition('resources'))->beforeNormalization()->ifNull()->then(function () {
         return [];
     })->ifString()->then(function ($v) {
         return [$v];
     })->end()->prototype('scalar')->end()->example('rpc.yml')->info('Route definitions'));
     $proto->append(new VariableNodeDefinition('defaults'));
     $proto->append((new VariableNodeDefinition('context'))->beforeNormalization()->ifString()->then(function ($v) {
         return [$v];
     })->end()->defaultValue(['Default'])->info('Endpoint-wide context')->example(['Default']));
     $endpoints->useAttributeAsKey('name');
     $proto->addDefaultsIfNotSet();
 }
Exemplo n.º 12
0
 /**
  * Setups configuration for the extension.
  *
  * @param ArrayNodeDefinition $builder
  */
 public function configure(ArrayNodeDefinition $builder)
 {
     $builder->addDefaultsIfNotSet()->children()->scalarNode('pattern')->defaultValue('/placeholder\\(([a-zA-Z0-9_\\.\\-]+)\\)/')->info('All values that match PATTERN will be try to transform.')->end()->arrayNode('defaults')->prototype('scalar')->end();
 }
 /**
  * {@inheritdoc}
  */
 public function addConfiguration(ArrayNodeDefinition $pluginNode)
 {
     $pluginNode->addDefaultsIfNotSet()->children()->scalarNode('policy')->defaultValue('none')->info('Policy applied if no scope is requested by the client (default "none").')->end()->arrayNode('available_scope')->useAttributeAsKey('name')->treatNullLike([])->prototype('scalar')->end()->info('A list of scopes supported by this server (optional).')->end()->end();
 }
Exemplo n.º 14
0
 /**
  *
  * @access private
  * @param  \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $node
  * @return \CCDNUser\AdminBundle\DependencyInjection\Configuration
  */
 private function addUserSection(ArrayNodeDefinition $node)
 {
     $node->addDefaultsIfNotSet()->canBeUnset()->children()->arrayNode('account')->addDefaultsIfNotSet()->canBeUnset()->children()->arrayNode('show_newest_users')->addDefaultsIfNotSet()->canBeUnset()->children()->scalarNode('layout_template')->defaultValue($this->defaultValueLayoutTemplate)->end()->scalarNode('member_since_datetime_format')->defaultValue('d-m-Y - H:i')->end()->end()->end()->arrayNode('show_user')->addDefaultsIfNotSet()->canBeUnset()->children()->scalarNode('layout_template')->defaultValue($this->defaultValueLayoutTemplate)->end()->scalarNode('member_since_datetime_format')->defaultValue('d-m-Y - H:i')->end()->end()->end()->arrayNode('edit_user_account')->addDefaultsIfNotSet()->canBeUnset()->children()->scalarNode('layout_template')->defaultValue($this->defaultValueLayoutTemplate)->end()->scalarNode('form_theme')->defaultValue($this->defaultValueFormTheme)->end()->end()->end()->end()->end()->end();
     return $this;
 }
Exemplo n.º 15
0
 private function addServiceSection(ArrayNodeDefinition $node)
 {
     $node->addDefaultsIfNotSet()->children()->arrayNode('service')->addDefaultsIfNotSet()->children()->scalarNode('storage')->defaultValue('fos_oauth_server.storage.default')->cannotBeEmpty()->end()->scalarNode('user_provider')->defaultValue(true)->end()->scalarNode('scope_page')->defaultNull()->end()->scalarNode('client_manager')->defaultValue('fos_oauth_server.client_manager.default')->end()->scalarNode('access_token_manager')->defaultValue('fos_oauth_server.access_token_manager.default')->end()->scalarNode('refresh_token_manager')->defaultValue('fos_oauth_server.refresh_token_manager.default')->end()->scalarNode('auth_code_manager')->defaultValue('fos_oauth_server.auth_code_manager.default')->end()->arrayNode('options')->useAttributeAsKey('key')->treatNullLike(array())->prototype('scalar')->end()->end()->end()->end()->end()->end();
 }
Exemplo n.º 16
0
 /**
  * Add classes section
  *
  * @param ArrayNodeDefinition $node
  */
 public function addClassesSection(ArrayNodeDefinition $node)
 {
     $node->addDefaultsIfNotSet()->children()->scalarNode('driver')->isRequired()->cannotBeEmpty()->end()->scalarNode('manager')->defaultValue('default')->end()->arrayNode('validation_groups')->addDefaultsIfNotSet()->children()->scalarNode('news')->defaultValue('AvooDemoNews')->end()->end()->end()->arrayNode('templates')->addDefaultsIfNotSet()->children()->scalarNode('news')->defaultValue('AvooDemoBundle:News')->end()->end()->end()->arrayNode('classes')->addDefaultsIfNotSet()->children()->arrayNode('news')->addDefaultsIfNotSet()->children()->scalarNode('model')->end()->scalarNode('controller')->defaultValue('Avoo\\DemoBundle\\Controller\\NewsController')->end()->scalarNode('repository')->defaultValue('Avoo\\DemoBundle\\Doctrine\\ORM\\NewsRepository')->end()->scalarNode('form')->defaultValue('Avoo\\DemoBundle\\Form\\Type\\NewsFormType')->end()->end()->end()->end()->end()->end();
 }
Exemplo n.º 17
0
 private function addServiceSection(ArrayNodeDefinition $node)
 {
     $node->addDefaultsIfNotSet()->children()->arrayNode('service')->addDefaultsIfNotSet()->children()->scalarNode('mailer')->defaultValue('fos_user.mailer.default')->end()->scalarNode('email_canonicalizer')->defaultValue('fos_user.util.email_canonicalizer.default')->end()->scalarNode('username_canonicalizer')->defaultValue('fos_user.util.username_canonicalizer.default')->end()->scalarNode('user_manager')->defaultValue('fos_user.user_manager.default')->end()->end()->end()->end()->end();
 }
 /**
  * {@inheritdoc}
  */
 public function configure(ArrayNodeDefinition $builder)
 {
     $builder->addDefaultsIfNotSet()->children()->scalarNode('path')->defaultValue(__DIR__ . 'vendor')->end()->arrayNode('symlink')->children()->scalarNode('from')->defaultValue('.')->end()->scalarNode('to')->isRequired()->end()->end()->end()->booleanNode('flush_database')->defaultValue(true)->end()->arrayNode('connection')->children()->scalarNode('db')->defaultValue('wordpress')->end()->scalarNode('username')->defaultValue('root')->end()->scalarNode('password')->defaultValue('')->end()->end()->end()->arrayNode('mail')->children()->scalarNode('directory')->defaultValue(getenv('WORDPRESS_FAKE_MAIL_DIR'))->end()->scalarNode('divider')->defaultValue('%%===================%%')->end()->end()->end()->end();
 }
 public function addConfiguration(ArrayNodeDefinition $pluginNode)
 {
     $pluginNode->addDefaultsIfNotSet()->children()->scalarNode('default')->defaultNull()->end()->end();
 }
 /**
  * {@inheritDoc}
  */
 public function configure(ArrayNodeDefinition $builder)
 {
     $builder->addDefaultsIfNotSet()->children()->scalarNode('persister')->defaultNull()->end()->end();
 }
Exemplo n.º 21
0
 public function configure(ArrayNodeDefinition $builder)
 {
     $builder->addDefaultsIfNotSet()->children()->scalarNode('json_file')->end()->scalarNode('hostname')->end()->scalarNode('port')->end()->end();
 }
Exemplo n.º 22
0
 /**
  * Configure the root node
  *
  * @param ArrayNodeDefinition $rootNode Root node
  */
 protected function setupTree(ArrayNodeDefinition $rootNode)
 {
     $rootNode->addDefaultsIfNotSet()->children()->arrayNode('menu')->addDefaultsIfNotSet()->children()->booleanNode('add_categories')->defaultFalse()->end()->booleanNode('add_plugins')->defaultTrue()->end()->end()->end()->end();
 }
 /**
  * {@inheritdoc}
  */
 public function addConfiguration(ArrayNodeDefinition $pluginNode)
 {
     $pluginNode->addDefaultsIfNotSet()->children()->scalarNode('default')->defaultNull()->info('The default token type used by this server. Not needed if you only have one access token type (e.g. "Bearer", "MAC", "POP"). If not set, the first token type will be the default one.')->end()->end();
 }
Exemplo n.º 24
0
 public function configure(ArrayNodeDefinition $builder)
 {
     $builder->addDefaultsIfNotSet()->children()->scalarNode('wd_host')->defaultValue('http://localhost:4444/wd/hub')->end()->scalarNode('browser')->defaultValue('firefox')->end()->end()->end();
     $this->driverFactory->configure($builder);
 }
Exemplo n.º 25
0
 private function addServiceSection(ArrayNodeDefinition $node)
 {
     $node->addDefaultsIfNotSet()->children()->arrayNode('service')->addDefaultsIfNotSet()->children()->scalarNode('mailer')->defaultValue('jlm_front.mailer.default')->end()->end()->end()->end()->end();
 }
Exemplo n.º 26
0
 private function addPaginatorConfiguration(ArrayNodeDefinition $node)
 {
     $node->addDefaultsIfNotSet()->children()->arrayNode('paginator')->addDefaultsIfNotSet()->children()->scalarNode('default_twig')->cannotBeEmpty()->defaultValue('KitpagesDataGridBundle:Paginator:paginator.html.twig')->end()->scalarNode('item_count_in_page')->cannotBeEmpty()->defaultValue(50)->end()->scalarNode('visible_page_count_in_paginator')->cannotBeEmpty()->defaultValue(5)->end()->end()->end()->end();
 }
Exemplo n.º 27
0
 /**
  * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidDefinitionException
  */
 public function testConcreteNodeSpecificOption()
 {
     $node = new ArrayNodeDefinition('root');
     $node->addDefaultsIfNotSet()->prototype('array');
     $node->getNode();
 }
Exemplo n.º 28
0
 /**
  * Adds 'services' section.
  *
  * @param ArrayNodeDefinition $node
  */
 public function addServicesSection(ArrayNodeDefinition $node)
 {
     $node->addDefaultsIfNotSet()->children()->arrayNode('service')->addDefaultsIfNotSet()->children()->scalarNode('configuration')->defaultValue('avoo_elo.configuration.default')->end()->scalarNode('aggregation')->defaultValue('avoo_elo.aggregation.default')->end()->scalarNode('calculator')->defaultValue('avoo_elo.calculator.default')->end()->end()->end()->end();
 }
 /**
  * {@inheritDoc}
  */
 public function configure(ArrayNodeDefinition $builder)
 {
     $builder->addDefaultsIfNotSet()->children()->scalarNode('base_url')->defaultNull()->end()->scalarNode('service_descriptions')->defaultNull()->end()->end()->end();
 }
 /**
  * {@inheritdoc}
  */
 public function addConfiguration(ArrayNodeDefinition $pluginNode)
 {
     $pluginNode->addDefaultsIfNotSet()->children()->integerNode('min_length')->info('The minimum length of the MAC key generated during the access token issuance.')->min(1)->defaultValue(20)->end()->integerNode('max_length')->info('The maximum length of the MAC key generated during the access token issuance.')->min(2)->defaultValue(30)->end()->scalarNode('algorithm')->info('The algorithm used by the client to compute the authorization header.')->defaultValue('hmac-sha-256')->end()->integerNode('timestamp_lifetime')->info('The lifetime of the timestamp used to compute the authorization header. This value should be as low as possible to prevent replay attacks.')->min(1)->defaultValue(10)->end()->end();
 }