Remove deprecated implementation of ChoiceLoaderInterface in intl forms

This commit is contained in:
Yonel Ceruto 2019-05-28 15:53:42 -04:00
parent 9cc2a4ecd1
commit b22cbf41c0
8 changed files with 4 additions and 336 deletions

View File

@ -12,28 +12,13 @@
namespace Symfony\Component\Form\Extension\Core\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
use Symfony\Component\Form\ChoiceList\Loader\IntlCallbackChoiceLoader;
use Symfony\Component\Intl\Countries;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
class CountryType extends AbstractType implements ChoiceLoaderInterface
class CountryType extends AbstractType
{
/**
* Country loaded choice list.
*
* The choices are lazy loaded and generated from the Intl component.
*
* {@link \Symfony\Component\Intl\Intl::getRegionBundle()}.
*
* @var ArrayChoiceList
*
* @deprecated since Symfony 4.1
*/
private $choiceList;
/**
* {@inheritdoc}
*/
@ -69,61 +54,4 @@ class CountryType extends AbstractType implements ChoiceLoaderInterface
{
return 'country';
}
/**
* {@inheritdoc}
*
* @deprecated since Symfony 4.1
*/
public function loadChoiceList($value = null)
{
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.1, use the "choice_loader" option instead.', __METHOD__), E_USER_DEPRECATED);
if (null !== $this->choiceList) {
return $this->choiceList;
}
return $this->choiceList = new ArrayChoiceList(array_flip(Countries::getNames()), $value);
}
/**
* {@inheritdoc}
*
* @deprecated since Symfony 4.1
*/
public function loadChoicesForValues(array $values, $value = null)
{
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.1, use the "choice_loader" option instead.', __METHOD__), E_USER_DEPRECATED);
// Optimize
$values = array_filter($values);
if (empty($values)) {
return [];
}
return $this->loadChoiceList($value)->getChoicesForValues($values);
}
/**
* {@inheritdoc}
*
* @deprecated since Symfony 4.1
*/
public function loadValuesForChoices(array $choices, $value = null)
{
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.1, use the "choice_loader" option instead.', __METHOD__), E_USER_DEPRECATED);
// Optimize
$choices = array_filter($choices);
if (empty($choices)) {
return [];
}
// If no callable is set, choices are the same as values
if (null === $value) {
return $choices;
}
return $this->loadChoiceList($value)->getValuesForChoices($choices);
}
}

View File

@ -12,28 +12,13 @@
namespace Symfony\Component\Form\Extension\Core\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
use Symfony\Component\Form\ChoiceList\Loader\IntlCallbackChoiceLoader;
use Symfony\Component\Intl\Currencies;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
class CurrencyType extends AbstractType implements ChoiceLoaderInterface
class CurrencyType extends AbstractType
{
/**
* Currency loaded choice list.
*
* The choices are lazy loaded and generated from the Intl component.
*
* {@link \Symfony\Component\Intl\Intl::getCurrencyBundle()}.
*
* @var ArrayChoiceList
*
* @deprecated since Symfony 4.1
*/
private $choiceList;
/**
* {@inheritdoc}
*/
@ -69,61 +54,4 @@ class CurrencyType extends AbstractType implements ChoiceLoaderInterface
{
return 'currency';
}
/**
* {@inheritdoc}
*
* @deprecated since Symfony 4.1
*/
public function loadChoiceList($value = null)
{
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.1, use the "choice_loader" option instead.', __METHOD__), E_USER_DEPRECATED);
if (null !== $this->choiceList) {
return $this->choiceList;
}
return $this->choiceList = new ArrayChoiceList(array_flip(Currencies::getNames()), $value);
}
/**
* {@inheritdoc}
*
* @deprecated since Symfony 4.1
*/
public function loadChoicesForValues(array $values, $value = null)
{
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.1, use the "choice_loader" option instead.', __METHOD__), E_USER_DEPRECATED);
// Optimize
$values = array_filter($values);
if (empty($values)) {
return [];
}
return $this->loadChoiceList($value)->getChoicesForValues($values);
}
/**
* {@inheritdoc}
*
* @deprecated since Symfony 4.1
*/
public function loadValuesForChoices(array $choices, $value = null)
{
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.1, use the "choice_loader" option instead.', __METHOD__), E_USER_DEPRECATED);
// Optimize
$choices = array_filter($choices);
if (empty($choices)) {
return [];
}
// If no callable is set, choices are the same as values
if (null === $value) {
return $choices;
}
return $this->loadChoiceList($value)->getValuesForChoices($choices);
}
}

View File

@ -12,28 +12,13 @@
namespace Symfony\Component\Form\Extension\Core\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
use Symfony\Component\Form\ChoiceList\Loader\IntlCallbackChoiceLoader;
use Symfony\Component\Intl\Languages;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
class LanguageType extends AbstractType implements ChoiceLoaderInterface
class LanguageType extends AbstractType
{
/**
* Language loaded choice list.
*
* The choices are lazy loaded and generated from the Intl component.
*
* {@link \Symfony\Component\Intl\Intl::getLanguageBundle()}.
*
* @var ArrayChoiceList
*
* @deprecated since Symfony 4.1
*/
private $choiceList;
/**
* {@inheritdoc}
*/
@ -69,61 +54,4 @@ class LanguageType extends AbstractType implements ChoiceLoaderInterface
{
return 'language';
}
/**
* {@inheritdoc}
*
* @deprecated since Symfony 4.1
*/
public function loadChoiceList($value = null)
{
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.1, use the "choice_loader" option instead.', __METHOD__), E_USER_DEPRECATED);
if (null !== $this->choiceList) {
return $this->choiceList;
}
return $this->choiceList = new ArrayChoiceList(array_flip(Languages::getNames()), $value);
}
/**
* {@inheritdoc}
*
* @deprecated since Symfony 4.1
*/
public function loadChoicesForValues(array $values, $value = null)
{
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.1, use the "choice_loader" option instead.', __METHOD__), E_USER_DEPRECATED);
// Optimize
$values = array_filter($values);
if (empty($values)) {
return [];
}
return $this->loadChoiceList($value)->getChoicesForValues($values);
}
/**
* {@inheritdoc}
*
* @deprecated since Symfony 4.1
*/
public function loadValuesForChoices(array $choices, $value = null)
{
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.1, use the "choice_loader" option instead.', __METHOD__), E_USER_DEPRECATED);
// Optimize
$choices = array_filter($choices);
if (empty($choices)) {
return [];
}
// If no callable is set, choices are the same as values
if (null === $value) {
return $choices;
}
return $this->loadChoiceList($value)->getValuesForChoices($choices);
}
}

