[Form] removed deprecated features

This commit is contained in:
Fabien Potencier 2015-09-30 21:11:51 +02:00
parent 582f3a39b7
commit 33f3400a81
44 changed files with 28 additions and 2824 deletions

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

@ -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;
/**

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);

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',

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);

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');
}

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);

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

@ -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

@ -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

@ -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

@ -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

@ -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();
}
}