From 91234cd89aed6c5e5d6ec5947d2099ed787b6392 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 29 Aug 2013 07:19:56 +0200 Subject: [PATCH 1/5] [HttpKernel] changed fragment URLs to be relative by default (closes #8458) --- .../Fragment/RoutableFragmentRenderer.php | 13 +++++++--- .../Fragment/EsiFragmentRendererTest.php | 2 +- .../Fragment/HIncludeFragmentRendererTest.php | 2 +- .../Fragment/RoutableFragmentRendererTest.php | 24 ++++++++++++------- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Fragment/RoutableFragmentRenderer.php b/src/Symfony/Component/HttpKernel/Fragment/RoutableFragmentRenderer.php index 1f3b84f619..bd133ce46e 100644 --- a/src/Symfony/Component/HttpKernel/Fragment/RoutableFragmentRenderer.php +++ b/src/Symfony/Component/HttpKernel/Fragment/RoutableFragmentRenderer.php @@ -40,11 +40,12 @@ abstract class RoutableFragmentRenderer implements FragmentRendererInterface * Generates a fragment URI for a given controller. * * @param ControllerReference $reference A ControllerReference instance - * @param Request $request A Request instance + * @param Request $request A Request instance + * @param Boolean $absolute Whether to generate an absolute URL or not * * @return string A fragment URI */ - protected function generateFragmentUri(ControllerReference $reference, Request $request) + protected function generateFragmentUri(ControllerReference $reference, Request $request, $absolute = false) { // We need to forward the current _format and _locale values as we don't have // a proper routing pattern to do the job for us. @@ -62,6 +63,12 @@ abstract class RoutableFragmentRenderer implements FragmentRendererInterface $reference->query['_path'] = http_build_query($reference->attributes, '', '&'); - return $request->getUriForPath($this->fragmentPath.'?'.http_build_query($reference->query, '', '&')); + $path = $this->fragmentPath.'?'.http_build_query($reference->query, '', '&'); + + if ($absolute) { + return $request->getUriForPath($path); + } + + return $request->getBaseUrl().$path; } } diff --git a/src/Symfony/Component/HttpKernel/Tests/Fragment/EsiFragmentRendererTest.php b/src/Symfony/Component/HttpKernel/Tests/Fragment/EsiFragmentRendererTest.php index 5bbfdace9b..e6b8b2cd48 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Fragment/EsiFragmentRendererTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Fragment/EsiFragmentRendererTest.php @@ -48,7 +48,7 @@ class EsiFragmentRendererTest extends \PHPUnit_Framework_TestCase $this->assertEquals('', $strategy->render('/', $request)->getContent()); $this->assertEquals("\n", $strategy->render('/', $request, array('comment' => 'This is a comment'))->getContent()); $this->assertEquals('', $strategy->render('/', $request, array('alt' => 'foo'))->getContent()); - $this->assertEquals('', $strategy->render(new ControllerReference('main_controller', array(), array()), $request, array('alt' => new ControllerReference('alt_controller', array(), array())))->getContent()); + $this->assertEquals('', $strategy->render(new ControllerReference('main_controller', array(), array()), $request, array('alt' => new ControllerReference('alt_controller', array(), array())))->getContent()); } private function getInlineStrategy($called = false) diff --git a/src/Symfony/Component/HttpKernel/Tests/Fragment/HIncludeFragmentRendererTest.php b/src/Symfony/Component/HttpKernel/Tests/Fragment/HIncludeFragmentRendererTest.php index 84c185ef19..d0d9bb286e 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Fragment/HIncludeFragmentRendererTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Fragment/HIncludeFragmentRendererTest.php @@ -38,7 +38,7 @@ class HIncludeFragmentRendererTest extends \PHPUnit_Framework_TestCase { $strategy = new HIncludeFragmentRenderer(null, new UriSigner('foo')); - $this->assertEquals('', $strategy->render(new ControllerReference('main_controller', array(), array()), Request::create('/'))->getContent()); + $this->assertEquals('', $strategy->render(new ControllerReference('main_controller', array(), array()), Request::create('/'))->getContent()); } public function testRenderWithUri() diff --git a/src/Symfony/Component/HttpKernel/Tests/Fragment/RoutableFragmentRendererTest.php b/src/Symfony/Component/HttpKernel/Tests/Fragment/RoutableFragmentRendererTest.php index 69385dccbd..e8df8874f8 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Fragment/RoutableFragmentRendererTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Fragment/RoutableFragmentRendererTest.php @@ -25,14 +25,22 @@ class RoutableFragmentRendererTest extends \PHPUnit_Framework_TestCase $this->assertEquals($uri, $this->getRenderer()->doGenerateFragmentUri($controller, Request::create('/'))); } + /** + * @dataProvider getGenerateFragmentUriData + */ + public function testGenerateAbsoluteFragmentUri($uri, $controller) + { + $this->assertEquals('http://localhost'.$uri, $this->getRenderer()->doGenerateFragmentUri($controller, Request::create('/'), true)); + } + public function getGenerateFragmentUriData() { return array( - array('http://localhost/_fragment?_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array(), array())), - array('http://localhost/_fragment?_path=_format%3Dxml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array('_format' => 'xml'), array())), - array('http://localhost/_fragment?_path=foo%3Dfoo%26_format%3Djson%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array('foo' => 'foo', '_format' => 'json'), array())), - array('http://localhost/_fragment?bar=bar&_path=foo%3Dfoo%26_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array('foo' => 'foo'), array('bar' => 'bar'))), - array('http://localhost/_fragment?foo=foo&_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array(), array('foo' => 'foo'))), + array('/_fragment?_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array(), array())), + array('/_fragment?_path=_format%3Dxml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array('_format' => 'xml'), array())), + array('/_fragment?_path=foo%3Dfoo%26_format%3Djson%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array('foo' => 'foo', '_format' => 'json'), array())), + array('/_fragment?bar=bar&_path=foo%3Dfoo%26_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array('foo' => 'foo'), array('bar' => 'bar'))), + array('/_fragment?foo=foo&_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array(), array('foo' => 'foo'))), ); } @@ -43,7 +51,7 @@ class RoutableFragmentRendererTest extends \PHPUnit_Framework_TestCase $request->setLocale('fr'); $controller = new ControllerReference('controller', array(), array()); - $this->assertEquals('http://localhost/_fragment?_path=_format%3Djson%26_locale%3Dfr%26_controller%3Dcontroller', $this->getRenderer()->doGenerateFragmentUri($controller, $request)); + $this->assertEquals('/_fragment?_path=_format%3Djson%26_locale%3Dfr%26_controller%3Dcontroller', $this->getRenderer()->doGenerateFragmentUri($controller, $request)); } private function getRenderer() @@ -57,8 +65,8 @@ class Renderer extends RoutableFragmentRenderer public function render($uri, Request $request, array $options = array()) {} public function getName() {} - public function doGenerateFragmentUri(ControllerReference $reference, Request $request) + public function doGenerateFragmentUri(ControllerReference $reference, Request $request, $absolute = false) { - return parent::generateFragmentUri($reference, $request); + return parent::generateFragmentUri($reference, $request, $absolute); } } From 4d01e7ebbd0e802e2b47d2ca4ac808d50af9f864 Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Thu, 29 Aug 2013 12:32:30 -0700 Subject: [PATCH 2/5] fixed misleading doc block --- src/Symfony/Component/HttpFoundation/Request.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 4641eadab1..7f79df9c49 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -719,9 +719,9 @@ class Request /** * Returns the client IP addresses. * - * The most trusted IP address is first, and the less trusted one last. - * The "real" client IP address is the last one, but this is also the - * less trusted one. + * The least trusted IP address is first, and the most trusted one last. + * The "real" client IP address is the first one, but this is also the + * least trusted one. * * Use this method carefully; you should use getClientIp() instead. * From 96bb731b28f473279eb3b3d642bd9e376729c530 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B3th=20G=C3=A1bor?= Date: Fri, 30 Aug 2013 12:51:09 +0200 Subject: [PATCH 3/5] optimized circular reference checker --- .../Compiler/CheckCircularReferencesPass.php | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/CheckCircularReferencesPass.php b/src/Symfony/Component/DependencyInjection/Compiler/CheckCircularReferencesPass.php index 03528fefa9..e81110dc01 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/CheckCircularReferencesPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/CheckCircularReferencesPass.php @@ -28,6 +28,7 @@ class CheckCircularReferencesPass implements CompilerPassInterface { private $currentId; private $currentPath; + private $checkedNodes; /** * Checks the ContainerBuilder object for circular references. @@ -38,6 +39,7 @@ class CheckCircularReferencesPass implements CompilerPassInterface { $graph = $container->getCompiler()->getServiceReferenceGraph(); + $this->checkedNodes = array(); foreach ($graph->getNodes() as $id => $node) { $this->currentId = $id; $this->currentPath = array($id); @@ -58,15 +60,20 @@ class CheckCircularReferencesPass implements CompilerPassInterface foreach ($edges as $edge) { $node = $edge->getDestNode(); $id = $node->getId(); - $searchKey = array_search($id, $this->currentPath); - $this->currentPath[] = $id; - if (false !== $searchKey) { - throw new ServiceCircularReferenceException($id, array_slice($this->currentPath, $searchKey)); + if (empty($this->checkedNodes[$id])) { + $searchKey = array_search($id, $this->currentPath); + $this->currentPath[] = $id; + + if (false !== $searchKey) { + throw new ServiceCircularReferenceException($id, array_slice($this->currentPath, $searchKey)); + } + + $this->checkOutEdges($node->getOutEdges()); + + $this->checkedNodes[$id] = true; + array_pop($this->currentPath); } - - $this->checkOutEdges($node->getOutEdges()); - array_pop($this->currentPath); } } } From 6d8e91bf4fff712a6664f7cc64d6329de57ba2e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=A4rtner?= Date: Fri, 30 Aug 2013 00:32:35 +0200 Subject: [PATCH 4/5] Fixed PHPDoc Blocks These ```RunTimeExceptions``` are NOT the native ones, therefor the should not be ```\``` in front of them. --- src/Symfony/Component/Process/Process.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index 520794ed54..bee8c9d9d7 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -289,8 +289,8 @@ class Process * * @return Process The new process * - * @throws \RuntimeException When process can't be launch or is stopped - * @throws \RuntimeException When process is already running + * @throws RuntimeException When process can't be launch or is stopped + * @throws RuntimeException When process is already running * * @see start() */ @@ -317,8 +317,8 @@ class Process * * @return integer The exitcode of the process * - * @throws \RuntimeException When process timed out - * @throws \RuntimeException When process stopped after receiving signal + * @throws RuntimeException When process timed out + * @throws RuntimeException When process stopped after receiving signal */ public function wait($callback = null) { From f02dbd6641d78f4edc849de72cfcd6d3b59a8e74 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 30 Aug 2013 14:58:19 +0200 Subject: [PATCH 5/5] [Security] fixed some phpdoc --- .../Component/Security/Http/Firewall/SwitchUserListener.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php b/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php index bad6b2b7cc..77000968e1 100644 --- a/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php @@ -68,11 +68,11 @@ class SwitchUserListener implements ListenerInterface } /** - * Handles digest authentication. + * Handles the switch to another user. * * @param GetResponseEvent $event A GetResponseEvent instance * - * @throws \LogicException + * @throws \LogicException if switching to a user failed */ public function handle(GetResponseEvent $event) {