Browse Source

[RequestHandler] removed RequestInterface and ResponseInterface, added RequestHandlerInterface (removed the run() method)

Fabien Potencier 15 năm trước cách đây
mục cha
commit
d498de88f0

+ 1 - 1
src/Symfony/Components/RequestHandler/Request.php

@@ -23,7 +23,7 @@ namespace Symfony\Components\RequestHandler;
  * @subpackage Components_RequestHandler
  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
  */
-class Request implements RequestInterface
+class Request
 {
   public $path;
   public $request;

+ 12 - 12
src/Symfony/Components/RequestHandler/RequestHandler.php

@@ -22,7 +22,7 @@ use Symfony\Components\RequestHandler\Exception\NotFoundHttpException;
  * @subpackage Components_RequestHandler
  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
  */
-class RequestHandler
+class RequestHandler implements RequestHandlerInterface
 {
   protected $dispatcher;
 
@@ -42,14 +42,14 @@ class RequestHandler
    * All exceptions are caught, and a core.exception event is notified
    * for user management.
    *
-   * @param  RequestInterface  $request  A Request instance
-   * @param  Boolean           $main     Whether this is the main request or not
+   * @param  Request $request A Request instance
+   * @param  Boolean $main    Whether this is the main request or not
    *
-   * @return ResponseInterface $response A Response instance
+   * @return Response $response A Response instance
    *
-   * @throws \Exception When Exception couldn't be catch by event processing
+   * @throws \Exception When Exception couldn't be caught by event processing
    */
-  public function handle(RequestInterface $request, $main = true)
+  public function handle(Request $request, $main = true)
   {
     $main = (Boolean) $main;
 
@@ -75,15 +75,15 @@ class RequestHandler
    *
    * Exceptions are not caught.
    *
-   * @param  RequestInterface  $request  A Request instance
-   * @param  Boolean           $main     Whether this is the main request or not
+   * @param  Request $request A Request instance
+   * @param  Boolean $main    Whether this is the main request or not
    *
-   * @return ResponseInterface $response A Response instance
+   * @return Response $response A Response instance
    *
    * @throws \LogicException       If one of the listener does not behave as expected
    * @throws NotFoundHttpException When controller cannot be found
    */
-  public function handleRaw(RequestInterface $request, $main = true)
+  public function handleRaw(Request $request, $main = true)
   {
     $main = (Boolean) $main;
 
@@ -146,7 +146,7 @@ class RequestHandler
    */
   protected function filterResponse($response, $message, $main)
   {
-    if (!$response instanceof ResponseInterface)
+    if (!$response instanceof Response)
     {
       throw new \RuntimeException($message);
     }
@@ -154,7 +154,7 @@ class RequestHandler
     $event = $this->dispatcher->filter(new Event($this, 'core.response', array('main_request' => $main)), $response);
     $response = $event->getReturnValue();
 
-    if (!$response instanceof ResponseInterface)
+    if (!$response instanceof Response)
     {
       throw new \RuntimeException('A "core.response" listener returned a non response object.');
     }

+ 0 - 23
src/Symfony/Components/RequestHandler/RequestInterface.php

@@ -1,23 +0,0 @@
-<?php
-
-namespace Symfony\Components\RequestHandler;
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * RequestInterface is the interface that all client request classes must implement.
- *
- * @package    Symfony
- * @subpackage Components_RequestHandler
- * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
- */
-interface RequestInterface
-{
-}

+ 1 - 1
src/Symfony/Components/RequestHandler/Response.php

@@ -18,7 +18,7 @@ namespace Symfony\Components\RequestHandler;
  * @subpackage Components_RequestHandler
  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
  */
-class Response implements ResponseInterface
+class Response
 {
   protected $content;
   protected $version;

+ 0 - 24
src/Symfony/Components/RequestHandler/ResponseInterface.php

@@ -1,24 +0,0 @@
-<?php
-
-namespace Symfony\Components\RequestHandler;
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * ResponseInterface is the interface that all server response classes must implement.
- *
- * @package    Symfony
- * @subpackage Components_RequestHandler
- * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
- */
-interface ResponseInterface
-{
-  function send();
-}

+ 1 - 3
src/Symfony/Foundation/Bundle/KernelExtension.php

@@ -52,10 +52,8 @@ class KernelExtension extends LoaderExtension
         'Symfony\\Components\\EventDispatcher\\Event',
         'Symfony\\Components\\Routing\\Matcher\\UrlMatcherInterface',
         'Symfony\\Components\\Routing\\Matcher\\UrlMatcher',
-        'Symfony\\Components\\RequestHandler\\RequestInterface',
-        'Symfony\\Components\\RequestHandler\\Request',
         'Symfony\\Components\\RequestHandler\\RequestHandler',
-        'Symfony\\Components\\RequestHandler\\ResponseInterface',
+        'Symfony\\Components\\RequestHandler\\Request',
         'Symfony\\Components\\RequestHandler\\Response',
         'Symfony\\Components\\Templating\\Loader\\LoaderInterface',
         'Symfony\\Components\\Templating\\Loader\\Loader',

+ 4 - 8
src/Symfony/Foundation/Kernel.php

@@ -7,7 +7,8 @@ use Symfony\Components\DependencyInjection\Builder;
 use Symfony\Components\DependencyInjection\BuilderConfiguration;
 use Symfony\Components\DependencyInjection\Dumper\PhpDumper;
 use Symfony\Components\DependencyInjection\FileResource;
-use Symfony\Components\RequestHandler\RequestInterface;
+use Symfony\Components\RequestHandler\Request;
+use Symfony\Components\RequestHandler\RequestHandlerInterface;
 
 /*
  * This file is part of the Symfony package.
@@ -26,7 +27,7 @@ use Symfony\Components\RequestHandler\RequestInterface;
  * @subpackage Foundation
  * @author     Fabien Potencier <fabien.potencier@symfony-project.org>
  */
-abstract class Kernel implements \Serializable
+abstract class Kernel implements RequestHandlerInterface, \Serializable
 {
   protected $bundles;
   protected $bundleDirs;
@@ -154,12 +155,7 @@ abstract class Kernel implements \Serializable
     $this->boot();
   }
 
-  public function run()
-  {
-    $this->handle()->send();
-  }
-
-  public function handle(RequestInterface $request = null)
+  public function handle(Request $request = null, $main = true)
   {
     if (false === $this->booted)
     {

+ 5 - 11
src/Symfony/Foundation/bootstrap.php

@@ -154,10 +154,8 @@ class KernelExtension extends LoaderExtension
         'Symfony\\Components\\EventDispatcher\\Event',
         'Symfony\\Components\\Routing\\Matcher\\UrlMatcherInterface',
         'Symfony\\Components\\Routing\\Matcher\\UrlMatcher',
-        'Symfony\\Components\\RequestHandler\\RequestInterface',
-        'Symfony\\Components\\RequestHandler\\Request',
         'Symfony\\Components\\RequestHandler\\RequestHandler',
-        'Symfony\\Components\\RequestHandler\\ResponseInterface',
+        'Symfony\\Components\\RequestHandler\\Request',
         'Symfony\\Components\\RequestHandler\\Response',
         'Symfony\\Components\\Templating\\Loader\\LoaderInterface',
         'Symfony\\Components\\Templating\\Loader\\Loader',
@@ -368,12 +366,13 @@ use Symfony\Components\DependencyInjection\Builder;
 use Symfony\Components\DependencyInjection\BuilderConfiguration;
 use Symfony\Components\DependencyInjection\Dumper\PhpDumper;
 use Symfony\Components\DependencyInjection\FileResource;
-use Symfony\Components\RequestHandler\RequestInterface;
+use Symfony\Components\RequestHandler\Request;
+use Symfony\Components\RequestHandler\RequestHandlerInterface;
 
 
 
 
-abstract class Kernel implements \Serializable
+abstract class Kernel implements RequestHandlerInterface, \Serializable
 {
   protected $bundles;
   protected $bundleDirs;
@@ -471,12 +470,7 @@ abstract class Kernel implements \Serializable
     $this->boot();
   }
 
-  public function run()
-  {
-    $this->handle()->send();
-  }
-
-  public function handle(RequestInterface $request = null)
+  public function handle(Request $request = null, $main = true)
   {
     if (false === $this->booted)
     {

+ 4 - 4
src/Symfony/Framework/WebBundle/Listener/ResponseFilter.php

@@ -4,8 +4,8 @@ namespace Symfony\Framework\WebBundle\Listener;
 
 use Symfony\Components\EventDispatcher\EventDispatcher;
 use Symfony\Components\EventDispatcher\Event;
-use Symfony\Components\RequestHandler\RequestInterface;
-use Symfony\Components\RequestHandler\ResponseInterface;
+use Symfony\Components\RequestHandler\Request;
+use Symfony\Components\RequestHandler\Response;
 
 /*
  * This file is part of the Symfony framework.
@@ -28,7 +28,7 @@ class ResponseFilter
   protected $dispatcher;
   protected $request;
 
-  public function __construct(EventDispatcher $dispatcher, RequestInterface $request)
+  public function __construct(EventDispatcher $dispatcher, Request $request)
   {
     $this->dispatcher = $dispatcher;
     $this->request = $request;
@@ -39,7 +39,7 @@ class ResponseFilter
     $this->dispatcher->connect('core.response', array($this, 'filter'));
   }
 
-  public function filter(Event $event, ResponseInterface $response)
+  public function filter(Event $event, Response $response)
   {
     if (!$event->getParameter('main_request') || $response->hasHeader('Content-Type'))
     {

+ 1 - 1
src/Symfony/Framework/WebBundle/Resources/skeleton/web/front_controller.php

@@ -3,4 +3,4 @@
 require_once __DIR__.'/../{{ application }}/{{ class }}Kernel.php';
 
 $kernel = new {{ class }}Kernel('prod', false);
-$kernel->run();
+$kernel->handler()->send();

+ 1 - 1
src/Symfony/Framework/WebBundle/Resources/skeleton/web/front_controller_debug.php

@@ -10,4 +10,4 @@ if (!in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1')))
 require_once __DIR__.'/../{{ application }}/{{ class }}Kernel.php';
 
 $kernel = new {{ class }}Kernel('dev', true);
-$kernel->run();
+$kernel->handler()->send();