View File

@ -12,28 +12,13 @@
namespace Symfony\Component\Form\Extension\Core\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
use Symfony\Component\Form\ChoiceList\Loader\IntlCallbackChoiceLoader;
use Symfony\Component\Intl\Locales;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
class LocaleType extends AbstractType implements ChoiceLoaderInterface
class LocaleType extends AbstractType
{
/**
* Locale loaded choice list.
*
* The choices are lazy loaded and generated from the Intl component.
*
* {@link \Symfony\Component\Intl\Intl::getLocaleBundle()}.
*
* @var ArrayChoiceList
*
* @deprecated since Symfony 4.1
*/
private $choiceList;
/**
* {@inheritdoc}
*/
@ -69,61 +54,4 @@ class LocaleType extends AbstractType implements ChoiceLoaderInterface
{
return 'locale';
}
/**
* {@inheritdoc}
*
* @deprecated since Symfony 4.1
*/
public function loadChoiceList($value = null)
{
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.1, use the "choice_loader" option instead.', __METHOD__), E_USER_DEPRECATED);
if (null !== $this->choiceList) {
return $this->choiceList;
}
return $this->choiceList = new ArrayChoiceList(array_flip(Locales::getNames()), $value);
}
/**
* {@inheritdoc}
*
* @deprecated since Symfony 4.1
*/
public function loadChoicesForValues(array $values, $value = null)
{
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.1, use the "choice_loader" option instead.', __METHOD__), E_USER_DEPRECATED);
// Optimize
$values = array_filter($values);
if (empty($values)) {
return [];
}
return $this->loadChoiceList($value)->getChoicesForValues($values);
}
/**
* {@inheritdoc}
*
* @deprecated since Symfony 4.1
*/
public function loadValuesForChoices(array $choices, $value = null)
{
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.1, use the "choice_loader" option instead.', __METHOD__), E_USER_DEPRECATED);
// Optimize
$choices = array_filter($choices);
if (empty($choices)) {
return [];
}
// If no callable is set, choices are the same as values
if (null === $value) {
return $choices;
}
return $this->loadChoiceList($value)->getValuesForChoices($choices);
}
}

View File

@ -12,7 +12,6 @@
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
use Symfony\Component\Form\Extension\Core\Type\CountryType;
use Symfony\Component\Intl\Util\IntlTestHelper;
class CountryTypeTest extends BaseTypeTest
@ -81,14 +80,4 @@ class CountryTypeTest extends BaseTypeTest
{
parent::testSubmitNullUsesDefaultEmptyData($emptyData, $expectedData);
}
/**
* @group legacy
*/
public function testInvalidChoiceValuesAreDropped()
{
$type = new CountryType();
$this->assertSame([], $type->loadChoicesForValues(['foo']));
}
}

View File

@ -12,7 +12,6 @@
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
use Symfony\Component\Form\Extension\Core\Type\CurrencyType;
use Symfony\Component\Intl\Util\IntlTestHelper;
class CurrencyTypeTest extends BaseTypeTest
@ -62,14 +61,4 @@ class CurrencyTypeTest extends BaseTypeTest
{
parent::testSubmitNullUsesDefaultEmptyData($emptyData, $expectedData);
}
/**
* @group legacy
*/
public function testInvalidChoiceValuesAreDropped()
{
$type = new CurrencyType();
$this->assertSame([], $type->loadChoicesForValues(['foo']));
}
}

View File

@ -12,7 +12,6 @@
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
use Symfony\Component\Form\Extension\Core\Type\LanguageType;
use Symfony\Component\Intl\Util\IntlTestHelper;
class LanguageTypeTest extends BaseTypeTest
@ -73,14 +72,4 @@ class LanguageTypeTest extends BaseTypeTest
{
parent::testSubmitNullUsesDefaultEmptyData($emptyData, $expectedData);
}
/**
* @group legacy
*/
public function testInvalidChoiceValuesAreDropped()
{
$type = new LanguageType();
$this->assertSame([], $type->loadChoicesForValues(['foo']));
}
}

View File

@ -12,7 +12,6 @@
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
use Symfony\Component\Form\Extension\Core\Type\LocaleType;
use Symfony\Component\Intl\Util\IntlTestHelper;
class LocaleTypeTest extends BaseTypeTest
@ -62,14 +61,4 @@ class LocaleTypeTest extends BaseTypeTest
{
parent::testSubmitNullUsesDefaultEmptyData($emptyData, $expectedData);
}
/**
* @group legacy
*/
public function testInvalidChoiceValuesAreDropped()
{
$type = new LocaleType();
$this->assertSame([], $type->loadChoicesForValues(['foo']));
}
}