本文整理汇总了PHP中Symfony\Component\OptionsResolver\OptionsResolver::setNormalizers方法的典型用法代码示例。如果您正苦于以下问题:PHP OptionsResolver::setNormalizers方法的具体用法?PHP OptionsResolver::setNormalizers怎么用?PHP OptionsResolver::setNormalizers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\OptionsResolver\OptionsResolver
的用法示例。
在下文中一共展示了OptionsResolver::setNormalizers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setNormalizers
private function setNormalizers()
{
$this->resolver->setNormalizers([self::CHARSETS => function (Options $options, $value) {
$value = array_map('strtoupper', $value);
$value = $this->replaceWin1250WithIso($value);
$value = $this->filterSupportedCharsets($value);
$value = $this->moveUtfFirst($value);
return $value;
}]);
}
示例2: setNormalizers
private function setNormalizers()
{
$this->resolver->setNormalizers([TCO::RESOURCES => function (Options $options, $resources) {
$absolutizedResources = [];
foreach ($resources as $key => $resource) {
$key = $options['templatesPath'] . '/' . $key;
$absolutizedResources[$key] = $resource;
}
return $absolutizedResources;
}, TCO::TEMPLATES => function (Options $options, $value) {
return $this->makeTemplatePathsAbsolute($value, $options);
}]);
}
示例3: configureOptions
/**
* Options:
* - grid_widget_route - route of widget where selection grid will be rendered
* - grid_name - name of grid that will be used for entity selection
* - grid_parameters - parameters need to be passed to grid request
* - grid_render_parameters - render parameters need to be set for grid rendering
* - existing_entity_grid_id - grid row field name used as entity identifier
* - create_enabled - enables new entity creation
* - create_acl - ACL resource used to determine that create is allowed, by default CREATE for entity used
* - create_form_route - route name for creation form
* - create_form_route_parameters - route parameters for create_form_route_parameters
*
* {@inheritDoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(['existing_entity_grid_id' => 'id', 'create_enabled' => true, 'create_acl' => null, 'create_form_route' => null, 'create_form_route_parameters' => [], 'grid_widget_route' => 'oro_datagrid_widget', 'grid_name' => null, 'grid_parameters' => [], 'grid_render_parameters' => []]);
$resolver->setNormalizers(['create_enabled' => function (Options $options, $createEnabled) {
$createRouteName = $options->get('create_form_route');
$createEnabled = $createEnabled && !empty($createRouteName);
if ($createEnabled) {
$aclName = $options->get('create_acl');
if (empty($aclName)) {
$aclObjectName = 'Entity:' . $options->get('entity_class');
$createEnabled = $this->securityFacade->isGranted('CREATE', $aclObjectName);
} else {
$createEnabled = $this->securityFacade->isGranted($aclName);
}
}
return $createEnabled;
}, 'grid_name' => function (Options $options, $gridName) {
if (!empty($gridName)) {
return $gridName;
}
$formConfig = $this->configManager->getProvider('form')->getConfig($options->get('entity_class'));
if ($formConfig->has('grid_name')) {
return $formConfig->get('grid_name');
}
throw new InvalidConfigurationException('The option "grid_name" must be set.');
}]);
}
示例4: setNormalizers
private function setNormalizers()
{
$this->resolver->setNormalizers([CO::ANNOTATION_GROUPS => function (Options $options, $value) {
$value = (array) $value;
if ($options[CO::DEPRECATED]) {
$value[] = CO::DEPRECATED;
}
if ($options[CO::TODO]) {
$value[] = CO::TODO;
}
return array_unique($value);
}, CO::DESTINATION => function (Options $options, $value) {
return FileSystem::getAbsolutePath($value);
}, CO::BASE_URL => function (Options $options, $value) {
return rtrim($value, '/');
}, CO::SKIP_DOC_PATH => function (Options $options, $value) {
$value = (array) $value;
foreach ($value as $key => $source) {
$value[$key] = FileSystem::getAbsolutePath($source);
}
return $value;
}, CO::SOURCE => function (Options $options, $value) {
if (!is_array($value)) {
$value = [$value];
}
foreach ($value as $key => $source) {
$value[$key] = FileSystem::getAbsolutePath($source);
}
return $value;
}, CO::SOURCE_CODE => function (Options $options) {
return !$options[CO::NO_SOURCE_CODE];
}, CO::TEMPLATE_CONFIG => function (Options $options, $value) {
return FileSystem::getAbsolutePath($value);
}]);
}
示例5: configureOptions
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(['field' => 'string', 'type' => 'text', 'options' => [], 'allow_add' => true, 'allow_delete' => true]);
$resolver->setNormalizers(['type' => function () {
return new StubLocalizedFallbackValueType();
}, 'options' => function () {
return [];
}]);
}
示例6: setNormalizers
public function setNormalizers(array $normalizers)
{
if (!$this->isLatest()) {
return parent::setNormalizers($normalizers);
}
foreach ($normalizers as $option => $normalizer) {
parent::setNormalizer($option, $normalizer);
}
return $this;
}
示例7: testNormalizersTransformFinalOptions
public function testNormalizersTransformFinalOptions()
{
$this->resolver->setDefaults(array('foo' => 'bar', 'bam' => 'baz'));
$this->resolver->setNormalizers(array('foo' => function (Options $options, $value) {
return $options['bam'] . '[' . $value . ']';
}));
$expected = array('foo' => 'baz[bar]', 'bam' => 'baz');
$this->assertEquals($expected, $this->resolver->resolve(array()));
$expected = array('foo' => 'boo[custom]', 'bam' => 'boo');
$this->assertEquals($expected, $this->resolver->resolve(array('foo' => 'custom', 'bam' => 'boo')));
}
示例8: configureOptions
public function configureOptions(OptionsResolver $resolver)
{
$addTypeConstraint = function ($options, $value) {
// Constraint should always be converted to an array
$value = is_object($value) ? array($value) : (array) $value;
$value[] = new IpAddress();
return $value;
};
$resolver->setDefaults(array('placeholder' => '192.0.2.193, *.example.com, ...'));
$resolver->setNormalizers(array('constraints' => $addTypeConstraint));
}
示例9: configureOptions
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array('number' => 5, 'configs' => array(), 'expanded' => true, 'choices' => function (Options $options) {
$choices = array();
for ($i = 1; $i <= $options['number']; $i++) {
$choices[$i] = null;
}
return $choices;
}));
$resolver->setNormalizers(array('expanded' => function (Options $options, $value) {
return true;
}));
}
示例10: configureOptions
protected function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(['extension' => 'stockpile', 'directory' => sys_get_temp_dir() . '/stockpile']);
$resolver->setRequired(['directory']);
$resolver->setNormalizers(['extension' => function (Options $options, $extension) {
$extension = Driver::normalizeKey($extension);
$extension = strtolower($extension);
$extension = trim($extension, '.');
return '.' . $extension;
}, 'directory' => function (Options $options, $directory) {
return self::normalizeKey($directory);
}]);
}
示例11: configureOptions
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$configurator = $this->configurator;
$resolver->setDefaults(array('allow_extra_fields' => true, 'data_class' => function (Options $options) use($configurator) {
$entity = $options['entity'];
$entityConfig = $configurator->getEntityConfiguration($entity);
return $entityConfig['class'];
}))->setRequired(array('entity', 'view'));
if ($this->useLegacyFormComponent()) {
$resolver->setNormalizers(array('attr' => $this->getAttributesNormalizer()));
} else {
$resolver->setNormalizer('attr', $this->getAttributesNormalizer());
}
}
示例12: loadTransitions
/**
* @param StateMachineInterface $stateMachine
*/
private function loadTransitions(StateMachineInterface $stateMachine)
{
$resolver = new OptionsResolver();
$resolver->setRequired(array('from', 'to'));
$resolver->setOptional(array('guard'));
$resolver->setNormalizers(array('from' => function (Options $options, $v) {
return (array) $v;
}, 'guard' => function (Options $options, $v) {
return !isset($v) ? null : $v;
}));
foreach ($this->config['transitions'] as $transition => $config) {
$config = $resolver->resolve($config);
$stateMachine->addTransition(new Transition($transition, $config['from'], $config['to'], $config['guard']));
}
}
示例13: configureOptionsResolver
public function configureOptionsResolver(OptionsResolver $resolver)
{
$allowedProfileTypes = array('Giftcards\\Encryption\\Profile\\Profile');
$resolver->setRequired(array('profile'));
if ($this->profileRegistry) {
$allowedProfileTypes[] = 'string';
$profileRegistry = $this->profileRegistry;
$resolver->setNormalizers(array('profile' => function ($_, $profile) use($profileRegistry) {
if ($profile instanceof Profile) {
return $profile;
}
return $profileRegistry->get((string) $profile);
}));
}
$resolver->setAllowedTypes(array('profile' => $allowedProfileTypes));
}
示例14: configureOptions
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array('data_class' => null, 'multiple' => true, 'render_label' => false, 'model_transformer' => 'Sylius\\Bundle\\TaxonomyBundle\\Form\\DataTransformer\\TaxonSelectionToCollectionTransformer'));
$resolver->setNormalizers(array('model_transformer' => function (Options $options, $value) {
if (!is_array($value)) {
$value = array('class' => $value, 'save_objects' => true);
} else {
if (!isset($value['class'])) {
$value['class'] = 'Sylius\\Bundle\\TaxonomyBundle\\Form\\DataTransformer\\TaxonSelectionToCollectionTransformer';
}
if (!isset($value['save_objects'])) {
$value['save_objects'] = true;
}
}
return $value;
}));
}
示例15: setUpResolver
/**
* @param OptionsResolver $resolver
* @param string $integrationType
*/
protected function setUpResolver(OptionsResolver $resolver, $integrationType)
{
$defined = array();
$defaults = array();
$options = $this->getOptions();
foreach ($options as $name => $option) {
if ($integrationType && !empty($option['for types']) && !in_array($integrationType, $option['for types'])) {
unset($options[$name]);
continue;
}
if (!empty($option['default'])) {
$defaults[$name] = $option['default'];
} else {
$defined[] = $name;
}
}
$resolver->setDefined($defined);
$resolver->setDefaults($defaults);
$required = array();
$normalizers = array();
foreach ($options as $name => $option) {
if (!empty($option['required']) && (empty($option['for types']) || $integrationType)) {
$required[] = $name;
}
if (!empty($option['normalizer'])) {
$normalizers[$name] = $option['normalizer'];
}
if (!empty($option['type'])) {
$resolver->setAllowedTypes($name, $option['type']);
}
if (!empty($option['validator'])) {
$resolver->setAllowedValues($name, $option['validator']);
} elseif (!empty($option['options'])) {
$resolver->setAllowedValues($name, $option['options']);
}
}
$resolver->setRequired($required);
$resolver->setNormalizers($normalizers);
}