feature #16024 [Validator] removed deprecated features in Validator and Form (fabpot)

This PR was merged into the 3.0-dev branch.

Discussion
----------

[Validator] removed deprecated features in Validator and Form

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Commits
-------

33f3400 [Form] removed deprecated features
582f3a3 [Form] removed deprecated FormType::getName()
bfba6ca [Form] removed precision option
17cedd3 [Form] removed usage of Validator deprecated features
8fd32ba [Validator] remove the API_VERSION
2a6b629 [Validator] removed deprecated methods
925ecaf [Validator] removed deprecated features in Constraints
This commit is contained in:
Fabien Potencier 2015-10-01 17:00:24 +02:00
commit 48d11693b5
204 changed files with 328 additions and 7090 deletions

View File

@ -22,7 +22,6 @@ use Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntityValidator;
use Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest;
use Symfony\Component\Validator\Validation;
use Doctrine\ORM\Tools\SchemaTool;
/**
@ -47,11 +46,6 @@ class UniqueEntityValidatorTest extends AbstractConstraintValidatorTest
*/
protected $repository;
protected function getApiVersion()
{
return Validation::API_VERSION_2_5;
}
protected function setUp()
{
$this->em = DoctrineTestHelper::createTestEntityManager();

View File

@ -13,7 +13,7 @@ namespace Symfony\Bridge\Twig\Extension;
use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser;
use Symfony\Bridge\Twig\Form\TwigRendererInterface;
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
/**
* FormExtension extends Twig with form capabilities.

View File

@ -156,15 +156,7 @@ abstract class AbstractExtension implements FormExtensionInterface
throw new UnexpectedTypeException($type, 'Symfony\Component\Form\FormTypeInterface');
}
// Since Symfony 3.0 types are identified by their FQCN
$fqcn = get_class($type);
$legacyName = $type->getName();
$this->types[$fqcn] = $type;
if ($legacyName) {
$this->types[$legacyName] = $type;
}
$this->types[get_class($type)] = $type;
}
}

View File

@ -47,15 +47,6 @@ abstract class AbstractType implements FormTypeInterface
{
}
/**
* {@inheritdoc}
*/
public function getName()
{
// As of Symfony 2.8, the name defaults to the fully-qualified class name
return get_class($this);
}
/**
* Returns the prefix of the template block name for this type.
*
@ -66,11 +57,7 @@ abstract class AbstractType implements FormTypeInterface
*/
public function getBlockPrefix()
{
$fqcn = get_class($this);
$name = $this->getName();
// For BC: Use the name as block prefix if one is set
return $name !== $fqcn ? $name : StringUtil::fqcnToBlockPrefix($fqcn);
return StringUtil::fqcnToBlockPrefix(get_class($this));
}
/**

View File

@ -378,23 +378,6 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
throw new BadMethodCallException('Buttons do not support data mapping.');
}
/**
* Unsupported method.
*
* This method should not be invoked.
*
* @param bool $virtual
*
* @throws BadMethodCallException
*
* @deprecated since version 2.3, to be removed in 3.0. Use
* {@link setInheritData()} instead.
*/
public function setVirtual($virtual)
{
throw new BadMethodCallException('Buttons cannot be virtual.');
}
/**
* Unsupported method.
*
@ -587,21 +570,6 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
return false;
}
/**
* Unsupported method.
*
* @return bool Always returns false.
*
* @deprecated since version 2.3, to be removed in 3.0.
* Use {@link getInheritData()} instead.
*/
public function getVirtual()
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.3 and will be removed in 3.0. Use the Symfony\Component\Form\FormConfigBuilder::getInheritData method instead.', E_USER_DEPRECATED);
return false;
}
/**
* Unsupported method.
*

View File

@ -15,12 +15,10 @@ use Symfony\Component\Form\ChoiceList\ArrayKeyChoiceList;
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
use Symfony\Component\Form\ChoiceList\LazyChoiceList;
use Symfony\Component\Form\ChoiceList\LegacyChoiceListAdapter;
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView;
use Symfony\Component\Form\ChoiceList\View\ChoiceListView;
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
use Symfony\Component\Form\Extension\Core\View\ChoiceView as LegacyChoiceView;
/**
* Default implementation of {@link ChoiceListFactoryInterface}.
@ -65,23 +63,6 @@ class DefaultChoiceListFactory implements ChoiceListFactoryInterface
*/
public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, $index = null, $groupBy = null, $attr = null)
{
// Backwards compatibility
if ($list instanceof LegacyChoiceListAdapter && empty($preferredChoices)
&& null === $label && null === $index && null === $groupBy && null === $attr) {
$mapToNonLegacyChoiceView = function (LegacyChoiceView &$choiceView) {
$choiceView = new ChoiceView($choiceView->data, $choiceView->value, $choiceView->label);
};
$adaptedList = $list->getAdaptedList();
$remainingViews = $adaptedList->getRemainingViews();
$preferredViews = $adaptedList->getPreferredViews();
array_walk_recursive($remainingViews, $mapToNonLegacyChoiceView);
array_walk_recursive($preferredViews, $mapToNonLegacyChoiceView);
return new ChoiceListView($remainingViews, $preferredViews);
}
$preferredViews = array();
$otherViews = array();
$choices = $list->getChoices();

View File

@ -1,144 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\ChoiceList;
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface as LegacyChoiceListInterface;
/**
* Adapts a legacy choice list implementation to {@link ChoiceListInterface}.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated Added for backwards compatibility in Symfony 2.7, to be
* removed in Symfony 3.0.
*/
class LegacyChoiceListAdapter implements ChoiceListInterface
{
/**
* @var LegacyChoiceListInterface
*/
private $adaptedList;
/**
* @var array|null
*/
private $choices;
/**
* @var array|null
*/
private $values;
/**
* @var array|null
*/
private $structuredValues;
/**
* Adapts a legacy choice list to {@link ChoiceListInterface}.
*
* @param LegacyChoiceListInterface $adaptedList The adapted list
*/
public function __construct(LegacyChoiceListInterface $adaptedList)
{
$this->adaptedList = $adaptedList;
}
/**
* {@inheritdoc}
*/
public function getChoices()
{
if (!$this->choices) {
$this->initialize();
}
return $this->choices;
}
/**
* {@inheritdoc}
*/
public function getValues()
{
if (!$this->values) {
$this->initialize();
}
return $this->values;
}
/**
* {@inheritdoc}
*/
public function getStructuredValues()
{
if (!$this->structuredValues) {
$this->initialize();
}
return $this->structuredValues;
}
/**
* {@inheritdoc}
*/
public function getOriginalKeys()
{
if (!$this->structuredValues) {
$this->initialize();
}
return array_flip($this->structuredValues);
}
/**
* {@inheritdoc}
*/
public function getChoicesForValues(array $values)
{
return $this->adaptedList->getChoicesForValues($values);
}
/**
* {@inheritdoc}
*/
public function getValuesForChoices(array $choices)
{
return $this->adaptedList->getValuesForChoices($choices);
}
/**
* Returns the adapted choice list.
*
* @return LegacyChoiceListInterface The adapted list
*/
public function getAdaptedList()
{
return $this->adaptedList;
}
private function initialize()
{
$this->choices = array();
$this->values = array();
$this->structuredValues = $this->adaptedList->getValues();
$innerChoices = $this->adaptedList->getChoices();
foreach ($innerChoices as $index => $choice) {
$value = $this->structuredValues[$index];
$this->values[] = $value;
$this->choices[$value] = $choice;
}
}
}

View File

@ -9,15 +9,12 @@
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Extension\Core\View;
namespace Symfony\Component\Form\ChoiceList\View;
/**
* Represents a choice in templates.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.7, to be removed in 3.0.
* Use {@link \Symfony\Component\Form\ChoiceList\View\ChoiceView} instead.
*/
class ChoiceView
{
@ -42,32 +39,6 @@ class ChoiceView
*/
public $data;
/**
* Creates a new ChoiceView.
*
* @param mixed $data The original choice.
* @param string $value The view representation of the choice.
* @param string $label The label displayed to humans.
*/
public function __construct($data, $value, $label)
{
$this->data = $data;
$this->value = $value;
$this->label = $label;
}
}
namespace Symfony\Component\Form\ChoiceList\View;
use Symfony\Component\Form\Extension\Core\View\ChoiceView as LegacyChoiceView;
/**
* Represents a choice in templates.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class ChoiceView extends LegacyChoiceView
{
/**
* Additional attributes for the HTML tag.
*
@ -85,8 +56,9 @@ class ChoiceView extends LegacyChoiceView
*/
public function __construct($data, $value, $label, array $attr = array())
{
parent::__construct($data, $value, $label);
$this->data = $data;
$this->value = $value;
$this->label = $label;
$this->attr = $attr;
}
}

View File

@ -1,30 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Exception;
/**
* Alias of {@link AlreadySubmittedException}.
*
* @deprecated since version 2.3, to be removed in 3.0.
* Use {@link AlreadySubmittedException} instead.
*/
class AlreadyBoundException extends LogicException
{
public function __construct($message = '', $code = 0, \Exception $previous = null)
{
if (__CLASS__ === get_class($this)) {
@trigger_error('The '.__CLASS__.' class is deprecated since version 2.3 and will be removed in 3.0. Use the Symfony\Component\Form\Exception\AlreadySubmittedException class instead.', E_USER_DEPRECATED);
}
parent::__construct($message, $code, $previous);
}
}

View File

@ -17,6 +17,6 @@ namespace Symfony\Component\Form\Exception;
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class AlreadySubmittedException extends AlreadyBoundException
class AlreadySubmittedException extends LogicException
{
}

View File

