当前位置: 首页>>代码示例>>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;未经允许,请勿转载。