Merge branch '2.7' into 2.8

* 2.7:
  [Twig] Fix deprecations with Twig 1.29
  fix the docblock in regard to the role argument
  Cast result to int before adding to it
This commit is contained in:
Nicolas Grekas 2016-12-08 15:41:31 +01:00
commit 7f633d143c
11 changed files with 78 additions and 34 deletions

View File

@ -72,8 +72,7 @@ class TwigExtractorTest extends \PHPUnit_Framework_TestCase
}
/**
* @expectedException \Twig_Error
* @expectedExceptionMessageRegExp /Unclosed "block" in ".*extractor(\/|\\)syntax_error\.twig" at line 1/
* @expectedException \Twig_Error
* @dataProvider resourcesWithSyntaxErrorsProvider
*/
public function testExtractSyntaxError($resources)
@ -82,7 +81,19 @@ class TwigExtractorTest extends \PHPUnit_Framework_TestCase
$twig->addExtension(new TranslationExtension($this->getMock('Symfony\Component\Translation\TranslatorInterface')));
$extractor = new TwigExtractor($twig);
$extractor->extract($resources, new MessageCatalogue('en'));
try {
$extractor->extract($resources, new MessageCatalogue('en'));
} catch (\Twig_Error $e) {
if (method_exists($e, 'getSourceContext')) {
$this->assertSame(dirname(__DIR__).strtr('/Fixtures/extractor/syntax_error.twig', '/', DIRECTORY_SEPARATOR), $e->getFile());
$this->assertSame(1, $e->getLine());
$this->assertSame('Unclosed "block".', $e->getMessage());
} else {
$this->expectExceptionMessageRegExp('/Unclosed "block" in ".*extractor(\\/|\\\\)syntax_error\\.twig" at line 1/');
}
throw $e;
}
}
/**

View File

@ -61,10 +61,14 @@ class TwigExtractor extends AbstractFileExtractor implements ExtractorInterface
try {
$this->extractTemplate(file_get_contents($file->getPathname()), $catalogue);
} catch (\Twig_Error $e) {
if ($file instanceof SplFileInfo) {
$e->setTemplateName($file->getRelativePathname());
} elseif ($file instanceof \SplFileInfo) {
$e->setTemplateName($file->getRealPath() ?: $file->getPathname());
if ($file instanceof \SplFileInfo) {
$path = $file->getRealPath() ?: $file->getPathname();
$name = $file instanceof SplFileInfo ? $file->getRelativePathname() : $path;
if (method_exists($e, 'setSourceContext')) {
$e->setSourceContext(new \Twig_Source('', $name, $path));
} else {
$e->setTemplateName($name);
}
}
throw $e;

View File

@ -74,7 +74,13 @@ class TwigEngine extends BaseEngine implements EngineInterface
if ($name instanceof TemplateReference) {
try {
// try to get the real name of the template where the error occurred
$e->setTemplateName(sprintf('%s', $this->locator->locate($this->parser->parse($e->getTemplateName()))));
$name = $e->getTemplateName();
$path = (string) $this->locator->locate($this->parser->parse($name));
if (method_exists($e, 'setSourceContext')) {
$e->setSourceContext(new \Twig_Source('', $name, $path));
} else {
$e->setTemplateName($path);
}
} catch (\Exception $e2) {
}
}

View File

@ -72,9 +72,11 @@
<ul id="menu-profiler">
{% for name, template in templates %}
{% set menu -%}
{% with { collector: profile.getcollector(name), profiler_markup_version: profiler_markup_version } %}
{{- block('menu', template) -}}
{% endwith %}
{% if block('menu', template) is defined %}
{% with { collector: profile.getcollector(name), profiler_markup_version: profiler_markup_version } %}
{{- block('menu', template) -}}
{% endwith %}
{% endif %}
{%- endset %}
{% if menu is not empty %}
<li class="{{ name }} {{ name == panel ? 'selected' : '' }}">

View File

@ -26,15 +26,17 @@
<div id="sfToolbarMainContent-{{ token }}" class="sf-toolbarreset clear-fix" data-no-turbolink>
{% for name, template in templates %}
{% with {
collector: profile.getcollector(name),
profiler_url: profiler_url,
token: profile.token,
name: name,
profiler_markup_version: profiler_markup_version
} %}
{{ block('toolbar', template) }}
{% endwith %}
{% if block('toolbar', template) is defined %}
{% with {
collector: profile.getcollector(name),
profiler_url: profiler_url,
token: profile.token,
name: name,
profiler_markup_version: profiler_markup_version
} %}
{{ block('toolbar', template) }}
{% endwith %}
{% endif %}
{% endfor %}
{% if 'normal' != position %}

View File

@ -369,21 +369,22 @@ class XmlFileLoader extends FileLoader
$arg->setAttribute('key', $arg->getAttribute('name'));
}
if (!$arg->hasAttribute('key')) {
$key = !$arguments ? 0 : max(array_keys($arguments)) + 1;
} else {
$key = $arg->getAttribute('key');
}
// parameter keys are case insensitive
if ('parameter' == $name && $lowercase) {
$key = strtolower($key);
}
// this is used by DefinitionDecorator to overwrite a specific
// argument of the parent definition
if ($arg->hasAttribute('index')) {
$key = 'index_'.$arg->getAttribute('index');
} elseif (!$arg->hasAttribute('key')) {
// Append an empty argument, then fetch its key to overwrite it later
$arguments[] = null;
$keys = array_keys($arguments);
$key = array_pop($keys);
} else {
$key = $arg->getAttribute('key');
// parameter keys are case insensitive
if ('parameter' == $name && $lowercase) {
$key = strtolower($key);
}
}
switch ($arg->getAttribute('type')) {

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="foo" class="Foo">
<argument key="type">foo</argument>
<argument>bar</argument>
</service>
</services>
</container>

View File

@ -577,4 +577,13 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($container->getDefinition('bar')->isAutowired());
}
public function testArgumentWithKeyOutsideCollection()
{
$container = new ContainerBuilder();
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
$loader->load('with_key_outside_collection.xml');
$this->assertSame(array('type' => 'foo', 'bar'), $container->getDefinition('foo')->getArguments());
}
}

View File

@ -33,7 +33,7 @@ abstract class AbstractToken implements TokenInterface
/**
* Constructor.
*
* @param RoleInterface[]|string[] $roles An array of roles
* @param (RoleInterface|string)[] $roles An array of roles
*
* @throws \InvalidArgumentException
*/

View File

@ -29,7 +29,7 @@ class PreAuthenticatedToken extends AbstractToken
* @param string|object $user The user can be a UserInterface instance, or an object implementing a __toString method or the username as a regular string
* @param mixed $credentials The user credentials
* @param string $providerKey The provider key
* @param RoleInterface[]|string[] $roles An array of roles
* @param (RoleInterface|string)[] $roles An array of roles
*/
public function __construct($user, $credentials, $providerKey, array $roles = array())
{

View File

@ -29,7 +29,7 @@ class UsernamePasswordToken extends AbstractToken
* @param string|object $user The username (like a nickname, email address, etc.), or a UserInterface instance or an object implementing a __toString method
* @param string $credentials This usually is the password of the user
* @param string $providerKey The provider key
* @param RoleInterface[]|string[] $roles An array of roles
* @param (RoleInterface|string)[] $roles An array of roles
*
* @throws \InvalidArgumentException
*/