@ -1,523 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Extension\Core\ChoiceList;
@trigger_error('The '.__NAMESPACE__.'\ChoiceList class is deprecated since version 2.7 and will be removed in 3.0. Use Symfony\Component\Form\ChoiceList\ArrayChoiceList instead.', E_USER_DEPRECATED);
use Symfony\Component\Form\FormConfigBuilder;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\Exception\InvalidConfigurationException;
use Symfony\Component\Form\Exception\InvalidArgumentException;
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
/**
* A choice list for choices of arbitrary data types.
*
* Choices and labels are passed in two arrays. The indices of the choices
* and the labels should match. Choices may also be given as hierarchy of
* unlimited depth by creating nested arrays. The title of the sub-hierarchy
* can be stored in the array key pointing to the nested array. The topmost
* level of the hierarchy may also be a \Traversable.
*
* <code>
* $choices = array(true, false);
* $labels = array('Agree', 'Disagree');
* $choiceList = new ArrayChoiceList($choices, $labels);
* </code>
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.7, to be removed in 3.0.
* Use {@link \Symfony\Component\Form\ChoiceList\ArrayChoiceList} instead.
*/
class ChoiceList implements ChoiceListInterface
{
/**
* The choices with their indices as keys.
*
* @var array
*/
protected $choices = array();
/**
* The choice values with the indices of the matching choices as keys.
*
* @var array
*/
protected $values = array();
/**
* The preferred view objects as hierarchy containing also the choice groups
* with the indices of the matching choices as bottom-level keys.
*
* @var array
*/
private $preferredViews = array();
/**
* The non-preferred view objects as hierarchy containing also the choice
* groups with the indices of the matching choices as bottom-level keys.
*
* @var array
*/
private $remainingViews = array();
/**
* Creates a new choice list.
*
* @param array|\Traversable $choices The array of choices. Choices may also be given
* as hierarchy of unlimited depth. Hierarchies are
* created by creating nested arrays. The title of
* the sub-hierarchy can be stored in the array
* key pointing to the nested array. The topmost
* level of the hierarchy may also be a \Traversable.
* @param array $labels The array of labels. The structure of this array
* should match the structure of $choices.
* @param array $preferredChoices A flat array of choices that should be
* presented to the user with priority.
*
* @throws UnexpectedTypeException If the choices are not an array or \Traversable.
*/
public function __construct($choices, array $labels, array $preferredChoices = array())
{
if (!is_array($choices) && !$choices instanceof \Traversable) {
throw new UnexpectedTypeException($choices, 'array or \Traversable');
}
$this->initialize($choices, $labels, $preferredChoices);
}
/**
* Initializes the list with choices.
*
* Safe to be called multiple times. The list is cleared on every call.
*
* @param array|\Traversable $choices The choices to write into the list.
* @param array $labels The labels belonging to the choices.
* @param array $preferredChoices The choices to display with priority.
*/
protected function initialize($choices, array $labels, array $preferredChoices)
{
$this->choices = array();
$this->values = array();
$this->preferredViews = array();
$this->remainingViews = array();
$this->addChoices(
$this->preferredViews,
$this->remainingViews,
$choices,
$labels,
$preferredChoices
);
}
/**
* {@inheritdoc}
*/
public function getChoices()
{
return $this->choices;
}
/**
* {@inheritdoc}
*/
public function getValues()
{
return $this->values;
}
/**
* {@inheritdoc}
*/
public function getPreferredViews()
{
return $this->preferredViews;
}
/**
* {@inheritdoc}
*/
public function getRemainingViews()
{
return $this->remainingViews;
}
/**
* {@inheritdoc}
*/
public function getChoicesForValues(array $values)
{
$values = $this->fixValues($values);
$choices = array();
foreach ($values as $i => $givenValue) {
foreach ($this->values as $j => $value) {
if ($value === $givenValue) {
$choices[$i] = $this->choices[$j];
unset($values[$i]);
if (0 === count($values)) {
break 2;
}
}
}
}
return $choices;
}
/**
* {@inheritdoc}
*/
public function getValuesForChoices(array $choices)
{
$choices = $this->fixChoices($choices);
$values = array();
foreach ($choices as $i => $givenChoice) {
foreach ($this->choices as $j => $choice) {
if ($choice === $givenChoice) {
$values[$i] = $this->values[$j];
unset($choices[$i]);
if (0 === count($choices)) {
break 2;
}
}
}
}
return $values;
}
/**
* {@inheritdoc}
*
* @deprecated since version 2.4, to be removed in 3.0.
*/
public function getIndicesForChoices(array $choices)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.4 and will be removed in 3.0.', E_USER_DEPRECATED);
$choices = $this->fixChoices($choices);
$indices = array();
foreach ($choices as $i => $givenChoice) {
foreach ($this->choices as $j => $choice) {
if ($choice === $givenChoice) {
$indices[$i] = $j;
unset($choices[$i]);
if (0 === count($choices)) {
break 2;
}
}
}
}
return $indices;
}
/**
* {@inheritdoc}
*
* @deprecated since version 2.4, to be removed in 3.0.
*/
public function getIndicesForValues(array $values)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.4 and will be removed in 3.0.', E_USER_DEPRECATED);
$values = $this->fixValues($values);
$indices = array();
foreach ($values as $i => $givenValue) {
foreach ($this->values as $j => $value) {
if ($value === $givenValue) {
$indices[$i] = $j;
unset($values[$i]);
if (0 === count($values)) {
break 2;
}
}
}
}
return $indices;
}
/**
* Recursively adds the given choices to the list.
*
* @param array $bucketForPreferred The bucket where to store the preferred
* view objects.
* @param array $bucketForRemaining The bucket where to store the
* non-preferred view objects.
* @param array|\Traversable $choices The list of choices.
* @param array $labels The labels corresponding to the choices.
* @param array $preferredChoices The preferred choices.
*
* @throws InvalidArgumentException If the structures of the choices and labels array do not match.
* @throws InvalidConfigurationException If no valid value or index could be created for a choice.
*/
protected function addChoices(array &$bucketForPreferred, array &$bucketForRemaining, $choices, array $labels, array $preferredChoices)
{
// Add choices to the nested buckets
foreach ($choices as $group => $choice) {
if (!array_key_exists($group, $labels)) {
throw new InvalidArgumentException('The structures of the choices and labels array do not match.');
}
if (is_array($choice)) {
// Don't do the work if the array is empty
if (count($choice) > 0) {
$this->addChoiceGroup(
$group,
$bucketForPreferred,
$bucketForRemaining,
$choice,
$labels[$group],
$preferredChoices
);
}
} else {
$this->addChoice(
$bucketForPreferred,
$bucketForRemaining,
$choice,
$labels[$group],
$preferredChoices
);
}
}
}
/**
* Recursively adds a choice group.
*
* @param string $group The name of the group.
* @param array $bucketForPreferred The bucket where to store the preferred
* view objects.
* @param array $bucketForRemaining The bucket where to store the
* non-preferred view objects.
* @param array $choices The list of choices in the group.
* @param array $labels The labels corresponding to the choices in the group.
* @param array $preferredChoices The preferred choices.
*
* @throws InvalidConfigurationException If no valid value or index could be created for a choice.
*/
protected function addChoiceGroup($group, array &$bucketForPreferred, array &$bucketForRemaining, array $choices, array $labels, array $preferredChoices)
{
// If this is a choice group, create a new level in the choice
// key hierarchy
$bucketForPreferred[$group] = array();
$bucketForRemaining[$group] = array();
$this->addChoices(
$bucketForPreferred[$group],
$bucketForRemaining[$group],
$choices,
$labels,
$preferredChoices
);
// Remove child levels if empty
if (empty($bucketForPreferred[$group])) {
unset($bucketForPreferred[$group]);
}
if (empty($bucketForRemaining[$group])) {
unset($bucketForRemaining[$group]);
}
}
/**
* Adds a new choice.
*
* @param array $bucketForPreferred The bucket where to store the preferred
* view objects.
* @param array $bucketForRemaining The bucket where to store the
* non-preferred view objects.
* @param mixed $choice The choice to add.
* @param string $label The label for the choice.
* @param array $preferredChoices The preferred choices.
*
* @throws InvalidConfigurationException If no valid value or index could be created.
*/
protected function addChoice(array &$bucketForPreferred, array &$bucketForRemaining, $choice, $label, array $preferredChoices)
{
$index = $this->createIndex($choice);
if ('' === $index || null === $index || !FormConfigBuilder::isValidName((string) $index)) {
throw new InvalidConfigurationException(sprintf('The index "%s" created by the choice list is invalid. It should be a valid, non-empty Form name.', $index));
}
$value = $this->createValue($choice);
if (!is_string($value)) {
throw new InvalidConfigurationException(sprintf('The value created by the choice list is of type "%s", but should be a string.', gettype($value)));
}
$view = new ChoiceView($choice, $value, $label);
$this->choices[$index] = $this->fixChoice($choice);
$this->values[$index] = $value;
if ($this->isPreferred($choice, $preferredChoices)) {
$bucketForPreferred[$index] = $view;
} else {
$bucketForRemaining[$index] = $view;
}
}
/**
* Returns whether the given choice should be preferred judging by the
* given array of preferred choices.
*
* Extension point to optimize performance by changing the structure of the
* $preferredChoices array.
*
* @param mixed $choice The choice to test.
* @param array $preferredChoices An array of preferred choices.
*
* @return bool Whether the choice is preferred.
*/
protected function isPreferred($choice, array $preferredChoices)
{
return in_array($choice, $preferredChoices, true);
}
/**
* Creates a new unique index for this choice.
*
* Extension point to change the indexing strategy.
*
* @param mixed $choice The choice to create an index for
*
* @return int|string A unique index containing only ASCII letters,
* digits and underscores.
*/
protected function createIndex($choice)
{
return count($this->choices);
}
/**
* Creates a new unique value for this choice.
*
* By default, an integer is generated since it cannot be guaranteed that
* all values in the list are convertible to (unique) strings. Subclasses
* can override this behaviour if they can guarantee this property.
*
* @param mixed $choice The choice to create a value for
*
* @return string A unique string.
*/
protected function createValue($choice)
{
return (string) count($this->values);
}
/**
* Fixes the data type of the given choice value to avoid comparison
* problems.
*
* @param mixed $value The choice value.
*
* @return string The value as string.
*/
protected function fixValue($value)
{
return (string) $value;
}
/**
* Fixes the data types of the given choice values to avoid comparison
* problems.
*
* @param array $values The choice values.
*
* @return array The values as strings.
*/
protected function fixValues(array $values)
{
foreach ($values as $i => $value) {
$values[$i] = $this->fixValue($value);
}
return $values;
}
/**
* Fixes the data type of the given choice index to avoid comparison
* problems.
*
* @param mixed $index The choice index.
*
* @return int|string The index as PHP array key.
*/
protected function fixIndex($index)
{
if (is_bool($index) || (string) (int) $index === (string) $index) {
return (int) $index;
}
return (string) $index;
}
/**
* Fixes the data types of the given choice indices to avoid comparison
* problems.
*
* @param array $indices The choice indices.
*
* @return array The indices as strings.
*/
protected function fixIndices(array $indices)
{
foreach ($indices as $i => $index) {
$indices[$i] = $this->fixIndex($index);
}
return $indices;
}
/**
* Fixes the data type of the given choice to avoid comparison problems.
*
* Extension point. In this implementation, choices are guaranteed to
* always maintain their type and thus can be typesafely compared.
*
* @param mixed $choice The choice
*
* @return mixed The fixed choice
*/
protected function fixChoice($choice)
{
return $choice;
}
/**
* Fixes the data type of the given choices to avoid comparison problems.
*
* @param array $choices The choices.
*
* @return array The fixed choices.
*
* @see fixChoice()
*/
protected function fixChoices(array $choices)
{
return $choices;
}
}

View File

@ -1,168 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Extension\Core\ChoiceList;
/**
* Contains choices that can be selected in a form field.
*
* Each choice has three different properties:
*
* - Choice: The choice that should be returned to the application by the
* choice field. Can be any scalar value or an object, but no
* array.
* - Label: A text representing the choice that is displayed to the user.
* - Value: A uniquely identifying value that can contain arbitrary
* characters, but no arrays or objects. This value is displayed
* in the HTML "value" attribute.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.7, to be removed in 3.0.
* Use {@link \Symfony\Component\Form\ChoiceList\ChoiceListInterface} instead.
*/
interface ChoiceListInterface
{
/**
* Returns the list of choices.
*
* @return array The choices with their indices as keys
*/
public function getChoices();
/**
* Returns the values for the choices.
*
* @return array The values with the corresponding choice indices as keys
*/
public function getValues();
/**
* Returns the choice views of the preferred choices as nested array with
* the choice groups as top-level keys.
*
* Example:
*
* <source>
* array(
* 'Group 1' => array(
* 10 => ChoiceView object,
* 20 => ChoiceView object,
* ),
* 'Group 2' => array(
* 30 => ChoiceView object,
* ),
* )
* </source>
*
* @return array A nested array containing the views with the corresponding
* choice indices as keys on the lowest levels and the choice
* group names in the keys of the higher levels
*/
public function getPreferredViews();
/**
* Returns the choice views of the choices that are not preferred as nested
* array with the choice groups as top-level keys.
*
* Example:
*
* <source>
* array(
* 'Group 1' => array(
* 10 => ChoiceView object,
* 20 => ChoiceView object,
* ),
* 'Group 2' => array(
* 30 => ChoiceView object,
* ),
* )
* </source>
*
* @return array A nested array containing the views with the corresponding
* choice indices as keys on the lowest levels and the choice
* group names in the keys of the higher levels
*
* @see getPreferredValues()
*/
public function getRemainingViews();
/**
* Returns the choices corresponding to the given values.
*
* The choices can have any data type.
*
* The choices must be returned with the same keys and in the same order
* as the corresponding values in the given array.
*
* @param array $values An array of choice values. Not existing values in
* this array are ignored
*
* @return array An array of choices with ascending, 0-based numeric keys
*/
public function getChoicesForValues(array $values);
/**
* Returns the values corresponding to the given choices.
*
* The values must be strings.
*
* The values must be returned with the same keys and in the same order
* as the corresponding choices in the given array.
*
* @param array $choices An array of choices. Not existing choices in this
* array are ignored
*
* @return array An array of choice values with ascending, 0-based numeric
* keys
*/
public function getValuesForChoices(array $choices);
/**
* Returns the indices corresponding to the given choices.
*
* The indices must be positive integers or strings accepted by
* {@link \Symfony\Component\Form\FormConfigBuilder::validateName()}.
*
* The index "placeholder" is internally reserved.
*
* The indices must be returned with the same keys and in the same order
* as the corresponding choices in the given array.
*
* @param array $choices An array of choices. Not existing choices in this
* array are ignored
*
* @return array An array of indices with ascending, 0-based numeric keys
*
* @deprecated since version 2.4, to be removed in 3.0.
*/
public function getIndicesForChoices(array $choices);
/**
* Returns the indices corresponding to the given values.
*
* The indices must be positive integers or strings accepted by
* {@link \Symfony\Component\Form\FormConfigBuilder::validateName()}.
*
* The index "placeholder" is internally reserved.
*
* The indices must be returned with the same keys and in the same order
* as the corresponding values in the given array.
*
* @param array $values An array of choice values. Not existing values in
* this array are ignored
*
* @return array An array of indices with ascending, 0-based numeric keys
*
* @deprecated since version 2.4, to be removed in 3.0.
*/
public function getIndicesForValues(array $values);
}

View File

@ -1,162 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Extension\Core\ChoiceList;
@trigger_error('The '.__NAMESPACE__.'\LazyChoiceList class is deprecated since version 2.7 and will be removed in 3.0. Use Symfony\Component\Form\ChoiceList\ArrayChoiceList instead.', E_USER_DEPRECATED);
use Symfony\Component\Form\Exception\InvalidArgumentException;
/**
* A choice list that is loaded lazily.
*
* This list loads itself as soon as any of the getters is accessed for the
* first time. You should implement loadChoiceList() in your child classes,
* which should return a ChoiceListInterface instance.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.7, to be removed in 3.0.
* Use {@link \Symfony\Component\Form\ChoiceList\LazyChoiceList} instead.
*/
abstract class LazyChoiceList implements ChoiceListInterface
{
/**
* The loaded choice list.
*
* @var ChoiceListInterface
*/
private $choiceList;
/**
* {@inheritdoc}
*/
public function getChoices()
{
if (!$this->choiceList) {
$this->load();
}
return $this->choiceList->getChoices();
}
/**
* {@inheritdoc}
*/
public function getValues()
{
if (!$this->choiceList) {
$this->load();
}
return $this->choiceList->getValues();
}
/**
* {@inheritdoc}
*/
public function getPreferredViews()
{
if (!$this->choiceList) {
$this->load();
}
return $this->choiceList->getPreferredViews();
}
/**
* {@inheritdoc}
*/
public function getRemainingViews()
{
if (!$this->choiceList) {
$this->load();
}
return $this->choiceList->getRemainingViews();
}
/**
* {@inheritdoc}
*/
public function getChoicesForValues(array $values)
{
if (!$this->choiceList) {
$this->load();
}
return $this->choiceList->getChoicesForValues($values);
}
/**
* {@inheritdoc}
*/
public function getValuesForChoices(array $choices)
{
if (!$this->choiceList) {
$this->load();
}
return $this->choiceList->getValuesForChoices($choices);
}
/**
* {@inheritdoc}
*
* @deprecated since version 2.4, to be removed in 3.0.
*/
public function getIndicesForChoices(array $choices)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.4 and will be removed in 3.0.', E_USER_DEPRECATED);
if (!$this->choiceList) {
$this->load();
}
return $this->choiceList->getIndicesForChoices($choices);
}
/**
* {@inheritdoc}
*
* @deprecated since version 2.4, to be removed in 3.0.
*/
public function getIndicesForValues(array $values)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.4 and will be removed in 3.0.', E_USER_DEPRECATED);
if (!$this->choiceList) {
$this->load();
}
return $this->choiceList->getIndicesForValues($values);
}
/**
* Loads the choice list.
*
* Should be implemented by child classes.
*
* @return ChoiceListInterface The loaded choice list
*/
abstract protected function loadChoiceList();
private function load()
{
$choiceList = $this->loadChoiceList();
if (!$choiceList instanceof ChoiceListInterface) {
throw new InvalidArgumentException(sprintf('loadChoiceList() should return a ChoiceListInterface instance. Got %s', gettype($choiceList)));
}
$this->choiceList = $choiceList;
}
}

View File

