本文整理汇总了PHP中Symfony\Component\OptionsResolver\OptionsResolverInterface::setNormalizers方法的典型用法代码示例。如果您正苦于以下问题:PHP OptionsResolverInterface::setNormalizers方法的具体用法?PHP OptionsResolverInterface::setNormalizers怎么用?PHP OptionsResolverInterface::setNormalizers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\OptionsResolver\OptionsResolverInterface
的用法示例。
在下文中一共展示了OptionsResolverInterface::setNormalizers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @param EventDispatcherInterface $dispatcher
*/
public function __construct(EventDispatcherInterface $dispatcher)
{
$this->dispatcher = $dispatcher;
$this->specResolver = new OptionsResolver;
$this->specResolver->setDefaults(
array(
'on' => self::ALL,
'from' => self::ALL,
'to' => self::ALL,
'exclude_from' => array(),
'exclude_to' => array(),
)
);
$this->specResolver->setAllowedTypes(
array(
'on' => array('string', 'array'),
'from' => array('string', 'array'),
'to' => array('string', 'array'),
'exclude_from' => array('string', 'array'),
'exclude_to' => array('string', 'array'),
)
);
$toArrayNormalizer = function (Options $options, $value) {
return (array)$value;
};
$this->specResolver->setNormalizers(
array(
'on' => $toArrayNormalizer,
'from' => $toArrayNormalizer,
'to' => $toArrayNormalizer,
'exclude_to' => $toArrayNormalizer,
'exclude_from' => $toArrayNormalizer,
)
);
}
示例2: configureResolver
/**
* {@inheritdoc}
*/
public function configureResolver(OptionsResolverInterface $resolver)
{
$patientNormalizer = function (Options $options, $value) {
static $resource;
if (!$resource) {
$resource = $options['patient_resource']->getRepository();
}
return $resource->getByMRN($value);
};
$codes = $this->getCodes();
$diagnosisNormalizer = function (Options $options, $value) use($codes) {
static $resource;
if (!$resource) {
$resource = $options['diagnosis_resource']->getRepository();
}
if ($patient = $options['patient']) {
foreach ($patient->getDiagnoses() as $diagnosis) {
if (in_array($diagnosis->getCode()->getCode(), $codes)) {
return $diagnosis;
}
}
}
};
$dateNormalizer = function (Options $options, $value) {
return empty($value) ? null : new DateTime($value);
};
$resolver->setRequired(array('patient', 'activity_date'));
$resolver->setOptional(array('diagnosis'));
$resolver->setAllowedTypes(array('patient' => array('string'), 'diagnosis' => array('Accard\\Component\\Diagnosis\\Model\\DiagnosisInterface', 'null'), 'activity_date' => array('string', 'null')));
$resolver->setNormalizers(array('patient' => $patientNormalizer, 'diagnosis' => $diagnosisNormalizer, 'activity_date' => $dateNormalizer));
}
示例3: setDefaultOptions
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array('attr' => $this->defaultAttributes));
$resolver->setNormalizers(array('attr' => function (Options $options, $value) {
return array_merge($this->defaultAttributes, $value);
}));
}
示例4: setDefaultOptions
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$defaultFieldOptions = ['multiple' => true];
$resolver->setDefaults(['dictionary_code' => null, 'class' => null, 'field_options' => $defaultFieldOptions]);
$resolver->setNormalizers(['class' => function (Options $options, $value) {
if ($value !== null) {
return $value;
}
if (empty($options['dictionary_code'])) {
throw new InvalidOptionsException('Either "class" or "dictionary_code" must option must be set.');
}
$class = ExtendHelper::buildEnumValueClassName($options['dictionary_code']);
if (!is_a($class, 'Oro\\Bundle\\EntityExtendBundle\\Entity\\AbstractEnumValue', true)) {
throw new InvalidOptionsException(sprintf('"%s" must be a child of "%s"', $class, 'Oro\\Bundle\\EntityExtendBundle\\Entity\\AbstractEnumValue'));
}
return $class;
}, 'field_options' => function (Options $options, $value) use(&$defaultFieldOptions) {
if (isset($options['class'])) {
$nullValue = null;
if ($options->has('null_value')) {
$nullValue = $options->get('null_value');
}
$value['choices'] = $this->getChoices($options['class'], $nullValue);
} else {
$value['choices'] = [];
}
return array_merge($defaultFieldOptions, $value);
}]);
}
示例5: setDefaultOptions
/**
* (non-PHPdoc)
* @see Symfony\Component\Form.AbstractType::setDefaultOptions()
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array('translation_domain' => 'NeutronFormBundle', 'date_format' => \IntlDateFormatter::LONG, 'date_pattern' => null, 'time_format' => \IntlDateFormatter::MEDIUM));
$resolver->setNormalizers(array('read_only' => function (Options $options, $value) {
return true;
}));
}
示例6: setDefaultOptions
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
if (!$this->channelClass) {
throw new \InvalidArgumentException('Channel class is missing');
}
$queryBuilderNormalizer = function (Options $options, $qb) {
/** @var EntityManager $em */
$em = $options['em'];
/** @var EntityRepository $repository */
$repository = $em->getRepository($this->channelClass);
$entities = $options->get('entities');
/** @var QueryBuilder $queryBuilder */
$queryBuilder = $qb($repository, $entities);
$queryBuilder->join('c.dataSource', 'd')->andWhere($queryBuilder->expr()->andX($queryBuilder->expr()->eq('d.type', ':type'), $queryBuilder->expr()->eq('d.enabled', ':enabled')))->setParameter('type', ChannelType::TYPE)->setParameter('enabled', true);
$filteredQb = clone $queryBuilder;
/** @var Channel[] $channels */
$channels = $filteredQb->getQuery()->getResult();
$skipEntities = [];
foreach ($channels as $channel) {
$dataSource = $channel->getDataSource();
if (!(bool) $dataSource->getSynchronizationSettings()->offsetGetOr('isTwoWaySyncEnabled')) {
$skipEntities[] = $channel->getId();
}
}
if ($skipEntities) {
$queryBuilder->andWhere($queryBuilder->expr()->notIn('c.id', ':skipEntities'))->setParameter('skipEntities', $skipEntities);
}
return $queryBuilder;
};
$resolver->setNormalizers(['query_builder' => $queryBuilderNormalizer]);
}
示例7: setDefaultOptions
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array('em' => null, 'property' => null, 'queryBuilder' => null, 'multiple' => true, 'values_delimiter' => ','))->setAllowedValues(array('multiple' => array(true, false)));
$resolver->setRequired(array('class'));
$registry = $this->registry;
$emNormalizer = function (Options $options, $em) use($registry) {
if (null !== $em) {
if ($em instanceof EntityManager) {
return $em;
} elseif (is_string($em)) {
$em = $registry->getManager($em);
} else {
throw new FormException(sprintf('Option "em" should be a string or entity manager object, %s given', is_object($em) ? get_class($em) : gettype($em)));
}
} else {
$em = $registry->getManagerForClass($options['class']);
}
if (null === $em) {
throw new FormException(sprintf('Class "%s" is not a managed Doctrine entity. Did you forget to map it?', $options['class']));
}
return $em;
};
$queryBuilderNormalizer = function (Options $options, $queryBuilder) {
if (null !== $queryBuilder && !is_callable($queryBuilder)) {
throw new FormException(sprintf('Option "queryBuilder" should be a callable, %s given', is_object($queryBuilder) ? get_class($queryBuilder) : gettype($queryBuilder)));
}
return $queryBuilder;
};
$resolver->setNormalizers(array('em' => $emNormalizer, 'queryBuilder' => $queryBuilderNormalizer));
}
示例8: setDefaultOptions
/**
* {@inheritDoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array('entity_class' => null, 'config_id' => null));
$resolver->setNormalizers(array('choices' => function (Options $options, $value) {
if (!empty($value)) {
return $value;
}
$entityClass = $options['entity_class'];
if (!$entityClass && $options->has('config_id')) {
$configId = $options['config_id'];
if ($configId && $configId instanceof ConfigIdInterface) {
$entityClass = $configId->getClassName();
}
}
$choices = array();
if ($entityClass) {
/** @var WorkflowDefinition[] $definitions */
$definitions = $this->registry->getRepository('OroWorkflowBundle:WorkflowDefinition')->findBy(array('relatedEntity' => $entityClass));
foreach ($definitions as $definition) {
$name = $definition->getName();
$label = $definition->getLabel();
$choices[$name] = $label;
}
}
return $choices;
}));
}
示例9: setDefaultOptions
/**
* {@inheritDoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$uploadConfig = array('uploadRoute' => 'comur_api_upload', 'uploadUrl' => null, 'webDir' => null, 'fileExt' => '*.jpg;*.gif;*.png;*.jpeg', 'libraryDir' => null, 'libraryRoute' => 'comur_api_image_library', 'showLibrary' => true, 'saveOriginal' => false, 'generateFilename' => true);
$cropConfig = array('minWidth' => 1, 'minHeight' => 1, 'aspectRatio' => true, 'cropRoute' => 'comur_api_crop', 'forceResize' => true, 'thumbs' => null);
$resolver->setDefaults(array('uploadConfig' => $uploadConfig, 'cropConfig' => $cropConfig, 'inherit_data' => true));
$isGallery = $this->isGallery;
$galleryDir = $this->galleryDir;
$resolver->setNormalizers(array('uploadConfig' => function (Options $options, $value) use($uploadConfig, $isGallery, $galleryDir) {
$config = array_merge($uploadConfig, $value);
if ($isGallery) {
$config['uploadUrl'] = $config['uploadUrl'] . '/' . $galleryDir;
$config['webDir'] = $config['webDir'] . '/' . $galleryDir;
$config['saveOriginal'] = false;
}
if (!isset($config['libraryDir'])) {
$config['libraryDir'] = $config['uploadUrl'];
}
// if($config['saveOriginal']){
// $options['compound']=true;
// }
return $config;
}, 'cropConfig' => function (Options $options, $value) use($cropConfig) {
return array_merge($cropConfig, $value);
}));
}
示例10: setDefaultOptions
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$defaultConfigs = ['placeholder' => 'oro.entity.form.choose_entity', 'result_template_twig' => 'OroEntityBundle:Choice:entity/result.html.twig', 'selection_template_twig' => 'OroEntityBundle:Choice:entity/selection.html.twig'];
$resolver->setDefaults(['choices' => function (Options $options) {
return $this->getChoices($options['show_plural']);
}, 'choice_attr' => function ($choice) {
return $this->getChoiceAttributes($choice);
}, 'empty_value' => '', 'show_plural' => false, 'configs' => $defaultConfigs, 'translatable_options' => false, 'group_by' => function () {
// @codingStandardsIgnoreStart
/**
* This option was added since duplicated values are removed otherwise
* (which happens if there are at least 2 entities having the same translations in
* currently used language)
*
* Groups are created by flipping choices first
* https://github.com/symfony/symfony/blob/c25e054d9e6b376d1f242e9d92454e7037bc4c01/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php#L444
* then choiceView is created from each group:
* https://github.com/symfony/symfony/blob/c25e054d9e6b376d1f242e9d92454e7037bc4c01/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php#L174
*/
// @codingStandardsIgnoreEnd
return null;
}]);
$resolver->setNormalizers(['configs' => function (Options $options, $configs) use($defaultConfigs) {
return array_merge($defaultConfigs, $configs);
}]);
}
示例11: setDefaultOptions
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(['multiple' => true, 'expanded' => true, 'choices' => $this->getChoices()]);
$resolver->setNormalizers(['disabled' => function (Options $options, $value) {
return $this->isReadOnly($options) ? true : $value;
}]);
}
示例12: setDefaultOptions
/**
* Custom options:
* - "workflow_item" - required, instance of WorkflowItem entity
* - "step_name" - optional, name of step
*
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setRequired(array('workflow_item'));
$resolver->setOptional(array('step_name'));
$resolver->setAllowedTypes(array('step_name' => 'string'));
$resolver->setNormalizers(array('step_name' => function (Options $options, $stepName) {
/** @var Workflow $workflow */
$workflow = $options['workflow'];
/** @var WorkflowItem $workflowItem */
$workflowItem = $options['workflow_item'];
if (!$stepName) {
$stepName = $workflowItem->getCurrentStepName();
}
if (!$workflow->getStepManager()->getStep($stepName)) {
throw new InvalidConfigurationException(sprintf('Invalid reference to unknown step "%s" of workflow "%s".', $stepName, $workflow->getName()));
}
return $stepName;
}, 'disable_attribute_fields' => function (Options $options, $disableAttributeFields) {
/** @var Workflow $workflow */
$workflow = $options['workflow'];
/** @var WorkflowItem $workflowItem */
$workflowItem = $options['workflow_item'];
$step = $workflow->getStepManager()->getStep($options['step_name']);
if ($step->getName() !== $workflowItem->getCurrentStepName() || $workflowItem->isClosed()) {
$disableAttributeFields = true;
}
return $disableAttributeFields;
}));
}
示例13: setDefaultOptions
/**
* {@inheritDoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setRequired(['attribute_type']);
$resolver->setDefaults(['empty_value' => 'orob2b.attribute.attribute_type_constraint.none']);
$resolver->setNormalizers(['choices' => function (Options $options, $value) {
if (!empty($value)) {
return $value;
}
$choices = [];
if ($options['attribute_type'] instanceof AttributeTypeInterface) {
$constraints = $options['attribute_type']->getOptionalConstraints();
} elseif (is_string($options['attribute_type'])) {
$attributeType = $this->attributeTypeRegistry->getTypeByName($options['attribute_type']);
if (!$attributeType) {
throw new \LogicException(sprintf('Attribute type name "%s" is not exist in attribute type registry.', $options['attribute_type']));
}
$constraints = $attributeType->getOptionalConstraints();
} else {
throw new UnexpectedTypeException($options['attribute_type'], 'OroB2B\\Bundle\\AttributeBundle\\AttributeType\\AttributeTypeInterface or string');
}
foreach ($constraints as $choice) {
$choices[$choice->getAlias()] = 'orob2b.validation.constraint.alias.' . $choice->getAlias();
}
return $choices;
}]);
}
示例14: setDefaultOptions
/**
* (non-PHPdoc)
* @see Symfony\Component\Form.AbstractType::setDefaultOptions()
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$defaultConfigs = array('showOn' => 'button', 'dateFormat' => 'yy-mm-dd', 'timeFormat' => 'HH:mm', 'showSecond' => false);
$resolver->setDefaults(array('input' => 'datetime', 'with_seconds' => false, 'use_meridiem' => false, 'date_timezone' => null, 'user_timezone' => null, 'datetime_format' => 'Y-m-d H:i', 'parts' => array('year', 'month', 'day', 'hour', 'minute'), 'translation_domain' => 'NeutronFormBundle', 'configs' => $defaultConfigs));
$resolver->setNormalizers(array('datetime_format' => function (Options $options, $value) {
if ($options->has('with_seconds') && $options->get('with_seconds') === true) {
return $options->get('use_meridiem') === true ? 'Y-m-d h:i:s a' : 'Y-m-d H:i:s';
}
return $options->get('use_meridiem') === true ? 'Y-m-d h:i a' : 'Y-m-d H:i';
}, 'parts' => function (Options $options, $value) {
if ($options->has('with_seconds') && $options->get('with_seconds') === true) {
return array('year', 'month', 'day', 'hour', 'minute', 'second');
}
return array('year', 'month', 'day', 'hour', 'minute');
}, 'configs' => function (Options $options, $value) use($defaultConfigs) {
$configs = array_replace_recursive($defaultConfigs, $value);
if (!$options->has('with_seconds') || $options->get('with_seconds') === false) {
$configs['timeFormat'] = $options->get('use_meridiem') === true ? 'hh:mm tt' : 'HH:mm';
$configs['showSecond'] = false;
} else {
$configs['timeFormat'] = $options->get('use_meridiem') === true ? 'hh:mm:ss tt' : 'HH:mm:ss';
$configs['showSecond'] = true;
}
return $configs;
}));
$resolver->setAllowedValues(array('input' => array('datetime', 'string', 'timestamp', 'array'), 'datetime_format' => array('Y-m-d H:i:s', 'Y-m-d h:i:s a', 'Y-m-d H:i', 'Y-m-d h:i a')));
}
示例15: setDefaultOptions
/**
* Options:
* - 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 setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(['existing_entity_grid_id' => 'id', 'create_enabled' => true, 'create_acl' => null, 'create_form_route' => null, 'create_form_route_parameters' => [], '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.');
}]);
}