本文整理汇总了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;
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例7: getConfig
/**
* Setups configuration for current extension.
*
* @param ArrayNodeDefinition $builder
*/
public function getConfig(ArrayNodeDefinition $builder)
{
$builder->useAttributeAsKey('name')->prototype('variable');
}
示例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();
}