@ -1,267 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Extension\Core\ChoiceList;
@trigger_error('The '.__NAMESPACE__.'\ObjectChoiceList class is deprecated since version 2.7 and will be removed in 3.0. Use Symfony\Component\Form\ChoiceList\ArrayChoiceList instead.', E_USER_DEPRECATED);
use Symfony\Component\Form\Exception\StringCastException;
use Symfony\Component\Form\Exception\InvalidArgumentException;
use Symfony\Component\PropertyAccess\PropertyPath;
use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
/**
* A choice list for object choices.
*
* Supports generation of choice labels, choice groups and choice values
* by calling getters of the object (or associated objects).
*
* <code>
* $choices = array($user1, $user2);
*
* // call getName() to determine the choice labels
* $choiceList = new ObjectChoiceList($choices, 'name');
* </code>
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since Symfony 2.7, to be removed in version 3.0.
* Use {@link \Symfony\Component\Form\ChoiceList\ArrayChoiceList} instead.
*/
class ObjectChoiceList extends ChoiceList
{
/**
* @var PropertyAccessorInterface
*/
private $propertyAccessor;
/**
* The property path used to obtain the choice label.
*
* @var PropertyPath
*/
private $labelPath;
/**
* The property path used for object grouping.
*
* @var PropertyPath
*/
private $groupPath;
/**
* The property path used to obtain the choice value.
*
* @var PropertyPath
*/
private $valuePath;
/**
* Creates a new object choice list.
*
* @param array|\Traversable $choices The array of choices. Choices may also be given
* as hierarchy of unlimited depth by creating nested
* arrays. The title of the sub-hierarchy can be
* stored in the array key pointing to the nested
* array. The topmost level of the hierarchy may also
* be a \Traversable.
* @param string $labelPath A property path pointing to the property used
* for the choice labels. The value is obtained
* by calling the getter on the object. If the
* path is NULL, the object's __toString() method
* is used instead.
* @param array $preferredChoices A flat array of choices that should be
* presented to the user with priority.
* @param string $groupPath A property path pointing to the property used
* to group the choices. Only allowed if
* the choices are given as flat array.
* @param string $valuePath A property path pointing to the property used
* for the choice values. If not given, integers
* are generated instead.
* @param PropertyAccessorInterface $propertyAccessor The reflection graph for reading property paths.
*/
public function __construct($choices, $labelPath = null, array $preferredChoices = array(), $groupPath = null, $valuePath = null, PropertyAccessorInterface $propertyAccessor = null)
{
$this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
$this->labelPath = null !== $labelPath ? new PropertyPath($labelPath) : null;
$this->groupPath = null !== $groupPath ? new PropertyPath($groupPath) : null;
$this->valuePath = null !== $valuePath ? new PropertyPath($valuePath) : null;
parent::__construct($choices, array(), $preferredChoices);
}
/**
* Initializes the list with choices.
*
* Safe to be called multiple times. The list is cleared on every call.
*
* @param array|\Traversable $choices The choices to write into the list.
* @param array $labels Ignored.
* @param array $preferredChoices The choices to display with priority.
*
* @throws InvalidArgumentException When passing a hierarchy of choices and using
* the "groupPath" option at the same time.
*/
protected function initialize($choices, array $labels, array $preferredChoices)
{
if (null !== $this->groupPath) {
$groupedChoices = array();
foreach ($choices as $i => $choice) {
if (is_array($choice)) {
throw new InvalidArgumentException('You should pass a plain object array (without groups) when using the "groupPath" option.');
}
try {
$group = $this->propertyAccessor->getValue($choice, $this->groupPath);
} catch (NoSuchPropertyException $e) {
// Don't group items whose group property does not exist
// see https://github.com/symfony/symfony/commit/d9b7abb7c7a0f28e0ce970afc5e305dce5dccddf
$group = null;
}
if (null === $group) {
$groupedChoices[$i] = $choice;
} else {
$groupName = (string) $group;
if (!isset($groupedChoices[$groupName])) {
$groupedChoices[$groupName] = array();
}
$groupedChoices[$groupName][$i] = $choice;
}
}
$choices = $groupedChoices;
}
$labels = array();
$this->extractLabels($choices, $labels);
parent::initialize($choices, $labels, $preferredChoices);
}
/**
* {@inheritdoc}
*/
public function getValuesForChoices(array $choices)
{
if (!$this->valuePath) {
return parent::getValuesForChoices($choices);
}
// Use the value path to compare the choices
$choices = $this->fixChoices($choices);
$values = array();
foreach ($choices as $i => $givenChoice) {
// Ignore non-readable choices
if (!is_object($givenChoice) && !is_array($givenChoice)) {
continue;
}
$givenValue = (string) $this->propertyAccessor->getValue($givenChoice, $this->valuePath);
foreach ($this->values as $value) {
if ($value === $givenValue) {
$values[$i] = $value;
unset($choices[$i]);
if (0 === count($choices)) {
break 2;
}
}
}
}
return $values;
}
/**
* {@inheritdoc}
*
* @deprecated since version 2.4, to be removed in 3.0.
*/
public function getIndicesForChoices(array $choices)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.4 and will be removed in 3.0.', E_USER_DEPRECATED);
if (!$this->valuePath) {
return parent::getIndicesForChoices($choices);
}
// Use the value path to compare the choices
$choices = $this->fixChoices($choices);
$indices = array();
foreach ($choices as $i => $givenChoice) {
// Ignore non-readable choices
if (!is_object($givenChoice) && !is_array($givenChoice)) {
continue;
}
$givenValue = (string) $this->propertyAccessor->getValue($givenChoice, $this->valuePath);
foreach ($this->values as $j => $value) {
if ($value === $givenValue) {
$indices[$i] = $j;
unset($choices[$i]);
if (0 === count($choices)) {
break 2;
}
}
}
}
return $indices;
}
/**
* Creates a new unique value for this choice.
*
* If a property path for the value was given at object creation,
* the getter behind that path is now called to obtain a new value.
* Otherwise a new integer is generated.
*
* @param mixed $choice The choice to create a value for
*
* @return int|string A unique value without character limitations.
*/
protected function createValue($choice)
{
if ($this->valuePath) {
return (string) $this->propertyAccessor->getValue($choice, $this->valuePath);
}
return parent::createValue($choice);
}
private function extractLabels($choices, array &$labels)
{
foreach ($choices as $i => $choice) {
if (is_array($choice)) {
$labels[$i] = array();
$this->extractLabels($choice, $labels[$i]);
} elseif ($this->labelPath) {
$labels[$i] = $this->propertyAccessor->getValue($choice, $this->labelPath);
} elseif (method_exists($choice, '__toString')) {
$labels[$i] = (string) $choice;
} else {
throw new StringCastException(sprintf('A "__toString()" method was not found on the objects of type "%s" passed to the choice field. To read a custom getter instead, set the argument $labelPath to the desired property path.', get_class($choice)));
}
}
}
}

View File

@ -1,169 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Extension\Core\ChoiceList;
@trigger_error('The '.__NAMESPACE__.'\SimpleChoiceList class is deprecated since version 2.7 and will be removed in 3.0. Use Symfony\Component\Form\ChoiceList\ArrayChoiceList instead.', E_USER_DEPRECATED);
/**
* A choice list for choices of type string or integer.
*
* Choices and their associated labels can be passed in a single array. Since
* choices are passed as array keys, only strings or integer choices are
* allowed. Choices may also be given as hierarchy of unlimited depth by
* creating nested arrays. The title of the sub-hierarchy can be stored in the
* array key pointing to the nested array.
*
* <code>
* $choiceList = new SimpleChoiceList(array(
* 'creditcard' => 'Credit card payment',
* 'cash' => 'Cash payment',
* ));
* </code>
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.7, to be removed in 3.0.
* Use {@link \Symfony\Component\Form\ChoiceList\ArrayChoiceList} instead.
*/
class SimpleChoiceList extends ChoiceList
{
/**
* Creates a new simple choice list.
*
* @param array $choices The array of choices with the choices as keys and
* the labels as values. Choices may also be given
* as hierarchy of unlimited depth by creating nested
* arrays. The title of the sub-hierarchy is stored
* in the array key pointing to the nested array.
* @param array $preferredChoices A flat array of choices that should be
* presented to the user with priority.
*/
public function __construct(array $choices, array $preferredChoices = array())
{
// Flip preferred choices to speed up lookup
parent::__construct($choices, $choices, array_flip($preferredChoices));
}
/**
* {@inheritdoc}
*/
public function getChoicesForValues(array $values)
{
$values = $this->fixValues($values);
// The values are identical to the choices, so we can just return them
// to improve performance a little bit
return $this->fixChoices(array_intersect($values, $this->getValues()));
}
/**
* {@inheritdoc}
*/
public function getValuesForChoices(array $choices)
{
$choices = $this->fixChoices($choices);
// The choices are identical to the values, so we can just return them
// to improve performance a little bit
return $this->fixValues(array_intersect($choices, $this->getValues()));
}
/**
* Recursively adds the given choices to the list.
*
* Takes care of splitting the single $choices array passed in the
* constructor into choices and labels.
*
* @param array $bucketForPreferred The bucket where to store the preferred
* view objects.
* @param array $bucketForRemaining The bucket where to store the
* non-preferred view objects.
* @param array|\Traversable $choices The list of choices.
* @param array $labels Ignored.
* @param array $preferredChoices The preferred choices.
*/
protected function addChoices(array &$bucketForPreferred, array &$bucketForRemaining, $choices, array $labels, array $preferredChoices)
{
// Add choices to the nested buckets
foreach ($choices as $choice => $label) {
if (is_array($label)) {
// Don't do the work if the array is empty
if (count($label) > 0) {
$this->addChoiceGroup(
$choice,
$bucketForPreferred,
$bucketForRemaining,
$label,
$label,
$preferredChoices
);
}
} else {
$this->addChoice(
$bucketForPreferred,
$bucketForRemaining,
$choice,
$label,
$preferredChoices
);
}
}
}
/**
* Returns whether the given choice should be preferred judging by the
* given array of preferred choices.
*
* Optimized for performance by treating the preferred choices as array
* where choices are stored in the keys.
*
* @param mixed $choice The choice to test.
* @param array $preferredChoices An array of preferred choices.
*
* @return bool Whether the choice is preferred.
*/
protected function isPreferred($choice, array $preferredChoices)
{
// Optimize performance over the default implementation
return isset($preferredChoices[$choice]);
}
/**
* Converts the choice to a valid PHP array key.
*
* @param mixed $choice The choice
*
* @return string|int A valid PHP array key
*/
protected function fixChoice($choice)
{
return $this->fixIndex($choice);
}
/**
* {@inheritdoc}
*/
protected function fixChoices(array $choices)
{
return $this->fixIndices($choices);
}
/**
* {@inheritdoc}
*/
protected function createValue($choice)
{
// Choices are guaranteed to be unique and scalar, so we can simply
// convert them to strings
return (string) $choice;
}
}

View File

@ -1,121 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
@trigger_error('The class '.__NAMESPACE__.'\ChoiceToBooleanArrayTransformer is deprecated since version 2.7 and will be removed in 3.0. Use Symfony\Component\Form\Extension\Core\DataMapper\RadioListMapper instead.', E_USER_DEPRECATED);
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\TransformationFailedException;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.7, to be removed in 3.0.
* Use {@link \Symfony\Component\Form\ChoiceList\LazyChoiceList} instead.
*/
class ChoiceToBooleanArrayTransformer implements DataTransformerInterface
{
private $choiceList;
private $placeholderPresent;
/**
* Constructor.
*
* @param ChoiceListInterface $choiceList
* @param bool $placeholderPresent
*/
public function __construct(ChoiceListInterface $choiceList, $placeholderPresent)
{
$this->choiceList = $choiceList;
$this->placeholderPresent = $placeholderPresent;
}
/**
* Transforms a single choice to a format appropriate for the nested
* checkboxes/radio buttons.
*
* The result is an array with the options as keys and true/false as values,
* depending on whether a given option is selected. If this field is rendered
* as select tag, the value is not modified.
*
* @param mixed $choice An array if "multiple" is set to true, a scalar
* value otherwise.
*
* @return mixed An array
*
* @throws TransformationFailedException If the given value is not scalar or
* if the choices can not be retrieved.
*/
public function transform($choice)
{
try {
$values = $this->choiceList->getValues();
} catch (\Exception $e) {
throw new TransformationFailedException('Can not get the choice list', $e->getCode(), $e);
}
$valueMap = array_flip($this->choiceList->getValuesForChoices(array($choice)));
foreach ($values as $i => $value) {
$values[$i] = isset($valueMap[$value]);
}
if ($this->placeholderPresent) {
$values['placeholder'] = 0 === count($valueMap);
}
return $values;
}
/**
* Transforms a checkbox/radio button array to a single choice.
*
* The input value is an array with the choices as keys and true/false as
* values, depending on whether a given choice is selected. The output
* is the selected choice.
*
* @param array $values An array of values
*
* @return mixed A scalar value
*
* @throws TransformationFailedException If the given value is not an array,
* if the recuperation of the choices
* fails or if some choice can't be
* found.
*/
public function reverseTransform($values)
{
if (!is_array($values)) {
throw new TransformationFailedException('Expected an array.');
}
try {
$choices = $this->choiceList->getChoices();
} catch (\Exception $e) {
throw new TransformationFailedException('Can not get the choice list', $e->getCode(), $e);
}
foreach ($values as $i => $selected) {
if ($selected) {
if (isset($choices[$i])) {
return $choices[$i] === '' ? null : $choices[$i];
} elseif ($this->placeholderPresent && 'placeholder' === $i) {
return;
} else {
throw new TransformationFailedException(sprintf('The choice "%s" does not exist', $i));
}
}
}
}
}

View File

