Skip to content

Commit

Permalink
feature #23046 [Form] Missing deprecated paths removal (ogizanagi)
Browse files Browse the repository at this point in the history
This PR was merged into the 4.0-dev branch.

Discussion
----------

[Form] Missing deprecated paths removal

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no <!-- don't forget updating src/**/CHANGELOG.md files -->
| BC breaks?    | yes
| Deprecations? | no <!-- don't forget updating UPGRADE-*.md files -->
| Tests pass?   | yes
| Fixed tickets | N/A <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | N/A

Commits
-------

761bcca [Form] Missing deprecated paths removal
  • Loading branch information
nicolas-grekas committed Jun 3, 2017
2 parents 6f0f7e1 + 761bcca commit 19c4bb7
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 207 deletions.
Expand Up @@ -38,7 +38,6 @@
<argument /><!-- All services with tag "form.type" are stored in a service locator by FormPass -->
<argument type="collection" /><!-- All services with tag "form.type_extension" are stored here by FormPass -->
<argument type="iterator" /><!-- All services with tag "form.type_guesser" are stored here by FormPass -->
<argument>null</argument><!-- @deprecated argument in 3.3, to be removed in 4.0 -->
</service>

<!-- ValidatorTypeGuesser -->
Expand Down
Expand Up @@ -26,7 +26,6 @@
<service id="data_collector.form" class="Symfony\Component\Form\Extension\DataCollector\FormDataCollector" public="true">
<tag name="data_collector" template="@WebProfiler/Collector/form.html.twig" id="form" priority="310" />
<argument type="service" id="data_collector.form.extractor" />
<argument>false</argument>
</service>
</services>
</container>
5 changes: 5 additions & 0 deletions src/Symfony/Component/Form/CHANGELOG.md
Expand Up @@ -13,6 +13,11 @@ CHANGELOG
* removed the support for caching loaded choice lists in `LazyChoiceList`,
cache the choice list in the used `ChoiceLoaderInterface` implementation
instead
* removed the support for objects implementing both `\Traversable` and `\ArrayAccess` in `ResizeFormListener::preSubmit()`
* removed the ability to use `FormDataCollector` without the `symfony/var-dumper` component
* removed passing a `ValueExporter` instance to the `FormDataExtractor::__construct()` method
* removed passing guesser services ids as the fourth argument of `DependencyInjectionExtension::__construct()`
* removed the ability to validate an unsubmitted form.

3.3.0
-----
Expand Down
Expand Up @@ -102,11 +102,7 @@ public function preSubmit(FormEvent $event)
$form = $event->getForm();
$data = $event->getData();

if ($data instanceof \Traversable && $data instanceof \ArrayAccess) {
@trigger_error('Support for objects implementing both \Traversable and \ArrayAccess is deprecated since version 3.1 and will be removed in 4.0. Use an array instead.', E_USER_DEPRECATED);
}

