Merge branch '2.3'

* 2.3:
  [Security] fixed some phpdoc
  Fixed PHPDoc Blocks
  optimized circular reference checker
  fixed misleading doc block
  [HttpKernel] changed fragment URLs to be relative by default (closes #8458)

Conflicts:
	src/Symfony/Component/HttpKernel/Fragment/RoutableFragmentRenderer.php
	src/Symfony/Component/HttpKernel/Tests/Fragment/RoutableFragmentRendererTest.php
This commit is contained in:
Fabien Potencier 2013-08-30 15:15:50 +02:00
commit e838bf04ca
9 changed files with 57 additions and 30 deletions

View File

@ -28,6 +28,7 @@ class CheckCircularReferencesPass implements CompilerPassInterface
{ {
private $currentId; private $currentId;
private $currentPath; private $currentPath;
private $checkedNodes;
/** /**
* Checks the ContainerBuilder object for circular references. * Checks the ContainerBuilder object for circular references.
@ -38,6 +39,7 @@ class CheckCircularReferencesPass implements CompilerPassInterface
{ {
$graph = $container->getCompiler()->getServiceReferenceGraph(); $graph = $container->getCompiler()->getServiceReferenceGraph();
$this->checkedNodes = array();
foreach ($graph->getNodes() as $id => $node) { foreach ($graph->getNodes() as $id => $node) {
$this->currentId = $id; $this->currentId = $id;
$this->currentPath = array($id); $this->currentPath = array($id);
@ -58,15 +60,20 @@ class CheckCircularReferencesPass implements CompilerPassInterface
foreach ($edges as $edge) { foreach ($edges as $edge) {
$node = $edge->getDestNode(); $node = $edge->getDestNode();
$id = $node->getId(); $id = $node->getId();
$searchKey = array_search($id, $this->currentPath);
$this->currentPath[] = $id;
if (false !== $searchKey) { if (empty($this->checkedNodes[$id])) {
throw new ServiceCircularReferenceException($id, array_slice($this->currentPath, $searchKey)); $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);
} }
} }
} }

View File

@ -726,9 +726,9 @@ class Request
/** /**
* Returns the client IP addresses. * Returns the client IP addresses.
* *
* The most trusted IP address is first, and the less trusted one last. * The least trusted IP address is first, and the most trusted one last.
* The "real" client IP address is the last one, but this is also the * The "real" client IP address is the first one, but this is also the
* less trusted one. * least trusted one.
* *
* Use this method carefully; you should use getClientIp() instead. * Use this method carefully; you should use getClientIp() instead.
* *

View File

@ -68,7 +68,7 @@ class InlineFragmentRenderer extends RoutableFragmentRenderer
} }
} }
$uri = $this->generateFragmentUri($uri, $request, false); $uri = $this->generateFragmentUri($uri, $request, false, false);
$reference->attributes = array_merge($attributes, $reference->attributes); $reference->attributes = array_merge($attributes, $reference->attributes);
} }

View File

@ -41,11 +41,12 @@ abstract class RoutableFragmentRenderer implements FragmentRendererInterface
* *
* @param ControllerReference $reference A ControllerReference instance * @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
* @param Boolean $strict Whether to allow non-scalar attributes or not * @param Boolean $strict Whether to allow non-scalar attributes or not
* *
* @return string A fragment URI * @return string A fragment URI
*/ */
protected function generateFragmentUri(ControllerReference $reference, Request $request, $strict = true) protected function generateFragmentUri(ControllerReference $reference, Request $request, $absolute = false, $strict = true)
{ {
if ($strict) { if ($strict) {
$this->checkNonScalar($reference->attributes); $this->checkNonScalar($reference->attributes);
@ -67,7 +68,13 @@ abstract class RoutableFragmentRenderer implements FragmentRendererInterface
$reference->query['_path'] = http_build_query($reference->attributes, '', '&'); $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;
} }
private function checkNonScalar($values) private function checkNonScalar($values)

View File

@ -41,7 +41,7 @@ class EsiFragmentRendererTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('<esi:include src="/" />', $strategy->render('/', $request)->getContent()); $this->assertEquals('<esi:include src="/" />', $strategy->render('/', $request)->getContent());
$this->assertEquals("<esi:comment text=\"This is a comment\" />\n<esi:include src=\"/\" />", $strategy->render('/', $request, array('comment' => 'This is a comment'))->getContent()); $this->assertEquals("<esi:comment text=\"This is a comment\" />\n<esi:include src=\"/\" />", $strategy->render('/', $request, array('comment' => 'This is a comment'))->getContent());
$this->assertEquals('<esi:include src="/" alt="foo" />', $strategy->render('/', $request, array('alt' => 'foo'))->getContent()); $this->assertEquals('<esi:include src="/" alt="foo" />', $strategy->render('/', $request, array('alt' => 'foo'))->getContent());
$this->assertEquals('<esi:include src="http://localhost/_fragment?_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dmain_controller" alt="http://localhost/_fragment?_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dalt_controller" />', $strategy->render(new ControllerReference('main_controller', array(), array()), $request, array('alt' => new ControllerReference('alt_controller', array(), array())))->getContent()); $this->assertEquals('<esi:include src="/_fragment?_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dmain_controller" alt="/_fragment?_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dalt_controller" />', $strategy->render(new ControllerReference('main_controller', array(), array()), $request, array('alt' => new ControllerReference('alt_controller', array(), array())))->getContent());
} }
private function getInlineStrategy($called = false) private function getInlineStrategy($called = false)

View File

@ -31,7 +31,7 @@ class HIncludeFragmentRendererTest extends \PHPUnit_Framework_TestCase
{ {
$strategy = new HIncludeFragmentRenderer(null, new UriSigner('foo')); $strategy = new HIncludeFragmentRenderer(null, new UriSigner('foo'));
$this->assertEquals('<hx:include src="http://localhost/_fragment?_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dmain_controller&amp;_hash=g4b3vtCnhkZBFKrciEFwG7fucVo%3D"></hx:include>', $strategy->render(new ControllerReference('main_controller', array(), array()), Request::create('/'))->getContent()); $this->assertEquals('<hx:include src="/_fragment?_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dmain_controller&amp;_hash=5RZ1IkwF487EaXt6buHka73CCtQ%3D"></hx:include>', $strategy->render(new ControllerReference('main_controller', array(), array()), Request::create('/'))->getContent());
} }
public function testRenderWithUri() public function testRenderWithUri()

View File

@ -24,15 +24,23 @@ class RoutableFragmentRendererTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($uri, $this->callGenerateFragmentUriMethod($controller, Request::create('/'))); $this->assertEquals($uri, $this->callGenerateFragmentUriMethod($controller, Request::create('/')));
} }
/**
* @dataProvider getGenerateFragmentUriData
*/
public function testGenerateAbsoluteFragmentUri($uri, $controller)
{
$this->assertEquals('http://localhost'.$uri, $this->callGenerateFragmentUriMethod($controller, Request::create('/'), true));
}
public function getGenerateFragmentUriData() public function getGenerateFragmentUriData()
{ {
return array( return array(
array('http://localhost/_fragment?_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array(), array())), array('/_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('/_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('/_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('/_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?foo=foo&_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array(), array('foo' => 'foo'))),
array('http://localhost/_fragment?_path=foo%255B0%255D%3Dfoo%26foo%255B1%255D%3Dbar%26_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array('foo' => array('foo', 'bar')), array())), array('/_fragment?_path=foo%255B0%255D%3Dfoo%26foo%255B1%255D%3Dbar%26_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array('foo' => array('foo', 'bar')), array())),
); );
} }
@ -43,7 +51,7 @@ class RoutableFragmentRendererTest extends \PHPUnit_Framework_TestCase
$request->setLocale('fr'); $request->setLocale('fr');
$controller = new ControllerReference('controller', array(), array()); $controller = new ControllerReference('controller', array(), array());
$this->assertEquals('http://localhost/_fragment?_path=_format%3Djson%26_locale%3Dfr%26_controller%3Dcontroller', $this->callGenerateFragmentUriMethod($controller, $request)); $this->assertEquals('/_fragment?_path=_format%3Djson%26_locale%3Dfr%26_controller%3Dcontroller', $this->callGenerateFragmentUriMethod($controller, $request));
} }
/** /**
@ -63,14 +71,14 @@ class RoutableFragmentRendererTest extends \PHPUnit_Framework_TestCase
); );
} }
private function callGenerateFragmentUriMethod(ControllerReference $reference, Request $request) private function callGenerateFragmentUriMethod(ControllerReference $reference, Request $request, $absolute = false)
{ {
$renderer = $this->getMockForAbstractClass('Symfony\Component\HttpKernel\Fragment\RoutableFragmentRenderer'); $renderer = $this->getMockForAbstractClass('Symfony\Component\HttpKernel\Fragment\RoutableFragmentRenderer');
$r = new \ReflectionObject($renderer); $r = new \ReflectionObject($renderer);
$m = $r->getMethod('generateFragmentUri'); $m = $r->getMethod('generateFragmentUri');
$m->setAccessible(true); $m->setAccessible(true);
return $m->invoke($renderer, $reference, $request); return $m->invoke($renderer, $reference, $request, $absolute);
} }
} }
@ -82,4 +90,9 @@ class Foo
{ {
return $this->foo; return $this->foo;
} }
public function doGenerateFragmentUri(ControllerReference $reference, Request $request, $absolute = false, $strict = true)
{
return parent::generateFragmentUri($reference, $request, $absolute, $strict);
}
} }

View File

@ -268,8 +268,8 @@ class Process
* *
* @return Process The new process * @return Process The new process
* *
* @throws \RuntimeException When process can't be launch or is stopped * @throws RuntimeException When process can't be launch or is stopped
* @throws \RuntimeException When process is already running * @throws RuntimeException When process is already running
* *
* @see start() * @see start()
*/ */
@ -296,8 +296,8 @@ class Process
* *
* @return integer The exitcode of the process * @return integer The exitcode of the process
* *
* @throws \RuntimeException When process timed out * @throws RuntimeException When process timed out
* @throws \RuntimeException When process stopped after receiving signal * @throws RuntimeException When process stopped after receiving signal
*/ */
public function wait($callback = null) public function wait($callback = null)
{ {

View File

@ -68,11 +68,11 @@ class SwitchUserListener implements ListenerInterface
} }
/** /**
* Handles digest authentication. * Handles the switch to another user.
* *
* @param GetResponseEvent $event A GetResponseEvent instance * @param GetResponseEvent $event A GetResponseEvent instance
* *
* @throws \LogicException * @throws \LogicException if switching to a user failed
*/ */
public function handle(GetResponseEvent $event) public function handle(GetResponseEvent $event)
{ {