@ -1,122 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
@trigger_error('The class '.__NAMESPACE__.'\ChoicesToBooleanArrayTransformer is deprecated since version 2.7 and will be removed in 3.0. Use Symfony\Component\Form\Extension\Core\DataMapper\CheckboxListMapper instead.', E_USER_DEPRECATED);
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\TransformationFailedException;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.7, to be removed in 3.0.
* Use {@link \Symfony\Component\Form\ChoiceList\LazyChoiceList} instead.
*/
class ChoicesToBooleanArrayTransformer implements DataTransformerInterface
{
private $choiceList;
public function __construct(ChoiceListInterface $choiceList)
{
$this->choiceList = $choiceList;
}
/**
* Transforms an array of choices to a format appropriate for the nested
* checkboxes/radio buttons.
*
* The result is an array with the options as keys and true/false as values,
* depending on whether a given option is selected. If this field is rendered
* as select tag, the value is not modified.
*
* @param mixed $array An array
*
* @return mixed An array
*
* @throws TransformationFailedException If the given value is not an array
* or if the choices can not be retrieved.
*/
public function transform($array)
{
if (null === $array) {
return array();
}
if (!is_array($array)) {
throw new TransformationFailedException('Expected an array.');
}
try {
$values = $this->choiceList->getValues();
} catch (\Exception $e) {
throw new TransformationFailedException('Can not get the choice list', $e->getCode(), $e);
}
$valueMap = array_flip($this->choiceList->getValuesForChoices($array));
foreach ($values as $i => $value) {
$values[$i] = isset($valueMap[$value]);
}
return $values;
}
/**
* Transforms a checkbox/radio button array to an array of choices.
*
* The input value is an array with the choices as keys and true/false as
* values, depending on whether a given choice is selected. The output
* is an array with the selected choices.
*
* @param mixed $values An array
*
* @return mixed An array
*
* @throws TransformationFailedException If the given value is not an array,
* if the recuperation of the choices
* fails or if some choice can't be
* found.
*/
public function reverseTransform($values)
{
if (!is_array($values)) {
throw new TransformationFailedException('Expected an array.');
}
try {
$choices = $this->choiceList->getChoices();
} catch (\Exception $e) {
throw new TransformationFailedException('Can not get the choice list', $e->getCode(), $e);
}
$result = array();
$unknown = array();
foreach ($values as $i => $selected) {
if ($selected) {
if (isset($choices[$i])) {
$result[] = $choices[$i];
} else {
$unknown[] = $i;
}
}
}
if (count($unknown) > 0) {
throw new TransformationFailedException(sprintf('The choices "%s" were not found', implode('", "', $unknown)));
}
return $result;
}
}

View File

@ -72,27 +72,6 @@ class NumberToLocalizedStringTransformer implements DataTransformerInterface
*/
const ROUND_HALF_DOWN = \NumberFormatter::ROUND_HALFDOWN;
/**
* Alias for {@link self::ROUND_HALF_EVEN}.
*
* @deprecated since version 2.4, to be removed in 3.0.
*/
const ROUND_HALFEVEN = \NumberFormatter::ROUND_HALFEVEN;
/**
* Alias for {@link self::ROUND_HALF_UP}.
*
* @deprecated since version 2.4, to be removed in 3.0.
*/
const ROUND_HALFUP = \NumberFormatter::ROUND_HALFUP;
/**
* Alias for {@link self::ROUND_HALF_DOWN}.
*
* @deprecated since version 2.4, to be removed in 3.0.
*/
const ROUND_HALFDOWN = \NumberFormatter::ROUND_HALFDOWN;
/**
* @deprecated since version 2.7, will be replaced by a $scale private property in 3.0.
*/

View File

@ -1,103 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Extension\Core\EventListener;
@trigger_error('The class '.__NAMESPACE__.'\FixCheckboxInputListener is deprecated since version 2.7 and will be removed in 3.0. Use Symfony\Component\Form\Extension\Core\DataMapper\CheckboxListMapper instead.', E_USER_DEPRECATED);
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
/**
* Takes care of converting the input from a list of checkboxes to a correctly
* indexed array.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.7, to be removed in 3.0.
* Use {@link \Symfony\Component\Form\Extension\Core\DataMapper\CheckboxListMapper} instead.
*/
class FixCheckboxInputListener implements EventSubscriberInterface
{
private $choiceList;
/**
* Constructor.
*
* @param ChoiceListInterface $choiceList
*/
public function __construct(ChoiceListInterface $choiceList)
{
$this->choiceList = $choiceList;
}
public function preSubmit(FormEvent $event)
{
$data = $event->getData();
if (is_array($data)) {
// Flip the submitted values for faster lookup
// It's better to flip this array than $existingValues because
// $submittedValues is generally smaller.
$submittedValues = array_flip($data);
// Since expanded choice fields are completely loaded anyway, we
// can just as well get the values again without losing performance.
$existingValues = $this->choiceList->getValues();
// Clear the data array and fill it with correct indices
$data = array();
foreach ($existingValues as $index => $value) {
if (isset($submittedValues[$value])) {
// Value was submitted
$data[$index] = $value;
unset($submittedValues[$value]);
}
}
if (count($submittedValues) > 0) {
throw new TransformationFailedException(sprintf(
'The following choices were not found: "%s"',
implode('", "', array_keys($submittedValues))
));
}
} elseif ('' === $data || null === $data) {
// Empty values are always accepted.
$data = array();
}
// Else leave the data unchanged to provoke an error during submission
$event->setData($data);
}
/**
* Alias of {@link preSubmit()}.
*
* @deprecated since version 2.3, to be removed in 3.0.
* Use {@link preSubmit()} instead.
*/
public function preBind(FormEvent $event)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.3 and will be removed in 3.0. Use the preSubmit() method instead.', E_USER_DEPRECATED);
$this->preSubmit($event);
}
public static function getSubscribedEvents()
{
return array(FormEvents::PRE_SUBMIT => 'preSubmit');
}
}

View File

@ -1,85 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Extension\Core\EventListener;
@trigger_error('The class '.__NAMESPACE__.'\FixRadioInputListener is deprecated since version 2.7 and will be removed in 3.0. Use Symfony\Component\Form\Extension\Core\DataMapper\RadioListMapper instead.', E_USER_DEPRECATED);
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
/**
* Takes care of converting the input from a single radio button
* to an array.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.7, to be removed in 3.0.
* Use {@link \Symfony\Component\Form\Extension\Core\DataMapper\RadioListMapper} instead.
*/
class FixRadioInputListener implements EventSubscriberInterface
{
private $choiceList;
private $placeholderPresent;
/**
* Constructor.
*
* @param ChoiceListInterface $choiceList
* @param bool $placeholderPresent
*/
public function __construct(ChoiceListInterface $choiceList, $placeholderPresent)
{
$this->choiceList = $choiceList;
$this->placeholderPresent = $placeholderPresent;
}
public function preSubmit(FormEvent $event)
{
$data = $event->getData();
// Since expanded choice fields are completely loaded anyway, we
// can just as well get the values again without losing performance.
$existingValues = $this->choiceList->getValues();
if (false !== ($index = array_search($data, $existingValues, true))) {
$data = array($index => $data);
} elseif ('' === $data || null === $data) {
// Empty values are always accepted.
$data = $this->placeholderPresent ? array('placeholder' => '') : array();
}
// Else leave the data unchanged to provoke an error during submission
$event->setData($data);
}
/**
* Alias of {@link preSubmit()}.
*
* @deprecated since version 2.3, to be removed in 3.0.
* Use {@link preSubmit()} instead.
*/
public function preBind(FormEvent $event)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.3 and will be removed in 3.0. Use the preSubmit() method instead.', E_USER_DEPRECATED);
$this->preSubmit($event);
}
public static function getSubscribedEvents()
{
return array(FormEvents::PRE_SUBMIT => 'preSubmit');
}
}

View File

@ -43,19 +43,6 @@ class FixUrlProtocolListener implements EventSubscriberInterface
}
}
/**
* Alias of {@link onSubmit()}.
*
* @deprecated since version 2.3, to be removed in 3.0.
* Use {@link onSubmit()} instead.
*/
public function onBind(FormEvent $event)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.3 and will be removed in 3.0. Use the onSubmit() method instead.', E_USER_DEPRECATED);
$this->onSubmit($event);
}
public static function getSubscribedEvents()
{
return array(FormEvents::SUBMIT => 'onSubmit');

View File

@ -125,17 +125,4 @@ class MergeCollectionListener implements EventSubscriberInterface
$event->setData($dataToMergeInto);
}
/**
* Alias of {@link onSubmit()}.
*
* @deprecated since version 2.3, to be removed in 3.0.
* Use {@link onSubmit()} instead.
*/
public function onBind(FormEvent $event)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.3 and will be removed in 3.0. Use the onSubmit() method instead.', E_USER_DEPRECATED);
$this->onSubmit($event);
}
}

View File

@ -180,30 +180,4 @@ class ResizeFormListener implements EventSubscriberInterface
$event->setData($data);
}
/**
* Alias of {@link preSubmit()}.
*
* @deprecated since version 2.3, to be removed in 3.0.
* Use {@link preSubmit()} instead.
*/
public function preBind(FormEvent $event)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.3 and will be removed in 3.0. Use the preSubmit() method instead.', E_USER_DEPRECATED);
$this->preSubmit($event);
}
/**
* Alias of {@link onSubmit()}.
*
* @deprecated since version 2.3, to be removed in 3.0.
* Use {@link onSubmit()} instead.
*/
public function onBind(FormEvent $event)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.3 and will be removed in 3.0. Use the onSubmit() method instead.', E_USER_DEPRECATED);
$this->onSubmit($event);
}
}

View File

@ -34,19 +34,6 @@ class TrimListener implements EventSubscriberInterface
$event->setData(StringUtil::trim($data));
}
/**
* Alias of {@link preSubmit()}.
*
* @deprecated since version 2.3, to be removed in 3.0.
* Use {@link preSubmit()} instead.
*/
public function preBind(FormEvent $event)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.3 and will be removed in 3.0. Use the preSubmit() method instead.', E_USER_DEPRECATED);
$this->preSubmit($event);
}
public static function getSubscribedEvents()
{
return array(FormEvents::PRE_SUBMIT => 'preSubmit');

View File

@ -15,7 +15,6 @@ use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\Util\StringUtil;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
@ -78,17 +77,7 @@ abstract class BaseType extends AbstractType
$blockPrefixes = array();
for ($type = $form->getConfig()->getType(); null !== $type; $type = $type->getParent()) {
if (method_exists($type, 'getBlockPrefix')) {
array_unshift($blockPrefixes, $type->getBlockPrefix());
} else {
@trigger_error(get_class($type).': The ResolvedFormTypeInterface::getBlockPrefix() method will be added in version 3.0. You should add it to your implementation.', E_USER_DEPRECATED);
$fqcn = get_class($type->getInnerType());
$name = $type->getName();
$hasCustomName = $name !== $fqcn;
array_unshift($blockPrefixes, $hasCustomName ? $name : StringUtil::fqcnToBlockPrefix($fqcn));
}
array_unshift($blockPrefixes, $type->getBlockPrefix());
}
$blockPrefixes[] = $uniqueBlockPrefix;
@ -111,7 +100,7 @@ abstract class BaseType extends AbstractType
// collection form have different types (dynamically), they should
// be rendered differently.
// https://github.com/symfony/symfony/issues/5038
'cache_key' => $uniqueBlockPrefix.'_'.$form->getConfig()->getType()->getName(),
'cache_key' => $uniqueBlockPrefix.'_'.$form->getConfig()->getType()->getBlockPrefix(),
));
}

View File

@ -34,14 +34,6 @@ class BirthdayType extends AbstractType
return __NAMESPACE__.'\DateType';
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/

View File

@ -28,14 +28,6 @@ class ButtonType extends BaseType implements ButtonTypeInterface
{
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/

View File

@ -62,14 +62,6 @@ class CheckboxType extends AbstractType
));
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/

View File

@ -13,7 +13,6 @@ namespace Symfony\Component\Form\Extension\Core\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\ChoiceList\Factory\PropertyAccessDecorator;
use Symfony\Component\Form\ChoiceList\LegacyChoiceListAdapter;
use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView;
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
use Symfony\Component\Form\ChoiceList\Factory\DefaultChoiceListFactory;
@ -28,7 +27,6 @@ use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface as LegacyChoiceListInterface;
use Symfony\Component\Form\Extension\Core\EventListener\MergeCollectionListener;
use Symfony\Component\Form\Extension\Core\DataTransformer\ChoiceToValueTransformer;
use Symfony\Component\Form\Extension\Core\DataTransformer\ChoicesToValuesTransformer;
@ -202,7 +200,6 @@ class ChoiceType extends AbstractType
}
// BC
$view->vars['empty_value'] = $view->vars['placeholder'];
$view->vars['empty_value_in_choices'] = $view->vars['placeholder_in_choices'];
if ($options['multiple'] && !$options['expanded']) {
@ -248,23 +245,14 @@ class ChoiceType extends AbstractType
return '';
};
$emptyValue = function (Options $options) {
return $options['required'] ? null : '';
};
// for BC with the "empty_value" option
$placeholder = function (Options $options) {
return $options['empty_value'];
return $options['required'] ? null : '';
};
$choiceListNormalizer = function (Options $options, $choiceList) use ($choiceListFactory) {
if ($choiceList) {
@trigger_error('The "choice_list" option is deprecated since version 2.7 and will be removed in 3.0. Use "choice_loader" instead.', E_USER_DEPRECATED);
if ($choiceList instanceof LegacyChoiceListInterface) {
return new LegacyChoiceListAdapter($choiceList);
}
return $choiceList;
}
@ -328,7 +316,6 @@ class ChoiceType extends AbstractType
'preferred_choices' => array(),
'group_by' => null,
'empty_data' => $emptyData,
'empty_value' => $emptyValue, // deprecated
'placeholder' => $placeholder,
'error_bubbling' => false,
'compound' => $compound,
@ -340,7 +327,6 @@ class ChoiceType extends AbstractType
));
$resolver->setNormalizer('choice_list', $choiceListNormalizer);
$resolver->setNormalizer('empty_value', $placeholderNormalizer);
$resolver->setNormalizer('placeholder', $placeholderNormalizer);
$resolver->setNormalizer('choice_translation_domain', $choiceTranslationDomainNormalizer);
@ -357,14 +343,6 @@ class ChoiceType extends AbstractType
$resolver->setAllowedTypes('group_by', array('null', 'array', '\Traversable', 'string', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath'));
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/

View File

@ -96,14 +96,6 @@ class CollectionType extends AbstractType
$resolver->setNormalizer('options', $optionsNormalizer);
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/

View File

@ -36,14 +36,6 @@ class CountryType extends AbstractType
return __NAMESPACE__.'\ChoiceType';
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/

View File

@ -36,14 +36,6 @@ class CurrencyType extends AbstractType
return __NAMESPACE__.'\ChoiceType';
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/

View File

@ -114,7 +114,6 @@ class DateTimeType extends AbstractType
'years',
'months',
'days',
'empty_value',
'placeholder',
'choice_translation_domain',
'required',
@ -130,7 +129,6 @@ class DateTimeType extends AbstractType
'seconds',
'with_minutes',
'with_seconds',
'empty_value',
'placeholder',
'choice_translation_domain',
'required',
@ -245,7 +243,6 @@ class DateTimeType extends AbstractType
// Don't add some defaults in order to preserve the defaults
// set in DateType and TimeType
$resolver->setDefined(array(
'empty_value', // deprecated
'placeholder',
'choice_translation_domain',
'years',
@ -283,14 +280,6 @@ class DateTimeType extends AbstractType
));
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/

View File

@ -183,14 +183,10 @@ class DateType extends AbstractType
return $options['widget'] !== 'single_text';
};
$emptyValue = $placeholderDefault = function (Options $options) {
$placeholderDefault = function (Options $options) {
return $options['required'] ? null : '';
};
$placeholder = function (Options $options) {
return $options['empty_value'];
};
$placeholderNormalizer = function (Options $options, $placeholder) use ($placeholderDefault) {
if (is_array($placeholder)) {
$default = $placeholderDefault($options);
@ -238,8 +234,7 @@ class DateType extends AbstractType
'format' => $format,
'model_timezone' => null,
'view_timezone' => null,
'empty_value' => $emptyValue, // deprecated
'placeholder' => $placeholder,
'placeholder' => $placeholderDefault,
'html5' => true,
// Don't modify \DateTime classes by reference, we treat
// them like immutable value objects
@ -254,7 +249,6 @@ class DateType extends AbstractType
'choice_translation_domain' => false,
));
$resolver->setNormalizer('empty_value', $placeholderNormalizer);
$resolver->setNormalizer('placeholder', $placeholderNormalizer);
$resolver->setNormalizer('choice_translation_domain', $choiceTranslationDomainNormalizer);
@ -276,14 +270,6 @@ class DateType extends AbstractType
$resolver->setAllowedTypes('days', 'array');
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/

View File

@ -23,14 +23,6 @@ class EmailType extends AbstractType
return __NAMESPACE__.'\TextType';
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/

View File

@ -57,14 +57,6 @@ class FileType extends AbstractType
));
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/

