From 7def83c0b1c7f1abde900c1fe7371d0f2e8f2571 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 11 Oct 2016 23:07:33 +0200 Subject: [PATCH 1/6] move tags from decorated to decorating service --- .../Compiler/DecoratorServicePass.php | 10 ++++++---- .../Compiler/DecoratorServicePassTest.php | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/DecoratorServicePass.php b/src/Symfony/Component/DependencyInjection/Compiler/DecoratorServicePass.php index ef0a19c6a7..c7a4ac89c1 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/DecoratorServicePass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/DecoratorServicePass.php @@ -42,10 +42,12 @@ class DecoratorServicePass implements CompilerPassInterface $public = $alias->isPublic(); $container->setAlias($renamedId, new Alias((string) $alias, false)); } else { - $definition = $container->getDefinition($inner); - $public = $definition->isPublic(); - $definition->setPublic(false); - $container->setDefinition($renamedId, $definition); + $decoratedDefinition = $container->getDefinition($inner); + $definition->setTags($decoratedDefinition->getTags(), $definition->getTags()); + $public = $decoratedDefinition->isPublic(); + $decoratedDefinition->setPublic(false); + $decoratedDefinition->setTags(array()); + $container->setDefinition($renamedId, $decoratedDefinition); } $container->setAlias($inner, new Alias($id, $public)); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/DecoratorServicePassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/DecoratorServicePassTest.php index 7ddf44dfc0..b197e42249 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/DecoratorServicePassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/DecoratorServicePassTest.php @@ -82,6 +82,24 @@ class DecoratorServicePassTest extends \PHPUnit_Framework_TestCase $this->assertNull($fooExtendedDefinition->getDecoratedService()); } + public function testProcessMovesTagsFromDecoratedDefinitionToDecoratingDefinition() + { + $container = new ContainerBuilder(); + $container + ->register('foo') + ->setTags(array('name' => 'bar')) + ; + $container + ->register('baz') + ->setDecoratedService('foo') + ; + + $this->process($container); + + $this->assertEmpty($container->getDefinition('baz.inner')->getTags()); + $this->assertEquals(array('name' => 'bar'), $container->getDefinition('baz')->getTags()); + } + protected function process(ContainerBuilder $container) { $repeatedPass = new DecoratorServicePass(); From 3d6b4502c80c1e616391beee6d618898abe1cd37 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 14 Oct 2016 13:10:27 +0200 Subject: [PATCH 2/6] no 304 response if method is not cacheable --- src/Symfony/Component/HttpFoundation/Response.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/Response.php b/src/Symfony/Component/HttpFoundation/Response.php index 9babc6345a..7a05a03cdc 100644 --- a/src/Symfony/Component/HttpFoundation/Response.php +++ b/src/Symfony/Component/HttpFoundation/Response.php @@ -1000,7 +1000,7 @@ class Response */ public function isNotModified(Request $request) { - if (!$request->isMethodSafe()) { + if (!$request->isMethodCacheable()) { return false; } From cd3206c5cba85bdef04ac1c0d015543064bf1ee8 Mon Sep 17 00:00:00 2001 From: Muhammed Akbulut Date: Fri, 29 Jul 2016 16:40:15 +0200 Subject: [PATCH 3/6] fixed Filesystem:makePathRelative and added 2 more testcases --- src/Symfony/Component/Filesystem/Filesystem.php | 8 ++++++-- src/Symfony/Component/Filesystem/Tests/FilesystemTest.php | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index f114a2de58..79e8420688 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -369,10 +369,14 @@ class Filesystem } // Determine how deep the start path is relative to the common path (ie, "web/bundles" = 2 levels) - $depth = count($startPathArr) - $index; + if (count($startPathArr) === 1 && $startPathArr[0] === '') { + $depth = 0; + } else { + $depth = count($startPathArr) - $index; + } // When we need to traverse from the start, and we are starting from a root path, don't add '../' - if ('/' === $startPath[0] && 0 === $index && 1 === $depth) { + if ('/' === $startPath[0] && 0 === $index && 0 === $depth) { $traverser = ''; } else { // Repeated "../" for each level need to reach the common path diff --git a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php index 0ca2904833..4f7457898b 100644 --- a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php +++ b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php @@ -840,6 +840,8 @@ class FilesystemTest extends FilesystemTestCase array('/a/aab/bb/', '/a/aa/', '../aab/bb/'), array('/a/aab/bb/', '/', 'a/aab/bb/'), array('/a/aab/bb/', '/b/aab', '../../a/aab/bb/'), + array('/aab/bb', '/aa', '../aab/bb/'), + array('/aab', '/aa', '../aab/'), ); if ('\\' === DIRECTORY_SEPARATOR) { From b69bd3f0ed94d9c8138d1cd379e734a67e7ce1bd Mon Sep 17 00:00:00 2001 From: Andre Smith Date: Tue, 11 Oct 2016 17:48:30 +0200 Subject: [PATCH 4/6] 3.0 Upgrade Guide: Added details describing how to pass data to a form through the options resolver --- UPGRADE-3.0.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/UPGRADE-3.0.md b/UPGRADE-3.0.md index b8b4a96223..68e3780d8a 100644 --- a/UPGRADE-3.0.md +++ b/UPGRADE-3.0.md @@ -348,6 +348,58 @@ UPGRADE FROM 2.x to 3.0 $form = $this->createForm(MyType::class); ``` + * Passing custom data to forms now needs to be done + through the options resolver. + + In the controller: + + Before: + ```php + $form = $this->createForm(new MyType($variable), $entity, array( + 'action' => $this->generateUrl('action_route'), + 'method' => 'PUT', + )); + ``` + After: + ```php + $form = $this->createForm(MyType::class, $entity, array( + 'action' => $this->generateUrl('action_route'), + 'method' => 'PUT', + 'custom_value' => $variable, + )); + ``` + In the form type: + + Before: + ```php + class MyType extends AbstractType + { + private $value; + + public function __construct($variableValue) + { + $this->value = $value; + } + // ... + } + ``` + + After: + ```php + public function buildForm(FormBuilderInterface $builder, array $options) + { + $value = $options['custom_value']; + // ... + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults(array( + 'custom_value' => null, + )); + } + ``` + * The alias option of the `form.type_extension` tag was removed in favor of the `extended_type`/`extended-type` option. From b0df3a7eb9afd93bf07f875cc429cc05b1b7d12b Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski Date: Sun, 16 Oct 2016 22:09:25 +0200 Subject: [PATCH 5/6] PHP CS Fixer: use php_unit_dedicate_assert --- .php_cs | 1 + .../Bundle/FrameworkBundle/Tests/Functional/ProfilerTest.php | 2 +- .../Bundle/TwigBundle/Tests/Functional/CacheWarmingTest.php | 4 ++-- .../Extension/Validator/Type/BaseValidatorExtensionTest.php | 4 ++-- .../Component/OptionsResolver/Tests/LegacyOptionsTest.php | 4 ++-- .../Component/Translation/Tests/Dumper/FileDumperTest.php | 4 ++-- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.php_cs b/.php_cs index 6043614819..5a702adb3a 100644 --- a/.php_cs +++ b/.php_cs @@ -6,6 +6,7 @@ return Symfony\CS\Config\Config::create() ->fixers(array( 'long_array_syntax', 'php_unit_construct', + 'php_unit_dedicate_assert', )) ->finder( Symfony\CS\Finder\DefaultFinder::create() diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ProfilerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ProfilerTest.php index a8741124fd..2d422b0292 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ProfilerTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ProfilerTest.php @@ -30,7 +30,7 @@ class ProfilerTest extends WebTestCase $client->enableProfiler(); $crawler = $client->request('GET', '/profiler'); $profile = $client->getProfile(); - $this->assertTrue(is_object($profile)); + $this->assertInternalType('object', $profile); $client->request('GET', '/profiler'); $this->assertFalse($client->getProfile()); diff --git a/src/Symfony/Bundle/TwigBundle/Tests/Functional/CacheWarmingTest.php b/src/Symfony/Bundle/TwigBundle/Tests/Functional/CacheWarmingTest.php index 0b04f81af0..b51e619a9d 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/Functional/CacheWarmingTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/Functional/CacheWarmingTest.php @@ -28,7 +28,7 @@ class NewCacheWamingTest extends \PHPUnit_Framework_TestCase $warmer->enableOptionalWarmers(); $warmer->warmUp($kernel->getCacheDir()); - $this->assertTrue(file_exists($kernel->getCacheDir().'/twig')); + $this->assertFileExists($kernel->getCacheDir().'/twig'); } public function testCacheIsNotWarmedWhenTemplatingIsDisabled() @@ -40,7 +40,7 @@ class NewCacheWamingTest extends \PHPUnit_Framework_TestCase $warmer->enableOptionalWarmers(); $warmer->warmUp($kernel->getCacheDir()); - $this->assertFalse(file_exists($kernel->getCacheDir().'/twig')); + $this->assertFileNotExists($kernel->getCacheDir().'/twig'); } protected function setUp() diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/Type/BaseValidatorExtensionTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/Type/BaseValidatorExtensionTest.php index 6a15bbfa9e..01f20c4127 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/Type/BaseValidatorExtensionTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/Type/BaseValidatorExtensionTest.php @@ -58,7 +58,7 @@ abstract class BaseValidatorExtensionTest extends TypeTestCase 'validation_groups' => array($this, 'testValidationGroupsCanBeSetToCallback'), )); - $this->assertTrue(is_callable($form->getConfig()->getOption('validation_groups'))); + $this->assertInternalType('callable', $form->getConfig()->getOption('validation_groups')); } public function testValidationGroupsCanBeSetToClosure() @@ -67,7 +67,7 @@ abstract class BaseValidatorExtensionTest extends TypeTestCase 'validation_groups' => function (FormInterface $form) { }, )); - $this->assertTrue(is_callable($form->getConfig()->getOption('validation_groups'))); + $this->assertInternalType('callable', $form->getConfig()->getOption('validation_groups')); } abstract protected function createForm(array $options = array()); diff --git a/src/Symfony/Component/OptionsResolver/Tests/LegacyOptionsTest.php b/src/Symfony/Component/OptionsResolver/Tests/LegacyOptionsTest.php index b65a09002e..fb4d25b5bc 100644 --- a/src/Symfony/Component/OptionsResolver/Tests/LegacyOptionsTest.php +++ b/src/Symfony/Component/OptionsResolver/Tests/LegacyOptionsTest.php @@ -275,7 +275,7 @@ class LegacyOptionsTest extends \PHPUnit_Framework_TestCase }); $resolved = $this->options->resolve(); - $this->assertTrue(is_callable($resolved['foo'])); + $this->assertInternalType('callable', $resolved['foo']); } public function testOverloadCannotBeEvaluatedLazilyWithoutFirstParamTypeHint() @@ -287,7 +287,7 @@ class LegacyOptionsTest extends \PHPUnit_Framework_TestCase }); $resolved = $this->options->resolve(); - $this->assertTrue(is_callable($resolved['foo'])); + $this->assertInternalType('callable', $resolved['foo']); } public function testRemoveOptionAndNormalizer() diff --git a/src/Symfony/Component/Translation/Tests/Dumper/FileDumperTest.php b/src/Symfony/Component/Translation/Tests/Dumper/FileDumperTest.php index 9682089092..bb2d9166ef 100644 --- a/src/Symfony/Component/Translation/Tests/Dumper/FileDumperTest.php +++ b/src/Symfony/Component/Translation/Tests/Dumper/FileDumperTest.php @@ -30,7 +30,7 @@ class FileDumperTest extends \PHPUnit_Framework_TestCase $dumper = new ConcreteFileDumper(); $dumper->dump($catalogue, array('path' => $tempDir)); - $this->assertTrue(file_exists($backupFile)); + $this->assertFileExists($backupFile); @unlink($file); @unlink($backupFile); @@ -49,7 +49,7 @@ class FileDumperTest extends \PHPUnit_Framework_TestCase $dumper->setRelativePathTemplate('test/translations/%domain%.%locale%.%extension%'); $dumper->dump($catalogue, array('path' => $tempDir)); - $this->assertTrue(file_exists($file)); + $this->assertFileExists($file); @unlink($file); @rmdir($translationsDir); From f0849d833118e69b0d630047594b046f0d4a34bc Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 15 Oct 2016 12:33:44 -0700 Subject: [PATCH 6/6] [TwigBridge] removed deprecations added in Twig 1.27 --- composer.json | 2 +- .../Bridge/Twig/Command/LintCommand.php | 2 +- .../Tests/Extension/RoutingExtensionTest.php | 2 +- .../Extension/TranslationExtensionTest.php | 2 +- .../Tests/NodeVisitor/TwigNodeProvider.php | 2 +- .../TokenParser/FormThemeTokenParserTest.php | 2 +- .../TokenParser/TransChoiceTokenParser.php | 2 +- .../Twig/TokenParser/TransTokenParser.php | 4 +-- .../Bridge/Twig/Translation/TwigExtractor.php | 6 ++--- src/Symfony/Bridge/Twig/composer.json | 2 +- .../Bundle/SecurityBundle/composer.json | 2 +- .../DependencyInjection/Configuration.php | 2 +- .../DependencyInjection/TwigExtensionTest.php | 2 +- .../LegacyRenderTokenParserTest.php | 2 +- src/Symfony/Bundle/TwigBundle/TwigEngine.php | 10 ++++---- src/Symfony/Bundle/TwigBundle/composer.json | 2 +- .../DataCollector/DumpDataCollector.php | 25 +++++++++++-------- 17 files changed, 37 insertions(+), 34 deletions(-) diff --git a/composer.json b/composer.json index 468b4f5b26..1a2e8c26b5 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "paragonie/random_compat": "~1.0", "symfony/polyfill-apcu": "~1.1", "symfony/polyfill-mbstring": "~1.1", - "twig/twig": "~1.26|~2.0", + "twig/twig": "~1.27|~2.0", "psr/log": "~1.0" }, "replace": { diff --git a/src/Symfony/Bridge/Twig/Command/LintCommand.php b/src/Symfony/Bridge/Twig/Command/LintCommand.php index df603f93fd..4ed63241b8 100644 --- a/src/Symfony/Bridge/Twig/Command/LintCommand.php +++ b/src/Symfony/Bridge/Twig/Command/LintCommand.php @@ -146,7 +146,7 @@ EOF try { $temporaryLoader = new \Twig_Loader_Array(array((string) $file => $template)); $twig->setLoader($temporaryLoader); - $nodeTree = $twig->parse($twig->tokenize($template, (string) $file)); + $nodeTree = $twig->parse($twig->tokenize(new \Twig_Source($template, (string) $file))); $twig->compile($nodeTree); $twig->setLoader($realLoader); } catch (\Twig_Error $e) { diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/RoutingExtensionTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/RoutingExtensionTest.php index 1c1ac645c8..87b6052f6f 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/RoutingExtensionTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/RoutingExtensionTest.php @@ -23,7 +23,7 @@ class RoutingExtensionTest extends \PHPUnit_Framework_TestCase $twig = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0)); $twig->addExtension(new RoutingExtension($this->getMock('Symfony\Component\Routing\Generator\UrlGeneratorInterface'))); - $nodes = $twig->parse($twig->tokenize($template)); + $nodes = $twig->parse($twig->tokenize(new \Twig_Source($template))); $this->assertSame($mustBeEscaped, $nodes->getNode('body')->getNode(0)->getNode('expr') instanceof \Twig_Node_Expression_Filter); } diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php index a02edc777a..0235c4da32 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php @@ -36,7 +36,7 @@ class TranslationExtensionTest extends \PHPUnit_Framework_TestCase $twig = new \Twig_Environment($loader, array('debug' => true, 'cache' => false)); $twig->addExtension(new TranslationExtension(new Translator('en', new MessageSelector()))); - echo $twig->compile($twig->parse($twig->tokenize($twig->getLoader()->getSource('index'), 'index')))."\n\n"; + echo $twig->compile($twig->parse($twig->tokenize(new \Twig_Source($twig->getLoader()->getSource('index'), 'index'))))."\n\n"; $this->assertEquals($expected, $this->getTemplate($template)->render($variables)); } diff --git a/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TwigNodeProvider.php b/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TwigNodeProvider.php index 0e401f62ea..a90b556c9e 100644 --- a/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TwigNodeProvider.php +++ b/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TwigNodeProvider.php @@ -25,7 +25,7 @@ class TwigNodeProvider new \Twig_Node_Expression_Array(array(), 0), new \Twig_Node_Expression_Array(array(), 0), null, - null + new \Twig_Source('') ); } diff --git a/src/Symfony/Bridge/Twig/Tests/TokenParser/FormThemeTokenParserTest.php b/src/Symfony/Bridge/Twig/Tests/TokenParser/FormThemeTokenParserTest.php index 2986cd1258..aa99132498 100644 --- a/src/Symfony/Bridge/Twig/Tests/TokenParser/FormThemeTokenParserTest.php +++ b/src/Symfony/Bridge/Twig/Tests/TokenParser/FormThemeTokenParserTest.php @@ -23,7 +23,7 @@ class FormThemeTokenParserTest extends \PHPUnit_Framework_TestCase { $env = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false, 'optimizations' => 0)); $env->addTokenParser(new FormThemeTokenParser()); - $stream = $env->tokenize($source); + $stream = $env->tokenize(new \Twig_Source($source)); $parser = new \Twig_Parser($env); $this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0)); diff --git a/src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php b/src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php index 7ea1a2c414..e9e65ad46f 100644 --- a/src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php +++ b/src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php @@ -64,7 +64,7 @@ class TransChoiceTokenParser extends TransTokenParser $body = $this->parser->subparse(array($this, 'decideTransChoiceFork'), true); if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) { - throw new \Twig_Error_Syntax('A message inside a transchoice tag must be a simple text.', $body->getLine(), $stream->getFilename()); + throw new \Twig_Error_Syntax('A message inside a transchoice tag must be a simple text.', $body->getLine(), $stream->getSourceContext()->getName()); } $stream->expect(\Twig_Token::BLOCK_END_TYPE); diff --git a/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php b/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php index 06472d0b42..1493cf8bcf 100644 --- a/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php +++ b/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php @@ -55,7 +55,7 @@ class TransTokenParser extends \Twig_TokenParser $stream->next(); $locale = $this->parser->getExpressionParser()->parseExpression(); } elseif (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) { - throw new \Twig_Error_Syntax('Unexpected token. Twig was looking for the "with", "from", or "into" keyword.', $stream->getCurrent()->getLine(), $stream->getFilename()); + throw new \Twig_Error_Syntax('Unexpected token. Twig was looking for the "with", "from", or "into" keyword.', $stream->getCurrent()->getLine(), $stream->getSourceContext()->getName()); } } @@ -64,7 +64,7 @@ class TransTokenParser extends \Twig_TokenParser $body = $this->parser->subparse(array($this, 'decideTransFork'), true); if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) { - throw new \Twig_Error_Syntax('A message inside a trans tag must be a simple text.', $body->getLine(), $stream->getFilename()); + throw new \Twig_Error_Syntax('A message inside a trans tag must be a simple text.', $body->getLine(), $stream->getSourceContext()->getName()); } $stream->expect(\Twig_Token::BLOCK_END_TYPE); diff --git a/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php b/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php index 2a9450c885..69ec1d9155 100644 --- a/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php +++ b/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php @@ -62,9 +62,9 @@ class TwigExtractor extends AbstractFileExtractor implements ExtractorInterface $this->extractTemplate(file_get_contents($file->getPathname()), $catalogue); } catch (\Twig_Error $e) { if ($file instanceof SplFileInfo) { - $e->setTemplateFile($file->getRelativePathname()); + $e->setTemplateName($file->getRelativePathname()); } elseif ($file instanceof \SplFileInfo) { - $e->setTemplateFile($file->getRealPath()); + $e->setTemplateName($file->getRealPath()); } throw $e; @@ -85,7 +85,7 @@ class TwigExtractor extends AbstractFileExtractor implements ExtractorInterface $visitor = $this->twig->getExtension('Symfony\Bridge\Twig\Extension\TranslationExtension')->getTranslationNodeVisitor(); $visitor->enable(); - $this->twig->parse($this->twig->tokenize($template)); + $this->twig->parse($this->twig->tokenize(new \Twig_Source($template))); foreach ($visitor->getMessages() as $message) { $catalogue->set(trim($message[0]), $this->prefix.trim($message[0]), $message[1] ?: $this->defaultDomain); diff --git a/src/Symfony/Bridge/Twig/composer.json b/src/Symfony/Bridge/Twig/composer.json index c82e7b8cf4..b83dc34c7f 100644 --- a/src/Symfony/Bridge/Twig/composer.json +++ b/src/Symfony/Bridge/Twig/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": ">=5.3.9", - "twig/twig": "~1.26|~2.0" + "twig/twig": "~1.27|~2.0" }, "require-dev": { "symfony/asset": "~2.7", diff --git a/src/Symfony/Bundle/SecurityBundle/composer.json b/src/Symfony/Bundle/SecurityBundle/composer.json index 0ca847bc1b..5c80d97691 100644 --- a/src/Symfony/Bundle/SecurityBundle/composer.json +++ b/src/Symfony/Bundle/SecurityBundle/composer.json @@ -37,7 +37,7 @@ "symfony/yaml": "~2.0,>=2.0.5", "symfony/expression-language": "~2.6", "doctrine/doctrine-bundle": "~1.2", - "twig/twig": "~1.26|~2.0", + "twig/twig": "~1.27|~2.0", "ircmaxell/password-compat": "~1.0" }, "autoload": { diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php index 52c70f3318..008f9b7e76 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php @@ -167,7 +167,7 @@ class Configuration implements ConfigurationInterface $rootNode ->fixXmlConfig('path') ->children() - ->variableNode('autoescape')->defaultValue('filename')->end() + ->variableNode('autoescape')->defaultValue('name')->end() ->scalarNode('autoescape_service')->defaultNull()->end() ->scalarNode('autoescape_service_method')->defaultNull()->end() ->scalarNode('base_template_class')->example('Twig_Template')->cannotBeEmpty()->end() diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php index cd3968034e..fcfa38a4bb 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php @@ -147,7 +147,7 @@ class TwigExtensionTest extends TestCase $this->compileContainer($container); $options = $container->getDefinition('twig')->getArgument(1); - $this->assertEquals('filename', $options['autoescape']); + $this->assertEquals('name', $options['autoescape']); } public function testGlobalsWithDifferentTypesAndValues() diff --git a/src/Symfony/Bundle/TwigBundle/Tests/TokenParser/LegacyRenderTokenParserTest.php b/src/Symfony/Bundle/TwigBundle/Tests/TokenParser/LegacyRenderTokenParserTest.php index e3d0a72a6c..b1f81ec8ee 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/TokenParser/LegacyRenderTokenParserTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/TokenParser/LegacyRenderTokenParserTest.php @@ -27,7 +27,7 @@ class LegacyRenderTokenParserTest extends TestCase { $env = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false, 'optimizations' => 0)); $env->addTokenParser(new RenderTokenParser()); - $stream = $env->tokenize($source); + $stream = $env->tokenize(new \Twig_Source($source)); $parser = new \Twig_Parser($env); $this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0)); diff --git a/src/Symfony/Bundle/TwigBundle/TwigEngine.php b/src/Symfony/Bundle/TwigBundle/TwigEngine.php index 3092fe9c5d..0d01648d57 100644 --- a/src/Symfony/Bundle/TwigBundle/TwigEngine.php +++ b/src/Symfony/Bundle/TwigBundle/TwigEngine.php @@ -54,13 +54,13 @@ class TwigEngine extends BaseEngine implements EngineInterface /** * @deprecated since version 2.7, to be removed in 3.0. - * Use the 'filename' strategy instead. + * Use the 'name' strategy instead. */ - public function guessDefaultEscapingStrategy($filename) + public function guessDefaultEscapingStrategy($name) { @trigger_error('The '.__METHOD__.' method is deprecated since version 2.7 and will be removed in 3.0. Use the Twig_FileExtensionEscapingStrategy::guess method instead.', E_USER_DEPRECATED); - return \Twig_FileExtensionEscapingStrategy::guess($filename); + return \Twig_FileExtensionEscapingStrategy::guess($name); } /** @@ -73,8 +73,8 @@ class TwigEngine extends BaseEngine implements EngineInterface } catch (\Twig_Error $e) { if ($name instanceof TemplateReference) { try { - // try to get the real file name of the template where the error occurred - $e->setTemplateFile(sprintf('%s', $this->locator->locate($this->parser->parse($e->getTemplateFile())))); + // 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())))); } catch (\Exception $e2) { } } diff --git a/src/Symfony/Bundle/TwigBundle/composer.json b/src/Symfony/Bundle/TwigBundle/composer.json index dfee0d6e80..4714ddb2e0 100644 --- a/src/Symfony/Bundle/TwigBundle/composer.json +++ b/src/Symfony/Bundle/TwigBundle/composer.json @@ -19,7 +19,7 @@ "php": ">=5.3.9", "symfony/asset": "~2.7", "symfony/twig-bridge": "~2.7", - "twig/twig": "~1.26|~2.0", + "twig/twig": "~1.27|~2.0", "symfony/http-foundation": "~2.5", "symfony/http-kernel": "~2.7" }, diff --git a/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php index 985db4b133..3a445f45bb 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php @@ -97,21 +97,24 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface break; } elseif (isset($trace[$i]['object']) && $trace[$i]['object'] instanceof \Twig_Template) { - $info = $trace[$i]['object']; - $name = $info->getTemplateName(); - $src = method_exists($info, 'getSource') ? $info->getSource() : $info->getEnvironment()->getLoader()->getSource($name); - $info = $info->getDebugInfo(); + $template = $trace[$i]['object']; + $name = $template->getTemplateName(); + $file = method_exists($template, 'getSourceContext') ? $template->getSourceContext()->getPath() : false; + $src = method_exists($template, 'getSourceContext') ? $template->getSourceContext()->getCode() : (method_exists($template, 'getSource') ? $template->getSource() : false); + $info = $template->getDebugInfo(); if (null !== $src && isset($info[$trace[$i - 1]['line']])) { - $file = false; $line = $info[$trace[$i - 1]['line']]; - $src = explode("\n", $src); - $fileExcerpt = array(); - for ($i = max($line - 3, 1), $max = min($line + 3, count($src)); $i <= $max; ++$i) { - $fileExcerpt[] = ''.$this->htmlEncode($src[$i - 1]).''; + if ($src) { + $src = explode("\n", $src); + $fileExcerpt = array(); + + for ($i = max($line - 3, 1), $max = min($line + 3, count($src)); $i <= $max; ++$i) { + $fileExcerpt[] = ''.$this->htmlEncode($src[$i - 1]).''; + } + + $fileExcerpt = '
    '.implode("\n", $fileExcerpt).'
'; } - - $fileExcerpt = '
    '.implode("\n", $fileExcerpt).'
'; } break; }