Skip to content

Commit 998cc40

Browse files
committed
[#6422] Detailed proof-read after the great PR from @iltar
1 parent 2ef8e85 commit 998cc40

File tree

3 files changed

+69
-63
lines changed

3 files changed

+69
-63
lines changed

components/http_kernel/introduction.rst

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ Framework - works.
8383
Initially, using the :class:`Symfony\\Component\\HttpKernel\\HttpKernel`
8484
is really simple and involves creating an
8585
:doc:`event dispatcher </components/event_dispatcher/introduction>` and a
86-
:ref:`controller resolver <component-http-kernel-resolve-controller>` (explained
87-
below). To complete your working kernel, you'll add more event listeners
88-
to the events discussed below::
86+
:ref:`controller and argument resolver <component-http-kernel-resolve-controller>`
87+
(explained below). To complete your working kernel, you'll add more event
88+
listeners to the events discussed below::
8989

9090
use Symfony\Component\HttpFoundation\Request;
9191
use Symfony\Component\HttpKernel\HttpKernel;
@@ -122,13 +122,12 @@ See ":ref:`http-kernel-working-example`" for a more concrete implementation.
122122
For general information on adding listeners to the events below, see
123123
:ref:`http-kernel-creating-listener`.
124124

125-
126125
.. caution::
127126

128-
As of 3.1 the :class:`Symfony\\Component\\Httpkernel\\HttpKernel` accepts a fourth argument, which
129-
must be an instance of :class:`Symfony\\Component\\Httpkernel\\Controller\\ArgumentResolverInterface`.
130-
In 4.0 this argument will become mandatory and the :class:`Symfony\\Component\\Httpkernel\\HttpKernel`
131-
will no longer be able to fall back to the :class:`Symfony\\Component\\Httpkernel\\Controller\\ControllerResolver`.
127+
As of 3.1 the :class:`Symfony\\Component\\Httpkernel\\HttpKernel` accepts a
128+
fourth argument, which must be an instance of
129+
:class:`Symfony\\Component\\Httpkernel\\Controller\\ArgumentResolverInterface`.
130+
In 4.0 this argument will become mandatory.
132131

133132
.. seealso::
134133

@@ -210,7 +209,7 @@ the next step in HttpKernel is to determine and prepare (i.e. resolve) the
210209
controller. The controller is the part of the end-application's code that
211210
is responsible for creating and returning the ``Response`` for a specific page.
212211
The only requirement is that it is a PHP callable - i.e. a function, method
213-
on an object, or a ``Closure``.
212+
on an object or a ``Closure``.
214213

215214
But *how* you determine the exact controller for a request is entirely up
216215
to your application. This is the job of the "controller resolver" - a class
@@ -239,11 +238,14 @@ This implementation is explained more in the sidebar below::
239238

240239
.. caution::
241240

242-
The ``getArguments()`` method in the :class:`Symfony\\Component\\Httpkernel\\Controller\\ControllerResolver`
243-
and respective interface :class:`Symfony\\Component\\Httpkernel\\Controller\\ControllerResolverInterface`
241+
The ``getArguments()`` method in the
242+
:class:`Symfony\\Component\\Httpkernel\\Controller\\ControllerResolver` and
243+
respective interface
244+
:class:`Symfony\\Component\\Httpkernel\\Controller\\ControllerResolverInterface`
244245
are deprecated as of 3.1 and will be removed in 4.0. You can use the
245-
:class:`Symfony\\Component\\Httpkernel\\Controller\\ArgumentResolver` which uses the
246-
:class:`Symfony\\Component\\Httpkernel\\Controller\\ArgumentResolverInterface` instead.
246+
:class:`Symfony\\Component\\Httpkernel\\Controller\\ArgumentResolver` which
247+
uses the :class:`Symfony\\Component\\Httpkernel\\Controller\\ArgumentResolverInterface`
248+
instead.
247249

248250
Internally, the ``HttpKernel::handle`` method first calls
249251
:method:`Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface::getController`
@@ -330,9 +332,9 @@ on the event object that's passed to listeners on this event.
330332
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
331333

332334
Next, ``HttpKernel::handle`` calls
333-
:method:`Symfony\\Component\\HttpKernel\\Controller\\ArgumentResolverInterface::getArguments`.
334-
Remember that the controller returned in ``getController`` is a callable.
335-
The purpose of ``getArguments`` is to return the array of arguments that
335+
:method:`ArgumentResolverInterface::getArguments() <Symfony\\Component\\HttpKernel\\Controller\\ArgumentResolverInterface::getArguments>`.
336+
Remember that the controller returned in ``getController()`` is a callable.
337+
The purpose of ``getArguments()`` is to return the array of arguments that
336338
should be passed to that controller. Exactly how this is done is completely
337339
up to your design, though the built-in :class:`Symfony\\Component\\HttpKernel\\Controller\\ArgumentResolver`
338340
is a good example.
@@ -353,7 +355,7 @@ of arguments that should be passed when executing that callable.
353355

354356
a) If the ``Request`` attributes bag contains a key that matches the name
355357
of the argument, that value is used. For example, if the first argument
356-
to a controller is ``$slug``, and there is a ``slug`` key in the ``Request``
358+
to a controller is ``$slug`` and there is a ``slug`` key in the ``Request``
357359
``attributes`` bag, that value is used (and typically this value came
358360
from the ``RouterListener``).
359361