View File

@ -84,14 +84,11 @@ class FormType extends BaseType
}
$view->vars = array_replace($view->vars, array(
'read_only' => isset($view->vars['attr']['readonly']) && false !== $view->vars['attr']['readonly'], // deprecated
'errors' => $form->getErrors(),
'valid' => $form->isSubmitted() ? $form->isValid() : true,
'value' => $form->getViewData(),
'data' => $form->getNormData(),
'required' => $form->isRequired(),
'max_length' => isset($options['attr']['maxlength']) ? $options['attr']['maxlength'] : null, // Deprecated
'pattern' => isset($options['attr']['pattern']) ? $options['attr']['pattern'] : null, // Deprecated
'size' => null,
'label_attr' => $options['label_attr'],
'compound' => $form->getConfig()->getCompound(),
@ -151,64 +148,17 @@ class FormType extends BaseType
return $options['compound'];
};
// BC with old "virtual" option
$inheritData = function (Options $options) {
if (null !== $options['virtual']) {
@trigger_error('The form option "virtual" is deprecated since version 2.3 and will be removed in 3.0. Use "inherit_data" instead.', E_USER_DEPRECATED);
return $options['virtual'];
}
return false;
};
// If data is given, the form is locked to that data
// (independent of its value)
$resolver->setDefined(array(
'data',
));
// BC clause for the "max_length" and "pattern" option
// Add these values to the "attr" option instead
$defaultAttr = function (Options $options) {
$attributes = array();
if (null !== $options['max_length']) {
$attributes['maxlength'] = $options['max_length'];
}
if (null !== $options['pattern']) {
$attributes['pattern'] = $options['pattern'];
}
return $attributes;
};
// BC for "read_only" option
$attrNormalizer = function (Options $options, array $attr) {
if (!isset($attr['readonly']) && $options['read_only']) {
$attr['readonly'] = true;
}
return $attr;
};
$readOnlyNormalizer = function (Options $options, $readOnly) {
if (null !== $readOnly) {
@trigger_error('The form option "read_only" is deprecated since version 2.8 and will be removed in 3.0. Use "attr[\'readonly\']" instead.', E_USER_DEPRECATED);
return $readOnly;
}
return false;
};
$resolver->setDefaults(array(
'data_class' => $dataClass,
'empty_data' => $emptyData,
'trim' => true,
'required' => true,
'read_only' => null, // deprecated
'max_length' => null,
'pattern' => null,
'property_path' => null,
@ -216,20 +166,16 @@ class FormType extends BaseType
'by_reference' => true,
'error_bubbling' => $errorBubbling,
'label_attr' => array(),
'virtual' => null,
'inherit_data' => $inheritData,
'inherit_data' => false,
'compound' => true,
'method' => 'POST',
// According to RFC 2396 (http://www.ietf.org/rfc/rfc2396.txt)
// section 4.2., empty URIs are considered same-document references
'action' => '',
'attr' => $defaultAttr,
'attr' => array(),
'post_max_size_message' => 'The uploaded file was too large. Please try to upload a smaller file.',
));
$resolver->setNormalizer('attr', $attrNormalizer);
$resolver->setNormalizer('read_only', $readOnlyNormalizer);
$resolver->setAllowedTypes('label_attr', 'array');
}
@ -240,14 +186,6 @@ class FormType extends BaseType
{
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/

View File

@ -30,14 +30,6 @@ class HiddenType extends AbstractType
));
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/

View File

