From 84f5de902d0dedfa94f70a1e65124f2bbdd6400c Mon Sep 17 00:00:00 2001 From: Yonel Ceruto Date: Sun, 28 May 2017 19:55:48 -0400 Subject: [PATCH 1/4] mix attr options between type-guess options and user options --- src/Symfony/Component/Form/FormFactory.php | 8 +++++++- src/Symfony/Component/Form/Tests/FormFactoryTest.php | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Form/FormFactory.php b/src/Symfony/Component/Form/FormFactory.php index ca228ba31d..34e3666dbd 100644 --- a/src/Symfony/Component/Form/FormFactory.php +++ b/src/Symfony/Component/Form/FormFactory.php @@ -126,7 +126,13 @@ class FormFactory implements FormFactoryInterface // user options may override guessed options if ($typeGuess) { - $options = array_merge($typeGuess->getOptions(), $options); + $attrs = array(); + $typeGuessOptions = $typeGuess->getOptions(); + if (isset($typeGuessOptions['attr']) && isset($options['attr'])) { + $attrs = array('attr' => array_merge($typeGuessOptions['attr'], $options['attr'])); + } + + $options = array_merge($typeGuessOptions, $options, $attrs); } return $this->createNamedBuilder($property, $type, $data, $options); diff --git a/src/Symfony/Component/Form/Tests/FormFactoryTest.php b/src/Symfony/Component/Form/Tests/FormFactoryTest.php index 4185a4a002..2fcb33bc3e 100644 --- a/src/Symfony/Component/Form/Tests/FormFactoryTest.php +++ b/src/Symfony/Component/Form/Tests/FormFactoryTest.php @@ -450,7 +450,7 @@ class FormFactoryTest extends TestCase ->with('Application\Author', 'firstName') ->will($this->returnValue(new TypeGuess( 'text', - array('attr' => array('maxlength' => 10)), + array('attr' => array('class' => 'foo', 'maxlength' => 10)), Guess::MEDIUM_CONFIDENCE ))); @@ -458,7 +458,7 @@ class FormFactoryTest extends TestCase $factory->expects($this->once()) ->method('createNamedBuilder') - ->with('firstName', 'text', null, array('attr' => array('maxlength' => 11))) + ->with('firstName', 'text', null, array('attr' => array('class' => 'foo', 'maxlength' => 11))) ->will($this->returnValue('builderInstance')); $this->builder = $factory->createBuilderForProperty( From 6dbdb1b750509264dd8061231f2491cb9ad7cd9a Mon Sep 17 00:00:00 2001 From: Oleg Voronkovich Date: Tue, 30 May 2017 20:42:15 +0300 Subject: [PATCH 2/4] [DependencyInjection] Use more clear message when unused environment variables detected --- .../Component/DependencyInjection/Dumper/PhpDumper.php | 2 +- .../DependencyInjection/Exception/EnvParameterException.php | 4 ++-- .../DependencyInjection/Tests/Dumper/PhpDumperTest.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index 4431418d85..dd514962ea 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -166,7 +166,7 @@ class PhpDumper extends Dumper } } if ($unusedEnvs) { - throw new EnvParameterException($unusedEnvs); + throw new EnvParameterException($unusedEnvs, null, 'Environment variables "%s" are never used. Please, check your container\'s configuration.'); } return $code; diff --git a/src/Symfony/Component/DependencyInjection/Exception/EnvParameterException.php b/src/Symfony/Component/DependencyInjection/Exception/EnvParameterException.php index 44dbab45b6..3839a4633b 100644 --- a/src/Symfony/Component/DependencyInjection/Exception/EnvParameterException.php +++ b/src/Symfony/Component/DependencyInjection/Exception/EnvParameterException.php @@ -18,8 +18,8 @@ namespace Symfony\Component\DependencyInjection\Exception; */ class EnvParameterException extends InvalidArgumentException { - public function __construct(array $usedEnvs, \Exception $previous = null) + public function __construct(array $envs, \Exception $previous = null, $message = 'Incompatible use of dynamic environment variables "%s" found in parameters.') { - parent::__construct(sprintf('Incompatible use of dynamic environment variables "%s" found in parameters.', implode('", "', $usedEnvs)), 0, $previous); + parent::__construct(sprintf($message, implode('", "', $envs)), 0, $previous); } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php index 2ad701aa6d..ee81219ef0 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php @@ -302,7 +302,7 @@ class PhpDumperTest extends TestCase /** * @expectedException \Symfony\Component\DependencyInjection\Exception\EnvParameterException - * @expectedExceptionMessage Incompatible use of dynamic environment variables "FOO" found in parameters. + * @expectedExceptionMessage Environment variables "FOO" are never used. Please, check your container's configuration. */ public function testUnusedEnvParameter() { From 405f64bb0143516475d087d0ae23c7f2fcd9c76f Mon Sep 17 00:00:00 2001 From: Martin Kirilov Date: Mon, 5 Jun 2017 03:15:00 +0300 Subject: [PATCH 3/4] [Cache] MemcachedAdapter not working with TagAwareAdapter It seems that when MemcachedAdapter is used with TagAwareAdapter, it fails to fetch items, even though I thoroughly tested fetching items with the exact same keys under the same namespace. Turns out the issue lies in `const TAGS_PREFIX = "\0tags\0";` for unknown to me reasons. Hardcoding that to '__tags__' in my project did the trick and I've been using it for a couple of days now and it seems fine. The reason I had to completely copy/paste this file in my local project is self:: instead of static:: usage. I am not sure whether that is a mistake or is done on purpose, but in order to have this work for me I need to be able to override that constant. Going with static:: seems like a good solution to me, then I can set whatever prefix I need for the tags. --- src/Symfony/Component/Cache/Adapter/AbstractAdapter.php | 3 +++ src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Cache/Adapter/AbstractAdapter.php b/src/Symfony/Component/Cache/Adapter/AbstractAdapter.php index 4a788963ea..b5f6a61b56 100644 --- a/src/Symfony/Component/Cache/Adapter/AbstractAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/AbstractAdapter.php @@ -426,6 +426,9 @@ abstract class AbstractAdapter implements AdapterInterface, LoggerAwareInterface try { foreach ($items as $id => $value) { + if (!isset($keys[$id])) { + $id = key($keys); + } $key = $keys[$id]; unset($keys[$id]); yield $key => $f($key, $value, true); diff --git a/src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php b/src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php index b8c4a08021..03ed203bec 100644 --- a/src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php @@ -261,7 +261,7 @@ class TagAwareAdapter implements TagAwareAdapterInterface foreach ($items as $key => $item) { if (!$tagKeys) { - yield $key => isset($invalidKeys[self::TAGS_PREFIX.$key]) ? $f($key, null, $item) : $item; + yield $key => isset($invalidKeys[static::TAGS_PREFIX.$key]) ? $f($key, null, $item) : $item; continue; } if (!isset($tagKeys[$key])) { @@ -287,7 +287,7 @@ class TagAwareAdapter implements TagAwareAdapterInterface $itemTags = $tagVersions = $tagKeys = null; foreach ($bufferedItems as $key => $item) { - yield $key => isset($invalidKeys[self::TAGS_PREFIX.$key]) ? $f($key, null, $item) : $item; + yield $key => isset($invalidKeys[static::TAGS_PREFIX.$key]) ? $f($key, null, $item) : $item; } $bufferedItems = null; } From a1cdc2d46e894d123c527bf204f18d4675163335 Mon Sep 17 00:00:00 2001 From: Maxime Steinhausser Date: Mon, 5 Jun 2017 22:05:32 +0200 Subject: [PATCH 4/4] [TwigBridge] Fix namespaced classes --- .../NodeVisitor/TranslationDefaultDomainNodeVisitor.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bridge/Twig/NodeVisitor/TranslationDefaultDomainNodeVisitor.php b/src/Symfony/Bridge/Twig/NodeVisitor/TranslationDefaultDomainNodeVisitor.php index c69ca843e8..b3c89d18eb 100644 --- a/src/Symfony/Bridge/Twig/NodeVisitor/TranslationDefaultDomainNodeVisitor.php +++ b/src/Symfony/Bridge/Twig/NodeVisitor/TranslationDefaultDomainNodeVisitor.php @@ -14,6 +14,7 @@ namespace Symfony\Bridge\Twig\NodeVisitor; use Symfony\Bridge\Twig\Node\TransNode; use Symfony\Bridge\Twig\Node\TransDefaultDomainNode; use Twig\Environment; +use Twig\Node\BlockNode; use Twig\Node\Expression\ArrayExpression; use Twig\Node\Expression\AssignNameExpression; use Twig\Node\Expression\ConstantExpression; @@ -21,6 +22,7 @@ use Twig\Node\Expression\FilterExpression; use Twig\Node\Expression\NameExpression; use Twig\Node\ModuleNode; use Twig\Node\Node; +use Twig\Node\SetNode; use Twig\NodeVisitor\AbstractNodeVisitor; /** @@ -48,7 +50,7 @@ class TranslationDefaultDomainNodeVisitor extends AbstractNodeVisitor */ protected function doEnterNode(Node $node, Environment $env) { - if ($node instanceof Node_Block || $node instanceof ModuleNode) { + if ($node instanceof BlockNode || $node instanceof ModuleNode) { $this->scope = $this->scope->enter(); } @@ -62,7 +64,7 @@ class TranslationDefaultDomainNodeVisitor extends AbstractNodeVisitor $name = new AssignNameExpression($var, $node->getTemplateLine()); $this->scope->set('domain', new NameExpression($var, $node->getTemplateLine())); - return new Node_Set(false, new Node(array($name)), new Node(array($node->getNode('expr'))), $node->getTemplateLine()); + return new SetNode(false, new Node(array($name)), new Node(array($node->getNode('expr'))), $node->getTemplateLine()); } } @@ -104,7 +106,7 @@ class TranslationDefaultDomainNodeVisitor extends AbstractNodeVisitor return false; } - if ($node instanceof Node_Block || $node instanceof ModuleNode) { + if ($node instanceof BlockNode || $node instanceof ModuleNode) { $this->scope = $this->scope->leave(); }