@@ -363,14 +365,15 @@ of arguments that should be passed when executing that callable.
363365
class, it will be injected as long as you extend the Symfony ``Request``.
364366

365367
c) If the function or method argument is `variadic`_ and the ``Request``
366-
``attributes`` bag contains and array for that argument, they will all be
368+
``attributes`` bag contains an array for that argument, they will all be
367369
available through the `variadic`_ argument.
368370

369371
This functionality is provided by resolvers implementing the
370372
:class:`Symfony\\Component\\HttpKernel\\Controller\\ArgumentValueResolverInterface`.
371-
There are four implementations which provide the default behavior of Symfony but
372-
customization is the key here. By implementing the ``ArgumentValueResolverInterface``
373-
yourself and passing this to the ``ArgumentResolver``, you can extend this functionality.
373+
There are four implementations which provide the default behavior of
374+
Symfony but customization is the key here. By implementing the
375+
``ArgumentValueResolverInterface`` yourself and passing this to the
376+
``ArgumentResolver``, you can extend this functionality.
374377

375378
.. _component-http-kernel-calling-controller:
376379

@@ -650,45 +653,44 @@ use any argument resolver that implements the
650653
However, the HttpKernel component comes with some built-in listeners and everything
651654
else that can be used to create a working example::
652655

653-
use Symfony\Component\EventDispatcher\EventDispatcher;
654-
use Symfony\Component\HttpFoundation\Request;
655-
use Symfony\Component\HttpFoundation\RequestStack;
656-
use Symfony\Component\HttpFoundation\Response;
657-
use Symfony\Component\HttpKernel\Controller\ArgumentResolver;
658-
use Symfony\Component\HttpKernel\Controller\ControllerResolver;
659-
use Symfony\Component\HttpKernel\EventListener\RouterListener;
660-
use Symfony\Component\HttpKernel\HttpKernel;
661-
use Symfony\Component\Routing\Matcher\UrlMatcher;
662-
use Symfony\Component\Routing\RequestContext;
663-
use Symfony\Component\Routing\Route;
664-
use Symfony\Component\Routing\RouteCollection;
665-
666-
$routes = new RouteCollection();
667-
$routes->add('hello', new Route('/hello/{name}', array(
668-
'_controller' => function (Request $request) {
669-
return new Response(
670-
sprintf("Hello %s", $request->get('name'))
671-
);
672-
})
673-
));
674-
675-
$request = Request::createFromGlobals();
656+
use Symfony\Component\EventDispatcher\EventDispatcher;
657+
use Symfony\Component\HttpFoundation\Request;
658+
use Symfony\Component\HttpFoundation\RequestStack;
659+
use Symfony\Component\HttpFoundation\Response;
660+
use Symfony\Component\HttpKernel\Controller\ArgumentResolver;
661+
use Symfony\Component\HttpKernel\Controller\ControllerResolver;
662+
use Symfony\Component\HttpKernel\EventListener\RouterListener;
663+
use Symfony\Component\HttpKernel\HttpKernel;
664+
use Symfony\Component\Routing\Matcher\UrlMatcher;
665+
use Symfony\Component\Routing\RequestContext;
666+
use Symfony\Component\Routing\Route;
667+
use Symfony\Component\Routing\RouteCollection;
668+
669+
$routes = new RouteCollection();
670+
$routes->add('hello', new Route('/hello/{name}', array(
671+
'_controller' => function (Request $request) {
672+
return new Response(
673+
sprintf("Hello %s", $request->get('name'))
674+
);
675+
})
676+
));
676677