@ -37,19 +37,9 @@ class IntegerType extends AbstractType
*/
public function configureOptions(OptionsResolver $resolver)
{
$scale = function (Options $options) {
if (null !== $options['precision']) {
@trigger_error('The form option "precision" is deprecated since version 2.7 and will be removed in 3.0. Use "scale" instead.', E_USER_DEPRECATED);
}
return $options['precision'];
};
$resolver->setDefaults(array(
// deprecated as of Symfony 2.7, to be removed in Symfony 3.0.
'precision' => null,
// default scale is locale specific (usually around 3)
'scale' => $scale,
'scale' => null,
'grouping' => false,
// Integer cast rounds towards 0, so do the same when displaying fractions
'rounding_mode' => IntegerToLocalizedStringTransformer::ROUND_DOWN,
@ -69,14 +59,6 @@ class IntegerType extends AbstractType
$resolver->setAllowedTypes('scale', array('null', 'int'));
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/

View File

@ -36,14 +36,6 @@ class LanguageType extends AbstractType
return __NAMESPACE__.'\ChoiceType';
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/

View File

@ -36,14 +36,6 @@ class LocaleType extends AbstractType
return __NAMESPACE__.'\ChoiceType';
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/

View File

@ -51,20 +51,8 @@ class MoneyType extends AbstractType
*/
public function configureOptions(OptionsResolver $resolver)
{
$scale = function (Options $options) {
if (null !== $options['precision']) {
@trigger_error('The form option "precision" is deprecated since version 2.7 and will be removed in 3.0. Use "scale" instead.', E_USER_DEPRECATED);
return $options['precision'];
}
return 2;
};
$resolver->setDefaults(array(
// deprecated as of Symfony 2.7, to be removed in Symfony 3.0
'precision' => null,
'scale' => $scale,
'scale' => 2,
'grouping' => false,
'divisor' => 1,
'currency' => 'EUR',
@ -74,14 +62,6 @@ class MoneyType extends AbstractType
$resolver->setAllowedTypes('scale', 'int');
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/

View File

@ -36,19 +36,9 @@ class NumberType extends AbstractType
*/
public function configureOptions(OptionsResolver $resolver)
{
$scale = function (Options $options) {
if (null !== $options['precision']) {
@trigger_error('The form option "precision" is deprecated since version 2.7 and will be removed in 3.0. Use "scale" instead.', E_USER_DEPRECATED);
}
return $options['precision'];
};
$resolver->setDefaults(array(
// deprecated as of Symfony 2.7, to be removed in Symfony 3.0
'precision' => null,
// default scale is locale specific (usually around 3)
'scale' => $scale,
'scale' => null,
'grouping' => false,
'rounding_mode' => NumberToLocalizedStringTransformer::ROUND_HALF_UP,
'compound' => false,
@ -67,14 +57,6 @@ class NumberType extends AbstractType
$resolver->setAllowedTypes('scale', array('null', 'int'));
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/

View File

@ -47,14 +47,6 @@ class PasswordType extends AbstractType
return __NAMESPACE__.'\TextType';
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/

View File

@ -32,20 +32,8 @@ class PercentType extends AbstractType
*/
public function configureOptions(OptionsResolver $resolver)
{
$scale = function (Options $options) {
if (null !== $options['precision']) {
@trigger_error('The form option "precision" is deprecated since version 2.7 and will be removed in 3.0. Use "scale" instead.', E_USER_DEPRECATED);
return $options['precision'];
}
return 0;
};
$resolver->setDefaults(array(
// deprecated as of Symfony 2.7, to be removed in Symfony 3.0.
'precision' => null,
'scale' => $scale,
'scale' => 0,
'type' => 'fractional',
'compound' => false,
));
@ -58,14 +46,6 @@ class PercentType extends AbstractType
$resolver->setAllowedTypes('scale', 'int');
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/

View File

@ -23,14 +23,6 @@ class RadioType extends AbstractType
return __NAMESPACE__.'\CheckboxType';
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/

View File

@ -23,14 +23,6 @@ class RangeType extends AbstractType
return __NAMESPACE__.'\TextType';
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/

View File

@ -61,14 +61,6 @@ class RepeatedType extends AbstractType
$resolver->setAllowedTypes('second_options', 'array');
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/

View File

@ -29,14 +29,6 @@ class ResetType extends AbstractType implements ButtonTypeInterface
return __NAMESPACE__.'\ButtonType';
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/

View File

@ -23,14 +23,6 @@ class SearchType extends AbstractType
return __NAMESPACE__.'\TextType';
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/

View File

@ -36,14 +36,6 @@ class SubmitType extends AbstractType implements SubmitButtonTypeInterface
return __NAMESPACE__.'\ButtonType';
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/

View File

@ -26,14 +26,6 @@ class TextType extends AbstractType
));
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/

View File

@ -33,14 +33,6 @@ class TextareaType extends AbstractType
return __NAMESPACE__.'\TextType';
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/

View File

@ -171,15 +171,10 @@ class TimeType extends AbstractType
return $options['widget'] !== 'single_text';
};
$emptyValue = $placeholderDefault = function (Options $options) {
$placeholder = $placeholderDefault = function (Options $options) {
return $options['required'] ? null : '';
};
// for BC with the "empty_value" option
$placeholder = function (Options $options) {
return $options['empty_value'];
};
$placeholderNormalizer = function (Options $options, $placeholder) use ($placeholderDefault) {
if (is_array($placeholder)) {
$default = $placeholderDefault($options);
@ -224,7 +219,6 @@ class TimeType extends AbstractType
'with_seconds' => false,
'model_timezone' => null,
'view_timezone' => null,
'empty_value' => $emptyValue, // deprecated
'placeholder' => $placeholder,
'html5' => true,
// Don't modify \DateTime classes by reference, we treat
@ -240,7 +234,6 @@ class TimeType extends AbstractType
'choice_translation_domain' => false,
));
$resolver->setNormalizer('empty_value', $placeholderNormalizer);
$resolver->setNormalizer('placeholder', $placeholderNormalizer);
$resolver->setNormalizer('choice_translation_domain', $choiceTranslationDomainNormalizer);
@ -261,14 +254,6 @@ class TimeType extends AbstractType
$resolver->setAllowedTypes('seconds', 'array');
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/

View File

@ -42,14 +42,6 @@ class TimezoneType extends AbstractType
return __NAMESPACE__.'\ChoiceType';
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/

View File

@ -46,14 +46,6 @@ class UrlType extends AbstractType
return __NAMESPACE__.'\TextType';
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/

View File

@ -1,24 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Extension\Core\View;
@trigger_error('The '.__NAMESPACE__.'\ChoiceView class is deprecated since version 2.7 and will be removed in 3.0. Use Symfony\Component\Form\ChoiceList\View\ChoiceView instead.', E_USER_DEPRECATED);
/*
* Represents a choice in templates.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.7, to be removed in 3.0.
* Use {@link \Symfony\Component\Form\ChoiceList\View\ChoiceView} instead.
*/
class_exists('Symfony\Component\Form\ChoiceList\View\ChoiceView');

View File

@ -1,78 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Extension\Csrf\CsrfProvider;
@trigger_error('The '.__NAMESPACE__.'\CsrfProviderAdapter class is deprecated since version 2.4 and will be removed in version 3.0. Use the Symfony\Component\Security\Csrf\CsrfTokenManager class instead.', E_USER_DEPRECATED);
use Symfony\Component\Form\Exception\BadMethodCallException;
use Symfony\Component\Security\Csrf\CsrfToken;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
/**
* Adapter for using old CSRF providers where the new {@link CsrfTokenManagerInterface}
* is expected.
*
* @since 2.4
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.4, to be removed in 3.0.
*/
class CsrfProviderAdapter implements CsrfTokenManagerInterface
{
/**
* @var CsrfProviderInterface
*/
private $csrfProvider;
public function __construct(CsrfProviderInterface $csrfProvider)
{
$this->csrfProvider = $csrfProvider;
}
public function getCsrfProvider()
{
return $this->csrfProvider;
}
/**
* {@inheritdoc}
*/
public function getToken($tokenId)
{
return new CsrfToken($tokenId, $this->csrfProvider->generateCsrfToken($tokenId));
}
/**
* {@inheritdoc}
*/
public function refreshToken($tokenId)
{
throw new BadMethodCallException('Not supported');
}
/**
* {@inheritdoc}
*/
public function removeToken($tokenId)
{
throw new BadMethodCallException('Not supported');
}
/**
* {@inheritdoc}
*/
public function isTokenValid(CsrfToken $token)
{
return $this->csrfProvider->isCsrfTokenValid($token->getId(), $token->getValue());
}
}

View File

@ -1,54 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Extension\Csrf\CsrfProvider;
/**
* Marks classes able to provide CSRF protection.
*
* You can generate a CSRF token by using the method generateCsrfToken(). To
* this method you should pass a value that is unique to the page that should
* be secured against CSRF attacks. This value doesn't necessarily have to be
* secret. Implementations of this interface are responsible for adding more
* secret information.
*
* If you want to secure a form submission against CSRF attacks, you could
* supply an "intention" string. This way you make sure that the form can only
* be submitted to pages that are designed to handle the form, that is, that use
* the same intention string to validate the CSRF token with isCsrfTokenValid().
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.4, to be removed in 3.0.
* Use {@link \Symfony\Component\Security\Csrf\CsrfTokenManagerInterface} instead.
*/
interface CsrfProviderInterface
{
/**
* Generates a CSRF token for a page of your application.
*
* @param string $intention Some value that identifies the action intention
* (i.e. "authenticate"). Doesn't have to be a secret value.
*
* @return string The generated token
*/
public function generateCsrfToken($intention);
/**
* Validates a CSRF token.
*
* @param string $intention The intention used when generating the CSRF token
* @param string $token The token supplied by the browser
*
* @return bool Whether the token supplied by the browser is correct
*/
public function isCsrfTokenValid($intention, $token);
}

View File

@ -1,66 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Extension\Csrf\CsrfProvider;
use Symfony\Component\Security\Csrf\CsrfToken;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
/**
* Adapter for using the new token generator with the old interface.
*
* @since 2.4
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.4, to be removed in 3.0.
*/
class CsrfTokenManagerAdapter implements CsrfProviderInterface
{
/**
* @var CsrfTokenManagerInterface
*/
private $tokenManager;
public function __construct(CsrfTokenManagerInterface $tokenManager)
{
$this->tokenManager = $tokenManager;
}
public function getTokenManager($triggerDeprecationError = true)
{
if ($triggerDeprecationError) {
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.4 and will be removed in version 3.0. Use the Symfony\Component\Security\Csrf\CsrfTokenManager class instead.', E_USER_DEPRECATED);
}
return $this->tokenManager;
}
/**
* {@inheritdoc}
*/
public function generateCsrfToken($intention)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.4 and will be removed in version 3.0. Use the Symfony\Component\Security\Csrf\CsrfTokenManager class instead.', E_USER_DEPRECATED);
return $this->tokenManager->getToken($intention)->getValue();
}
/**
* {@inheritdoc}
*/
public function isCsrfTokenValid($intention, $token)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.4 and will be removed in version 3.0. Use the Symfony\Component\Security\Csrf\CsrfTokenManager class instead.', E_USER_DEPRECATED);
return $this->tokenManager->isTokenValid(new CsrfToken($intention, $token));
}
}

View File

@ -1,82 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Extension\Csrf\CsrfProvider;
@trigger_error('The '.__NAMESPACE__.'\DefaultCsrfProvider is deprecated since version 2.4 and will be removed in version 3.0. Use the \Symfony\Component\Security\Csrf\TokenStorage\NativeSessionTokenStorage class instead.', E_USER_DEPRECATED);
/**
* Default implementation of CsrfProviderInterface.
*
* This provider uses the session ID returned by session_id() as well as a
* user-defined secret value to secure the CSRF token.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.4, to be removed in 3.0.
* Use {@link \Symfony\Component\Security\Csrf\CsrfTokenManager} in
* combination with {@link \Symfony\Component\Security\Csrf\TokenStorage\NativeSessionTokenStorage}
* instead.
*/
class DefaultCsrfProvider implements CsrfProviderInterface
{
/**
* A secret value used for generating the CSRF token.
*
* @var string
*/
protected $secret;
/**
* Initializes the provider with a secret value.
*
* A recommended value for the secret is a generated value with at least
* 32 characters and mixed letters, digits and special characters.
*
* @param string $secret A secret value included in the CSRF token
*/
public function __construct($secret)
{
$this->secret = $secret;
}
/**
* {@inheritdoc}
*/
public function generateCsrfToken($intention)
{
return sha1($this->secret.$intention.$this->getSessionId());
}
/**
* {@inheritdoc}
*/
public function isCsrfTokenValid($intention, $token)
{
return $token === $this->generateCsrfToken($intention);
}
/**
* Returns the ID of the user session.
*
* Automatically starts the session if necessary.
*
* @return string The session ID
*/
protected function getSessionId()
{
if (PHP_SESSION_NONE === session_status()) {
session_start();
}
return session_id();
}
}

View File

@ -1,65 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Extension\Csrf\CsrfProvider;
@trigger_error('The '.__NAMESPACE__.'\SessionCsrfProvider is deprecated since version 2.4 and will be removed in version 3.0. Use the Symfony\Component\Security\Csrf\TokenStorage\SessionTokenStorage class instead.', E_USER_DEPRECATED);
use Symfony\Component\HttpFoundation\Session\Session;
/**
* This provider uses a Symfony Session object to retrieve the user's
* session ID.
*
* @see DefaultCsrfProvider
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.4, to be removed in 3.0.
* Use {@link \Symfony\Component\Security\Csrf\CsrfTokenManager} in
* combination with {@link \Symfony\Component\Security\Csrf\TokenStorage\SessionTokenStorage}
* instead.
*/
class SessionCsrfProvider extends DefaultCsrfProvider
{
/**
* The user session from which the session ID is returned.
*
* @var Session
*/
protected $session;
/**
* Initializes the provider with a Session object and a secret value.
*
* A recommended value for the secret is a generated value with at least
* 32 characters and mixed letters, digits and special characters.
*
* @param Session $session The user session
* @param string $secret A secret value included in the CSRF token
*/
public function __construct(Session $session, $secret)
{
parent::__construct($secret);
$this->session = $session;
}
/**
* {@inheritdoc}
*/
protected function getSessionId()
{
$this->session->start();
return $this->session->getId();
}
}

View File

@ -114,17 +114,4 @@ class CsrfValidationListener implements EventSubscriberInterface
$event->setData($data);
}
/**
* Alias of {@link preSubmit()}.
*
* @deprecated since version 2.3, to be removed in 3.0.
* Use {@link preSubmit()} instead.
*/
public function preBind(FormEvent $event)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.3 and will be removed in 3.0. Use the preSubmit() method instead.', E_USER_DEPRECATED);
$this->preSubmit($event);
}
}

View File

@ -46,7 +46,6 @@ class FormDataExtractor implements FormDataExtractorInterface
$data = array(
'id' => $this->buildId($form),
'name' => $form->getName(),
'type' => $form->getConfig()->getType()->getName(),
'type_class' => get_class($form->getConfig()->getType()->getInnerType()),
'synchronized' => $this->valueExporter->exportValue($form->isSynchronized()),
'passed_options' => array(),

View File

@ -41,20 +41,7 @@ class DependencyInjectionExtension implements FormExtensionInterface
throw new InvalidArgumentException(sprintf('The field type "%s" is not registered with the service container.', $name));
}
$type = $this->container->get($this->typeServiceIds[$name]);
// BC: validate result of getName() for legacy names (non-FQCN)
if ($name !== get_class($type) && $type->getName() !== $name) {
throw new InvalidArgumentException(
sprintf('The type name specified for the service "%s" does not match the actual name. Expected "%s", given "%s"',
$this->typeServiceIds[$name],
$name,
$type->getName()
)
);
}
return $type;
return $this->container->get($this->typeServiceIds[$name]);
}
public function hasType($name)

View File

@ -21,12 +21,6 @@ class Form extends Constraint
const NOT_SYNCHRONIZED_ERROR = 1;
const NO_SUCH_FIELD_ERROR = 2;
/**
* @deprecated since version 2.6, to be removed in 3.0.
* Use {@self NOT_SYNCHRONIZED_ERROR} instead.
*/
const ERR_INVALID = 1;
protected static $errorNames = array(
self::NOT_SYNCHRONIZED_ERROR => 'NOT_SYNCHRONIZED_ERROR',
self::NO_SUCH_FIELD_ERROR => 'NO_SUCH_FIELD_ERROR',

View File

@ -14,7 +14,6 @@ namespace Symfony\Component\Form\Extension\Validator\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\Extension\Validator\ViolationMapper\ViolationMapperInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Component\Validator\ValidatorInterface as LegacyValidatorInterface;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\Extension\Validator\Constraints\Form;
@ -37,15 +36,11 @@ class ValidationListener implements EventSubscriberInterface
}
/**
* @param ValidatorInterface|LegacyValidatorInterface $validator
* @param ViolationMapperInterface $violationMapper
* @param ValidatorInterface $validator
* @param ViolationMapperInterface $violationMapper
*/
public function __construct($validator, ViolationMapperInterface $violationMapper)
public function __construct(ValidatorInterface $validator, ViolationMapperInterface $violationMapper)
{
if (!$validator instanceof ValidatorInterface && !$validator instanceof LegacyValidatorInterface) {
throw new \InvalidArgumentException('Validator must be instance of Symfony\Component\Validator\Validator\ValidatorInterface or Symfony\Component\Validator\ValidatorInterface');
}
$this->validator = $validator;
$this->violationMapper = $violationMapper;
}

View File

@ -15,7 +15,6 @@ use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Validator\ViolationMapper\ViolationMapper;
use Symfony\Component\Form\Extension\Validator\EventListener\ValidationListener;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Component\Validator\ValidatorInterface as LegacyValidatorInterface;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
@ -35,14 +34,10 @@ class FormTypeValidatorExtension extends BaseValidatorExtension
private $violationMapper;
/**
* @param ValidatorInterface|LegacyValidatorInterface $validator
* @param ValidatorInterface $validator
*/
public function __construct($validator)
public function __construct(ValidatorInterface $validator)
{
if (!$validator instanceof ValidatorInterface && !$validator instanceof LegacyValidatorInterface) {
throw new \InvalidArgumentException('Validator must be instance of Symfony\Component\Validator\Validator\ValidatorInterface or Symfony\Component\Validator\ValidatorInterface');
}
$this->validator = $validator;
$this->violationMapper = new ViolationMapper();
}
@ -67,18 +62,9 @@ class FormTypeValidatorExtension extends BaseValidatorExtension
return is_object($constraints) ? array($constraints) : (array) $constraints;
};
$cascadeValidationNormalizer = function (Options $options, $cascadeValidation) {
if (null !== $cascadeValidation) {
@trigger_error('The "cascade_validation" option is deprecated since version 2.8 and will be removed in 3.0. Use "constraints" with a Valid constraint instead.', E_USER_DEPRECATED);
}
return null === $cascadeValidation ? false : $cascadeValidation;
};
$resolver->setDefaults(array(
'error_mapping' => array(),
'constraints' => array(),
'cascade_validation' => null,
'invalid_message' => 'This value is not valid.',
'invalid_message_parameters' => array(),
'allow_extra_fields' => false,
@ -86,7 +72,6 @@ class FormTypeValidatorExtension extends BaseValidatorExtension
));
$resolver->setNormalizer('constraints', $constraintsNormalizer);
$resolver->setNormalizer('cascade_validation', $cascadeValidationNormalizer);
}
/**

View File

@ -11,13 +11,11 @@
namespace Symfony\Component\Form\Extension\Validator;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\Extension\Validator\Constraints\Form;
use Symfony\Component\Form\AbstractExtension;
use Symfony\Component\Validator\Constraints\Valid;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Component\Validator\ValidatorInterface as LegacyValidatorInterface;
/**
* Extension supporting the Symfony Validator component in forms.
@ -28,22 +26,9 @@ class ValidatorExtension extends AbstractExtension
{
private $validator;
/**
* @param ValidatorInterface|LegacyValidatorInterface $validator
*
* @throws UnexpectedTypeException If $validator is invalid
*/
public function __construct($validator)
public function __construct(ValidatorInterface $validator)
{
// 2.5 API
if ($validator instanceof ValidatorInterface) {
$metadata = $validator->getMetadataFor('Symfony\Component\Form\Form');
// 2.4 API
} elseif ($validator instanceof LegacyValidatorInterface) {
$metadata = $validator->getMetadataFactory()->getMetadataFor('Symfony\Component\Form\Form');
} else {
throw new UnexpectedTypeException($validator, 'Symfony\Component\Validator\Validator\ValidatorInterface or Symfony\Component\Validator\ValidatorInterface');
}
$metadata = $validator->getMetadataFor('Symfony\Component\Form\Form');
// Register the form constraints in the validator programmatically.
// This functionality is required when using the Form component without
@ -59,13 +44,7 @@ class ValidatorExtension extends AbstractExtension
public function loadTypeGuesser()
{
// 2.5 API
if ($this->validator instanceof ValidatorInterface) {
return new ValidatorTypeGuesser($this->validator);
}
// 2.4 API
return new ValidatorTypeGuesser($this->validator->getMetadataFactory());
return new ValidatorTypeGuesser($this->validator);
}
protected function loadTypeExtensions()

View File

@ -673,23 +673,6 @@ class Form implements \IteratorAggregate, FormInterface
return $this;
}
/**
* Alias of {@link submit()}.
*
* @deprecated since version 2.3, to be removed in 3.0.
* Use {@link submit()} instead.
*/
public function bind($submittedData)
{
// This method is deprecated for Request too, but the error is
// triggered in Form::submit() method.
if (!$submittedData instanceof Request) {
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.3 and will be removed in 3.0. Use the '.__CLASS__.'::submit method instead.', E_USER_DEPRECATED);
}
return $this->submit($submittedData);
}
/**
* {@inheritdoc}
*/
@ -716,19 +699,6 @@ class Form implements \IteratorAggregate, FormInterface
return $this->submitted;
}
/**
* Alias of {@link isSubmitted()}.
*
* @deprecated since version 2.3, to be removed in 3.0.
* Use {@link isSubmitted()} instead.
*/
public function isBound()
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.3 and will be removed in 3.0. Use the '.__CLASS__.'::isSubmitted method instead.', E_USER_DEPRECATED);
return $this->submitted;
}
/**
* {@inheritdoc}
*/
@ -834,25 +804,6 @@ class Form implements \IteratorAggregate, FormInterface
return new FormErrorIterator($this, $errors);
}
/**
* Returns a string representation of all form errors (including children errors).
*
* This method should only be used to help debug a form.
*
* @param int $level The indentation level (used internally)
*
* @return string A string representation of all errors
*
* @deprecated since version 2.5, to be removed in 3.0.
* Use {@link getErrors()} instead and cast the result to a string.
*/
public function getErrorsAsString($level = 0)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0. Use (string) Form::getErrors(true, false) instead.', E_USER_DEPRECATED);
return self::indent((string) $this->getErrors(true, false), $level);
}
/**
* {@inheritdoc}
*/

