Skip to content

Commit

Permalink
[HttpKernel] fixed scope management in HttpKernel
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fabpot committed Jan 23, 2011
1 parent 86b357d commit b577ce6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 34 deletions.
16 changes: 6 additions & 10 deletions src/Symfony/Bundle/FrameworkBundle/HttpKernel.php
Expand Up @@ -32,18 +32,14 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ

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;
}
}
}
34 changes: 10 additions & 24 deletions src/Symfony/Bundle/FrameworkBundle/Tests/HttpKernelTest.php
Expand Up @@ -25,18 +25,11 @@ public function testHandle($type)
->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')
Expand Down Expand Up @@ -80,18 +73,11 @@ public function testHandleRestoresThePreviousRequestOnException($type)
->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')
Expand Down

0 comments on commit b577ce6

Please sign in to comment.