本文整理汇总了PHP中Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition::defaultValue方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayNodeDefinition::defaultValue方法的具体用法?PHP ArrayNodeDefinition::defaultValue怎么用?PHP ArrayNodeDefinition::defaultValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition
的用法示例。
在下文中一共展示了ArrayNodeDefinition::defaultValue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createStepsNodeDefinition
/**
* Create a configuration node to define the steps of a process.
*
* @return ArrayNodeDefinition
*/
private function createStepsNodeDefinition()
{
$stepsNode = new ArrayNodeDefinition('steps');
$stepsNode->defaultValue(array())->useAttributeAsKey('name')->prototype('array')->addDefaultsIfNotSet()->children()->scalarNode('label')->defaultValue('')->end()->arrayNode('roles')->prototype('scalar')->end()->end()->arrayNode('model_status')->validate()->ifTrue(function ($value) {
return is_array($value) && count($value) < 2;
})->thenInvalid('You must specify an array with [ method, constant ]')->ifTrue(function ($value) {
return !defined($value[1]);
})->thenInvalid('You must specify a valid constant name as second parameter')->end()->prototype('scalar')->end()->end()->scalarNode('on_invalid')->defaultNull()->end()->end()->append($this->createNextStatesNodeDefinition())->end();
return $stepsNode;
}
示例2: configure
/**
* {@inheritdoc}
*/
public function configure(ArrayNodeDefinition $builder)
{
$builder->defaultValue(array('default' => array('enabled' => true, 'type' => null, 'settings' => array())))->treatNullLike(array())->treatFalseLike(array())->useAttributeAsKey('name')->prototype('array')->beforeNormalization()->ifTrue(function ($suite) {
return is_array($suite) && count($suite);
})->then(function ($suite) {
$suite['settings'] = isset($suite['settings']) ? $suite['settings'] : array();
foreach ($suite as $key => $val) {
$suiteKeys = array('enabled', 'type', 'settings');
if (!in_array($key, $suiteKeys)) {
$suite['settings'][$key] = $val;
unset($suite[$key]);
}
}
return $suite;
})->end()->normalizeKeys(false)->addDefaultsIfNotSet()->treatTrueLike(array('enabled' => true))->treatNullLike(array('enabled' => true))->treatFalseLike(array('enabled' => false))->children()->booleanNode('enabled')->info('Enables/disables suite')->defaultTrue()->end()->scalarNode('type')->info('Specifies suite type')->defaultValue(null)->end()->arrayNode('settings')->info('Specifies suite extra settings')->defaultValue(array())->useAttributeAsKey('name')->prototype('variable')->end()->end()->end()->end();
}
示例3: testPrototypeNodesCantHaveADefaultValueWhenUsingDefaultChildren
/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidDefinitionException
*/
public function testPrototypeNodesCantHaveADefaultValueWhenUsingDefaultChildren()
{
$node = new ArrayNodeDefinition('root');
$node->defaultValue(array())->addDefaultChildrenIfNoneSet('foo')->prototype('array');
$node->getNode();
}
示例4: configure
/**
* {@inheritdoc}
*/
public function configure(ArrayNodeDefinition $builder)
{
$builder->defaultValue(array($this->defaultFormatter => array('enabled' => true)))->useAttributeAsKey('name')->prototype('array')->beforeNormalization()->ifTrue(function ($a) {
return is_array($a) && !isset($a['enabled']);
})->then(function ($a) {
return array_merge($a, array('enabled' => true));
})->end()->useAttributeAsKey('name')->treatTrueLike(array('enabled' => true))->treatNullLike(array('enabled' => true))->treatFalseLike(array('enabled' => false))->prototype('variable')->end()->end();
}
示例5: getSubResourcesNode
/**
* @return ArrayNodeDefinition
*/
private function getSubResourcesNode()
{
$node = new ArrayNodeDefinition('sub_resources');
$node->defaultValue([])->prototype('array')->children()->scalarNode('assoc_parent')->end()->scalarNode('assoc_sub')->end()->end()->end();
return $node;
}