Skip to content

Commit

Permalink
merged branch bschussek/filtertonormalizer (PR symfony#5002)
Browse files Browse the repository at this point in the history
Commits
-------

3075fa6 [OptionsResolver] Renamed filters to normalizers

Discussion
----------

[OptionsResolver] Renamed filters to normalizers

Bug fix: no
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: -
Todo: -

This PR fixes the naming to be in line with the Serializer component.
  • Loading branch information
fabpot committed Jul 21, 2012
2 parents 9f157a1 + 3075fa6 commit 638058a
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 33 deletions.
6 changes: 3 additions & 3 deletions src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
return $choiceListCache[$hash];
};

$emFilter = function (Options $options, $em) use ($registry) {
$emNormalizer = function (Options $options, $em) use ($registry) {
/* @var ManagerRegistry $registry */
if (null !== $em) {
return $registry->getManager($em);
Expand All @@ -134,8 +134,8 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
'group_by' => null,
));

$resolver->setFilters(array(
'em' => $emFilter,
$resolver->setNormalizers(array(
'em' => $emNormalizer,
));
}

Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
return $options['required'] ? null : '';
};

$emptyValueFilter = function (Options $options, $emptyValue) {
$emptyValueNormalizer = function (Options $options, $emptyValue) {
if ($options['multiple'] || $options['expanded']) {
// never use an empty value for these cases
return null;
Expand Down Expand Up @@ -186,8 +186,8 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
'compound' => $compound,
));

$resolver->setFilters(array(
'empty_value' => $emptyValueFilter,
$resolver->setNormalizers(array(
'empty_value' => $emptyValueNormalizer,
));

$resolver->setAllowedTypes(array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function finishView(FormViewInterface $view, FormInterface $form, array $
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$optionsFilter = function (Options $options, $value) {
$optionsNormalizer = function (Options $options, $value) {
$value['block_name'] = 'entry';

return $value;
Expand All @@ -89,8 +89,8 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
'options' => array(),
));

$resolver->setFilters(array(
'options' => $optionsFilter,
$resolver->setNormalizers(array(
'options' => $optionsNormalizer,
));
}

Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Form/Extension/Core/Type/DateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
return $options['required'] ? null : '';
};

$emptyValueFilter = function (Options $options, $emptyValue) use ($emptyValueDefault) {
$emptyValueNormalizer = function (Options $options, $emptyValue) use ($emptyValueDefault) {
if (is_array($emptyValue)) {
$default = $emptyValueDefault($options);

Expand Down Expand Up @@ -216,8 +216,8 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
'compound' => $compound,
));

$resolver->setFilters(array(
'empty_value' => $emptyValueFilter,
$resolver->setNormalizers(array(
'empty_value' => $emptyValueNormalizer,
));

$resolver->setAllowedValues(array(
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Form/Extension/Core/Type/TimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
return $options['required'] ? null : '';
};

$emptyValueFilter = function (Options $options, $emptyValue) use ($emptyValueDefault) {
$emptyValueNormalizer = function (Options $options, $emptyValue) use ($emptyValueDefault) {
if (is_array($emptyValue)) {
$default = $emptyValueDefault($options);

Expand Down Expand Up @@ -186,8 +186,8 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
'compound' => $compound,
));

$resolver->setFilters(array(
'empty_value' => $emptyValueFilter,
$resolver->setNormalizers(array(
'empty_value' => $emptyValueNormalizer,
));

$resolver->setAllowedValues(array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
};

// Make sure that validation groups end up as null, closure or array
$validationGroupsFilter = function (Options $options, $groups) {
$validationGroupsNormalizer = function (Options $options, $groups) {
if (empty($groups)) {
return null;
}
Expand All @@ -72,7 +72,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
};

// Constraint should always be converted to an array
$constraintsFilter = function (Options $options, $constraints) {
$constraintsNormalizer = function (Options $options, $constraints) {
return is_object($constraints) ? array($constraints) : (array) $constraints;
};

Expand All @@ -88,9 +88,9 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
'post_max_size_message' => 'The uploaded file was too large. Please try to upload a smaller file.',
));

$resolver->setFilters(array(
'validation_groups' => $validationGroupsFilter,
'constraints' => $constraintsFilter,
$resolver->setNormalizers(array(
'validation_groups' => $validationGroupsNormalizer,
'constraints' => $constraintsNormalizer,
));
}

Expand Down
12 changes: 6 additions & 6 deletions src/Symfony/Component/OptionsResolver/OptionsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ class OptionsResolver implements OptionsResolverInterface
private $allowedTypes = array();

/**
* A list of filters transforming each resolved options.
* A list of normalizers transforming each resolved options.
* @var array
*/
private $filters = array();
private $normalizers = array();

/**
* Creates a new instance.
Expand Down Expand Up @@ -190,11 +190,11 @@ public function addAllowedTypes(array $allowedTypes)
/**
* {@inheritdoc}
*/
public function setFilters(array $filters)
public function setNormalizers(array $normalizers)
{
$this->validateOptionsExistence($filters);
$this->validateOptionsExistence($normalizers);

$this->filters = array_replace($this->filters, $filters);
$this->normalizers = array_replace($this->normalizers, $normalizers);

return $this;
}
Expand Down Expand Up @@ -232,7 +232,7 @@ public function resolve(array $options = array())
}

// Apply filters
foreach ($this->filters as $option => $filter) {
foreach ($this->normalizers as $option => $filter) {
$combinedOptions->overload($option, $filter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ public function setAllowedTypes(array $allowedTypes);
public function addAllowedTypes(array $allowedTypes);

/**
* Sets filters that are applied on resolved options.
* Sets normalizers that are applied on resolved options.
*
* The filters should be closures with the following signature:
* The normalizers should be closures with the following signature:
*
* <code>
* function (Options $options, $value)
Expand All @@ -159,13 +159,13 @@ public function addAllowedTypes(array $allowedTypes);
* The second parameter passed to the closure is the value of
* the option.
*
* The closure should return the filtered value.
* The closure should return the normalized value.
*
* @param array $filters An array of filter closures.
* @param array $normalizers An array of closures.
*
* @return OptionsResolverInterface The resolver instance.
*/
public function setFilters(array $filters);
public function setNormalizers(array $normalizers);

/**
* Returns whether an option is known.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,13 +538,13 @@ public function testNotRequiredIfRequiredAndDefaultValue()
$this->assertFalse($this->resolver->isRequired('foo'));
}

public function testFiltersTransformFinalOptions()
public function testNormalizersTransformFinalOptions()
{
$this->resolver->setDefaults(array(
'foo' => 'bar',
'bam' => 'baz',
));
$this->resolver->setFilters(array(
$this->resolver->setNormalizers(array(
'foo' => function (Options $options, $value) {
return $options['bam'] . '[' . $value . ']';
},
Expand Down

0 comments on commit 638058a

Please sign in to comment.