View File

@ -346,21 +346,6 @@ class FormConfigBuilder implements FormConfigBuilderInterface
return $this->inheritData;
}
/**
* Alias of {@link getInheritData()}.
*
* @return FormConfigBuilder The configuration object.
*
* @deprecated since version 2.3, to be removed in 3.0.
* Use {@link getInheritData()} instead.
*/
public function getVirtual()
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.3 and will be removed in 3.0. Use the FormConfigBuilder::getInheritData() method instead.', E_USER_DEPRECATED);
return $this->getInheritData();
}
/**
* {@inheritdoc}
*/
@ -710,23 +695,6 @@ class FormConfigBuilder implements FormConfigBuilderInterface
return $this;
}
/**
* Alias of {@link setInheritData()}.
*
* @param bool $inheritData Whether the form should inherit its parent's data.
*
* @return FormConfigBuilder The configuration object.
*
* @deprecated since version 2.3, to be removed in 3.0.
* Use {@link setInheritData()} instead.
*/
public function setVirtual($inheritData)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.3 and will be removed in 3.0. Use the FormConfigBuilder::setInheritData() method instead.', E_USER_DEPRECATED);
$this->setInheritData($inheritData);
}
/**
* {@inheritdoc}
*/

View File

@ -105,17 +105,12 @@ class FormFactory implements FormFactoryInterface
$options['data'] = $data;
}
if ($type instanceof FormTypeInterface) {
@trigger_error('Passing type instances to FormBuilder::add(), Form::add() or the FormFactory is deprecated since version 2.8 and will not be supported in 3.0. Use the fully-qualified type class name instead.', E_USER_DEPRECATED);
$type = $this->resolveType($type);
} elseif (is_string($type)) {
$type = $this->registry->getType($type);
} elseif ($type instanceof ResolvedFormTypeInterface) {
@trigger_error('Passing type instances to FormBuilder::add(), Form::add() or the FormFactory is deprecated since version 2.8 and will not be supported in 3.0. Use the fully-qualified type class name instead.', E_USER_DEPRECATED);
} else {
throw new UnexpectedTypeException($type, 'string, Symfony\Component\Form\ResolvedFormTypeInterface or Symfony\Component\Form\FormTypeInterface');
if (!is_string($type)) {
throw new UnexpectedTypeException($type, 'string');
}
$type = $this->registry->getType($type);
$builder = $type->createBuilder($this, $name, $options);
// Explicitly call buildForm() in order to be able to override either

View File

@ -34,11 +34,6 @@ class FormRegistry implements FormRegistryInterface
*/
private $types = array();
/**
* @var string[]
*/
private $legacyNames = array();
/**
* @var FormTypeGuesserInterface|false|null
*/
@ -100,10 +95,6 @@ class FormRegistry implements FormRegistryInterface
$this->resolveAndAddType($type);
}
if (isset($this->legacyNames[$name])) {
@trigger_error(sprintf('Accessing type "%s" by its string name is deprecated since version 2.8 and will be removed in 3.0. Use the fully-qualified type class name "%s" instead.', $name, get_class($this->types[$name]->getInnerType())), E_USER_DEPRECATED);
}
return $this->types[$name];
}
@ -120,28 +111,6 @@ class FormRegistry implements FormRegistryInterface
$typeExtensions = array();
$parentType = $type->getParent();
$fqcn = get_class($type);
$name = $type->getName();
$hasCustomName = $name !== $fqcn;
if ($parentType instanceof FormTypeInterface) {
@trigger_error('Returning a FormTypeInterface from FormTypeInterface::getParent() is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
$this->resolveAndAddType($parentType);
$parentType = $parentType->getName();
}
if ($hasCustomName) {
foreach ($this->extensions as $extension) {
$typeExtensions = array_merge(
$typeExtensions,
$extension->getTypeExtensions($name)
);
}
if ($typeExtensions) {
@trigger_error('Returning a type name from FormTypeExtensionInterface::getExtendedType() is deprecated since version 2.8 and will be removed in 3.0. Return the fully-qualified type class name instead.', E_USER_DEPRECATED);
}
}
foreach ($this->extensions as $extension) {
$typeExtensions = array_merge(
@ -157,12 +126,6 @@ class FormRegistry implements FormRegistryInterface
);
$this->types[$fqcn] = $resolvedType;
if ($hasCustomName) {
// Enable access by the explicit type name until Symfony 3.0
$this->types[$name] = $resolvedType;
$this->legacyNames[$name] = true;
}
}
/**
@ -170,10 +133,6 @@ class FormRegistry implements FormRegistryInterface
*/
public function hasType($name)
{
if (isset($this->legacyNames[$name])) {
@trigger_error(sprintf('Accessing type "%s" by its string name is deprecated since version 2.8 and will be removed in 3.0. Use the fully-qualified type class name "%s" instead.', $name, get_class($this->types[$name]->getInnerType())), E_USER_DEPRECATED);
}
if (isset($this->types[$name])) {
return true;
}

View File

@ -78,26 +78,7 @@ interface FormTypeInterface
/**
* Returns the name of the parent type.
*
* You can also return a type instance from this method, although doing so
* is discouraged because it leads to a performance penalty. The support
* for returning type instances may be dropped from future releases.
*
* Returning a {@link FormTypeInterface} instance is deprecated since
* Symfony 2.8 and will be unsupported as of Symfony 3.0. Return the
* fully-qualified class name of the parent type instead.
*
* @return string|null|FormTypeInterface The name of the parent type if any,
* null otherwise.
* @return string|null The name of the parent type if any, null otherwise
*/
public function getParent();
/**
* Returns the name of this type.
*
* @return string The name of this type
*
* @deprecated Deprecated since Symfony 2.8, to be removed in Symfony 3.0.
* Use the fully-qualified class name of the type instead.
*/
public function getName();
}

View File

@ -48,10 +48,6 @@ class PreloadedExtension implements FormExtensionInterface
$this->typeGuesser = $typeGuesser;
foreach ($types as $type) {
// Up to Symfony 2.8, types were identified by their names
$this->types[$type->getName()] = $type;
// Since Symfony 2.8, types are identified by their FQCN
$this->types[get_class($type)] = $type;
}
}

View File

