Browse Source

[FrameworkBundle] fixed built-in controllers

Fabien Potencier 14 years ago
parent
commit
714fa6f652

+ 7 - 1
src/Symfony/Bundle/FrameworkBundle/Controller/DefaultController.php

@@ -3,6 +3,7 @@
 namespace Symfony\Bundle\FrameworkBundle\Controller;
 
 use Symfony\Bundle\FrameworkBundle\Controller;
+use Symfony\Components\HttpFoundation\Response;
 
 /*
  * This file is part of the Symfony framework.
@@ -20,8 +21,13 @@ use Symfony\Bundle\FrameworkBundle\Controller;
  */
 class DefaultController extends Controller
 {
+    /**
+     * Renders the Symfony2 welcome page.
+     *
+     * @return Response A Response instance
+     */
     public function indexAction()
     {
-        return $this->render('FrameworkBundle:Default:index');
+        return $this['templating']->renderResponse('FrameworkBundle:Default:index');
     }
 }

+ 8 - 3
src/Symfony/Bundle/FrameworkBundle/Controller/ExceptionController.php

@@ -25,13 +25,18 @@ use Symfony\Components\HttpKernel\Exception\HttpException;
 class ExceptionController extends Controller
 {
     /**
+     * Converts an Exception to a Response.
+     *
+     * @param \Exception $exception An Exception instance
+     * @param Request    $request   The original Request instance
+     * @param array      $logs      An array of logs
+     *
      * @throws \InvalidArgumentException When the exception template does not exist
      */
     public function exceptionAction(\Exception $exception, Request $originalRequest, array $logs)
     {
         $template = $this->container->getParameter('kernel.debug') ? 'exception' : 'error';
 
-        $request = $this->getRequest();
         $format = $format = $originalRequest->getRequestFormat();
 
         // when using CLI, we force the format to be TXT
@@ -39,7 +44,7 @@ class ExceptionController extends Controller
             $format = 'txt';
         }
 
-        $template = $this->container->getTemplatingService()->getLoader()->load($template, array(
+        $template = $this['templating']->getLoader()->load($template, array(
             'bundle'     => 'FrameworkBundle',
             'controller' => 'Exception',
             'format'     => '.'.$format,
@@ -73,7 +78,7 @@ class ExceptionController extends Controller
         require $template;
         $content = ob_get_clean();
 
-        $response = $this->container->getResponseService();
+        $response = $this['response'];
         $response->setStatusCode($code);
         $response->setContent($content);
 

+ 16 - 6
src/Symfony/Bundle/FrameworkBundle/Controller/InternalController.php

@@ -3,6 +3,7 @@
 namespace Symfony\Bundle\FrameworkBundle\Controller;
 
 use Symfony\Bundle\FrameworkBundle\Controller;
+use Symfony\Components\HttpFoundation\Response;
 
 /*
  * This file is part of the Symfony framework.
@@ -20,16 +21,25 @@ use Symfony\Bundle\FrameworkBundle\Controller;
  */
 class InternalController extends Controller
 {
-    public function indexAction()
+    /**
+     * Forwards to the given controller with the given path.
+     *
+     * @param string $path       The path
+     * @param string $controller The controller name
+     *
+     * @return Response A Response instance
+     */
+    public function indexAction($path, $controller)
     {
-        $request = $this->getRequest();
+        $request = $this['request'];
+        $attributes = $request->attributes;
 
-        if ('none' !== $request->attributes->get('path'))
+        if ('none' !== $path)
         {
-            parse_str($request->attributes->get('path'), $tmp);
-            $request->attributes->add($tmp);
+            parse_str($path, $tmp);
+            $attributes->add($tmp);
         }
 
-        return $this->forward($request->attributes->get('controller'), $request->attributes->all(), $request->query->all());
+        return $this['controller_resolver']->forward($controller, $attributes->all(), $request->query->all());
     }
 }

+ 14 - 5
src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php

@@ -3,6 +3,7 @@
 namespace Symfony\Bundle\FrameworkBundle\Controller;
 
 use Symfony\Bundle\FrameworkBundle\Controller;
+use Symfony\Components\HttpFoundation\Response;
 
 /*
  * This file is part of the Symfony framework.
@@ -20,7 +21,7 @@ use Symfony\Bundle\FrameworkBundle\Controller;
  */
 class RedirectController extends Controller
 {
-    /*
+    /**
      * Redirects to another route.
      *
      * It expects a route path parameter.
@@ -28,11 +29,16 @@ class RedirectController extends Controller
      *
      * If the route empty, the status code will be 410.
      * If the permanent path parameter is set, the status code will be 302.
+     *
+     * @param string  $route     The route pattern to redirect to
+     * @param Boolean $permanent Whether the redirect is permanent or not
+     *
+     * @return Response A Response instance
      */
     public function redirectAction($route, $permanent = false)
     {
         if (!$route) {
-            $response = $this->container->getResponseService();
+            $response = $this['response'];
             $response->setStatusCode(410);
 
             return $response;
@@ -40,9 +46,12 @@ class RedirectController extends Controller
 
         $code = $permanent ? 301 : 302;
 
-        $parameters = $this->getRequest()->getPathParameters();
-        unset($parameters['_route'], $parameters['route']);
+        $attributes = $this['request']->attributes->all();
+        unset($attributes['_route'], $attributes['route']);
+
+        $response = $this['response'];
+        $response->setRedirect($this['router']->generate($route, $attributes), $code);
 
-        return $this->redirect($this->container->getRouterService()->generate($route, $parameters), $code);
+        return $response;
     }
 }

+ 9 - 1
src/Symfony/Bundle/FrameworkBundle/Controller/TemplateController.php

@@ -3,6 +3,7 @@
 namespace Symfony\Bundle\FrameworkBundle\Controller;
 
 use Symfony\Bundle\FrameworkBundle\Controller;
+use Symfony\Components\HttpFoundation\Response;
 
 /*
  * This file is part of the Symfony framework.
@@ -20,8 +21,15 @@ use Symfony\Bundle\FrameworkBundle\Controller;
  */
 class TemplateController extends Controller
 {
+    /**
+     * Renders a template.
+     *
+     * @param string $template The template name
+     *
+     * @return Response A Response instance
+     */
     public function templateAction($template)
     {
-        return $this->render($template);
+        return $this['templating']->renderResponse($template);
     }
 }