-
-
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
added some unit tests (and fixed some bugs)
- Loading branch information
commit f7da1f0eb83f549c2245a3d2d1036be0688c78c6
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
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
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
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
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
105 changes: 105 additions & 0 deletions
105
...ndle/FrameworkBundle/Tests/DependencyInjection/Compiler/HttpRenderingStrategyPassTest.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,105 @@ | ||
<?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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\HttpRenderingStrategyPass; | ||
|
||
class HttpRenderingStrategyPassTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* Tests that content rendering not implementing RenderingStrategyInterface | ||
* trigger an exception. | ||
* | ||
* @expectedException \InvalidArgumentException | ||
*/ | ||
public function testContentRendererWithoutInterface() | ||
{ | ||
// one service, not implementing any interface | ||
$services = array( | ||
'my_content_renderer' => array(), | ||
); | ||
|
||
$definition = $this->getMock('Symfony\Component\DependencyInjection\Definition'); | ||
$definition->expects($this->atLeastOnce()) | ||
->method('getClass') | ||
->will($this->returnValue('stdClass')); | ||
|
||
$builder = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder'); | ||
$builder->expects($this->any()) | ||
->method('hasDefinition') | ||
->will($this->returnValue(true)); | ||
|
||
// We don't test kernel.content_renderer_strategy here | ||
$builder->expects($this->atLeastOnce()) | ||
->method('findTaggedServiceIds') | ||
->will($this->returnValue($services)); | ||
|
||
$builder->expects($this->atLeastOnce()) | ||
->method('getDefinition') | ||
->will($this->returnValue($definition)); | ||
|
||
$pass = new HttpRenderingStrategyPass(); | ||
$pass->process($builder); | ||
} | ||
|
||
public function testValidContentRenderer() | ||
{ | ||
$services = array( | ||
'my_content_renderer' => array(), | ||
); | ||
|
||
$renderer = $this->getMock('Symfony\Component\DependencyInjection\Definition'); | ||
$renderer | ||
->expects($this->once()) | ||
->method('addMethodCall') | ||
->with('addStrategy', array(new Reference('my_content_renderer'))) | ||
; | ||
|
||
$definition = $this->getMock('Symfony\Component\DependencyInjection\Definition'); | ||
$definition->expects($this->atLeastOnce()) | ||
->method('getClass') | ||
->will($this->returnValue('Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\RenderingStrategyService')); | ||
|
||
$builder = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder'); | ||
$builder->expects($this->any()) | ||
->method('hasDefinition') | ||
->will($this->returnValue(true)); | ||
|
||
// We don't test kernel.content_renderer_strategy here | ||
$builder->expects($this->atLeastOnce()) | ||
->method('findTaggedServiceIds') | ||
->will($this->returnValue($services)); | ||
|
||
$builder->expects($this->atLeastOnce()) | ||
->method('getDefinition') | ||
->will($this->onConsecutiveCalls($renderer, $definition)); | ||
|
||
$pass = new HttpRenderingStrategyPass(); | ||
$pass->process($builder); | ||
} | ||
} | ||
|
||
class RenderingStrategyService implements \Symfony\Component\HttpKernel\RenderingStrategy\RenderingStrategyInterface | ||
{ | ||
public function render($uri, Request $request = null, array $options = array()) | ||
{ | ||
} | ||
|
||
public function getName() | ||
{ | ||
return 'test'; | ||
} | ||
} |
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
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
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
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
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
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
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
119 changes: 119 additions & 0 deletions
119
src/Symfony/Component/HttpKernel/Tests/EventListener/RouterProxyListenerTest.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,119 @@ | ||
<?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\EventListener; | ||
|
||
use Symfony\Component\HttpKernel\EventListener\RouterProxyListener; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpKernel\HttpKernelInterface; | ||
use Symfony\Component\HttpKernel\Event\GetResponseEvent; | ||
use Symfony\Component\HttpKernel\UriSigner; | ||
|
||
class RouterProxyListenerTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
protected function setUp() | ||
{ | ||
if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) { | ||
$this->markTestSkipped('The "EventDispatcher" component is not available'); | ||
} | ||
} | ||
|
||
public function testOnlyTrigerredOnProxyRoute() | ||
{ | ||
$request = Request::create('http://example.com/foo?path=foo%3D=bar'); | ||
|
||
$listener = new RouterProxyListener(new UriSigner('foo')); | ||
$event = $this->createGetResponseEvent($request, 'foobar'); | ||
|
||
$expected = $request->attributes->all(); | ||
|
||
$listener->onKernelRequest($event); | ||
|
||
$this->assertEquals($expected, $request->attributes->all()); | ||
$this->assertTrue($request->query->has('path')); | ||
} | ||
|
||
/** | ||
* @expectedException \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException | ||
*/ | ||
public function testAccessDeniedWithNonSafeMethods() | ||
{ | ||
$request = Request::create('http://example.com/foo', 'POST'); | ||
|
||
$listener = new RouterProxyListener(new UriSigner('foo')); | ||
$event = $this->createGetResponseEvent($request); | ||
|
||
$listener->onKernelRequest($event); | ||
} | ||
|
||
/** | ||
* @expectedException \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException | ||
*/ | ||
public function testAccessDeniedWithNonLocalIps() | ||
{ | ||
$request = Request::create('http://example.com/foo', 'GET', array(), array(), array(), array('REMOTE_ADDR' => '10.0.0.1')); | ||
|
||
$listener = new RouterProxyListener(new UriSigner('foo')); | ||
$event = $this->createGetResponseEvent($request); | ||
|
||
$listener->onKernelRequest($event); | ||
} | ||
|
||
/** | ||
* @expectedException \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException | ||
*/ | ||
public function testAccessDeniedWithWrongSignature() | ||
{ | ||
$request = Request::create('http://example.com/foo', 'GET', array(), array(), array(), array('REMOTE_ADDR' => '10.0.0.1')); | ||
|
||
$listener = new RouterProxyListener(new UriSigner('foo')); | ||
$event = $this->createGetResponseEvent($request); | ||
|
||
$listener->onKernelRequest($event); | ||
} | ||
|
||
public function testWithSignatureAndNoPath() | ||
{ | ||
$signer = new UriSigner('foo'); | ||
$request = Request::create($signer->sign('http://example.com/foo'), 'GET', array(), array(), array(), array('REMOTE_ADDR' => '10.0.0.1')); | ||
|
||
$listener = new RouterProxyListener($signer); | ||
$event = $this->createGetResponseEvent($request); | ||
|
||
$listener->onKernelRequest($event); | ||
|
||
$this->assertEquals(array('foo' => 'foo'), $request->attributes->get('_route_params')); | ||
$this->assertFalse($request->query->has('path')); | ||
} | ||
|
||
public function testWithSignatureAndPath() | ||
{ | ||
$signer = new UriSigner('foo'); | ||
$request = Request::create($signer->sign('http://example.com/foo?path=bar%3Dbar'), 'GET', array(), array(), array(), array('REMOTE_ADDR' => '10.0.0.1')); | ||
|
||
$listener = new RouterProxyListener($signer); | ||
$event = $this->createGetResponseEvent($request); | ||
|
||
$listener->onKernelRequest($event); | ||
|
||
$this->assertEquals(array('foo' => 'foo', 'bar' => 'bar'), $request->attributes->get('_route_params')); | ||
$this->assertFalse($request->query->has('path')); | ||
} | ||
|
||
private function createGetResponseEvent(Request $request, $route = '_proxy') | ||
{ | ||
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); | ||
$request->attributes->set('_route', $route); | ||
$request->attributes->set('_route_params', array('foo' => 'foo')); | ||
|
||
return new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); | ||
} | ||
} |
Oops, something went wrong.
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.
strategies could be marked as private, allowing to inline them in the container
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.
I thought about that, but because of a bug in the PHPDumper, that's not possible for hinclude. I'm working on fixing the bug so that we can use private services later on.
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.
see #6565 for the bug fix