Skip to content

[Form] Renamed form processors to request handlers #7732

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
Apr 20, 2013
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
10 changes: 7 additions & 3 deletions UPGRADE-3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ UPGRADE FROM 2.x to 3.0

* Passing a `Symfony\Component\HttpFoundation\Request` instance to
`FormInterface::bind()` was disabled. You should use
`FormInterface::process()` instead.
`FormInterface::handleRequest()` instead.

Before:

Expand All @@ -39,7 +39,9 @@ UPGRADE FROM 2.x to 3.0
After:

```
if ($form->process($request)->isValid()) {
$form->handleRequest();

if ($form->isValid()) {
// ...
}
```
Expand All @@ -48,7 +50,9 @@ UPGRADE FROM 2.x to 3.0
the method `isBound()`:

```
if ($form->process($request)->isBound()) {
$form->handleRequest();

if ($form->isBound()) {
// ...

if ($form->isValid()) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Form/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ public function isSynchronized()
*
* @throws BadMethodCallException
*/
public function process($request = null)
public function handleRequest($request = null)
{
throw new BadMethodCallException('Buttons cannot be processed. Call process() on the root form instead.');
}
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Form/ButtonBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,11 +483,11 @@ public function setMethod($method)
/**
* Unsupported method.
*
* @param FormProcessorInterface $formProcessor
* @param RequestHandlerInterface $requestHandler
*
* @throws BadMethodCallException
*/
public function setFormProcessor(FormProcessorInterface $formProcessor)
public function setRequestHandler(RequestHandlerInterface $requestHandler)
{
throw new BadMethodCallException('Buttons do not support form processors.');
}
Expand Down Expand Up @@ -766,7 +766,7 @@ public function getMethod()
*
* @return null Always returns null.
*/
public function getFormProcessor()
public function getRequestHandler()
{
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Form/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ CHANGELOG
* deprecated FormPerformanceTestCase and FormIntegrationTestCase in the Symfony\Component\Form\Tests namespace and moved them to the Symfony\Component\Form\Test namespace
* deprecated TypeTestCase in the Symfony\Component\Form\Tests\Extension\Core\Type namespace and moved it to the Symfony\Component\Form\Test namespace
* changed FormRenderer::humanize() to humanize also camel cased field name
* added FormProcessorInterface and FormInterface::process()
* added RequestHandlerInterface and FormInterface::handleRequest()
* deprecated passing a Request instance to FormInterface::bind()
* added options "method" and "action" to FormType
* deprecated option "virtual" in favor "inherit_data"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@
use Symfony\Component\Form\Exception\InvalidArgumentException;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormProcessorInterface;
use Symfony\Component\Form\RequestHandlerInterface;
use Symfony\Component\HttpFoundation\Request;

/**
* A form processor using the {@link Request} class of the HttpFoundation
* A request processor using the {@link Request} class of the HttpFoundation
* component.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class RequestFormProcessor implements FormProcessorInterface
class HttpFoundationRequestHandler implements RequestHandlerInterface
{
/**
* {@inheritdoc}
*/
public function processForm(FormInterface $form, $request = null)
public function handleRequest(FormInterface $form, $request = null)
{
if (!$request instanceof Request) {
throw new UnexpectedTypeException($request, 'Symfony\Component\HttpFoundation\Request');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Extension\HttpFoundation\EventListener\BindRequestListener;
use Symfony\Component\Form\Extension\HttpFoundation\RequestFormProcessor;
use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationRequestHandler;
use Symfony\Component\Form\FormBuilderInterface;

/**
Expand All @@ -27,14 +27,14 @@ class FormTypeHttpFoundationExtension extends AbstractTypeExtension
private $listener;

/**
* @var RequestFormProcessor
* @var HttpFoundationRequestHandler
*/
private $processor;
private $requestHandler;

public function __construct()
{
$this->listener = new BindRequestListener();
$this->processor = new RequestFormProcessor();
$this->requestHandler = new HttpFoundationRequestHandler();
}

/**
Expand All @@ -43,7 +43,7 @@ public function __construct()
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->addEventSubscriber($this->listener);
$builder->setFormProcessor($this->processor);
$builder->setRequestHandler($this->requestHandler);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Form/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,9 @@ public function getExtraData()
/**
* {@inheritdoc}
*/
public function process($request = null)
public function handleRequest($request = null)
{
$this->config->getFormProcessor()->processForm($this, $request);
$this->config->getRequestHandler()->handleRequest($this, $request);

return $this;
}
Expand Down
26 changes: 13 additions & 13 deletions src/Symfony/Component/Form/FormConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
class FormConfigBuilder implements FormConfigBuilderInterface
{
/**
* Caches a globally unique {@link NativeFormProcessor} instance.
* Caches a globally unique {@link NativeRequestHandler} instance.
*
* @var NativeFormProcessor
* @var NativeRequestHandler
*/
private static $nativeFormProcessor;
private static $nativeRequestProcessor;

/**
* The accepted request methods.
Expand Down Expand Up @@ -168,9 +168,9 @@ class FormConfigBuilder implements FormConfigBuilderInterface
private $method = 'POST';

/**
* @var FormProcessorInterface
* @var RequestHandlerInterface
*/
private $formProcessor;
private $requestHandler;

/**
* @var array
Expand Down Expand Up @@ -509,16 +509,16 @@ public function getMethod()
/**
* {@inheritdoc}
*/
public function getFormProcessor()
public function getRequestHandler()
{
if (null === $this->formProcessor) {
if (null === self::$nativeFormProcessor) {
self::$nativeFormProcessor = new NativeFormProcessor();
if (null === $this->requestHandler) {
if (null === self::$nativeRequestProcessor) {
self::$nativeRequestProcessor = new NativeRequestHandler();
}
$this->formProcessor = self::$nativeFormProcessor;
$this->requestHandler = self::$nativeRequestProcessor;
}

return $this->formProcessor;
return $this->requestHandler;
}

/**
Expand Down Expand Up @@ -832,13 +832,13 @@ public function setMethod($method)
/**
* {@inheritdoc}
*/
public function setFormProcessor(FormProcessorInterface $formProcessor)
public function setRequestHandler(RequestHandlerInterface $requestHandler)
{
if ($this->locked) {
throw new BadMethodCallException('The config builder cannot be modified anymore.');
}

$this->formProcessor = $formProcessor;
$this->requestHandler = $requestHandler;

return $this;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Form/FormConfigBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,11 @@ public function setAction($action);
public function setMethod($method);

/**
* @param FormProcessorInterface $formProcessor
* @param RequestHandlerInterface $requestHandler
*
* @return self The configuration object.
*/
public function setFormProcessor(FormProcessorInterface $formProcessor);
public function setRequestHandler(RequestHandlerInterface $requestHandler);

/**
* Builds and returns the form configuration.
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Form/FormConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ public function getAction();
public function getMethod();

/**
* @return FormProcessorInterface The form processor.
* @return RequestHandlerInterface The form processor.
*/
public function getFormProcessor();
public function getRequestHandler();

/**
* Returns all options passed during the construction of the form.
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Form/FormInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,15 @@ public function isSynchronized();
/**
* Processes the given request and binds the form if it was submitted.
*
* Internally, the request is forwarded to a {@link FormProcessorInterface}
* Internally, the request is forwarded to a {@link RequestHandlerInterface}
* instance. This instance determines the allowed value of the
* $request parameter.
*
* @param mixed $request The request to check.
*
* @return FormInterface The form instance.
*/
public function process($request = null);
public function handleRequest($request = null);

/**
* Binds data to the form, transforms and validates it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormProcessorInterface;
use Symfony\Component\Form\RequestHandlerInterface;

/**
* A form processor using PHP's super globals $_GET, $_POST and $_SERVER.
* A request handler using PHP's super globals $_GET, $_POST and $_SERVER.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class NativeFormProcessor implements FormProcessorInterface
class NativeRequestHandler implements RequestHandlerInterface
{
/**
* The allowed keys of the $_FILES array.
Expand All @@ -38,7 +38,7 @@ class NativeFormProcessor implements FormProcessorInterface
/**
* {@inheritdoc}
*/
public function processForm(FormInterface $form, $request = null)
public function handleRequest(FormInterface $form, $request = null)
{
if (null !== $request) {
throw new UnexpectedTypeException($request, 'null');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
interface FormProcessorInterface
interface RequestHandlerInterface
{
/**
* Binds a form from a request if it was submitted.
*
* @param FormInterface $form The form to bind.
* @param mixed $request The current request.
*/
public function processForm(FormInterface $form, $request = null);
public function handleRequest(FormInterface $form, $request = null);
}
Loading