@@ -234,47 +234,83 @@ inject *only* the exact service(s) that you need directly into the controller.
234234 are valid, exactly how you want to organize your reusable code is up to
235235 you.
236236
237- Base Controller Methods and their Service Replacements
237+ Base Controller Methods and Their Service Replacements
238238~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
239239
240- This table explains how to replace the convenience methods of the base
241- controller.
242-
243- +-----------------------------+----------------------+-----------------------------------------------------------------+
244- | Method | Service | PHP Code |
245- +=============================+======================+=================================================================+
246- | ``createForm `` | ``form.factory `` | ``$formFactory->create($type, $data, $options) `` |
247- +-----------------------------+----------------------+-----------------------------------------------------------------+
248- | ``createFormBuilder `` | ``form.factory `` | ``$formFactory->createBuilder('form', $data, $options) `` |
249- +-----------------------------+----------------------+-----------------------------------------------------------------+
250- | ``createNotFoundException `` | \- | ``throw new NotFoundHttpException($message, $previous); `` |
251- +-----------------------------+----------------------+-----------------------------------------------------------------+
252- | ``forward `` | ``http_kernel `` | ``$httpKernel->forward($controller, $path, $query) `` |
253- +-----------------------------+----------------------+-----------------------------------------------------------------+
254- | ``generateUrl `` | ``router `` | ``$router->generate($route, $params, $absolute) `` |
255- +-----------------------------+----------------------+-----------------------------------------------------------------+
256- | ``getDoctrine `` | ``doctrine `` | *Simply inject doctrine instead of fetching from the container * |
257- +-----------------------------+----------------------+-----------------------------------------------------------------+
258- | ``getUser `` | ``security.context `` | $user = null; |
259- | | | $token = $securityContext->getToken(); |
260- | | | if (null !== $token && is_object($token->getUser())) { |
261- | | | $user = $token->getUser(); |
262- | | | } |
263- +-----------------------------+----------------------+-----------------------------------------------------------------+
264- | ``isGranted `` | ``security.context `` | ``$authorizationChecker->isGranted($attributes, $object); `` |
265- +-----------------------------+----------------------+-----------------------------------------------------------------+
266- | ``redirect `` | \- | ``return new RedirectResponse($url, $status); `` |
267- +-----------------------------+----------------------+-----------------------------------------------------------------+
268- | ``render `` | ``templating `` | ``$templating->renderResponse($view, $parameters, $response) `` |
269- +-----------------------------+----------------------+-----------------------------------------------------------------+
270- | ``renderViev `` | ``templating `` | ``$templating->render($view, $parameters) `` |
271- +-----------------------------+----------------------+-----------------------------------------------------------------+
272- | ``stream `` | ``templating `` | $templating = $this->templating; |
273- | | | $callback = function () use ($templating, $view, $parameters) { |
274- | | | $templating->stream($view, $parameters); |
275- | | | } |
276- | | | return new StreamedResponse($callback); |
277- +-----------------------------+----------------------+-----------------------------------------------------------------+
240+ This list explains how to replace the convenience methods of the base
241+ controller:
242+
243+ :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller::createForm ` (service: ``form.factory ``)
244+ .. code-block :: php
245+
246+ $formFactory->create($type, $data, $options);
247+
248+ :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller::createFormBuilder ` (service: ``form.factory ``)
249+ .. code-block :: php
250+
251+ $formFactory->createBuilder('form', $data, $options);
252+
253+ :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller::createNotFoundException `
254+ .. code-block :: php
255+
256+ new NotFoundHttpException($message, $previous);
257+
258+ :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller::forward ` (service: ``http_kernel ``)
259+ .. code-block :: php
260+
261+ $httpKernel->forward($controller, $path, $query);
262+
263+ :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller::generateUrl ` (service: ``router ``)
264+ .. code-block :: php
265+
266+ $router->generate($route, $params, $absolute);
267+
268+ :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller::getDoctrine ` (service: ``doctrine ``)
269+
270+ *Simply inject doctrine instead of fetching it from the container *
271+
272+ :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller::getUser ` (service: ``security.context ``)
273+ .. code-block :: php
274+
275+ $user = null;
276+ $token = $securityContext->getToken();
277+ if (null !== $token && is_object($token->getUser())) {
278+ $user = $token->getUser();
279+ }
280+
281+ :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller::isGranted ` (service: ``security.context ``)
282+ .. code-block :: php
283+
284+ $authorizationChecker->isGranted($attributes, $object);
285+
286+ :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller::redirect `
287+ .. code-block :: php
288+
289+ use Symfony\Component\HttpFoundation\RedirectResponse;
290+
291+ return new RedirectResponse($url, $status);
292+
293+ :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller::render ` (service: ``templating ``)
294+ .. code-block :: php
295+
296+ $templating->renderResponse($view, $parameters, $response);
297+
298+ :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller::renderView ` (service: ``templating ``)
299+ .. code-block :: php
300+
301+ $templating->render($view, $parameters);
302+
303+ :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller::stream ` (service: ``templating ``)
304+ .. code-block :: php
305+
306+ use Symfony\Component\HttpFoundation\StreamedResponse;
307+
308+ $templating = $this->templating;
309+ $callback = function () use ($templating, $view, $parameters) {
310+ $templating->stream($view, $parameters);
311+ }
312+
313+ return new StreamedResponse($callback);
278314
279315 .. tip ::
280316
0 commit comments