當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ArrayNodeDefinition::useAttributeAsKey方法代碼示例

本文整理匯總了PHP中Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition::useAttributeAsKey方法的典型用法代碼示例。如果您正苦於以下問題:PHP ArrayNodeDefinition::useAttributeAsKey方法的具體用法?PHP ArrayNodeDefinition::useAttributeAsKey怎麽用?PHP ArrayNodeDefinition::useAttributeAsKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition的用法示例。


在下文中一共展示了ArrayNodeDefinition::useAttributeAsKey方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: createNextStatesNodeDefinition

 /**
  * Create a configuration node to define available next states of a step (or a processs)
  *
  * @return ArrayNodeDefinition
  */
 private function createNextStatesNodeDefinition()
 {
     $flowTypes = array(NextStateInterface::TYPE_STEP, NextStateInterface::TYPE_STEP_OR, NextStateInterface::TYPE_PROCESS);
     $nextStatesNode = new ArrayNodeDefinition('next_states');
     $nextStatesNode->useAttributeAsKey('name')->prototype('array')->addDefaultsIfNotSet()->children()->scalarNode('type')->defaultValue('step')->validate()->ifNotInArray($flowTypes)->thenInvalid('Invalid next element type "%s". Please use one of the following types: ' . implode(', ', $flowTypes))->end()->end()->variableNode('target')->cannotBeEmpty()->end()->end()->end();
     return $nextStatesNode;
 }
開發者ID:vas24x7,項目名稱:workflow-bundle,代碼行數:12,代碼來源:Configuration.php

示例2: configureRoutesNodeDefinition

 /**
  * @param ArrayNodeDefinition $routesNode
  */
 protected function configureRoutesNodeDefinition(ArrayNodeDefinition $routesNode)
 {
     $self = $this;
     $routesNode->useAttributeAsKey(true)->beforeNormalization()->always(function (array $vendors) use($self) {
         $self->assertKeysAreValidVendorNames($vendors);
         return $vendors;
     })->end()->prototype('array')->children()->scalarNode('server')->end()->scalarNode('uri')->end()->scalarNode('link')->end()->end()->end();
 }
開發者ID:Maksold,項目名稱:platform,代碼行數:11,代碼來源:AbstractConfiguration.php

示例3: getPathsSection

 private function getPathsSection()
 {
     $node = new ArrayNodeDefinition('paths');
     $node->useAttributeAsKey('path')->normalizeKeys(false);
     /** @var ArrayNodeDefinition $prototype */
     $prototype = $node->prototype('array');
     $this->appendPrototypedConfiguration($prototype);
     return $node;
 }
開發者ID:alchemy-fr,項目名稱:symfony-cors,代碼行數:9,代碼來源:CorsConfiguration.php

示例4: buildFilterNode

 /**
  * Builds configuration node by given filter name.
  *
  * @param string $filter
  *
  * @return ArrayNodeDefinition
  */
 private function buildFilterNode($filter)
 {
     $node = new ArrayNodeDefinition($filter);
     $children = $node->useAttributeAsKey('name')->beforeNormalization()->always(function ($a) {
         foreach ($a as $name => $v) {
             if ($name == 'pager') {
                 if (!isset($v['request_parameter'])) {
                     $a[$name]['request_parameter'] = 'page';
                 }
                 continue;
             }
             if (!is_array($v)) {
                 $a[$name] = ['field' => $v, 'request_parameter' => $name];
             } elseif (!isset($v['request_parameter'])) {
                 $a[$name]['request_parameter'] = $name;
             }
         }
         return $a;
     })->end()->prototype('array')->children()->scalarNode('name')->end()->scalarNode('request_parameter')->info('Request parameter name.')->end()->end();
     if ($filter != 'sort' && $filter != 'pager') {
         $children->children()->scalarNode('field')->info('Entity field name.')->isRequired()->end()->end();
     }
     switch ($filter) {
         case 'choice':
             $children->children()->arrayNode('choices')->useAttributeAsKey('value')->prototype('array')->beforeNormalization()->ifString()->then(function ($v) {
                 return ['name' => $v];
             })->end()->children()->scalarNode('value')->end()->scalarNode('name')->end()->end()->end()->end()->end();
             break;
         case 'sort':
             $children->children()->arrayNode('choices')->useAttributeAsKey('value')->beforeNormalization()->always(function ($a) {
                 foreach ($a as $name => $v) {
                     if (is_string($v)) {
                         $a[$name] = ['field' => $v, 'name' => $name];
                     } elseif (!isset($v['name'])) {
                         $a[$name]['name'] = $name;
                     }
                 }
                 return $a;
             })->end()->prototype('array')->children()->scalarNode('value')->end()->scalarNode('field')->isRequired()->end()->enumNode('order')->values(['asc', 'desc'])->defaultValue('asc')->end()->scalarNode('name')->end()->end()->end()->end()->end();
             break;
         case 'pager':
             $children->children()->integerNode('items_per_page')->defaultValue(10)->end()->end();
             break;
     }
     return $node;
 }