@ -24,16 +24,6 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
*/
class ResolvedFormType implements ResolvedFormTypeInterface
{
/**
* @var string
*/
private $name;
/**
* @var string
*/
private $blockPrefix;
/**
* @var FormTypeInterface
*/
@ -56,64 +46,17 @@ class ResolvedFormType implements ResolvedFormTypeInterface
public function __construct(FormTypeInterface $innerType, array $typeExtensions = array(), ResolvedFormTypeInterface $parent = null)
{
$fqcn = get_class($innerType);
$name = $innerType->getName();
$hasCustomName = $name !== $fqcn;
if (method_exists($innerType, 'getBlockPrefix')) {
$reflector = new \ReflectionMethod($innerType, 'getName');
$isOldOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractType';
$reflector = new \ReflectionMethod($innerType, 'getBlockPrefix');
$isNewOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractType';
// Bundles compatible with both 2.3 and 2.8 should implement both methods
// Anyone else should only override getBlockPrefix() if they actually
// want to have a different block prefix than the default one
if ($isOldOverwritten && !$isNewOverwritten) {
@trigger_error(get_class($this->innerType).': The FormTypeInterface::getName() method is deprecated since version 2.8 and will be removed in 3.0. Remove it from your classes. Use getBlockPrefix() if you want to customize the template block prefix. This method will be added to the FormTypeInterface with Symfony 3.0.', E_USER_DEPRECATED);
}
$blockPrefix = $innerType->getBlockPrefix();
} else {
@trigger_error(get_class($this->innerType).': The FormTypeInterface::getBlockPrefix() method will be added in version 3.0. You should extend AbstractType or add it to your implementation.', E_USER_DEPRECATED);
// Deal with classes that don't extend AbstractType
// Calculate block prefix from the FQCN by default
$blockPrefix = $hasCustomName ? $name : StringUtil::fqcnToBlockPrefix($fqcn);
}
// As of Symfony 2.8, getName() returns the FQCN by default
// Otherwise check that the name matches the old naming restrictions
if ($hasCustomName && !preg_match('/^[a-z0-9_]*$/i', $name)) {
throw new InvalidArgumentException(sprintf(
'The "%s" form type name ("%s") is not valid. Names must only contain letters, numbers, and "_".',
get_class($innerType),
$name
));
}
foreach ($typeExtensions as $extension) {
if (!$extension instanceof FormTypeExtensionInterface) {
throw new UnexpectedTypeException($extension, 'Symfony\Component\Form\FormTypeExtensionInterface');
}
}
$this->name = $name;
$this->blockPrefix = $blockPrefix;
$this->innerType = $innerType;
$this->typeExtensions = $typeExtensions;
$this->parent = $parent;
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->name;
}
/**
* Returns the prefix of the template block name for this type.
*
@ -121,7 +64,7 @@ class ResolvedFormType implements ResolvedFormTypeInterface
*/
public function getBlockPrefix()
{
return $this->blockPrefix;
return $this->innerType->getBlockPrefix();
}
/**

View File

@ -20,13 +20,6 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
*/
interface ResolvedFormTypeInterface
{
/**
* Returns the name of the type.
*
* @return string The type name.
*/
public function getName();
/**
* Returns the parent type.
*

View File

@ -1,45 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Test;
use Symfony\Component\Form\FormEvent;
/**
* @deprecated since version 2.3, to be removed in 3.0.
*/
class DeprecationErrorHandler
{
public static function handle($errorNumber, $message, $file, $line, $context)
{
if ($errorNumber & ~E_USER_DEPRECATED) {
return true;
}
return \PHPUnit_Util_ErrorHandler::handleError($errorNumber, $message, $file, $line);
}
public static function handleBC($errorNumber, $message, $file, $line, $context)
{
if ($errorNumber & ~E_USER_DEPRECATED) {
return true;
}
return false;
}
public static function preBind($listener, FormEvent $event)
{
set_error_handler(array('Symfony\Component\Form\Test\DeprecationErrorHandler', 'handle'));
$listener->preBind($event);
restore_error_handler();
}
}

View File

@ -137,14 +137,6 @@ class FormTypeTest extends BaseTypeTest
$this->assertSame(10, $view->vars['attr']['maxlength']);
}
public function testPassMaxLengthBCToView()
{
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array('max_length' => 10));
$view = $form->createView();
$this->assertSame(10, $view->vars['attr']['maxlength']);
}
public function testDataClassMayBeNull()
{
$this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(

View File

@ -1,27 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
use Symfony\Component\Form\Test\TypeTestCase as BaseTypeTestCase;
/**
* @deprecated since version 2.3, to be removed in 3.0.
* Use {@link \Symfony\Component\Form\Test\TypeTestCase} instead.
*/
abstract class TypeTestCase extends BaseTypeTestCase
{
protected function setUp()
{
@trigger_error('Abstract class '.__CLASS__.' is deprecated since version 2.3 and will be removed in 3.0. Use the Symfony\Component\Form\Test\TypeTestCase class instead.', E_USER_DEPRECATED);
parent::setUp();
}
}

View File

@ -81,7 +81,6 @@ class FormDataExtractorTest extends \PHPUnit_Framework_TestCase
$this->assertSame(array(
'id' => 'name',
'name' => 'name',
'type' => 'type_name',
'type_class' => 'stdClass',
'synchronized' => 'true',
'passed_options' => array(),
@ -115,7 +114,6 @@ class FormDataExtractorTest extends \PHPUnit_Framework_TestCase
$this->assertSame(array(
'id' => 'name',
'name' => 'name',
'type' => 'type_name',
'type_class' => 'stdClass',
'synchronized' => 'true',
'passed_options' => array(
@ -150,7 +148,6 @@ class FormDataExtractorTest extends \PHPUnit_Framework_TestCase
$this->assertSame(array(
'id' => 'name',
'name' => 'name',
'type' => 'type_name',
'type_class' => 'stdClass',
'synchronized' => 'true',
'passed_options' => array(),
@ -190,7 +187,6 @@ class FormDataExtractorTest extends \PHPUnit_Framework_TestCase
$this->assertSame(array(
'id' => 'grandParent_parent_name',
'name' => 'name',
'type' => 'type_name',
'type_class' => 'stdClass',
'synchronized' => 'true',
'passed_options' => array(),

View File

@ -22,7 +22,6 @@ use Symfony\Component\Validator\Constraints\NotNull;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Valid;
use Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest;
use Symfony\Component\Validator\Validation;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
@ -56,11 +55,6 @@ class FormValidatorTest extends AbstractConstraintValidatorTest
parent::setUp();
}
protected function getApiVersion()
{
return Validation::API_VERSION_2_5;
}
protected function createValidator()
{
return new FormValidator($this->serverParams);

View File

@ -180,33 +180,11 @@ class ValidationListenerTest extends \PHPUnit_Framework_TestCase
$this->listener->validateForm(new FormEvent($form, null));
}
public function testValidatorInterfaceSinceSymfony25()
public function testValidatorInterface()
{
// Mock of ValidatorInterface since apiVersion 2.5
$validator = $this->getMock('Symfony\Component\Validator\Validator\ValidatorInterface');
$listener = new ValidationListener($validator, $this->violationMapper);
$this->assertAttributeSame($validator, 'validator', $listener);
}
/**
* @group legacy
*/
public function testValidatorInterfaceUntilSymfony24()
{
// Mock of ValidatorInterface until apiVersion 2.4
$validator = $this->getMock('Symfony\Component\Validator\ValidatorInterface');
$listener = new ValidationListener($validator, $this->violationMapper);
$this->assertAttributeSame($validator, 'validator', $listener);
}
/**
* @group legacy
* @expectedException \InvalidArgumentException
*/
public function testInvalidValidatorInterface()
{
new ValidationListener(null, $this->violationMapper);
}
}

View File

@ -45,32 +45,14 @@ class FormTypeValidatorExtensionTest extends BaseValidatorExtensionTest
$this->assertSame(array($valid), $form->getConfig()->getOption('constraints'));
}
public function testValidatorInterfaceSinceSymfony25()
public function testValidatorInterface()
{
// Mock of ValidatorInterface since apiVersion 2.5
$validator = $this->getMock('Symfony\Component\Validator\Validator\ValidatorInterface');
$formTypeValidatorExtension = new FormTypeValidatorExtension($validator);
$this->assertAttributeSame($validator, 'validator', $formTypeValidatorExtension);
}
public function testValidatorInterfaceUntilSymfony24()
{
// Mock of ValidatorInterface until apiVersion 2.4
$validator = $this->getMock('Symfony\Component\Validator\ValidatorInterface');
$formTypeValidatorExtension = new FormTypeValidatorExtension($validator);
$this->assertAttributeSame($validator, 'validator', $formTypeValidatorExtension);
}
/**
* @expectedException \InvalidArgumentException
*/
public function testInvalidValidatorInterface()
{
new FormTypeValidatorExtension(null);
}
protected function createForm(array $options = array())
{
return $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, $options);

View File

@ -31,7 +31,7 @@ class TestExtension implements FormExtensionInterface
public function addType(FormTypeInterface $type)
{
$this->types[$type->getName() ?: get_class($type)] = $type;
$this->types[get_class($type)] = $type;
}
public function getType($name)

View File

@ -40,7 +40,7 @@ class FormFactoryBuilderTest extends \PHPUnit_Framework_TestCase
$extensions = $registry->getExtensions();
$this->assertCount(1, $extensions);
$this->assertTrue($extensions[0]->hasType($this->type->getName()));
$this->assertTrue($extensions[0]->hasType(get_class($this->type)));
$this->assertNull($extensions[0]->getTypeGuesser());
}

View File

@ -153,7 +153,7 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase
/**
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
* @expectedExceptionMessage Expected argument of type "string, Symfony\Component\Form\ResolvedFormTypeInterface or Symfony\Component\Form\FormTypeInterface", "stdClass" given
* @expectedExceptionMessage Expected argument of type "string", "stdClass" given
*/
public function testCreateNamedBuilderThrowsUnderstandableException()
{

View File

@ -1,30 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests;
use Symfony\Component\Form\Test\FormIntegrationTestCase as BaseFormIntegrationTestCase;
/**
* @deprecated since version 2.3, to be removed in 3.0.
* Use {@link \Symfony\Component\Form\Test\FormIntegrationTestCase} instead.
*/
abstract class FormIntegrationTestCase extends BaseFormIntegrationTestCase
{
/**
* {@inheritdoc}
*/
protected function setUp()
{
@trigger_error('The '.__CLASS__.' class is deprecated since version 2.3 and will be removed in 3.0. Use the Symfony\Component\Form\Test\FormIntegrationTestCase class instead.', E_USER_DEPRECATED);
parent::setUp();
}
}

View File

@ -1,30 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests;
use Symfony\Component\Form\Test\FormPerformanceTestCase as BaseFormPerformanceTestCase;
/**
* @deprecated since version 2.3, to be removed in 3.0.
* Use {@link \Symfony\Component\Form\Test\FormPerformanceTestCase} instead.
*/
abstract class FormPerformanceTestCase extends BaseFormPerformanceTestCase
{
/**
* {@inheritdoc}
*/
protected function setUp()
{
@trigger_error('The '.__CLASS__.' class is deprecated since version 2.3 and will be removed in 3.0. Use the Symfony\Component\Form\Test\FormPerformanceTestCase class instead.', E_USER_DEPRECATED);
parent::setUp();
}
}

View File

@ -323,51 +323,6 @@ class ResolvedFormTypeTest extends \PHPUnit_Framework_TestCase
$this->resolvedType->finishView($view, $form, $options);
}
/**
* @dataProvider provideValidNames
*/
public function testGetName($name)
{
$this->type->expects($this->once())
->method('getName')
->willReturn($name);
$resolvedType = new ResolvedFormType($this->type);
$this->assertSame($name, $resolvedType->getName());
}
/**
* @dataProvider provideInvalidNames
* @expectedException \Symfony\Component\Form\Exception\InvalidArgumentException
*/
public function testGetNameFailsIfInvalidChars($name)
{
$this->type->expects($this->once())
->method('getName')
->willReturn($name);
new ResolvedFormType($this->type);
}
public function provideValidNames()
{
return array(
array('text'),
array('type123'),
array('my_type123'),
);
}
public function provideInvalidNames()
{
return array(
array('my-type'),
array('my[type]'),
array('my{type}'),
);
}
public function testGetBlockPrefix()
{
$this->type->expects($this->once())

View File

@ -23,6 +23,21 @@ namespace Symfony\Component\Form\Util;
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class InheritDataAwareIterator extends VirtualFormAwareIterator
class InheritDataAwareIterator extends \IteratorIterator implements \RecursiveIterator
{
/**
* {@inheritdoc}
*/
public function getChildren()
{
return new static($this->current());
}
/**
*{@inheritdoc}
*/
public function hasChildren()
{
return (bool) $this->current()->getConfig()->getInheritData();
}
}

View File

@ -1,58 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Util;
/**
* Iterator that traverses an array of forms.
*
* You can wrap the iterator into a {@link \RecursiveIterator} in order to
* enter any child form that inherits its parent's data and iterate the children
* of that form as well.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.3, to be removed in 3.0.
* Use {@link InheritDataAwareIterator} instead.
*/
class VirtualFormAwareIterator extends \IteratorIterator implements \RecursiveIterator
{
public function __construct(\Traversable $iterator)
{
/*
* Prevent to trigger deprecation notice when already using the
* InheritDataAwareIterator class that extends this deprecated one.
* The {@link Symfony\Component\Form\Util\InheritDataAwareIterator::__construct} method
* forces this argument to false.
*/
if (__CLASS__ === get_class($this)) {
@trigger_error('The '.__CLASS__.' class is deprecated since version 2.3 and will be removed in 3.0. Use the Symfony\Component\Form\Util\InheritDataAwareIterator class instead.', E_USER_DEPRECATED);
}
parent::__construct($iterator);
}
/**
* {@inheritdoc}
*/
public function getChildren()
{
return new static($this->current());
}
/**
*{@inheritdoc}
*/
public function hasChildren()
{
return (bool) $this->current()->getConfig()->getInheritData();
}
}

View File

@ -1,30 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Validator;
/**
* An object backed by a PHP class.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.5, to be removed in 3.0.
* Use {@link Mapping\ClassMetadataInterface} instead.
*/
interface ClassBasedInterface
{
/**
* Returns the name of the backing PHP class.
*
* @return string The name of the backing class.
*/
public function getClassName();
}

View File

@ -11,9 +11,7 @@
namespace Symfony\Component\Validator;
use Symfony\Component\Validator\Context\ExecutionContextInterface as ExecutionContextInterface2Dot5;
use Symfony\Component\Validator\Violation\ConstraintViolationBuilderInterface;
use Symfony\Component\Validator\Violation\LegacyConstraintViolationBuilder;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
/**
* Base class for constraint validators.
@ -50,51 +48,6 @@ abstract class ConstraintValidator implements ConstraintValidatorInterface
$this->context = $context;
}
/**
* Wrapper for {@link ExecutionContextInterface::buildViolation} that
* supports the 2.4 context API.
*
* @param string $message The violation message
* @param array $parameters The message parameters
*
* @return ConstraintViolationBuilderInterface The violation builder
*
* @deprecated since version 2.5, to be removed in 3.0.
*/
protected function buildViolation($message, array $parameters = array())
{
@trigger_error('The '.__METHOD__.' is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
if ($this->context instanceof ExecutionContextInterface2Dot5) {
return $this->context->buildViolation($message, $parameters);
}
return new LegacyConstraintViolationBuilder($this->context, $message, $parameters);
}
/**
* Wrapper for {@link ExecutionContextInterface::buildViolation} that
* supports the 2.4 context API.
*
* @param ExecutionContextInterface $context The context to use
* @param string $message The violation message
* @param array $parameters The message parameters
*
* @return ConstraintViolationBuilderInterface The violation builder
*
* @deprecated since version 2.5, to be removed in 3.0.
*/
protected function buildViolationInContext(ExecutionContextInterface $context, $message, array $parameters = array())
{
@trigger_error('The '.__METHOD__.' is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
if ($context instanceof ExecutionContextInterface2Dot5) {
return $context->buildViolation($message, $parameters);
}
return new LegacyConstraintViolationBuilder($context, $message, $parameters);
}
/**
* Returns a string representation of the type of the value.
*

View File

@ -11,6 +11,8 @@
namespace Symfony\Component\Validator;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/

View File

@ -141,19 +141,6 @@ class ConstraintViolation implements ConstraintViolationInterface
/**
* {@inheritdoc}
*
* @deprecated since version 2.7, to be removed in 3.0.
* Use getParameters() instead
*/
public function getMessageParameters()
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.7, to be removed in 3.0. Use the ConstraintViolation::getParameters() method instead.', E_USER_DEPRECATED);
return $this->parameters;
}
/**
* Alias of {@link getMessageParameters()}.
*/
public function getParameters()
{
@ -162,19 +149,6 @@ class ConstraintViolation implements ConstraintViolationInterface
/**
* {@inheritdoc}
*
* @deprecated since version 2.7, to be removed in 3.0.
* Use getPlural() instead
*/
public function getMessagePluralization()
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.7, to be removed in 3.0. Use the ConstraintViolation::getPlural() method instead.', E_USER_DEPRECATED);
return $this->plural;
}
/**
* Alias of {@link getMessagePluralization()}.
*/
public function getPlural()
{

View File

@ -46,7 +46,7 @@ interface ConstraintViolationInterface
* Returns the raw violation message.
*
* The raw violation message contains placeholders for the parameters
* returned by {@link getMessageParameters}. Typically you'll pass the
* returned by {@link getParameters}. Typically you'll pass the
* message template and parameters to a translation engine.
*
* @return string The raw violation message.
@ -60,10 +60,8 @@ interface ConstraintViolationInterface
* that appear in the message template.
*
* @see getMessageTemplate()
*
* @deprecated since version 2.7, to be replaced by getParameters() in 3.0.
*/
public function getMessageParameters();
public function getParameters();
/**
* Returns a number for pluralizing the violation message.
@ -80,10 +78,8 @@ interface ConstraintViolationInterface
* pluralization form (in this case "choices").
*
* @return int|null The number to use to pluralize of the message.
*
* @deprecated since version 2.7, to be replaced by getPlural() in 3.0.
*/
public function getMessagePluralization();
public function getPlural();
/**
* Returns the root element of the validation.

View File

@ -13,7 +13,6 @@ namespace Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
/**
@ -40,17 +39,10 @@ class AllValidator extends ConstraintValidator
$context = $this->context;
if ($context instanceof ExecutionContextInterface) {
$validator = $context->getValidator()->inContext($context);
$validator = $context->getValidator()->inContext($context);
foreach ($value as $key => $element) {
$validator->atPath('['.$key.']')->validate($element, $constraint->constraints);
}
} else {
// 2.4 API
foreach ($value as $key => $element) {
$context->validateValue($element, $constraint->constraints, '['.$key.']');
}
foreach ($value as $key => $element) {
$validator->atPath('['.$key.']')->validate($element, $constraint->constraints);
}
}
}

View File

@ -28,13 +28,6 @@ class Callback extends Constraint
*/
public $callback;
/**
* @var array
*
* @deprecated since version 2.4, to be removed in 3.0.
*/
public $methods;
/**
* {@inheritdoc}
*/
@ -45,16 +38,9 @@ class Callback extends Constraint
$options = $options['value'];
}
if (is_array($options) && isset($options['methods'])) {
@trigger_error('The "methods" option of the '.__CLASS__.' class is deprecated since version 2.4 and will be removed in 3.0. Use the "callback" option instead.', E_USER_DEPRECATED);
}
if (is_array($options) && !isset($options['callback']) && !isset($options['methods']) && !isset($options['groups'])) {
if (is_array($options) && !isset($options['callback']) && !isset($options['groups'])) {
if (is_callable($options) || !$options) {
$options = array('callback' => $options);
} else {
// @deprecated, to be removed in 3.0
$options = array('methods' => $options);
}
}

View File

@ -32,45 +32,29 @@ class CallbackValidator extends ConstraintValidator
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Callback');
}
if (null !== $constraint->callback && null !== $constraint->methods) {
throw new ConstraintDefinitionException(
'The Callback constraint supports either the option "callback" '.
'or "methods", but not both at the same time.'
);
}
// has to be an array so that we can differentiate between callables
// and method names
if (null !== $constraint->methods && !is_array($constraint->methods)) {
throw new UnexpectedTypeException($constraint->methods, 'array');
}
$methods = $constraint->methods ?: array($constraint->callback);
foreach ($methods as $method) {
if ($method instanceof \Closure) {
$method($object, $this->context);
} elseif (is_array($method)) {
if (!is_callable($method)) {
if (isset($method[0]) && is_object($method[0])) {
$method[0] = get_class($method[0]);
}
throw new ConstraintDefinitionException(sprintf('%s targeted by Callback constraint is not a valid callable', json_encode($method)));
$method = $constraint->callback;
if ($method instanceof \Closure) {
$method($object, $this->context);
} elseif (is_array($method)) {
if (!is_callable($method)) {
if (isset($method[0]) && is_object($method[0])) {
$method[0] = get_class($method[0]);
}
throw new ConstraintDefinitionException(sprintf('%s targeted by Callback constraint is not a valid callable', json_encode($method)));
}
call_user_func($method, $object, $this->context);
} elseif (null !== $object) {
if (!method_exists($object, $method)) {
throw new ConstraintDefinitionException(sprintf('Method "%s" targeted by Callback constraint does not exist in class %s', $method, get_class($object)));
}
call_user_func($method, $object, $this->context);
} elseif (null !== $object) {
if (!method_exists($object, $method)) {
throw new ConstraintDefinitionException(sprintf('Method "%s" targeted by Callback constraint does not exist in class %s', $method, get_class($object)));
}
$reflMethod = new \ReflectionMethod($object, $method);
$reflMethod = new \ReflectionMethod($object, $method);
if ($reflMethod->isStatic()) {
$reflMethod->invoke(null, $object, $this->context);
} else {
$reflMethod->invoke($object, $this->context);
}
if ($reflMethod->isStatic()) {
$reflMethod->invoke(null, $object, $this->context);
} else {
$reflMethod->invoke($object, $this->context);
}
}
}

Some files were not shown because too many files have changed in this diff Show More