本文整理汇总了PHP中Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition类的典型用法代码示例。如果您正苦于以下问题:PHP ArrayNodeDefinition类的具体用法?PHP ArrayNodeDefinition怎么用?PHP ArrayNodeDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ArrayNodeDefinition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: append
/**
*
* @param ArrayNodeDefinition $root Config root node
* @param array $settings
*/
public static function append(ArrayNodeDefinition $root, $settings)
{
$builder = new TreeBuilder();
$node = $builder->root('settings')->addDefaultsIfNotSet()->children()->scalarNode(self::RESOLVED_KEY)->defaultTrue()->end();
foreach ($settings as $name => $setting) {
$child = $node->arrayNode($name)->addDefaultsIfNotSet()->children();
if (isset($setting['type']) && in_array($setting['type'], array('scalar', 'boolean', 'array'))) {
$type = $setting['type'];
} else {
$type = 'scalar';
}
switch ($type) {
case 'scalar':
$child->scalarNode('value')->defaultValue($setting['value']);
break;
case 'boolean':
$child->booleanNode('value')->defaultValue((bool) $setting['value']);
break;
case 'array':
$child->arrayNode('value')->treatNullLike(array())->prototype('scalar')->end()->defaultValue(isset($setting['value']) ? $setting['value'] : array());
break;
}
$child->scalarNode('scope')->defaultValue(isset($setting['scope']) ? $setting['scope'] : 'app');
}
$root->children()->append($node->end());
}
示例2: addConnectionsSection
/**
* Adds connections definition.
*
* @param \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $node
*/
protected function addConnectionsSection(ArrayNodeDefinition $node)
{
$node->children()->scalarNode('default_connection')->info('Name of the default connection')->end()->arrayNode('connections')->info('Solr Search Engine connection configuration')->useAttributeAsKey('connection_name')->performNoDeepMerging()->prototype('array')->beforeNormalization()->ifTrue(function ($v) {
return !empty($v['mapping']) && !is_array($v['mapping']);
})->then(function ($v) {
// If single endpoint is set for Content mapping, use it as default
// mapping for Content index
$v['mapping'] = array('default' => $v['mapping']);
return $v;
})->end()->beforeNormalization()->ifTrue(function ($v) {
return empty($v['entry_endpoints']) && (!empty($v['mapping']['translations']) || !empty($v['mapping']['default']) || !empty($v['mapping']['main_translations']));
})->then(function ($v) {
$endpointSet = array();
if (!empty($v['mapping']['translations'])) {
$endpointSet = array_flip($v['mapping']['translations']);
}
if (!empty($v['mapping']['default'])) {
$endpointSet[$v['mapping']['default']] = true;
}
if (!empty($v['mapping']['main_translations'])) {
$endpointSet[$v['mapping']['main_translations']] = true;
}
$v['entry_endpoints'] = array_keys($endpointSet);
return $v;
})->end()->children()->arrayNode('entry_endpoints')->info("A set of entry endpoint names.\n\n" . 'If not set, mapping endpoints will be used.')->example(array('endpoint1', 'endpoint2'))->prototype('scalar')->end()->end()->arrayNode('mapping')->info('Defines a map of translation language codes and Solr ' . "endpoint names for Content index.\n\n" . 'Optionally, you can define default and main translations ' . 'endpoints. Default one will be used for a translation if it ' . 'is not explicitly mapped, and main translations will be used ' . "for indexing translations in the main languages.\n\n" . 'If single endpoint name is given, it will be used as a ' . 'shortcut to define the default endpoint.')->addDefaultsIfNotSet()->example(array(array('translations' => array('cro-HR' => 'endpoint1', 'eng-GB' => 'endpoint2'), 'default' => 'endpoint3', 'main_translations' => 'endpoint4')))->children()->arrayNode('translations')->normalizeKeys(false)->useAttributeAsKey('language_code')->info('A map of translation language codes and Solr ' . 'endpoint names for Content index.')->example(array('cro-HR' => 'endpoint1', 'eng-GB' => 'endpoint2'))->prototype('scalar')->end()->end()->scalarNode('default')->defaultNull()->info('Default endpoint will be used for indexing ' . 'documents of a translation that is not explicitly ' . "mapped.\n\n" . 'This setting is optional.')->end()->scalarNode('main_translations')->defaultNull()->info('Main translations endpoint will be used to index ' . "documents of translations in the main languages\n\n" . 'This setting is optional. Use it to reduce the ' . 'number of Solr endpoints that the query is ' . 'distributed to when using always available fallback ' . 'or searching only on the main languages.')->end()->end()->end()->end()->end()->end();
}
示例3: addCaptchaConfigSection
public function addCaptchaConfigSection(ArrayNodeDefinition $rootNode, $page, array $captchaConfig)
{
$captchaId = isset($captchaConfig['captcha_id']) ? $captchaConfig['captcha_id'] : 'defaultCaptcha';
$userInputId = isset($captchaConfig['user_input_id']) ? $captchaConfig['user_input_id'] : 'captchaCode';
$captchaConfigFilePath = isset($captchaConfig['captcha_config_file_path']) ? $captchaConfig['captcha_config_file_path'] : null;
$rootNode->children()->arrayNode($page)->children()->scalarNode('captcha_id')->defaultValue($captchaId)->end()->scalarNode('user_input_id')->defaultValue($userInputId)->end()->scalarNode('captcha_config_file_path')->defaultValue($captchaConfigFilePath)->end()->end()->end()->end();
}
示例4: appendThemingNodes
/**
* Appends config nodes for "themes"
*
* @param ArrayNodeDefinition $parentNode
*/
protected function appendThemingNodes(ArrayNodeDefinition $parentNode)
{
$treeBuilder = new TreeBuilder();
$node = $treeBuilder->root('themes');
$node->useAttributeAsKey('theme-identifier')->normalizeKeys(false)->prototype('array')->children()->scalarNode('label')->info('The label is displayed in the theme management UI. Can be empty for "hidden" themes')->isRequired()->end()->scalarNode('icon')->info('The icon is displayed in the UI')->end()->scalarNode('logo')->info('The logo image is displayed in the UI')->end()->scalarNode('screenshot')->info('The screenshot image is used in theme management UI for the theme preview')->end()->scalarNode('directory')->info('The directory name where to look up for layout updates. By default theme identifier')->end()->scalarNode('parent')->info('The identifier of the parent theme')->end()->arrayNode('groups')->info('Layout groups for which the theme is applicable')->example('[main, embedded_forms, frontend]')->prototype('scalar')->end()->cannotBeEmpty()->end()->end()->end();
$parentNode->append($node)->children()->scalarNode('active_theme')->info('The identifier of the theme that should be used by default')->end()->end();
}
示例5: configurePageObjectFactory
/**
* @param ArrayNodeDefinition $builder
*/
private function configurePageObjectFactory(ArrayNodeDefinition $builder)
{
$factory = $builder->children()->arrayNode('factory');
$factory->beforeNormalization()->ifString()->then(function ($v) {
return array('id' => $v);
})->end()->children()->scalarNode('id')->info('id of a page object factory service')->end()->scalarNode('class_name_resolver')->info('id of a class name resolver service for the default factory')->end()->arrayNode('page_parameters')->info('parameters passed from the factory when creating a page')->prototype('scalar')->end()->end()->end();
}
示例6: addConfiguration
/**
* {@inheritDoc}
*/
public function addConfiguration(ArrayNodeDefinition $builder)
{
$builder
->children()
->scalarNode('bucket')->isRequired()->cannotBeEmpty()->end()
->scalarNode('cache')->defaultValue(false)->end()
->scalarNode('acl')->defaultValue('public-read')->cannotBeEmpty()->end()
->scalarNode('cache_prefix')->defaultValue(null)->end()
->arrayNode('client_config')
->isRequired()
->useAttributeAsKey('key')
->prototype('scalar')->end()
->end()
/* @deprecated Use `get_options` instead */
->arrayNode('url_options')
->useAttributeAsKey('key')
->prototype('scalar')->end()
->end()
->arrayNode('get_options')
->useAttributeAsKey('key')
->prototype('scalar')->end()
->end()
->arrayNode('put_options')
->useAttributeAsKey('key')
->prototype('scalar')->end()
->end()
->arrayNode('proxies')
->defaultValue(array())
->prototype('scalar')->end()
->end()
->end()
;
}
示例7: setupTree
/**
* Configure the root node
*
* @param ArrayNodeDefinition $rootNode
*/
protected function setupTree(ArrayNodeDefinition $rootNode)
{
$templateValidation = function ($value) {
if (is_string($value)) {
return $value;
}
throw new \InvalidArgumentException(sprintf('Status templates must be strings, "%s" found', $value));
};
$checkForNumeric = function ($value) {
if (is_numeric($value)) {
return $value;
}
throw new \InvalidArgumentException(sprintf('Status code for error templates must be numeric, "%s" found', $value));
};
$checkForNumericKeys = function (array $value) {
foreach ($value as $code => $template) {
if (!is_numeric($code)) {
throw new \InvalidArgumentException(sprintf('Status codes for error templates must be numeric, "%s" found', $code));
}
}
return $value;
};
$rootNode->children()->arrayNode('error_templates')->info('Error templates setup')->canBeEnabled()->children()->scalarNode('default')->info('Default template for exceptions')->defaultValue('Exception:error.html.twig')->validate()->always($templateValidation)->end()->end()->arrayNode('by_code')->info('Specific template by status code')->example('{ 404: Exception:error.html.twig }')->useAttributeAsKey('name')->prototype('scalar')->validate()->ifTrue(function ($value) {
return null !== $value;
})->then($templateValidation)->end()->end()->validate()->always($checkForNumericKeys)->end()->end()->scalarNode('fallback')->info('Default status code for non-http exceptions')->defaultFalse()->treatTrueLike(Response::HTTP_INTERNAL_SERVER_ERROR)->validate()->always($checkForNumeric)->end()->end()->end()->end()->end();
}
示例8: configure
/**
* @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();
}
示例9: addConfiguration
public function addConfiguration(ArrayNodeDefinition $rootNode)
{
$dsnParser = $this->dsnParser;
$rootNode->beforeNormalization()->always(function ($config) use($dsnParser) {
if (isset($config['dsn'])) {
$config = array_merge($config, $dsnParser->parse($config['dsn']));
}
if (isset($config[Client::REQUEST_OPTIONS])) {
$config['request']['options'] = $config[Client::REQUEST_OPTIONS];
unset($config[Client::REQUEST_OPTIONS]);
}
if (isset($config[Client::CURL_OPTIONS])) {
$config['curl']['options'] = $config[Client::CURL_OPTIONS];
unset($config[Client::CURL_OPTIONS]);
}
if (isset($config[Client::COMMAND_PARAMS])) {
$config['command']['params'] = $config[Client::COMMAND_PARAMS];
unset($config[Client::COMMAND_PARAMS]);
}
return $config;
})->end()->children()->scalarNode('public_key')->isRequired()->end()->scalarNode('secret_key')->isRequired()->end()->scalarNode('project_id')->isRequired()->end()->enumNode('protocol')->defaultValue('https')->values(array('http', 'https'))->end()->scalarNode('host')->defaultValue('app.getsentry.com')->end()->scalarNode('path')->defaultValue('/')->end()->scalarNode('port')->defaultNull()->end()->scalarNode('dsn')->end()->variableNode('exception_factory')->end()->arrayNode('request')->children()->arrayNode('options')->prototype('variable')->end()->end()->end()->end()->arrayNode('curl')->children()->arrayNode('options')->prototype('variable')->end()->end()->end()->end()->arrayNode('command')->addDefaultsIfNotSet()->children()->arrayNode('params')->addDefaultsIfNotSet()->children()->scalarNode('level')->end()->scalarNode('logger')->end()->scalarNode('platform')->end()->arrayNode('tags')->prototype('scalar')->end()->end()->arrayNode('extra')->prototype('scalar')->end()->end()->scalarNode('server_name')->defaultValue(gethostname())->end()->end()->end()->end()->end()->arrayNode('ignored_exceptions')->beforeNormalization()->always(function (array $ignoredExceptions) {
$newIgnoredExceptions = array();
foreach ($ignoredExceptions as $class => $ignored) {
if (!is_bool($ignored)) {
$class = $ignored;
$ignored = true;
}
$newIgnoredExceptions[$class] = $ignored;
}
return $newIgnoredExceptions;
})->end()->prototype('scalar')->end()->end()->end();
}
示例10: 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;
}
示例11: addSecuritySection
private function addSecuritySection(ArrayNodeDefinition $node)
{
$supportedSecurityXFrameOptions = [null, 'deny', 'same-origin'];
$node->children()->arrayNode('security')->addDefaultsIfNotSet()->children()->scalarNode('x_frame_options')->validate()->ifTrue(function ($value) use($supportedSecurityXFrameOptions) {
return !(in_array($value, $supportedSecurityXFrameOptions) || filter_var($value, FILTER_VALIDATE_URL));
})->thenInvalid('The x_frame_options option only allows values ' . json_encode($supportedSecurityXFrameOptions) . ' or an URI.')->end()->defaultValue(null)->end()->end()->end();
}
示例12: addTriggerNodes
/**
* @param ArrayNodeDefinition $nodeDefinition
* @return ArrayNodeDefinition
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function addTriggerNodes(ArrayNodeDefinition $nodeDefinition)
{
$nodeDefinition->children()->enumNode('event')->defaultNull()->values(ProcessTrigger::getAllowedEvents())->end()->scalarNode('field')->defaultNull()->end()->integerNode('priority')->defaultValue(Job::PRIORITY_DEFAULT)->end()->booleanNode('queued')->defaultFalse()->end()->scalarNode('time_shift')->defaultNull()->validate()->always(function ($value) {
// if value is an integer value
$integerValue = filter_var($value, FILTER_VALIDATE_INT);
if (false !== $integerValue) {
return $integerValue;
}
// if value is DateInterval spec
try {
return ProcessTrigger::convertDateIntervalToSeconds(new \DateInterval($value));
} catch (\Exception $e) {
throw new \LogicException(sprintf('Time shift "%s" is not compatible with DateInterval', $value));
}
})->end()->end()->scalarNode('cron')->defaultNull()->validate()->always(function ($value) {
if ($value !== null) {
// validate expression string
CronExpression::factory($value);
}
return $value;
})->end()->end()->end()->validate()->always(function ($data) {
if ($data['event'] && $data['cron']) {
throw new \LogicException('Only one child node "event" or "cron" must be configured.');
}
if ($data['cron'] && ($data['field'] || $data['queued'] || $data['time_shift'])) {
throw new \LogicException('Nodes "field", "queued" and "time_shift" are only allowed with event node.');
}
if ($data['field'] && $data['event'] !== ProcessTrigger::EVENT_UPDATE) {
throw new \LogicException('Field is only allowed for update event');
}
return $data;
})->end();
return $nodeDefinition;
}
示例13: addDynamicSection
private function addDynamicSection(ArrayNodeDefinition $root)
{
$root->children()->arrayNode('dynamic')->fixXmlConfig('controller_by_type', 'controllers_by_type')->fixXmlConfig('controller_by_class', 'controllers_by_class')->fixXmlConfig('template_by_class', 'templates_by_class')->fixXmlConfig('route_filter_by_id', 'route_filters_by_id')->fixXmlConfig('locale')->addDefaultsIfNotSet()->canBeEnabled()->children()->scalarNode('route_collection_limit')->defaultValue(0)->end()->scalarNode('generic_controller')->defaultNull()->end()->scalarNode('default_controller')->defaultNull()->end()->arrayNode('controllers_by_type')->useAttributeAsKey('type')->prototype('scalar')->end()->end()->arrayNode('controllers_by_class')->useAttributeAsKey('class')->prototype('scalar')->end()->end()->arrayNode('templates_by_class')->useAttributeAsKey('class')->prototype('scalar')->end()->end()->arrayNode('persistence')->addDefaultsIfNotSet()->validate()->ifTrue(function ($v) {
return count(array_filter($v, function ($persistence) {
return $persistence['enabled'];
})) > 1;
})->thenInvalid('Only one persistence layer can be enabled at the same time.')->end()->children()->arrayNode('phpcr')->addDefaultsIfNotSet()->canBeEnabled()->fixXmlConfig('route_basepath')->validate()->ifTrue(function ($v) {
isset($v['route_basepath']) && isset($v['route_basepaths']);
})->thenInvalid('Found values for both "route_basepath" and "route_basepaths", use "route_basepaths" instead.')->end()->beforeNormalization()->ifTrue(function ($v) {
return isset($v['route_basepath']) && !is_array($v['route_basepath']);
})->then(function ($v) {
@trigger_error('The route_basepath setting is deprecated as of version 1.4 and will be removed in 2.0. Use route_basepaths instead.', E_USER_DEPRECATED);
return $v;
})->end()->children()->scalarNode('manager_name')->defaultNull()->end()->arrayNode('route_basepaths')->beforeNormalization()->ifString()->then(function ($v) {
return array($v);
})->end()->prototype('scalar')->end()->defaultValue(array('/cms/routes'))->end()->scalarNode('admin_basepath')->defaultNull()->end()->scalarNode('content_basepath')->defaultValue('/cms/content')->end()->enumNode('use_sonata_admin')->beforeNormalization()->ifString()->then(function ($v) {
switch ($v) {
case 'true':
return true;
case 'false':
return false;
default:
return $v;
}
})->end()->values(array(true, false, 'auto'))->defaultValue('auto')->end()->enumNode('enable_initializer')->beforeNormalization()->ifString()->then(function ($v) {
switch ($v) {
case 'true':
return true;
case 'false':
return false;
default:
return $v;
}
})->end()->values(array(true, false, 'auto'))->defaultValue('auto')->end()->end()->end()->arrayNode('orm')->addDefaultsIfNotSet()->canBeEnabled()->children()->scalarNode('manager_name')->defaultNull()->end()->end()->end()->end()->end()->scalarNode('uri_filter_regexp')->defaultValue('')->end()->scalarNode('route_provider_service_id')->end()->arrayNode('route_filters_by_id')->canBeUnset()->defaultValue(array())->useAttributeAsKey('id')->prototype('scalar')->end()->end()->scalarNode('content_repository_service_id')->end()->arrayNode('locales')->prototype('scalar')->end()->end()->integerNode('limit_candidates')->defaultValue(20)->end()->booleanNode('match_implicit_locale')->defaultValue(true)->end()->booleanNode('auto_locale_pattern')->defaultValue(false)->end()->scalarNode('url_generator')->defaultValue('cmf_routing.generator')->info('URL generator service ID')->end()->end()->end()->end();
}
示例14: appendDataNodes
/**
* @param ArrayNodeDefinition $dataNode
*/
protected function appendDataNodes($dataNode)
{
$treeBuilder = new TreeBuilder();
$assetsNode = $treeBuilder->root('assets');
$assetsNode->useAttributeAsKey('asset-identifier')->normalizeKeys(false)->prototype('array')->children()->arrayNode('inputs')->info('Input assets list')->prototype('scalar')->end()->end()->arrayNode('filters')->info('Filters to manipulate input assets')->prototype('scalar')->end()->end()->scalarNode('output')->info('Output asset')->end()->end()->end();
$dataNode->append($assetsNode);
}
示例15: configure
/**
* Setups configuration for the extension.
*
* @param ArrayNodeDefinition $builder
*/
public function configure(ArrayNodeDefinition $builder)
{
$builder->children()->scalarNode("name")->defaultValue("emusehtml");
$builder->children()->scalarNode("renderer")->defaultValue("behat2");
$builder->children()->scalarNode("file_name")->defaultValue("generated");
$builder->children()->scalarNode('output')->defaultValue('.');
}