Merge branch '2.2' into 2.3

* 2.2:
  [HttpFoundation] removed double-slashes (closes #8388)
  [HttpFoundation] tried to keep the original Request URI as much as possible to avoid different behavior between ::createFromGlobals() and ::create()
  [TwigBridge] fixed form rendering when used in a template with dynamic inheritance
This commit is contained in:
Fabien Potencier 2013-09-12 22:07:23 +02:00
commit 8899e31a88
6 changed files with 34 additions and 4 deletions

View File

@ -167,6 +167,8 @@ class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererE
// theme is a reference and we don't want to change it.
$currentTheme = $theme;
$context = $this->environment->mergeGlobals(array());
// The do loop takes care of template inheritance.
// Add blocks from all templates in the inheritance tree, but avoid
// overriding blocks already set.
@ -178,6 +180,6 @@ class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererE
$this->resources[$cacheKey][$block] = $blockData;
}
}
} while (false !== $currentTheme = $currentTheme->getParent(array()));
} while (false !== $currentTheme = $currentTheme->getParent($context));
}
}

View File

@ -64,6 +64,8 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
$environment = new \Twig_Environment($loader, array('strict_variables' => true));
$environment->addExtension(new TranslationExtension(new StubTranslator()));
$environment->addGlobal('global', '');
// the value can be any template that exists
$environment->addGlobal('dynamic_template_name', 'child_label');
$environment->addExtension($this->extension);
$this->extension->initRuntime($environment);
@ -106,6 +108,18 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
);
}
public function testThemeBlockInheritanceUsingDynamicExtend()
{
$view = $this->factory
->createNamed('name', 'email')
->createView()
;
$renderer = $this->extension->renderer;
$renderer->setTheme($view, array('page_dynamic_extends.html.twig'));
$renderer->searchAndRenderBlock($view, 'row');
}
public function isSelectedChoiceProvider()
{
// The commented cases should not be necessary anymore, because the

View File

@ -0,0 +1 @@
{% extends dynamic_template_name ~ '.html.twig' %}

View File

@ -137,7 +137,7 @@ class File extends \SplFileInfo
throw new FileException(sprintf('Unable to write in the "%s" directory', $directory));
}
$target = $directory.DIRECTORY_SEPARATOR.(null === $name ? $this->getBasename() : $this->getName($name));
$target = trim($directory, '/\\').DIRECTORY_SEPARATOR.(null === $name ? $this->getBasename() : $this->getName($name));
return new File($target, false);
}

View File

@ -346,11 +346,20 @@ class Request
break;
}
$queryString = '';
if (isset($components['query'])) {
parse_str(html_entity_decode($components['query']), $qs);
$query = array_replace($qs, $query);
if ($query) {
$query = array_replace($qs, $query);
$queryString = http_build_query($query, '', '&');
} else {
$query = $qs;
$queryString = $components['query'];
}
} elseif ($query) {
$queryString = http_build_query($query, '', '&');
}
$queryString = http_build_query($query, '', '&');
$server['REQUEST_URI'] = $components['path'].('' !== $queryString ? '?'.$queryString : '');
$server['QUERY_STRING'] = $queryString;

View File

@ -211,6 +211,10 @@ class RequestTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('testnopass', $request->getUser());
$this->assertNull($request->getPassword());
$this->assertFalse($request->isSecure());
$request = Request::create('http://test.com/?foo');
$this->assertEquals('/?foo', $request->getRequestUri());
$this->assertEquals(array('foo' => ''), $request->query->all());
}
/**