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

This commit is contained in:
Fabien Potencier 2010-04-24 09:38:58 +02:00
parent 9cf78e637b
commit d498de88f0
11 changed files with 30 additions and 89 deletions

View File

@ -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;

View File

@ -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.');
}

View File

@ -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
{
}

View File

@ -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;

View File

@ -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();
}

View File

@ -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',

View File

@ -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)
{

View File

@ -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)
{

View File

@ -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'))
{

View File

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

View File

@ -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();