@@ -83,9 +83,9 @@ Framework - works.
8383Initially, using the:class: `Symfony\\ Component\\ HttpKernel\\ HttpKernel `
8484is 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: `controllerand 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.
122122For 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
210209controller. The controller is the part of the end-application's code that
211210is responsible for creating and returning the ``Response `` for a specific page.
212211The 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
215214But *how * you determine the exact controller for a request is entirely up
216215to 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
248250Internally, 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
332334Next, ``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
336338should be passed to that controller. Exactly how this is done is completely
337339up to your design, though the built-in:class: `Symfony\\ Component\\ HttpKernel\\ Controller\\ ArgumentResolver `
338340is 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 containsand array for that argument, they will all be
368+ ``attributes `` bag containsan 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
650653However, the HttpKernel component comes with some built-in listeners and everything
651654else 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 = newControllerResolver ();
683- $argumentResolver = newArgumentResolver( );
682+ $dispatcher = newEventDispatcher ();
683+ $dispatcher->addSubscriber(new RouterListener($matcher, newRequestStack()) );
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