開發者ID:mvar,項目名稱:filtered-list-bundle,代碼行數:53,代碼來源:Configuration.php

示例5: testPrototypedArrayNodeDefault

 /**
  * @dataProvider providePrototypedArrayNodeDefaults
  */
 public function testPrototypedArrayNodeDefault($args, $shouldThrowWhenUsingAttrAsKey, $shouldThrowWhenNotUsingAttrAsKey, $defaults)
 {
     $node = new ArrayNodeDefinition('root');
     $node->addDefaultChildrenIfNoneSet($args)->prototype('array');
     try {
         $tree = $node->getNode();
         $this->assertFalse($shouldThrowWhenNotUsingAttrAsKey);
         $this->assertEquals($defaults, $tree->getDefaultValue());
     } catch (InvalidDefinitionException $e) {
         $this->assertTrue($shouldThrowWhenNotUsingAttrAsKey);
     }
     $node = new ArrayNodeDefinition('root');
     $node->useAttributeAsKey('attr')->addDefaultChildrenIfNoneSet($args)->prototype('array');
     try {
         $tree = $node->getNode();
         $this->assertFalse($shouldThrowWhenUsingAttrAsKey);
         $this->assertEquals($defaults, $tree->getDefaultValue());
     } catch (InvalidDefinitionException $e) {
         $this->assertTrue($shouldThrowWhenUsingAttrAsKey);
     }
 }
開發者ID:Ener-Getick,項目名稱:symfony,代碼行數:24,代碼來源:ArrayNodeDefinitionTest.php

示例6: createWorkflowDefinition

 public function createWorkflowDefinition()
 {
     $processesNode = new ArrayNodeDefinition('workflows');
     $processesNode->useAttributeAsKey('name')->prototype('array')->children()->scalarNode('class')->defaultNull()->end()->scalarNode('entity')->defaultNull()->end()->end()->end();
     return $processesNode;
 }
開發者ID:simonoche,項目名稱:workflow-bundle,代碼行數:6,代碼來源:Configuration.php

示例7: getConfig

 /**
  * Setups configuration for current extension.
  *
  * @param ArrayNodeDefinition $builder
  */
 public function getConfig(ArrayNodeDefinition $builder)
 {
     $builder->useAttributeAsKey('name')->prototype('variable');
 }
開發者ID:saberyounis,項目名稱:Sonata-Project,代碼行數:9,代碼來源:Extension.php

示例8: getQueueArgumentsConfiguration

 /**
  * @return NodeDefinition
  */
 private function getQueueArgumentsConfiguration()
 {
     $node = new ArrayNodeDefinition('arguments');
     return $node->useAttributeAsKey('identifier')->beforeNormalization()->ifTrue(function ($arguments) {
         foreach ($arguments as $k => $v) {
             //Un-normalize keys
             if (false !== strpos($k, '_')) {
                 return true;
             }
         }
     })->then(function ($arguments) {
         foreach ($arguments as $k => $v) {
             if (false !== strpos($k, '_')) {
                 $arguments[str_replace('_', '-', $k)] = $v;
                 unset($arguments[$k]);
             }
         }
         return $arguments;
     })->end()->prototype('scalar')->end();
 }
開發者ID:olaurendeau,項目名稱:RabbitMqAdminToolkitBundle,代碼行數:23,代碼來源:Configuration.php


注:本文中的Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition::useAttributeAsKey方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。