本文整理汇总了PHP中Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayNodeDefinition::validate方法的具体用法?PHP ArrayNodeDefinition::validate怎么用?PHP ArrayNodeDefinition::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition
的用法示例。
在下文中一共展示了ArrayNodeDefinition::validate方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addFormSection
private function addFormSection(ArrayNodeDefinition $rootNode)
{
$rootNode->validate()->ifTrue(function ($v) {
return count($v['form']['resources']) > 0;
})->then(function ($v) {
$v['form_themes'] = array_values(array_unique(array_merge($v['form']['resources'], $v['form_themes'])));
return $v;
})->end()->children()->arrayNode('form')->info('Deprecated since 2.6, to be removed in 3.0. Use twig.form_themes instead')->addDefaultsIfNotSet()->fixXmlConfig('resource')->children()->arrayNode('resources')->addDefaultChildrenIfNoneSet()->prototype('scalar')->defaultValue('form_div_layout.html.twig')->end()->example(array('MyBundle::form.html.twig'))->validate()->ifNotInArray(array('form_div_layout.html.twig'))->then(function ($v) {
return array_merge(array('form_div_layout.html.twig'), $v);
})->end()->end()->end()->end()->end();
}
示例2: addPaymentSection
/**
* @param \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $node
* @return void
*/
private function addPaymentSection(ArrayNodeDefinition $node)
{
$node->validate()->ifTrue(function ($v) {
foreach ($v['methods'] as $methodCode => $service) {
if (null === $service || "" === $service) {
foreach ($v['services'] as $serviceConf) {
if ($methodCode === $serviceConf['code']) {
break 2;
}
}
return true;
}
}
return false;
})->thenInvalid("Custom payment methods require a service id. Provided payment methods need to be configured with their method code as key.")->end()->children()->arrayNode('services')->children()->arrayNode('paypal')->children()->scalarNode('name')->defaultValue('Paypal')->cannotBeEmpty()->end()->scalarNode('code')->defaultValue('paypal')->cannotBeEmpty()->end()->arrayNode('transformers')->children()->scalarNode('basket')->defaultValue('sonata.payment.transformer.basket')->cannotBeEmpty()->end()->scalarNode('order')->defaultValue('sonata.payment.transformer.order')->cannotBeEmpty()->end()->end()->end()->arrayNode('options')->children()->scalarNode('shop_secret_key')->cannotBeEmpty()->end()->scalarNode('web_connector_name')->defaultValue('curl')->cannotBeEmpty()->end()->scalarNode('account')->defaultValue('your_paypal_account@fake.com')->cannotBeEmpty()->end()->scalarNode('cert_id')->defaultValue('fake')->cannotBeEmpty()->end()->scalarNode('debug')->defaultValue(false)->cannotBeEmpty()->end()->scalarNode('paypal_cert_file')->defaultValue('%kernel.root_dir%/paypal_cert_pem_sandbox.txt')->cannotBeEmpty()->end()->scalarNode('url_action')->defaultValue('https://www.sandbox.paypal.com/cgi-bin/webscr')->cannotBeEmpty()->end()->scalarNode('class_order')->defaultValue('Application\\Sonata\\OrderBundle\\Entity\\Order')->cannotBeEmpty()->end()->scalarNode('url_callback')->defaultValue('sonata_payment_callback')->cannotBeEmpty()->end()->scalarNode('url_return_ko')->defaultValue('sonata_payment_error')->cannotBeEmpty()->end()->scalarNode('url_return_ok')->defaultValue('sonata_payment_confirmation')->cannotBeEmpty()->end()->scalarNode('method')->defaultValue('encryptViaBuffer')->cannotBeEmpty()->end()->scalarNode('key_file')->defaultValue('%kernel.root_dir%/my-prvkey.pem')->cannotBeEmpty()->end()->scalarNode('cert_file')->defaultValue('%kernel.root_dir%/my-pubcert.pem')->cannotBeEmpty()->end()->scalarNode('openssl')->defaultValue('/opt/local/bin/openssl')->cannotBeEmpty()->end()->end()->end()->end()->end()->arrayNode('debug')->children()->scalarNode('name')->defaultValue('Debug Payment')->cannotBeEmpty()->end()->scalarNode('code')->defaultValue('debug')->cannotBeEmpty()->end()->scalarNode('browser')->defaultValue('sonata.payment.browser.curl')->cannotBeEmpty()->end()->arrayNode('transformers')->children()->scalarNode('basket')->defaultValue('sonata.payment.transformer.basket')->cannotBeEmpty()->end()->scalarNode('order')->defaultValue('sonata.payment.transformer.order')->cannotBeEmpty()->end()->end()->end()->arrayNode('options')->children()->scalarNode('url_callback')->defaultValue('sonata_payment_callback')->cannotBeEmpty()->end()->scalarNode('url_return_ko')->defaultValue('sonata_payment_error')->cannotBeEmpty()->end()->scalarNode('url_return_ok')->defaultValue('sonata_payment_confirmation')->cannotBeEmpty()->end()->end()->end()->end()->end()->arrayNode('pass')->children()->scalarNode('name')->defaultValue('Pass')->cannotBeEmpty()->end()->scalarNode('code')->defaultValue('pass')->cannotBeEmpty()->end()->arrayNode('transformers')->children()->scalarNode('basket')->defaultValue('sonata.payment.transformer.basket')->cannotBeEmpty()->end()->scalarNode('order')->defaultValue('sonata.payment.transformer.order')->cannotBeEmpty()->end()->end()->end()->scalarNode('browser')->defaultValue('sonata.payment.browser.curl')->cannotBeEmpty()->end()->arrayNode('options')->children()->scalarNode('shop_secret_key')->cannotBeEmpty()->end()->scalarNode('url_callback')->defaultValue('sonata_payment_callback')->cannotBeEmpty()->end()->scalarNode('url_return_ko')->defaultValue('sonata_payment_error')->cannotBeEmpty()->end()->scalarNode('url_return_ok')->defaultValue('sonata_payment_confirmation')->cannotBeEmpty()->end()->end()->end()->end()->end()->arrayNode('check')->children()->scalarNode('name')->defaultValue('Check')->cannotBeEmpty()->end()->scalarNode('code')->defaultValue('check')->cannotBeEmpty()->end()->arrayNode('transformers')->children()->scalarNode('basket')->defaultValue('sonata.payment.transformer.basket')->cannotBeEmpty()->end()->scalarNode('order')->defaultValue('sonata.payment.transformer.order')->cannotBeEmpty()->end()->end()->end()->scalarNode('browser')->defaultValue('sonata.payment.browser.curl')->cannotBeEmpty()->end()->arrayNode('options')->children()->scalarNode('shop_secret_key')->cannotBeEmpty()->end()->scalarNode('url_callback')->defaultValue('sonata_payment_callback')->cannotBeEmpty()->end()->scalarNode('url_return_ko')->defaultValue('sonata_payment_error')->cannotBeEmpty()->end()->scalarNode('url_return_ok')->defaultValue('sonata_payment_confirmation')->cannotBeEmpty()->end()->end()->end()->end()->end()->arrayNode('scellius')->children()->scalarNode('name')->defaultValue('Scellius')->cannotBeEmpty()->end()->scalarNode('code')->defaultValue('scellius')->cannotBeEmpty()->end()->scalarNode('generator')->defaultValue('sonata.payment.provider.scellius.none_generator')->end()->arrayNode('transformers')->children()->scalarNode('basket')->defaultValue('sonata.payment.transformer.basket')->cannotBeEmpty()->end()->scalarNode('order')->defaultValue('sonata.payment.transformer.order')->cannotBeEmpty()->end()->end()->end()->arrayNode('options')->children()->scalarNode('url_callback')->defaultValue('sonata_payment_callback')->cannotBeEmpty()->end()->scalarNode('url_return_ko')->defaultValue('sonata_payment_error')->cannotBeEmpty()->end()->scalarNode('url_return_ok')->defaultValue('sonata_payment_confirmation')->cannotBeEmpty()->end()->scalarNode('template')->defaultValue('SonataPaymentBundle:Payment:scellius.html.twig')->cannotBeEmpty()->end()->scalarNode('shop_secret_key')->cannotBeEmpty()->end()->scalarNode('request_command')->cannotBeEmpty()->end()->scalarNode('response_command')->cannotBeEmpty()->end()->scalarNode('merchant_id')->cannotBeEmpty()->end()->scalarNode('merchant_country')->cannotBeEmpty()->end()->scalarNode('pathfile')->cannotBeEmpty()->end()->scalarNode('language')->cannotBeEmpty()->end()->scalarNode('payment_means')->cannotBeEmpty()->end()->scalarNode('base_folder')->cannotBeEmpty()->end()->scalarNode('data')->defaultValue('')->end()->scalarNode('header_flag')->defaultValue('no')->cannotBeEmpty()->end()->scalarNode('capture_day')->defaultValue('')->end()->scalarNode('capture_mode')->defaultValue('')->end()->scalarNode('bgcolor')->defaultValue('')->end()->scalarNode('block_align')->defaultValue('')->end()->scalarNode('block_order')->defaultValue('')->end()->scalarNode('textcolor')->defaultValue('')->end()->scalarNode('normal_return_logo')->defaultValue('')->end()->scalarNode('cancel_return_logo')->defaultValue('')->end()->scalarNode('submit_logo')->defaultValue('')->end()->scalarNode('logo_id')->defaultValue('')->end()->scalarNode('logo_id2')->defaultValue('')->end()->scalarNode('advert')->defaultValue('')->end()->scalarNode('background_id')->defaultValue('')->end()->scalarNode('templatefile')->defaultValue('')->end()->end()->end()->end()->end()->arrayNode('ogone')->children()->scalarNode('name')->defaultValue('Ogone')->cannotBeEmpty()->end()->scalarNode('code')->defaultValue('ogone')->cannotBeEmpty()->end()->arrayNode('transformers')->children()->scalarNode('basket')->defaultValue('sonata.payment.transformer.basket')->cannotBeEmpty()->end()->scalarNode('order')->defaultValue('sonata.payment.transformer.order')->cannotBeEmpty()->end()->end()->end()->arrayNode('options')->children()->scalarNode('url_callback')->defaultValue('sonata_payment_callback')->cannotBeEmpty()->end()->scalarNode('url_return_ko')->defaultValue('sonata_payment_error')->cannotBeEmpty()->end()->scalarNode('url_return_ok')->defaultValue('sonata_payment_confirmation')->cannotBeEmpty()->end()->scalarNode('form_url')->isRequired()->cannotBeEmpty()->end()->scalarNode('catalog_url')->isRequired()->cannotBeEmpty()->end()->scalarNode('home_url')->isRequired()->cannotBeEmpty()->end()->scalarNode('pspid')->isRequired()->cannotBeEmpty()->end()->scalarNode('sha_key')->isRequired()->cannotBeEmpty()->end()->scalarNode('sha-out_key')->isRequired()->cannotBeEmpty()->end()->scalarNode('template')->defaultValue('SonataPaymentBundle:Payment:ogone.html.twig')->cannotBeEmpty()->end()->end()->end()->end()->end()->end()->end()->arrayNode('methods')->useAttributeAsKey('code')->prototype('scalar')->end()->end()->end();
}
示例3: addDeliverySection
/**
* @param \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $node
*/
private function addDeliverySection(ArrayNodeDefinition $node)
{
$node->validate()->ifTrue(function ($v) {
foreach ($v['methods'] as $methodCode => $service) {
if (null === $service || '' === $service) {
foreach ($v['services'] as $serviceConf) {
if ($methodCode === $serviceConf['code']) {
break 2;
}
}
return true;
}
}
return false;
})->thenInvalid('Custom delivery methods require a service id. Provided delivery methods need to be configured with their method code as key.')->end()->children()->arrayNode('services')->children()->arrayNode('free_address_required')->children()->scalarNode('name')->defaultValue('free_address_required')->cannotBeEmpty()->end()->scalarNode('code')->defaultValue('free_address_required')->cannotBeEmpty()->end()->scalarNode('priority')->defaultValue(10)->cannotBeEmpty()->end()->end()->end()->arrayNode('free_address_not_required')->children()->scalarNode('name')->defaultValue('free_address_not_required')->cannotBeEmpty()->end()->scalarNode('code')->defaultValue('free_address_not_required')->cannotBeEmpty()->end()->scalarNode('priority')->defaultValue(10)->cannotBeEmpty()->end()->end()->end()->end()->end()->arrayNode('methods')->useAttributeAsKey('code')->prototype('scalar')->end()->end()->end();
}
示例4: buildRelationsTree
/**
* Builds relations config tree for given relation name.
*
* @param string $relationType
*
* @return ArrayNodeDefinition
*/
private function buildRelationsTree($relationType)
{
$filter = new ArrayNodeDefinition($relationType);
$filter->validate()->ifTrue(function ($v) {
return empty($v['include']) && empty($v['exclude']);
})->thenInvalid('Relation must have "include" or "exclude" fields specified.')->end()->validate()->ifTrue(function ($v) {
return !empty($v['include']) && !empty($v['exclude']);
})->thenInvalid('Relation must have only "include" or "exclude" fields specified.')->end()->children()->arrayNode('include')->beforeNormalization()->ifString()->then(function ($v) {
return [$v];
})->end()->prototype('scalar')->end()->end()->arrayNode('exclude')->beforeNormalization()->ifString()->then(function ($v) {
return [$v];
})->end()->prototype('scalar')->end()->end()->end();
return $filter;
}
示例5: addValidatorValidation
/**
* Add validation to a validator key
*
* @param ArrayNodeDefinition $node
*/
protected function addValidatorValidation(ArrayNodeDefinition $node)
{
$node->validate()->ifTrue(function ($value) {
if (!is_array($value)) {
return true;
}
// All key must be string. Used as alias for the validator service
if (count(array_filter(array_keys($value), 'is_string')) != count($value)) {
return true;
}
// All value must be array. Used as configuration for validator
if (count(array_filter(array_values($value), 'is_array')) != count($value)) {
return true;
}
return false;
})->thenInvalid('Invalid validators configuration')->end();
}
示例6: deleteChildIfEmpty
/**
* @param ArrayNodeDefinition $arrayNodeDefinition
* @param $field
*/
private function deleteChildIfEmpty(ArrayNodeDefinition $arrayNodeDefinition, $field)
{
$arrayNodeDefinition->validate()->ifTrue(function ($data) use($field) {
return isset($data[$field]) && ([] === $data[$field] || '' === $data[$field]);
})->then(function ($data) use($field) {
unset($data[$field]);
return $data;
});
}
示例7: createValidationsNodeDefinition
/**
* Create a configuration node to define validations for a step (or pre-validation on a next state).
*
* @return ArrayNodeDefinition
*/
private function createValidationsNodeDefinition()
{
$validatorSyntax = function (array $values) {
foreach ($values as $value) {
if (2 !== count($parts = explode(':', $value))) {
return true;
}
}
};
$validationsNode = new ArrayNodeDefinition('validations');
$validationsNode->validate()->ifTrue(function ($value) use($validatorSyntax) {
return is_array($value) && $validatorSyntax($value);
})->thenInvalid('You must specify valid validation name as serviceId:method string')->end()->prototype('scalar')->end();
return $validationsNode;
}