677-
$matcher = new UrlMatcher($routes, new RequestContext());
678+
$request = Request::createFromGlobals();
678679

679-
$dispatcher = new EventDispatcher();
680-
$dispatcher->addSubscriber(new RouterListener($matcher, new RequestStack()));
680+
$matcher = new UrlMatcher($routes, new RequestContext());
681681

682-
$controllerResolver = new ControllerResolver();
683-
$argumentResolver = new ArgumentResolver();
682+
$dispatcher = new EventDispatcher();
683+
$dispatcher->addSubscriber(new RouterListener($matcher, new RequestStack()));
684684

685-
$kernel = new HttpKernel($dispatcher, $controllerResolver, new RequestStack(), $argumentResolver);
685+
$controllerResolver = new ControllerResolver();
686+
$argumentResolver = new ArgumentResolver();
686687

687-
$response = $kernel->handle($request);
688-
$response->send();
688+
$kernel = new HttpKernel($dispatcher, $controllerResolver, new RequestStack(), $argumentResolver);
689689

690-
$kernel->terminate($request, $response);
690+
$response = $kernel->handle($request);
691+
$response->send();
691692

693+
$kernel->terminate($request, $response);
692694

693695
.. _http-kernel-sub-requests:
694696

create_framework/http_kernel_controller_resolver.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ based on a Request object. All controller resolvers implement the following inte
6060

6161
.. caution::
6262

63-
The ``getArguments()`` method in the :class:`Symfony\\Component\\Httpkernel\\Controller\\ControllerResolver`
64-
and respective interface :class:`Symfony\\Component\\Httpkernel\\Controller\\ControllerResolverInterface`
65-
are deprecated as of 3.1 and will be removed in 4.0. You can use the
66-
:class:`Symfony\\Component\\Httpkernel\\Controller\\ArgumentResolver` which uses the
67-
:class:`Symfony\\Component\\Httpkernel\\Controller\\ArgumentResolverInterface` instead.
63+
The ``getArguments()`` method is deprecated as of Symfony 3.1. and will be
64+
removed in 4.0. You can use the
65+
:class:`Symfony\\Component\\Httpkernel\\Controller\\ArgumentResolver` which
66+
uses the :class:`Symfony\\Component\\Httpkernel\\Controller\\ArgumentResolverInterface`
67+
instead.
6868

6969
The ``getController()`` method relies on the same convention as the one we
7070
have defined earlier: the ``_controller`` request attribute must contain the
@@ -142,10 +142,10 @@ Let's just inject the ``$year`` request attribute for our controller::
142142
}
143143
}
144144

145-
The controller resolver also takes care of validating the controller callable
146-
and its arguments. In case of a problem, it throws an exception with a nice
147-
message explaining the problem (the controller class does not exist, the
148-
method is not defined, an argument has no matching attribute, ...).
145+
The resolvers also take care of validating the controller callable and its
146+
arguments. In case of a problem, it throws an exception with a nice message
147+
explaining the problem (the controller class does not exist, the method is not
148+
defined, an argument has no matching attribute, ...).
149149

150150
.. note::
151151

reference/dic_tags.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,13 @@ For details on registering your own commands in the service container, read
354354
controller.argument_value_resolver
355355
----------------------------------
356356

357+
.. versionadded:: 3.1
358+
The ``controller.argument_value_resolver`` tag was introduced in Symfony 3.1.
359+
357360
**Purpose**: Register a value resolver for controller arguments such as ``Request``
358361

359-
Value resolvers implement the :class:`Symfony\\Component\\HttpKernel\\Controller\\ArgumentValueResolverInterface`
362+
Value resolvers implement the
363+
:class:`Symfony\\Component\\HttpKernel\\Controller\\ArgumentValueResolverInterface`
360364
and are used to resolve argument values for controllers as described here:
361365
:doc:`/cookbook/controller/argument_value_resolver`.
362366

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy