Skip to content

[Form] Missing deprecated paths removal #23046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this one should be done in lower branches too. See #23048

</service>
</services>
</container>
5 changes: 5 additions & 0 deletions src/Symfony/Component/Form/CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading