[Form] Removed Form::isBound(). Form::bind() is only a shortcut method now, use Form::isSubmitted() if you want to find out whether a form was submitted.
This commit is contained in:
parent
628a4d1fd8
commit
4f0283a508
@ -11,6 +11,6 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Form\Exception;
|
namespace Symfony\Component\Form\Exception;
|
||||||
|
|
||||||
class AlreadyBoundException extends FormException
|
class AlreadySubmittedException extends FormException
|
||||||
{
|
{
|
||||||
}
|
}
|
@ -16,7 +16,7 @@ use Symfony\Component\HttpFoundation\FileBag;
|
|||||||
use Symfony\Component\Validator\ValidatorInterface;
|
use Symfony\Component\Validator\ValidatorInterface;
|
||||||
use Symfony\Component\Form\Exception\FormException;
|
use Symfony\Component\Form\Exception\FormException;
|
||||||
use Symfony\Component\Form\Exception\MissingOptionsException;
|
use Symfony\Component\Form\Exception\MissingOptionsException;
|
||||||
use Symfony\Component\Form\Exception\AlreadyBoundException;
|
use Symfony\Component\Form\Exception\AlreadySubmittedException;
|
||||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||||
use Symfony\Component\Form\Exception\DanglingFieldException;
|
use Symfony\Component\Form\Exception\DanglingFieldException;
|
||||||
use Symfony\Component\Form\Exception\FieldDefinitionException;
|
use Symfony\Component\Form\Exception\FieldDefinitionException;
|
||||||
@ -51,12 +51,6 @@ class Form extends Field implements \IteratorAggregate, FormInterface
|
|||||||
*/
|
*/
|
||||||
protected $extraFields = array();
|
protected $extraFields = array();
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether a request was bound to the form
|
|
||||||
* @var Boolean
|
|
||||||
*/
|
|
||||||
protected $bound = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores the class that the data of this form must be instances of
|
* Stores the class that the data of this form must be instances of
|
||||||
* @var string
|
* @var string
|
||||||
@ -174,8 +168,8 @@ class Form extends Field implements \IteratorAggregate, FormInterface
|
|||||||
*/
|
*/
|
||||||
public function add($field)
|
public function add($field)
|
||||||
{
|
{
|
||||||
if ($this->isBound()) {
|
if ($this->isSubmitted()) {
|
||||||
throw new AlreadyBoundException('You cannot add fields after binding a form');
|
throw new AlreadySubmittedException('You cannot add fields after submitting a form');
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the field is given as string, ask the field factory of the form
|
// if the field is given as string, ask the field factory of the form
|
||||||
@ -711,8 +705,6 @@ class Form extends Field implements \IteratorAggregate, FormInterface
|
|||||||
*/
|
*/
|
||||||
public function bind(Request $request, $data = null)
|
public function bind(Request $request, $data = null)
|
||||||
{
|
{
|
||||||
$this->bound = true;
|
|
||||||
|
|
||||||
// Store object from which to read the default values and where to
|
// Store object from which to read the default values and where to
|
||||||
// write the submitted values
|
// write the submitted values
|
||||||
if (null !== $data) {
|
if (null !== $data) {
|
||||||
@ -730,14 +722,6 @@ class Form extends Field implements \IteratorAggregate, FormInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Boolean whether a request and an object were bound to the form
|
|
||||||
*/
|
|
||||||
public function isBound()
|
|
||||||
{
|
|
||||||
return $this->bound;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates the form and its domain object
|
* Validates the form and its domain object
|
||||||
*
|
*
|
||||||
|
@ -630,13 +630,13 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
|||||||
$form->addError($error, $path->getIterator(), Form::DATA_ERROR);
|
$form->addError($error, $path->getIterator(), Form::DATA_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAddThrowsExceptionIfAlreadyBound()
|
public function testAddThrowsExceptionIfAlreadySubmitted()
|
||||||
{
|
{
|
||||||
$form = new Form('author', array('validator' => $this->validator));
|
$form = new Form('author', array('validator' => $this->validator));
|
||||||
$form->add($this->createMockField('firstName'));
|
$form->add($this->createMockField('firstName'));
|
||||||
$form->bind(new Request());
|
$form->submit(array());
|
||||||
|
|
||||||
$this->setExpectedException('Symfony\Component\Form\Exception\AlreadyBoundException');
|
$this->setExpectedException('Symfony\Component\Form\Exception\AlreadySubmittedException');
|
||||||
$form->add($this->createMockField('lastName'));
|
$form->add($this->createMockField('lastName'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user