if (!is_array($data) && !($data instanceof \Traversable && $data instanceof \ArrayAccess)) {
if (!is_array($data)) {
$data = array();
}

Expand Down
Expand Up @@ -16,7 +16,6 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
use Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter;
use Symfony\Component\Validator\ConstraintViolationInterface;
use Symfony\Component\VarDumper\Caster\Caster;
use Symfony\Component\VarDumper\Caster\ClassStub;
Expand Down Expand Up @@ -72,27 +71,23 @@ class FormDataCollector extends DataCollector implements FormDataCollectorInterf
*/
private $formsByView;

/**
* @var ValueExporter
*/
private $valueExporter;

/**
* @var ClonerInterface
*/
private $cloner;

private $hasVarDumper;

public function __construct(FormDataExtractorInterface $dataExtractor)
{
if (!class_exists(ClassStub::class)) {
throw new \LogicException(sprintf('The VarDumper component is needed for using the %s class. Install symfony/var-dumper version 3.4 or above.', __CLASS__));
}

$this->dataExtractor = $dataExtractor;
$this->data = array(
'forms' => array(),
'forms_by_hash' => array(),
'nb_errors' => 0,
);
$this->hasVarDumper = class_exists(ClassStub::class);
}

/**
Expand Down Expand Up @@ -241,11 +236,9 @@ public function getData()

public function serialize()
{
if ($this->hasVarDumper) {
foreach ($this->data['forms_by_hash'] as &$form) {
if (isset($form['type_class']) && !$form['type_class'] instanceof ClassStub) {
$form['type_class'] = new ClassStub($form['type_class']);
}
foreach ($this->data['forms_by_hash'] as &$form) {
if (isset($form['type_class']) && !$form['type_class'] instanceof ClassStub) {
$form['type_class'] = new ClassStub($form['type_class']);
}
}

Expand All @@ -261,55 +254,43 @@ protected function cloneVar($var, $isClass = false)
return $var;
}
if (null === $this->cloner) {
if ($this->hasVarDumper) {
$this->cloner = new VarCloner();
$this->cloner->setMaxItems(-1);
$this->cloner->addCasters(array(
'*' => function ($v, array $a, Stub $s, $isNested) {
foreach ($a as &$v) {
if (is_object($v) && !$v instanceof \DateTimeInterface) {
$v = new CutStub($v);
}
$this->cloner = new VarCloner();
$this->cloner->setMaxItems(-1);
$this->cloner->addCasters(array(
'*' => function ($v, array $a, Stub $s, $isNested) {
foreach ($a as &$v) {
if (is_object($v) && !$v instanceof \DateTimeInterface) {
$v = new CutStub($v);
}

return $a;
},
\Exception::class => function (\Exception $e, array $a, Stub $s) {
if (isset($a[$k = "\0Exception\0previous"])) {
unset($a[$k]);
++$s->cut;
}

return $a;
},
FormInterface::class => function (FormInterface $f, array $a) {
return array(
Caster::PREFIX_VIRTUAL.'name' => $f->getName(),
Caster::PREFIX_VIRTUAL.'type_class' => new ClassStub(get_class($f->getConfig()->getType()->getInnerType())),
);
},
ConstraintViolationInterface::class => function (ConstraintViolationInterface $v, array $a) {
return array(
Caster::PREFIX_VIRTUAL.'root' => $v->getRoot(),
Caster::PREFIX_VIRTUAL.'path' => $v->getPropertyPath(),
Caster::PREFIX_VIRTUAL.'value' => $v->getInvalidValue(),
);
},
));
} else {
@trigger_error(sprintf('Using the %s() method without the VarDumper component is deprecated since version 3.2 and won\'t be supported in 4.0. Install symfony/var-dumper version 3.2 or above.', __METHOD__), E_USER_DEPRECATED);
$this->cloner = false;
}
}
if (false !== $this->cloner) {
return $this->cloner->cloneVar($var, Caster::EXCLUDE_VERBOSE);
}

if (null === $this->valueExporter) {
$this->valueExporter = new ValueExporter();
}

return $a;
},
\Exception::class => function (\Exception $e, array $a, Stub $s) {
if (isset($a[$k = "\0Exception\0previous"])) {
unset($a[$k]);
++$s->cut;
}

return $a;
},
FormInterface::class => function (FormInterface $f, array $a) {
return array(
Caster::PREFIX_VIRTUAL.'name' => $f->getName(),
Caster::PREFIX_VIRTUAL.'type_class' => new ClassStub(get_class($f->getConfig()->getType()->getInnerType())),
);
},
ConstraintViolationInterface::class => function (ConstraintViolationInterface $v, array $a) {
return array(
Caster::PREFIX_VIRTUAL.'root' => $v->getRoot(),
Caster::PREFIX_VIRTUAL.'path' => $v->getPropertyPath(),
Caster::PREFIX_VIRTUAL.'value' => $v->getInvalidValue(),
);
},
));
}

return $this->valueExporter->exportValue($var);
return $this->cloner->cloneVar($var, Caster::EXCLUDE_VERBOSE);
}

private function &recursiveBuildPreliminaryFormTree(FormInterface $form, array &$outputByHash)
Expand Down
Expand Up @@ -13,7 +13,6 @@

use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter;
use Symfony\Component\Validator\ConstraintViolationInterface;

/**
Expand All @@ -23,16 +22,6 @@
*/
class FormDataExtractor implements FormDataExtractorInterface
{
/**
* Constructs a new data extractor.
*/
public function __construct(ValueExporter $valueExporter = null, $triggerDeprecationNotice = true)
{
if (null !== $valueExporter && $triggerDeprecationNotice) {
@trigger_error('Passing a ValueExporter instance to '.__METHOD__.'() is deprecated in version 3.2 and will be removed in 4.0.', E_USER_DEPRECATED);
}
}

/**
* {@inheritdoc}
*/
Expand Down
Expand Up @@ -24,42 +24,22 @@ class DependencyInjectionExtension implements FormExtensionInterface
private $typeExtensionServices;
private $guesserServices;

// @deprecated to be removed in Symfony 4.0
private $typeServiceIds;
private $guesserServiceIds;

/**
* Constructor.
*
* @param ContainerInterface $typeContainer
* @param iterable[] $typeExtensionServices
* @param iterable $guesserServices
*/
public function __construct(ContainerInterface $typeContainer, array $typeExtensionServices, $guesserServices, array $guesserServiceIds = null)
public function __construct(ContainerInterface $typeContainer, array $typeExtensionServices, $guesserServices)
{
if (null !== $guesserServiceIds) {
@trigger_error(sprintf('Passing four arguments to the %s::__construct() method is deprecated since Symfony 3.3 and will be disallowed in Symfony 4.0. The new constructor only accepts three arguments.', __CLASS__), E_USER_DEPRECATED);
$this->guesserServiceIds = $guesserServiceIds;
$this->typeServiceIds = $typeExtensionServices;
$typeExtensionServices = $guesserServices;
$guesserServices = $guesserServiceIds;
}

$this->typeContainer = $typeContainer;
$this->typeExtensionServices = $typeExtensionServices;
$this->guesserServices = $guesserServices;
}

public function getType($name)
{
if (null !== $this->guesserServiceIds) {
if (!isset($this->typeServiceIds[$name])) {
throw new InvalidArgumentException(sprintf('The field type "%s" is not registered in the service container.', $name));
}

return $this->typeContainer->get($this->typeServiceIds[$name]);
}

if (!$this->typeContainer->has($name)) {
throw new InvalidArgumentException(sprintf('The field type "%s" is not registered in the service container.', $name));
}
Expand All @@ -69,10 +49,6 @@ public function getType($name)

public function hasType($name)
{
if (null !== $this->guesserServiceIds) {
return isset($this->typeServiceIds[$name]);
}

return $this->typeContainer->has($name);
}

Expand All @@ -82,10 +58,6 @@ public function getTypeExtensions($name)

if (isset($this->typeExtensionServices[$name])) {
foreach ($this->typeExtensionServices[$name] as $serviceId => $extension) {
if (null !== $this->guesserServiceIds) {
$extension = $this->typeContainer->get($serviceId = $extension);
}

$extensions[] = $extension;

// validate result of getExtendedType() to ensure it is consistent with the service definition
Expand Down Expand Up @@ -116,10 +88,6 @@ public function getTypeGuesser()
$guessers = array();

foreach ($this->guesserServices as $serviceId => $service) {
if (null !== $this->guesserServiceIds) {
$service = $this->typeContainer->get($serviceId = $service);
}

$guessers[] = $service;
}

Expand Down
4 changes: 1 addition & 3 deletions src/Symfony/Component/Form/Form.php
Expand Up @@ -736,9 +736,7 @@ public function isEmpty()
public function isValid()
{
if (!$this->submitted) {
@trigger_error('Call Form::isValid() with an unsubmitted form is deprecated since version 3.2 and will throw an exception in 4.0. Use Form::isSubmitted() before Form::isValid() instead.', E_USER_DEPRECATED);

return false;
throw new LogicException('Cannot check if an unsubmitted form is valid. Call Form::isSubmitted() before Form::isValid().');
}

if ($this->isDisabled()) {
Expand Down

0 comments on commit 19c4bb7

Please sign in to comment.