minor #12720 [Hackday] [Form] Deprecation messages for Form::bind() and Form::isBound() (stefanosala)

This PR was merged into the 2.7 branch.

Discussion
----------

[Hackday] [Form] Deprecation messages for Form::bind() and Form::isBound()

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | #12713, #12711
| License       | MIT
| Doc PR        | -

Commits
-------

eb9e4d3 [Form] Add deprecation message for Form::bind() and Form::isBound()
This commit is contained in:
Fabien Potencier 2015-01-03 15:46:49 +01:00
commit ff25c81002

View File

@ -20,6 +20,7 @@ use Symfony\Component\Form\Exception\OutOfBoundsException;
use Symfony\Component\Form\Util\FormUtil;
use Symfony\Component\Form\Util\InheritDataAwareIterator;
use Symfony\Component\Form\Util\OrderedHashMap;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\PropertyAccess\PropertyPath;
/**
@ -505,6 +506,10 @@ class Form implements \IteratorAggregate, FormInterface
*/
public function submit($submittedData, $clearMissing = true)
{
if ($submittedData instanceof Request) {
trigger_error('Passing a Symfony\Component\HttpFoundation\Request object to '.__CLASS__.'::bind() and '.__METHOD__.'() is deprecated since 2.3 and will be removed in 3.0, please use '.__CLASS__.'::handleRequest(). If you want to test whether the form was submitted separately, you can use the method '.__CLASS__.'::isSubmitted()', E_USER_DEPRECATED);
}
if ($this->submitted) {
throw new AlreadySubmittedException('A form can only be submitted once');
}
@ -676,6 +681,12 @@ class Form implements \IteratorAggregate, FormInterface
*/
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(__METHOD__.'() is deprecated since 2.3 and will be removed in 3.0. Please use '.__CLASS__.'::submit() instead.', E_USER_DEPRECATED);
}
return $this->submit($submittedData);
}
@ -713,6 +724,8 @@ class Form implements \IteratorAggregate, FormInterface
*/
public function isBound()
{
trigger_error(__METHOD__.'() is deprecated since 2.3 and will be removed in 3.0. Please use '.__CLASS__.'::isSubmitted() instead.', E_USER_DEPRECATED);
return $this->submitted;
}