Commit e96f9be8 authored by Fabien Potencier's avatar Fabien Potencier

removed the request service in favor of the request_stack one

parent 26e85436
......@@ -138,12 +138,6 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte
return new RedirectableUrlMatcher($app['routes'], $app['request_context']);
});
$this['request_error'] = $this->protect(function () {
throw new \RuntimeException('Accessed request service outside of request scope. Try moving that call to a before handler or controller.');
});
$this['request'] = $this['request_error'];
$this['request.http_port'] = 80;
$this['request.https_port'] = 443;
$this['debug'] = false;
......@@ -533,17 +527,9 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte
$this->boot();
}
$current = HttpKernelInterface::SUB_REQUEST === $type ? $this['request'] : $this['request_error'];
$this['request'] = $request;
$this->flush();
$response = $this['kernel']->handle($request, $type, $catch);
$this['request'] = $current;
return $response;
return $this['kernel']->handle($request, $type, $catch);
}
/**
......
......@@ -49,7 +49,7 @@ class ExceptionListenerWrapper
$code = $exception instanceof HttpExceptionInterface ? $exception->getStatusCode() : 500;
$response = call_user_func($this->callback, $exception, $code);
$response = call_user_func($this->callback, $exception, $event->getRequest(), $code);
$this->ensureResponse($response, $event);
}
......
......@@ -416,30 +416,6 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$app->handle(Request::create('/'), HttpKernelInterface::MASTER_REQUEST, false);
}
/**
* @expectedException \RuntimeException
*/
public function testAccessingRequestOutsideOfScopeShouldThrowRuntimeException()
{
$app = new Application();
$request = $app['request'];
}
/**
* @expectedException \RuntimeException
*/
public function testAccessingRequestOutsideOfScopeShouldThrowRuntimeExceptionAfterHandling()
{
$app = new Application();
$app->get('/', function () {
return 'hello';
});
$app->handle(Request::create('/'), HttpKernelInterface::MASTER_REQUEST, false);
$request = $app['request'];
}
public function testSubRequest()
{
$app = new Application();
......@@ -453,27 +429,6 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('foo', $app->handle(Request::create('/'))->getContent());
}
public function testSubRequestDoesNotReplaceMainRequestAfterHandling()
{
$mainRequest = Request::create('/');
$subRequest = Request::create('/sub');
$app = new Application();
$app->get('/sub', function (Request $request) {
return new Response('foo');
});
$app->get('/', function (Request $request) use ($subRequest, $app) {
$response = $app->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
// request in app must be the main request here
$response->setContent($response->getContent().' '.$app['request']->getPathInfo());
return $response;
});
$this->assertEquals('foo /', $app->handle($mainRequest)->getContent());
}
public function testRegisterShouldReturnSelf()
{
$app = new Application();
......
......@@ -191,8 +191,8 @@ class MiddlewareTest extends \PHPUnit_Framework_TestCase
{
$app = new Application();
$app->before(function () use ($app) {
$app['project'] = $app['request']->get('project');
$app->before(function (Request $request) use ($app) {
$app['project'] = $request->get('project');
});
$app->match('/foo/{project}', function () use ($app) {
......
......@@ -152,12 +152,12 @@ class RouterTest extends \PHPUnit_Framework_TestCase
{
$app = new Application();
$app->get('/foo', function () use ($app) {
return new Response($app['request']->getRequestUri());
$app->get('/foo', function (Request $request) use ($app) {
return new Response($request->getRequestUri());
});
$app->error(function ($e) use ($app) {
return new Response($app['request']->getRequestUri());
$app->error(function ($e, Request $request, $code) use ($app) {
return new Response($request->getRequestUri());
});
foreach (array('/foo', '/bar') as $path) {
......
......@@ -13,6 +13,7 @@ namespace Silex\Tests;
use Silex\Application;
use Silex\WebTestCase;
use Symfony\Component\HttpFoundation\Request;
/**
* Functional test cases.
......@@ -33,9 +34,9 @@ class WebTestCaseTest extends WebTestCase
return '<h1>title</h1>';
});
$app->match('/server', function () use ($app) {
$user = $app['request']->server->get('PHP_AUTH_USER');
$pass = $app['request']->server->get('PHP_AUTH_PW');
$app->match('/server', function (Request $request) use ($app) {
$user = $request->server->get('PHP_AUTH_USER');
$pass = $request->server->get('PHP_AUTH_PW');
return "<h1>$user:$pass</h1>";
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment