merged branch bschussek/improve-naming (PR #7732)

This PR was merged into the master branch.

Discussion
----------

[Form] Renamed form processors to request handlers

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | https://github.com/symfony/symfony-docs/pull/2092

Commits
-------

ae7c378 [Form] Renamed form processors to request handlers
This commit is contained in:
Fabien Potencier 2013-04-20 17:48:04 +02:00
commit a00d7dc223
19 changed files with 102 additions and 98 deletions

View File

@ -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:
@ -39,7 +39,9 @@ UPGRADE FROM 2.x to 3.0
After:
```
if ($form->process($request)->isValid()) {
$form->handleRequest();
if ($form->isValid()) {
// ...
}
```
@ -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()) {

View File

@ -350,7 +350,7 @@ class Button implements \IteratorAggregate, FormInterface
*
* @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.');
}

View File

@ -483,11 +483,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/**
* 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.');
}
@ -766,7 +766,7 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
*
* @return null Always returns null.
*/
public function getFormProcessor()
public function getRequestHandler()
{
return null;
}

View File

@ -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"

View File

@ -14,21 +14,21 @@ namespace Symfony\Component\Form\Extension\HttpFoundation;
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');

View File

@ -13,7 +13,7 @@ namespace Symfony\Component\Form\Extension\HttpFoundation\Type;
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;
/**
@ -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();
}
/**
@ -43,7 +43,7 @@ class FormTypeHttpFoundationExtension extends AbstractTypeExtension
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->addEventSubscriber($this->listener);
$builder->setFormProcessor($this->processor);
$builder->setRequestHandler($this->requestHandler);
}
/**

View File

@ -454,9 +454,9 @@ class Form implements \IteratorAggregate, FormInterface
/**
* {@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;
}

View File

@ -28,11 +28,11 @@ use Symfony\Component\EventDispatcher\ImmutableEventDispatcher;
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.
@ -168,9 +168,9 @@ class FormConfigBuilder implements FormConfigBuilderInterface
private $method = 'POST';
/**
* @var FormProcessorInterface
* @var RequestHandlerInterface
*/
private $formProcessor;
private $requestHandler;
/**
* @var array
@ -509,16 +509,16 @@ class FormConfigBuilder implements FormConfigBuilderInterface
/**
* {@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;
}
/**
@ -832,13 +832,13 @@ class FormConfigBuilder implements FormConfigBuilderInterface
/**
* {@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;
}

View File

@ -256,11 +256,11 @@ interface FormConfigBuilderInterface extends FormConfigInterface
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.

View File

@ -201,9 +201,9 @@ interface FormConfigInterface
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.

View File

@ -229,7 +229,7 @@ interface FormInterface extends \ArrayAccess, \Traversable, \Countable
/**
* 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.
*
@ -237,7 +237,7 @@ interface FormInterface extends \ArrayAccess, \Traversable, \Countable
*
* @return FormInterface The form instance.
*/
public function process($request = null);
public function handleRequest($request = null);
/**
* Binds data to the form, transforms and validates it.

View File

@ -13,14 +13,14 @@ namespace Symfony\Component\Form;
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.
@ -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');

View File

@ -16,7 +16,7 @@ namespace Symfony\Component\Form;
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
interface FormProcessorInterface
interface RequestHandlerInterface
{
/**
* Binds a form from a request if it was submitted.
@ -24,5 +24,5 @@ interface FormProcessorInterface
* @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);
}

View File

@ -14,18 +14,18 @@ namespace Symfony\Component\Form\Tests;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
abstract class AbstractFormProcessorTest extends \PHPUnit_Framework_TestCase
abstract class AbstractRequestHandlerTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Symfony\Component\Form\FormProcessorInterface
* @var \Symfony\Component\Form\RequestHandlerInterface
*/
protected $processor;
protected $requestHandler;
protected $request;
protected function setUp()
{
$this->processor = $this->getFormProcessor();
$this->requestHandler = $this->getRequestHandler();
$this->request = null;
}
@ -61,7 +61,7 @@ abstract class AbstractFormProcessorTest extends \PHPUnit_Framework_TestCase
->method('bind')
->with('DATA');
$this->processor->processForm($form, $this->request);
$this->requestHandler->handleRequest($form, $this->request);
}
/**
@ -80,7 +80,7 @@ abstract class AbstractFormProcessorTest extends \PHPUnit_Framework_TestCase
$form->expects($this->never())
->method('bind');
$this->processor->processForm($form, $this->request);
$this->requestHandler->handleRequest($form, $this->request);
}
/**
@ -98,7 +98,7 @@ abstract class AbstractFormProcessorTest extends \PHPUnit_Framework_TestCase
->method('bind')
->with($this->identicalTo(null));
$this->processor->processForm($form, $this->request);
$this->requestHandler->handleRequest($form, $this->request);
}
/**
@ -116,7 +116,7 @@ abstract class AbstractFormProcessorTest extends \PHPUnit_Framework_TestCase
->method('bind')
->with($this->identicalTo(array()));
$this->processor->processForm($form, $this->request);
$this->requestHandler->handleRequest($form, $this->request);
}
public function testDoNotBindIfNameNotInRequestAndGetRequest()
@ -130,7 +130,7 @@ abstract class AbstractFormProcessorTest extends \PHPUnit_Framework_TestCase
$form->expects($this->never())
->method('bind');
$this->processor->processForm($form, $this->request);
$this->requestHandler->handleRequest($form, $this->request);
}
/**
@ -155,7 +155,7 @@ abstract class AbstractFormProcessorTest extends \PHPUnit_Framework_TestCase
->method('bind')
->with($requestData);
$this->processor->processForm($form, $this->request);
$this->requestHandler->handleRequest($form, $this->request);
}
/**
@ -178,7 +178,7 @@ abstract class AbstractFormProcessorTest extends \PHPUnit_Framework_TestCase
$form->expects($this->never())
->method('bind');
$this->processor->processForm($form, $this->request);
$this->requestHandler->handleRequest($form, $this->request);
}
/**
@ -206,7 +206,7 @@ abstract class AbstractFormProcessorTest extends \PHPUnit_Framework_TestCase
'field2' => $file,
));
$this->processor->processForm($form, $this->request);
$this->requestHandler->handleRequest($form, $this->request);
}
/**
@ -227,7 +227,7 @@ abstract class AbstractFormProcessorTest extends \PHPUnit_Framework_TestCase
->method('bind')
->with('DATA');
$this->processor->processForm($form, $this->request);
$this->requestHandler->handleRequest($form, $this->request);
}
/**
@ -248,12 +248,12 @@ abstract class AbstractFormProcessorTest extends \PHPUnit_Framework_TestCase
->method('bind')
->with($file);
$this->processor->processForm($form, $this->request);
$this->requestHandler->handleRequest($form, $this->request);
}
abstract protected function setRequestData($method, $data, $files = array());
abstract protected function getFormProcessor();
abstract protected function getRequestHandler();
abstract protected function getMockFile();

View File

@ -11,7 +11,7 @@
namespace Symfony\Component\Form\Tests;
use Symfony\Component\Form\Extension\HttpFoundation\RequestFormProcessor;
use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationRequestHandler;
use Symfony\Component\Form\FormError;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\File\UploadedFile;
@ -481,12 +481,12 @@ class CompoundFormTest extends AbstractFormTest
->setMethod($method)
->setCompound(true)
->setDataMapper($this->getDataMapper())
->setFormProcessor(new RequestFormProcessor())
->setRequestHandler(new HttpFoundationRequestHandler())
->getForm();
$form->add($this->getBuilder('name')->getForm());
$form->add($this->getBuilder('image')->getForm());
$form->process($request);
$form->handleRequest($request);
$file = new UploadedFile($path, 'upload.png', 'image/png', 123, UPLOAD_ERR_OK);
@ -531,12 +531,12 @@ class CompoundFormTest extends AbstractFormTest
->setMethod($method)
->setCompound(true)
->setDataMapper($this->getDataMapper())
->setFormProcessor(new RequestFormProcessor())
->setRequestHandler(new HttpFoundationRequestHandler())
->getForm();
$form->add($this->getBuilder('name')->getForm());
$form->add($this->getBuilder('image')->getForm());
$form->process($request);
$form->handleRequest($request);
$file = new UploadedFile($path, 'upload.png', 'image/png', 123, UPLOAD_ERR_OK);
@ -575,10 +575,10 @@ class CompoundFormTest extends AbstractFormTest
$form = $this->getBuilder('image')
->setMethod($method)
->setFormProcessor(new RequestFormProcessor())
->setRequestHandler(new HttpFoundationRequestHandler())
->getForm();
$form->process($request);
$form->handleRequest($request);
$file = new UploadedFile($path, 'upload.png', 'image/png', 123, UPLOAD_ERR_OK);
@ -609,10 +609,10 @@ class CompoundFormTest extends AbstractFormTest
$form = $this->getBuilder('name')
->setMethod($method)
->setFormProcessor(new RequestFormProcessor())
->setRequestHandler(new HttpFoundationRequestHandler())
->getForm();
$form->process($request);
$form->handleRequest($request);
$this->assertEquals('Bernhard', $form->getData());
@ -640,12 +640,12 @@ class CompoundFormTest extends AbstractFormTest
->setMethod('GET')
->setCompound(true)
->setDataMapper($this->getDataMapper())
->setFormProcessor(new RequestFormProcessor())
->setRequestHandler(new HttpFoundationRequestHandler())
->getForm();
$form->add($this->getBuilder('firstName')->getForm());
$form->add($this->getBuilder('lastName')->getForm());
$form->process($request);
$form->handleRequest($request);
$this->assertEquals('Bernhard', $form['firstName']->getData());
$this->assertEquals('Schussek', $form['lastName']->getData());
@ -671,12 +671,12 @@ class CompoundFormTest extends AbstractFormTest
->setMethod('GET')
->setCompound(true)
->setDataMapper($this->getDataMapper())
->setFormProcessor(new RequestFormProcessor())
->setRequestHandler(new HttpFoundationRequestHandler())
->getForm();
$form->add($this->getBuilder('firstName')->getForm());
$form->add($this->getBuilder('lastName')->getForm());
$form->process($request);
$form->handleRequest($request);
$this->assertEquals('Bernhard', $form['firstName']->getData());
$this->assertEquals('Schussek', $form['lastName']->getData());

View File

@ -11,28 +11,28 @@
namespace Symfony\Component\Form\Tests\Extension\HttpFoundation;
use Symfony\Component\Form\Extension\HttpFoundation\RequestFormProcessor;
use Symfony\Component\Form\Tests\AbstractFormProcessorTest;
use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationRequestHandler;
use Symfony\Component\Form\Tests\AbstractRequestHandlerTest;
use Symfony\Component\HttpFoundation\Request;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class RequestFormProcessorTest extends AbstractFormProcessorTest
class HttpFoundationRequestHandlerTest extends AbstractRequestHandlerTest
{
/**
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
*/
public function testRequestShouldNotBeNull()
{
$this->processor->processForm($this->getMockForm('name', 'GET'));
$this->requestHandler->handleRequest($this->getMockForm('name', 'GET'));
}
/**
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
*/
public function testRequestShouldBeInstanceOfRequest()
{
$this->processor->processForm($this->getMockForm('name', 'GET'), new \stdClass());
$this->requestHandler->handleRequest($this->getMockForm('name', 'GET'), new \stdClass());
}
protected function setRequestData($method, $data, $files = array())
@ -40,9 +40,9 @@ class RequestFormProcessorTest extends AbstractFormProcessorTest
$this->request = Request::create('http://localhost', $method, $data, array(), $files);
}
protected function getFormProcessor()
protected function getRequestHandler()
{
return new RequestFormProcessor();
return new HttpFoundationRequestHandler();
}
protected function getMockFile()

