-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[WIP] Kernel refactor #6459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[WIP] Kernel refactor #6459
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9aaceb1
moved the logic from HttpKernel in FrameworkBundle to the HttpKernel …
fabpot a0c49c3
[TwigBridge] added a render_* function to ease usage of custom render…
fabpot 892f00f
[HttpKernel] added a URL signer mechanism for hincludes
fabpot 403bb06
[HttpKernel] added missing phpdoc and tweaked existing ones
fabpot 1f1392d
[HttpKernel] simplified and enhanced code managing the hinclude strategy
fabpot adc067e
[FrameworkBundle] made some services private
fabpot 1240690
[HttpKernel] made the strategy a regular parameter in HttpContentRend…
fabpot a8ea4e4
[FrameworkBundle] deprecated HttpKernel::forward() (it is only used o…
fabpot bd102c5
made the content renderer work even when ESI is disabled or when no t…
fabpot 2eea768
moved the deprecation logic calls outside the new HttpContentRenderer…
fabpot f17f586
moved the container aware HTTP kernel to the HttpKernel component
fabpot f7da1f0
added some unit tests (and fixed some bugs)
fabpot 76fefe3
updated CHANGELOG and UPGRADE files
fabpot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
moved the container aware HTTP kernel to the HttpKernel component
- Loading branch information
commit f17f5867a876772021aeb769e38b05f8ee497f07
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/Symfony/Component/HttpKernel/DependencyInjection/ContainerAwareHttpKernel.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\HttpKernel\DependencyInjection; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpKernel\HttpKernelInterface; | ||
use Symfony\Component\HttpKernel\HttpKernel; | ||
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
/** | ||
* This HttpKernel is used to manage scope changes of the DI container. | ||
* | ||
* @author Fabien Potencier <fabien@symfony.com> | ||
* @author Johannes M. Schmitt <schmittjoh@gmail.com> | ||
*/ | ||
class ContainerAwareHttpKernel extends HttpKernel | ||
{ | ||
protected $container; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param EventDispatcherInterface $dispatcher An EventDispatcherInterface instance | ||
* @param ContainerInterface $container A ContainerInterface instance | ||
* @param ControllerResolverInterface $controllerResolver A ControllerResolverInterface instance | ||
*/ | ||
public function __construct(EventDispatcherInterface $dispatcher, ContainerInterface $container, ControllerResolverInterface $controllerResolver) | ||
{ | ||
parent::__construct($dispatcher, $controllerResolver); | ||
|
||
$this->container = $container; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true) | ||
{ | ||
$request->headers->set('X-Php-Ob-Level', ob_get_level()); | ||
|
||
$this->container->enterScope('request'); | ||
$this->container->set('request', $request, 'request'); | ||
|
||
try { | ||
$response = parent::handle($request, $type, $catch); | ||
} catch (\Exception $e) { | ||
$this->container->leaveScope('request'); | ||
|
||
throw $e; | ||
} | ||
|
||
$this->container->leaveScope('request'); | ||
|
||
return $response; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/Symfony/Component/HttpKernel/Tests/RenderingStrategy/DefaultRenderingStrategyTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\HttpKernel\Tests\RenderingStrategy; | ||
|
||
use Symfony\Component\HttpKernel\HttpKernelInterface; | ||
use Symfony\Component\HttpKernel\HttpKernel; | ||
use Symfony\Component\HttpKernel\RenderingStrategy\DefaultRenderingStrategy; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\EventDispatcher\EventDispatcher; | ||
|
||
class DefaultRenderingStrategyTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
protected function setUp() | ||
{ | ||
if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) { | ||
$this->markTestSkipped('The "EventDispatcher" component is not available'); | ||
} | ||
|
||
if (!class_exists('Symfony\Component\HttpFoundation\Request')) { | ||
$this->markTestSkipped('The "HttpFoundation" component is not available'); | ||
} | ||
} | ||
|
||
public function testExceptionInSubRequestsDoesNotMangleOutputBuffers() | ||
{ | ||
$resolver = $this->getMock('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface'); | ||
$resolver | ||
->expects($this->once()) | ||
->method('getController') | ||
->will($this->returnValue(function () { | ||
ob_start(); | ||
echo 'bar'; | ||
throw new \RuntimeException(); | ||
})) | ||
; | ||
$resolver | ||
->expects($this->once()) | ||
->method('getArguments') | ||
->will($this->returnValue(array())) | ||
; | ||
|
||
$kernel = new HttpKernel(new EventDispatcher(), $resolver); | ||
$renderer = new DefaultRenderingStrategy($kernel); | ||
|
||
// simulate a main request with output buffering | ||
ob_start(); | ||
echo 'Foo'; | ||
|
||
// simulate a sub-request with output buffering and an exception | ||
$renderer->render('/', Request::create('/'), array('ignore_errors' => true)); | ||
|
||
$this->assertEquals('Foo', ob_get_clean()); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should add a
trigger_error
call in the constructorThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, as this class is still used in the DIC, which means that everyone will have the deprecated message without being able to fix it. And we cannot switch to the new class as it does not have the
forward
andrender
methods. Anyway, I don't think that too many people need to care about this.