[HttpKernel] fixed scope management in HttpKernel
We should always leave the request scope at the end of the request processing. If not, the HttpKernel leaves the container in a different state.
This commit is contained in:
parent
86b357d70b
commit
b577ce665a
@ -32,18 +32,14 @@ class HttpKernel extends BaseHttpKernel
|
||||
|
||||
try {
|
||||
$response = parent::handle($request, $type, $catch);
|
||||
|
||||
if (HttpKernelInterface::MASTER_REQUEST !== $type) {
|
||||
$this->container->leaveScope('request');
|
||||
}
|
||||
|
||||
return $response;
|
||||
} catch (\Exception $e) {
|
||||
if (HttpKernelInterface::MASTER_REQUEST !== $type) {
|
||||
$this->container->leaveScope('request');
|
||||
}
|
||||
$this->container->leaveScope('request');
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->container->leaveScope('request');
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,18 +25,11 @@ class HttpKernelTest extends \PHPUnit_Framework_TestCase
|
||||
->method('enterScope')
|
||||
->with($this->equalTo('request'))
|
||||
;
|
||||
if ($type !== HttpKernelInterface::MASTER_REQUEST) {
|
||||
$container
|
||||
->expects($this->once())
|
||||
->method('leaveScope')
|
||||
->with($this->equalTo('request'))
|
||||
;
|
||||
} else {
|
||||
$container
|
||||
->expects($this->never())
|
||||
->method('leaveScope')
|
||||
;
|
||||
}
|
||||
$container
|
||||
->expects($this->once())
|
||||
->method('leaveScope')
|
||||
->with($this->equalTo('request'))
|
||||
;
|
||||
$container
|
||||
->expects($this->once())
|
||||
->method('set')
|
||||
@ -80,18 +73,11 @@ class HttpKernelTest extends \PHPUnit_Framework_TestCase
|
||||
->method('enterScope')
|
||||
->with($this->equalTo('request'))
|
||||
;
|
||||
if ($type !== HttpKernelInterface::MASTER_REQUEST) {
|
||||
$container
|
||||
->expects($this->once())
|
||||
->method('leaveScope')
|
||||
->with($this->equalTo('request'))
|
||||
;
|
||||
} else {
|
||||
$container
|
||||
->expects($this->never())
|
||||
->method('leaveScope')
|
||||
;
|
||||
}
|
||||
$container
|
||||
->expects($this->once())
|
||||
->method('leaveScope')
|
||||
->with($this->equalTo('request'))
|
||||
;
|
||||
$container
|
||||
->expects($this->once())
|
||||
->method('set')
|
||||
|
Reference in New Issue
Block a user