View File

@ -91,19 +91,19 @@ class FormConfigTest extends \PHPUnit_Framework_TestCase
}
}
public function testGetFormProcessorCreatesNativeFormProcessorIfNotSet()
public function testGetRequestHandlerCreatesNativeRequestHandlerIfNotSet()
{
$config = $this->getConfigBuilder()->getFormConfig();
$this->assertInstanceOf('Symfony\Component\Form\NativeFormProcessor', $config->getFormProcessor());
$this->assertInstanceOf('Symfony\Component\Form\NativeRequestHandler', $config->getRequestHandler());
}
public function testGetFormProcessorReusesNativeFormProcessorInstance()
public function testGetRequestHandlerReusesNativeRequestHandlerInstance()
{
$config1 = $this->getConfigBuilder()->getFormConfig();
$config2 = $this->getConfigBuilder()->getFormConfig();
$this->assertSame($config1->getFormProcessor(), $config2->getFormProcessor());
$this->assertSame($config1->getRequestHandler(), $config2->getRequestHandler());
}
public function testSetMethodAllowsGet()

View File

@ -11,12 +11,12 @@
namespace Symfony\Component\Form\Tests;
use Symfony\Component\Form\NativeFormProcessor;
use Symfony\Component\Form\NativeRequestHandler;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class NativeFormProcessorTest extends AbstractFormProcessorTest
class NativeRequestHandlerTest extends AbstractRequestHandlerTest
{
private static $serverBackup;
@ -53,7 +53,7 @@ class NativeFormProcessorTest extends AbstractFormProcessorTest
*/
public function testRequestShouldBeNull()
{
$this->processor->processForm($this->getMockForm('name', 'GET'), 'request');
$this->requestHandler->handleRequest($this->getMockForm('name', 'GET'), 'request');
}
public function testMethodOverrideHeaderTakesPrecedenceIfPost()
@ -70,7 +70,7 @@ class NativeFormProcessorTest extends AbstractFormProcessorTest
->method('bind')
->with('DATA');
$this->processor->processForm($form, $this->request);
$this->requestHandler->handleRequest($form, $this->request);
}
public function testConvertEmptyUploadedFilesToNull()
@ -89,7 +89,7 @@ class NativeFormProcessorTest extends AbstractFormProcessorTest
->method('bind')
->with($this->identicalTo(null));
$this->processor->processForm($form, $this->request);
$this->requestHandler->handleRequest($form, $this->request);
}
public function testFixBuggyFilesArray()
@ -126,7 +126,7 @@ class NativeFormProcessorTest extends AbstractFormProcessorTest
),
));
$this->processor->processForm($form, $this->request);
$this->requestHandler->handleRequest($form, $this->request);
}
public function testFixBuggyNestedFilesArray()
@ -165,7 +165,7 @@ class NativeFormProcessorTest extends AbstractFormProcessorTest
),
));
$this->processor->processForm($form, $this->request);
$this->requestHandler->handleRequest($form, $this->request);
}
public function testMethodOverrideHeaderIgnoredIfNotPost()
@ -181,7 +181,7 @@ class NativeFormProcessorTest extends AbstractFormProcessorTest
$form->expects($this->never())
->method('bind');
$this->processor->processForm($form, $this->request);
$this->requestHandler->handleRequest($form, $this->request);
}
protected function setRequestData($method, $data, $files = array())
@ -201,9 +201,9 @@ class NativeFormProcessorTest extends AbstractFormProcessorTest
);
}
protected function getFormProcessor()
protected function getRequestHandler()
{
return new NativeFormProcessor();
return new NativeRequestHandler();
}
protected function getMockFile()

View File

@ -878,19 +878,19 @@ class SimpleFormTest extends AbstractFormTest
$parent->bind('not-an-array');
}
public function testProcessForwardsToFormProcessor()
public function testHandleRequestForwardsToRequestHandler()
{
$processor = $this->getMock('Symfony\Component\Form\FormProcessorInterface');
$processor = $this->getMock('Symfony\Component\Form\RequestHandlerInterface');
$form = $this->getBuilder()
->setFormProcessor($processor)
->setRequestHandler($processor)
->getForm();
$processor->expects($this->once())
->method('processForm')
->method('handleRequest')
->with($this->identicalTo($form), 'REQUEST');
$this->assertSame($form, $form->process('REQUEST'));
$this->assertSame($form, $form->handleRequest('REQUEST'));
}
public function testFormInheritsParentData()