diff --git a/.travis.yml b/.travis.yml index 79d43ab1d3e59..0054e30811050 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: php +dist: precise sudo: false git: diff --git a/CHANGELOG-3.2.md b/CHANGELOG-3.2.md index 1a4d44e19981e..544ae4b071c06 100644 --- a/CHANGELOG-3.2.md +++ b/CHANGELOG-3.2.md @@ -7,6 +7,22 @@ in 3.2 minor versions. To get the diff for a specific change, go to https://github.com/symfony/symfony/commit/XXX where XXX is the change hash To get the diff between two versions, go to https://github.com/symfony/symfony/compare/v3.2.0...v3.2.1 +* 3.2.13 (2017-08-01) + + * bug #22244 [Console] Fix passing options with defaultCommand (Jakub Sacha) + * bug #23684 [Debug] Missing escape in debug output (c960657) + * bug #23654 [DI] Fix using private services in expressions (nicolas-grekas) + * bug #23662 [VarDumper] Adapt to php 7.2 changes (nicolas-grekas) + * bug #23649 [Form][TwigBridge] Don't render _method in form_rest() for a child form (fmarchalemisys) + * bug #23023 [DoctrineBridge][PropertyInfo] Added support for Doctrine Embeddables (vudaltsov) + * bug #23619 [Validator] Fix IbanValidator for ukrainian IBANs (paroe) + * bug #23586 Fix case sensitive sameSite cookie (mikefrancis) + * bug #23238 [Security] ensure the 'route' index is set before attempting to use it (gsdevme) + * bug #23330 [WebProfilerBundle] Fix full sized dump hovering in toolbar (ogizanagi) + * bug #23580 Fix login redirect when referer contains a query string (fabpot) + * bug #23558 [FrameworkBundle] fix ValidatorCacheWarmer: use serializing ArrayAdapter (dmaicher) + * bug #23574 [VarDumper] Move locale sniffing to dump() time (nicolas-grekas) + * 3.2.12 (2017-07-17) * bug #23549 [PropertyInfo] conflict for phpdocumentor/reflection-docblock 3.2 (xabbuh) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 9cf36e6beb382..8b1eec6264271 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -19,13 +19,13 @@ Symfony is the result of the work of many people who made the code better - Ryan Weaver (weaverryan) - Javier Eguiluz (javier.eguiluz) - Hugo Hamon (hhamon) - - Abdellatif Ait boudad (aitboudad) - Maxime Steinhausser (ogizanagi) + - Abdellatif Ait boudad (aitboudad) - Robin Chalas (chalas_r) - Romain Neutron (romain) - Pascal Borreli (pborreli) - - Wouter De Jong (wouterj) - Grégoire Pineau (lyrixx) + - Wouter De Jong (wouterj) - Joseph Bielawski (stloyd) - Karma Dordrak (drak) - Lukas Kahwe Smith (lsmith) @@ -35,8 +35,8 @@ Symfony is the result of the work of many people who made the code better - Benjamin Eberlei (beberlei) - Igor Wiedler (igorw) - Eriksen Costa (eriksencosta) - - Jules Pietri (heah) - Roland Franssen (ro0) + - Jules Pietri (heah) - Sarah Khalil (saro0h) - Guilhem Niot (energetick) - Jonathan Wage (jwage) @@ -93,6 +93,7 @@ Symfony is the result of the work of many people who made the code better - Maxime STEINHAUSSER - Alexander M. Turek (derrabus) - Michal Piotrowski (eventhorizon) + - Dany Maillard (maidmaid) - Issei Murasawa (issei_m) - Tim Nagel (merk) - Brice BERNARD (brikou) @@ -133,7 +134,6 @@ Symfony is the result of the work of many people who made the code better - Guilherme Blanco (guilhermeblanco) - Pablo Godel (pgodel) - Jérémie Augustin (jaugustin) - - Dany Maillard (maidmaid) - Andréia Bohner (andreia) - Rafael Dohms (rdohms) - Arnaud Kleinpeter (nanocom) @@ -141,6 +141,7 @@ Symfony is the result of the work of many people who made the code better - David Maicher (dmaicher) - Mikael Pajunen - Joel Wurtz (brouznouf) + - Jérôme Vasseur (jvasseur) - Grégoire Paris (greg0ire) - Philipp Wahala (hifi) - Vyacheslav Pavlov @@ -150,7 +151,6 @@ Symfony is the result of the work of many people who made the code better - Thomas Rabaix (rande) - Rouven Weßling (realityking) - Teoh Han Hui (teohhanhui) - - Jérôme Vasseur (jvasseur) - Clemens Tolboom - Helmer Aaviksoo - Hiromi Hishida (77web) @@ -162,6 +162,7 @@ Symfony is the result of the work of many people who made the code better - Artur Kotyrba - jeremyFreeAgent (Jérémy Romey) (jeremyfreeagent) - James Halsall (jaitsu) + - Chris Wilkinson (thewilkybarkid) - Warnar Boekkooi (boekkooi) - Dmitrii Chekaliuk (lazyhammer) - Clément JOBEILI (dator) @@ -175,7 +176,6 @@ Symfony is the result of the work of many people who made the code better - Benjamin Dulau (dbenjamin) - James Halsall (jaitsu) - Mathieu Lemoine (lemoinem) - - Chris Wilkinson (thewilkybarkid) - Andreas Hucks (meandmymonkey) - Noel Guilbert (noel) - Stepan Anchugov (kix) @@ -240,6 +240,7 @@ Symfony is the result of the work of many people who made the code better - Alif Rachmawadi - Kristen Gilden (kgilden) - Pierre-Yves LEBECQ (pylebecq) + - Jordan Samouh (jordansamouh) - Alex Pott - Jakub Kucharovic (jkucharovic) - Uwe Jäger (uwej711) @@ -250,6 +251,7 @@ Symfony is the result of the work of many people who made the code better - GordonsLondon - Jan Sorgalla (jsor) - Ray + - Nikolay Labinskiy (e-moe) - Leo Feyer - Chekote - Thomas Adam @@ -276,8 +278,8 @@ Symfony is the result of the work of many people who made the code better - Marc Weistroff (futurecat) - Christian Schmidt - Hidde Wieringa (hiddewie) + - Alessandro Chitolina - Chad Sikorra (chadsikorra) - - Jordan Samouh (jordansamouh) - Chris Smith (cs278) - Florian Klein (docteurklein) - Manuel Kiessling (manuelkiessling) @@ -296,7 +298,6 @@ Symfony is the result of the work of many people who made the code better - Victor Bocharsky (bocharsky_bw) - Jan Decavele (jandc) - Gustavo Piltcher - - Nikolay Labinskiy (e-moe) - Stepan Tanasiychuk (stfalcon) - Tiago Ribeiro (fixe) - Hidde Boomsma (hboomsma) @@ -311,6 +312,7 @@ Symfony is the result of the work of many people who made the code better - Thomas Schulz (king2500) - Dariusz Rumiński - Berny Cantos (xphere81) + - Thierry Thuon (lepiaf) - Ricard Clau (ricardclau) - Mark Challoner (markchalloner) - Gregor Harlan (gharlan) @@ -329,6 +331,7 @@ Symfony is the result of the work of many people who made the code better - Inal DJAFAR (inalgnu) - Christian Gärtner (dagardner) - Tomasz Kowalczyk (thunderer) + - Michael Babker (mbabker) - François-Xavier de Guillebon (de-gui_f) - Damien Alexandre (damienalexandre) - Felix Labrecque @@ -337,7 +340,6 @@ Symfony is the result of the work of many people who made the code better - Robbert Klarenbeek (robbertkl) - Thomas Calvet (fancyweb) - Niels Keurentjes (curry684) - - Alessandro Chitolina - JhonnyL - hossein zolfi (ocean) - Clément Gautier (clementgautier) @@ -403,6 +405,7 @@ Symfony is the result of the work of many people who made the code better - Olivier Dolbeau (odolbeau) - Jan Rosier (rosier) - Thomas Royer (cydonia7) + - Arturs Vonda - Josip Kruslin - Asmir Mustafic (goetas) - vagrant @@ -430,6 +433,7 @@ Symfony is the result of the work of many people who made the code better - David Badura (davidbadura) - Zander Baldwin - Adam Harvey + - Maxime Veber (nek-) - Alex Bakhturin - Alexander Obuhovich (aik099) - boombatower @@ -443,6 +447,7 @@ Symfony is the result of the work of many people who made the code better - Gladhon - Benoît Burnichon (bburnichon) - Sebastian Bergmann + - Miroslav Sustek - Pablo Díez (pablodip) - Kevin McBride - Sergio Santoro @@ -552,7 +557,6 @@ Symfony is the result of the work of many people who made the code better - Maxime Douailin - Jean Pasdeloup (pasdeloup) - Benjamin Cremer (bcremer) - - Thierry Thuon (lepiaf) - Javier López (loalf) - Reinier Kip - Geoffrey Brier (geoffrey-brier) @@ -574,6 +578,7 @@ Symfony is the result of the work of many people who made the code better - Alex Bogomazov (alebo) - maxime.steinhausser - Stefan Warman + - Thomas Perez (scullwm) - Tristan Maindron (tmaindron) - Wesley Lancel - Ke WANG (yktd26) @@ -582,7 +587,6 @@ Symfony is the result of the work of many people who made the code better - Sergey Kolodyazhnyy (skolodyazhnyy) - umpirski - Denis Brumann (dbrumann) - - Michael Babker (mbabker) - Quentin de Longraye (quentinus95) - Chris Heng (gigablah) - Richard Bradley @@ -592,7 +596,6 @@ Symfony is the result of the work of many people who made the code better - Michael Devery (mickadoo) - Antoine Corcy - Artur Eshenbrener - - Arturs Vonda - Sascha Grossenbacher - Szijarto Tamas - Catalin Dan @@ -622,7 +625,6 @@ Symfony is the result of the work of many people who made the code better - develop - ReenExe - Mark Sonnabaum - - Maxime Veber (nek-) - Richard Quadling - jochenvdv - Arturas Smorgun (asarturas) @@ -671,7 +673,6 @@ Symfony is the result of the work of many people who made the code better - Christian Soronellas (theunic) - Yosmany Garcia (yosmanyga) - Wouter de Wild - - Miroslav Sustek - Degory Valentine - Benoit Lévêque (benoit_leveque) - Jeroen Fiege (fieg) @@ -695,6 +696,7 @@ Symfony is the result of the work of many people who made the code better - Jan Prieser - Adrien Lucas (adrienlucas) - Zhuravlev Alexander (scif) + - Yanick Witschi (toflar) - James Michael DuPont - Tom Klingenberg - Christopher Hall (mythmakr) @@ -836,7 +838,6 @@ Symfony is the result of the work of many people who made the code better - Danilo Silva - Zachary Tong (polyfractal) - Hryhorii Hrebiniuk - - Thomas Perez (scullwm) - Dennis Fridrich (dfridrich) - hamza - dantleech @@ -865,6 +866,7 @@ Symfony is the result of the work of many people who made the code better - Goran Juric - Laurent Ghirardotti (laurentg) - Nicolas Macherey + - AKeeman (akeeman) - Lin Clark - Jeremy David (jeremy.david) - Robin Lehrmann (robinlehrmann) @@ -1106,6 +1108,7 @@ Symfony is the result of the work of many people who made the code better - Max Romanovsky (maxromanovsky) - Mathieu Morlon - Daniel Tschinder + - Alexander Schranz - Rafał Muszyński (rafmus90) - Timothy Anido (xanido) - Rick Prent @@ -1413,6 +1416,7 @@ Symfony is the result of the work of many people who made the code better - Rosio (ben-rosio) - Simon Paarlberg (blamh) - Jeroen Thora (bolle) + - Brieuc THOMAS (brieucthomas) - Masao Maeda (brtriver) - Darius Leskauskas (darles) - David Joos (djoos) @@ -1442,7 +1446,6 @@ Symfony is the result of the work of many people who made the code better - Cyrille Jouineau (tuxosaurus) - Yorkie Chadwick (yorkie76) - GuillaumeVerdon - - Yanick Witschi - Ondrej Mirtes - akimsko - Youpie diff --git a/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php b/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php index e07c7b0bc2cba..eacac5e0490a7 100644 --- a/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php +++ b/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php @@ -50,7 +50,17 @@ public function getProperties($class, array $context = array()) return; } - return array_merge($metadata->getFieldNames(), $metadata->getAssociationNames()); + $properties = array_merge($metadata->getFieldNames(), $metadata->getAssociationNames()); + + if ($metadata instanceof ClassMetadataInfo && class_exists('Doctrine\ORM\Mapping\Embedded') && $metadata->embeddedClasses) { + $properties = array_filter($properties, function ($property) { + return false === strpos($property, '.'); + }); + + $properties = array_merge($properties, array_keys($metadata->embeddedClasses)); + } + + return $properties; } /** @@ -105,6 +115,10 @@ public function getTypes($class, $property, array $context = array()) )); } + if ($metadata instanceof ClassMetadataInfo && class_exists('Doctrine\ORM\Mapping\Embedded') && isset($metadata->embeddedClasses[$property])) { + return array(new Type(Type::BUILTIN_TYPE_OBJECT, false, $metadata->embeddedClasses[$property]['class'])); + } + if ($metadata->hasField($property)) { $typeOfField = $metadata->getTypeOfField($property); $nullable = $metadata instanceof ClassMetadataInfo && $metadata->isNullable($property); diff --git a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php index 48822d5888fbc..4f5d8bbd5dc5c 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php @@ -64,6 +64,21 @@ public function testGetProperties() ); } + public function testGetPropertiesWithEmbedded() + { + if (!class_exists('Doctrine\ORM\Mapping\Embedded')) { + $this->markTestSkipped('@Embedded is not available in Doctrine ORM lower than 2.5.'); + } + + $this->assertEquals( + array( + 'id', + 'embedded', + ), + $this->extractor->getProperties('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineWithEmbedded') + ); + } + /** * @dataProvider typesProvider */ @@ -72,6 +87,27 @@ public function testExtract($property, array $type = null) $this->assertEquals($type, $this->extractor->getTypes('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineDummy', $property, array())); } + public function testExtractWithEmbedded() + { + if (!class_exists('Doctrine\ORM\Mapping\Embedded')) { + $this->markTestSkipped('@Embedded is not available in Doctrine ORM lower than 2.5.'); + } + + $expectedTypes = array(new Type( + Type::BUILTIN_TYPE_OBJECT, + false, + 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineEmbeddable' + )); + + $actualTypes = $this->extractor->getTypes( + 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineWithEmbedded', + 'embedded', + array() + ); + + $this->assertEquals($expectedTypes, $actualTypes); + } + public function typesProvider() { return array( diff --git a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineEmbeddable.php b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineEmbeddable.php new file mode 100644 index 0000000000000..a00856ed7331e --- /dev/null +++ b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineEmbeddable.php @@ -0,0 +1,28 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures; + +use Doctrine\ORM\Mapping\Column; +use Doctrine\ORM\Mapping\Embeddable; + +/** + * @Embeddable + * + * @author Udaltsov Valentin + */ +class DoctrineEmbeddable +{ + /** + * @Column(type="string") + */ + protected $field; +} diff --git a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineWithEmbedded.php b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineWithEmbedded.php new file mode 100644 index 0000000000000..a1e011338f0b0 --- /dev/null +++ b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineWithEmbedded.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures; + +use Doctrine\ORM\Mapping\Column; +use Doctrine\ORM\Mapping\Entity; +use Doctrine\ORM\Mapping\Id; +use Doctrine\ORM\Mapping\Embedded; + +/** + * @Entity + * + * @author Udaltsov Valentin + */ +class DoctrineWithEmbedded +{ + /** + * @Id + * @Column(type="smallint") + */ + public $id; + + /** + * @Embedded(class="DoctrineEmbeddable") + */ + protected $embedded; +} diff --git a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Dumper/PhpDumperTest.php b/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Dumper/PhpDumperTest.php index a191901753d24..62cc3cd38d38f 100644 --- a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Dumper/PhpDumperTest.php +++ b/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Dumper/PhpDumperTest.php @@ -12,7 +12,6 @@ namespace Symfony\Bridge\ProxyManager\Tests\LazyProxy\Dumper; use PHPUnit\Framework\TestCase; -use ProxyManager\ProxyGenerator\LazyLoading\MethodGenerator\StaticProxyConstructor; use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Dumper\PhpDumper; @@ -27,21 +26,9 @@ class PhpDumperTest extends TestCase { public function testDumpContainerWithProxyService() { - $container = new ContainerBuilder(); - - $container->register('foo', 'stdClass'); - $container->getDefinition('foo')->setLazy(true); - $container->compile(); - - $dumper = new PhpDumper($container); - - $dumper->setProxyDumper(new ProxyDumper()); - - $dumpedString = $dumper->dump(); - $this->assertStringMatchesFormatFile( __DIR__.'/../Fixtures/php/lazy_service_structure.txt', - $dumpedString, + $this->dumpLazyServiceProjectServiceContainer(), '->dump() does generate proxy lazy loading logic.' ); } @@ -51,17 +38,15 @@ public function testDumpContainerWithProxyService() */ public function testDumpContainerWithProxyServiceWillShareProxies() { - if (class_exists(StaticProxyConstructor::class)) { // detecting ProxyManager v2 - require_once __DIR__.'/../Fixtures/php/lazy_service_with_hints.php'; - } else { - require_once __DIR__.'/../Fixtures/php/lazy_service.php'; + if (!class_exists('LazyServiceProjectServiceContainer', false)) { + eval('?>'.$this->dumpLazyServiceProjectServiceContainer()); } $container = new \LazyServiceProjectServiceContainer(); - /* @var $proxy \stdClass_c1d194250ee2e2b7d2eab8b8212368a8 */ $proxy = $container->get('foo'); - $this->assertInstanceOf('stdClass_c1d194250ee2e2b7d2eab8b8212368a8', $proxy); + $this->assertInstanceOf('stdClass', $proxy); + $this->assertInstanceOf('ProxyManager\Proxy\LazyLoadingInterface', $proxy); $this->assertSame($proxy, $container->get('foo')); $this->assertFalse($proxy->isProxyInitialized()); @@ -71,4 +56,19 @@ public function testDumpContainerWithProxyServiceWillShareProxies() $this->assertTrue($proxy->isProxyInitialized()); $this->assertSame($proxy, $container->get('foo')); } + + private function dumpLazyServiceProjectServiceContainer() + { + $container = new ContainerBuilder(); + + $container->register('foo', 'stdClass'); + $container->getDefinition('foo')->setLazy(true); + $container->compile(); + + $dumper = new PhpDumper($container); + + $dumper->setProxyDumper(new ProxyDumper()); + + return $dumper->dump(array('class' => 'LazyServiceProjectServiceContainer')); + } } diff --git a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Fixtures/php/lazy_service.php b/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Fixtures/php/lazy_service.php deleted file mode 100644 index 77e04571e089c..0000000000000 --- a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Fixtures/php/lazy_service.php +++ /dev/null @@ -1,182 +0,0 @@ - 'getFooService', - ); - - /** - * Constructor. - */ - public function __construct() - { - $this->services = array(); - } - - /** - * Gets the 'foo' service. - * - * This service is shared. - * This method always returns the same instance of the service. - * - * @param bool $lazyLoad whether to try lazy-loading the service with a proxy - * - * @return stdClass A stdClass instance - */ - public function getFooService($lazyLoad = true) - { - if ($lazyLoad) { - return $this->services['foo'] = new stdClass_c1d194250ee2e2b7d2eab8b8212368a8( - function (&$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) { - $wrappedInstance = $this->getFooService(false); - - $proxy->setProxyInitializer(null); - - return true; - } - ); - } - - return new \stdClass(); - } -} - -class stdClass_c1d194250ee2e2b7d2eab8b8212368a8 extends \stdClass implements \ProxyManager\Proxy\LazyLoadingInterface, \ProxyManager\Proxy\ValueHolderInterface -{ - /** - * @var \Closure|null initializer responsible for generating the wrapped object - */ - private $valueHolder5157dd96e88c0 = null; - - /** - * @var \Closure|null initializer responsible for generating the wrapped object - */ - private $initializer5157dd96e8924 = null; - - /** - * @override constructor for lazy initialization - * - * @param \Closure|null $initializer - */ - public function __construct($initializer) - { - $this->initializer5157dd96e8924 = $initializer; - } - - /** - * @param string $name - */ - public function __get($name) - { - $this->initializer5157dd96e8924 && $this->initializer5157dd96e8924->__invoke($this->valueHolder5157dd96e88c0, $this, '__get', array('name' => $name)); - - return $this->valueHolder5157dd96e88c0->$name; - } - - /** - * @param string $name - * @param mixed $value - */ - public function __set($name, $value) - { - $this->initializer5157dd96e8924 && $this->initializer5157dd96e8924->__invoke($this->valueHolder5157dd96e88c0, $this, '__set', array('name' => $name, 'value' => $value)); - - $this->valueHolder5157dd96e88c0->$name = $value; - } - - /** - * @param string $name - * - * @return bool - */ - public function __isset($name) - { - $this->initializer5157dd96e8924 && $this->initializer5157dd96e8924->__invoke($this->valueHolder5157dd96e88c0, $this, '__isset', array('name' => $name)); - - return isset($this->valueHolder5157dd96e88c0->$name); - } - - /** - * @param string $name - */ - public function __unset($name) - { - $this->initializer5157dd96e8924 && $this->initializer5157dd96e8924->__invoke($this->valueHolder5157dd96e88c0, $this, '__unset', array('name' => $name)); - - unset($this->valueHolder5157dd96e88c0->$name); - } - - public function __clone() - { - $this->initializer5157dd96e8924 && $this->initializer5157dd96e8924->__invoke($this->valueHolder5157dd96e88c0, $this, '__clone', array()); - - $this->valueHolder5157dd96e88c0 = clone $this->valueHolder5157dd96e88c0; - } - - public function __sleep() - { - $this->initializer5157dd96e8924 && $this->initializer5157dd96e8924->__invoke($this->valueHolder5157dd96e88c0, $this, '__sleep', array()); - - return array('valueHolder5157dd96e88c0'); - } - - public function __wakeup() - { - } - - /** - * {@inheritdoc} - */ - public function setProxyInitializer(\Closure $initializer = null) - { - $this->initializer5157dd96e8924 = $initializer; - } - - /** - * {@inheritdoc} - */ - public function getProxyInitializer() - { - return $this->initializer5157dd96e8924; - } - - /** - * {@inheritdoc} - */ - public function initializeProxy() - { - return $this->initializer5157dd96e8924 && $this->initializer5157dd96e8924->__invoke($this->valueHolder5157dd96e88c0, $this, 'initializeProxy', array()); - } - - /** - * {@inheritdoc} - */ - public function isProxyInitialized() - { - return null !== $this->valueHolder5157dd96e88c0; - } - - /** - * {@inheritdoc} - */ - public function getWrappedValueHolderValue() - { - return $this->valueHolder5157dd96e88c0; - } -} diff --git a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Fixtures/php/lazy_service_structure.txt b/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Fixtures/php/lazy_service_structure.txt index 496b0241a5ba7..09729e790539a 100644 --- a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Fixtures/php/lazy_service_structure.txt +++ b/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Fixtures/php/lazy_service_structure.txt @@ -1,7 +1,7 @@ 'getFooService', - ); - - /** - * Constructor. - */ - public function __construct() - { - $this->services = array(); - } - - /** - * Gets the 'foo' service. - * - * This service is shared. - * This method always returns the same instance of the service. - * - * @param bool $lazyLoad whether to try lazy-loading the service with a proxy - * - * @return stdClass A stdClass instance - */ - public function getFooService($lazyLoad = true) - { - if ($lazyLoad) { - return $this->services['foo'] = new stdClass_c1d194250ee2e2b7d2eab8b8212368a8( - function (&$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) { - $wrappedInstance = $this->getFooService(false); - - $proxy->setProxyInitializer(null); - - return true; - } - ); - } - - return new \stdClass(); - } -} - -class stdClass_c1d194250ee2e2b7d2eab8b8212368a8 extends \stdClass implements \ProxyManager\Proxy\LazyLoadingInterface, \ProxyManager\Proxy\ValueHolderInterface -{ - /** - * @var \Closure|null initializer responsible for generating the wrapped object - */ - private $valueHolder5157dd96e88c0 = null; - - /** - * @var \Closure|null initializer responsible for generating the wrapped object - */ - private $initializer5157dd96e8924 = null; - - /** - * @override constructor for lazy initialization - * - * @param \Closure|null $initializer - */ - public function __construct($initializer) - { - $this->initializer5157dd96e8924 = $initializer; - } - - /** - * @param string $name - */ - public function __get($name) - { - $this->initializer5157dd96e8924 && $this->initializer5157dd96e8924->__invoke($this->valueHolder5157dd96e88c0, $this, '__get', array('name' => $name)); - - return $this->valueHolder5157dd96e88c0->$name; - } - - /** - * @param string $name - * @param mixed $value - */ - public function __set($name, $value) - { - $this->initializer5157dd96e8924 && $this->initializer5157dd96e8924->__invoke($this->valueHolder5157dd96e88c0, $this, '__set', array('name' => $name, 'value' => $value)); - - $this->valueHolder5157dd96e88c0->$name = $value; - } - - /** - * @param string $name - * - * @return bool - */ - public function __isset($name) - { - $this->initializer5157dd96e8924 && $this->initializer5157dd96e8924->__invoke($this->valueHolder5157dd96e88c0, $this, '__isset', array('name' => $name)); - - return isset($this->valueHolder5157dd96e88c0->$name); - } - - /** - * @param string $name - */ - public function __unset($name) - { - $this->initializer5157dd96e8924 && $this->initializer5157dd96e8924->__invoke($this->valueHolder5157dd96e88c0, $this, '__unset', array('name' => $name)); - - unset($this->valueHolder5157dd96e88c0->$name); - } - - public function __clone() - { - $this->initializer5157dd96e8924 && $this->initializer5157dd96e8924->__invoke($this->valueHolder5157dd96e88c0, $this, '__clone', array()); - - $this->valueHolder5157dd96e88c0 = clone $this->valueHolder5157dd96e88c0; - } - - public function __sleep() - { - $this->initializer5157dd96e8924 && $this->initializer5157dd96e8924->__invoke($this->valueHolder5157dd96e88c0, $this, '__sleep', array()); - - return array('valueHolder5157dd96e88c0'); - } - - public function __wakeup() - { - } - - /** - * {@inheritdoc} - */ - public function setProxyInitializer(\Closure $initializer = null) - { - $this->initializer5157dd96e8924 = $initializer; - } - - /** - * {@inheritdoc} - */ - public function getProxyInitializer() - { - return $this->initializer5157dd96e8924; - } - - /** - * {@inheritdoc} - */ - public function initializeProxy(): bool - { - return $this->initializer5157dd96e8924 && $this->initializer5157dd96e8924->__invoke($this->valueHolder5157dd96e88c0, $this, 'initializeProxy', array()); - } - - /** - * {@inheritdoc} - */ - public function isProxyInitialized(): bool - { - return null !== $this->valueHolder5157dd96e88c0; - } - - /** - * {@inheritdoc} - */ - public function getWrappedValueHolderValue() - { - return $this->valueHolder5157dd96e88c0; - } -} diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig index 82394abbda50c..aa308845e2457 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig @@ -322,7 +322,7 @@ {% endif %} {%- endfor %} - {% if not form.methodRendered %} + {% if not form.methodRendered and form.parent is null %} {%- do form.setMethodRendered() -%} {% set method = method|upper %} {%- if method in ["GET", "POST"] -%} diff --git a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AbstractPhpFileCacheWarmer.php b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AbstractPhpFileCacheWarmer.php new file mode 100644 index 0000000000000..25801a7829c91 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AbstractPhpFileCacheWarmer.php @@ -0,0 +1,92 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\CacheWarmer; + +use Psr\Cache\CacheItemPoolInterface; +use Symfony\Component\Cache\Adapter\AdapterInterface; +use Symfony\Component\Cache\Adapter\ArrayAdapter; +use Symfony\Component\Cache\Adapter\PhpArrayAdapter; +use Symfony\Component\Cache\Adapter\ProxyAdapter; +use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; + +/** + * @internal + */ +abstract class AbstractPhpFileCacheWarmer implements CacheWarmerInterface +{ + private $phpArrayFile; + private $fallbackPool; + + /** + * @param string $phpArrayFile The PHP file where metadata are cached + * @param CacheItemPoolInterface $fallbackPool The pool where runtime-discovered metadata are cached + */ + public function __construct($phpArrayFile, CacheItemPoolInterface $fallbackPool) + { + $this->phpArrayFile = $phpArrayFile; + if (!$fallbackPool instanceof AdapterInterface) { + $fallbackPool = new ProxyAdapter($fallbackPool); + } + $this->fallbackPool = $fallbackPool; + } + + /** + * {@inheritdoc} + */ + public function isOptional() + { + return true; + } + + /** + * {@inheritdoc} + */ + public function warmUp($cacheDir) + { + $arrayAdapter = new ArrayAdapter(); + + spl_autoload_register(array(PhpArrayAdapter::class, 'throwOnRequiredClass')); + try { + if (!$this->doWarmUp($cacheDir, $arrayAdapter)) { + return; + } + } finally { + spl_autoload_unregister(array(PhpArrayAdapter::class, 'throwOnRequiredClass')); + } + + // the ArrayAdapter stores the values serialized + // to avoid mutation of the data after it was written to the cache + // so here we un-serialize the values first + $values = array_map(function ($val) { return null !== $val ? unserialize($val) : null; }, $arrayAdapter->getValues()); + + $this->warmUpPhpArrayAdapter(new PhpArrayAdapter($this->phpArrayFile, $this->fallbackPool), $values); + + foreach ($values as $k => $v) { + $item = $this->fallbackPool->getItem($k); + $this->fallbackPool->saveDeferred($item->set($v)); + } + $this->fallbackPool->commit(); + } + + protected function warmUpPhpArrayAdapter(PhpArrayAdapter $phpArrayAdapter, array $values) + { + $phpArrayAdapter->warmUp($values); + } + + /** + * @param string $cacheDir + * @param ArrayAdapter $arrayAdapter + * + * @return bool false if there is nothing to warm-up + */ + abstract protected function doWarmUp($cacheDir, ArrayAdapter $arrayAdapter); +} diff --git a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AnnotationsCacheWarmer.php b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AnnotationsCacheWarmer.php index a6fb4ed095d2b..4026b53bd7740 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AnnotationsCacheWarmer.php +++ b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AnnotationsCacheWarmer.php @@ -15,12 +15,8 @@ use Doctrine\Common\Annotations\CachedReader; use Doctrine\Common\Annotations\Reader; use Psr\Cache\CacheItemPoolInterface; -use Symfony\Component\Cache\Adapter\AdapterInterface; use Symfony\Component\Cache\Adapter\ArrayAdapter; -use Symfony\Component\Cache\Adapter\PhpArrayAdapter; -use Symfony\Component\Cache\Adapter\ProxyAdapter; use Symfony\Component\Cache\DoctrineProvider; -use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; /** * Warms up annotation caches for classes found in composer's autoload class map @@ -28,11 +24,9 @@ * * @author Titouan Galopin */ -class AnnotationsCacheWarmer implements CacheWarmerInterface +class AnnotationsCacheWarmer extends AbstractPhpFileCacheWarmer { private $annotationReader; - private $phpArrayFile; - private $fallbackPool; /** * @param Reader $annotationReader @@ -41,70 +35,41 @@ class AnnotationsCacheWarmer implements CacheWarmerInterface */ public function __construct(Reader $annotationReader, $phpArrayFile, CacheItemPoolInterface $fallbackPool) { + parent::__construct($phpArrayFile, $fallbackPool); $this->annotationReader = $annotationReader; - $this->phpArrayFile = $phpArrayFile; - if (!$fallbackPool instanceof AdapterInterface) { - $fallbackPool = new ProxyAdapter($fallbackPool); - } - $this->fallbackPool = $fallbackPool; } /** * {@inheritdoc} */ - public function warmUp($cacheDir) + protected function doWarmUp($cacheDir, ArrayAdapter $arrayAdapter) { - $adapter = new PhpArrayAdapter($this->phpArrayFile, $this->fallbackPool); $annotatedClassPatterns = $cacheDir.'/annotations.map'; if (!is_file($annotatedClassPatterns)) { - $adapter->warmUp(array()); - - return; + return true; } $annotatedClasses = include $annotatedClassPatterns; - - $arrayPool = new ArrayAdapter(0, false); - $reader = new CachedReader($this->annotationReader, new DoctrineProvider($arrayPool)); - - spl_autoload_register(array($adapter, 'throwOnRequiredClass')); - try { - foreach ($annotatedClasses as $class) { - try { - $this->readAllComponents($reader, $class); - } catch (\ReflectionException $e) { - // ignore failing reflection - } catch (AnnotationException $e) { - /* - * Ignore any AnnotationException to not break the cache warming process if an Annotation is badly - * configured or could not be found / read / etc. - * - * In particular cases, an Annotation in your code can be used and defined only for a specific - * environment but is always added to the annotations.map file by some Symfony default behaviors, - * and you always end up with a not found Annotation. - */ - } + $reader = new CachedReader($this->annotationReader, new DoctrineProvider($arrayAdapter)); + + foreach ($annotatedClasses as $class) { + try { + $this->readAllComponents($reader, $class); + } catch (\ReflectionException $e) { + // ignore failing reflection + } catch (AnnotationException $e) { + /* + * Ignore any AnnotationException to not break the cache warming process if an Annotation is badly + * configured or could not be found / read / etc. + * + * In particular cases, an Annotation in your code can be used and defined only for a specific + * environment but is always added to the annotations.map file by some Symfony default behaviors, + * and you always end up with a not found Annotation. + */ } - } finally { - spl_autoload_unregister(array($adapter, 'throwOnRequiredClass')); - } - - $values = $arrayPool->getValues(); - $adapter->warmUp($values); - - foreach ($values as $k => $v) { - $item = $this->fallbackPool->getItem($k); - $this->fallbackPool->saveDeferred($item->set($v)); } - $this->fallbackPool->commit(); - } - /** - * {@inheritdoc} - */ - public function isOptional() - { return true; } diff --git a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/SerializerCacheWarmer.php b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/SerializerCacheWarmer.php index c017f51268b3d..75cc2bcf9b384 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/SerializerCacheWarmer.php +++ b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/SerializerCacheWarmer.php @@ -13,11 +13,7 @@ use Doctrine\Common\Annotations\AnnotationException; use Psr\Cache\CacheItemPoolInterface; -use Symfony\Component\Cache\Adapter\AdapterInterface; use Symfony\Component\Cache\Adapter\ArrayAdapter; -use Symfony\Component\Cache\Adapter\PhpArrayAdapter; -use Symfony\Component\Cache\Adapter\ProxyAdapter; -use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory; use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory; use Symfony\Component\Serializer\Mapping\Loader\LoaderChain; @@ -30,11 +26,9 @@ * * @author Titouan Galopin */ -class SerializerCacheWarmer implements CacheWarmerInterface +class SerializerCacheWarmer extends AbstractPhpFileCacheWarmer { private $loaders; - private $phpArrayFile; - private $fallbackPool; /** * @param LoaderInterface[] $loaders The serializer metadata loaders @@ -43,60 +37,33 @@ class SerializerCacheWarmer implements CacheWarmerInterface */ public function __construct(array $loaders, $phpArrayFile, CacheItemPoolInterface $fallbackPool) { + parent::__construct($phpArrayFile, $fallbackPool); $this->loaders = $loaders; - $this->phpArrayFile = $phpArrayFile; - if (!$fallbackPool instanceof AdapterInterface) { - $fallbackPool = new ProxyAdapter($fallbackPool); - } - $this->fallbackPool = $fallbackPool; } /** * {@inheritdoc} */ - public function warmUp($cacheDir) + protected function doWarmUp($cacheDir, ArrayAdapter $arrayAdapter) { if (!class_exists(CacheClassMetadataFactory::class) || !method_exists(XmlFileLoader::class, 'getMappedClasses') || !method_exists(YamlFileLoader::class, 'getMappedClasses')) { - return; + return false; } - $adapter = new PhpArrayAdapter($this->phpArrayFile, $this->fallbackPool); - $arrayPool = new ArrayAdapter(0, false); - - $metadataFactory = new CacheClassMetadataFactory(new ClassMetadataFactory(new LoaderChain($this->loaders)), $arrayPool); + $metadataFactory = new CacheClassMetadataFactory(new ClassMetadataFactory(new LoaderChain($this->loaders)), $arrayAdapter); - spl_autoload_register(array($adapter, 'throwOnRequiredClass')); - try { - foreach ($this->extractSupportedLoaders($this->loaders) as $loader) { - foreach ($loader->getMappedClasses() as $mappedClass) { - try { - $metadataFactory->getMetadataFor($mappedClass); - } catch (\ReflectionException $e) { - // ignore failing reflection - } catch (AnnotationException $e) { - // ignore failing annotations - } + foreach ($this->extractSupportedLoaders($this->loaders) as $loader) { + foreach ($loader->getMappedClasses() as $mappedClass) { + try { + $metadataFactory->getMetadataFor($mappedClass); + } catch (\ReflectionException $e) { + // ignore failing reflection + } catch (AnnotationException $e) { + // ignore failing annotations } } - } finally { - spl_autoload_unregister(array($adapter, 'throwOnRequiredClass')); - } - - $values = $arrayPool->getValues(); - $adapter->warmUp($values); - - foreach ($values as $k => $v) { - $item = $this->fallbackPool->getItem($k); - $this->fallbackPool->saveDeferred($item->set($v)); } - $this->fallbackPool->commit(); - } - /** - * {@inheritdoc} - */ - public function isOptional() - { return true; } diff --git a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/ValidatorCacheWarmer.php b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/ValidatorCacheWarmer.php index 81291d772fbf0..20f76cb4fdd73 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/ValidatorCacheWarmer.php +++ b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/ValidatorCacheWarmer.php @@ -13,11 +13,8 @@ use Doctrine\Common\Annotations\AnnotationException; use Psr\Cache\CacheItemPoolInterface; -use Symfony\Component\Cache\Adapter\AdapterInterface; use Symfony\Component\Cache\Adapter\ArrayAdapter; use Symfony\Component\Cache\Adapter\PhpArrayAdapter; -use Symfony\Component\Cache\Adapter\ProxyAdapter; -use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; use Symfony\Component\Validator\Mapping\Cache\Psr6Cache; use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory; use Symfony\Component\Validator\Mapping\Loader\LoaderChain; @@ -31,11 +28,9 @@ * * @author Titouan Galopin */ -class ValidatorCacheWarmer implements CacheWarmerInterface +class ValidatorCacheWarmer extends AbstractPhpFileCacheWarmer { private $validatorBuilder; - private $phpArrayFile; - private $fallbackPool; /** * @param ValidatorBuilderInterface $validatorBuilder @@ -44,64 +39,43 @@ class ValidatorCacheWarmer implements CacheWarmerInterface */ public function __construct(ValidatorBuilderInterface $validatorBuilder, $phpArrayFile, CacheItemPoolInterface $fallbackPool) { + parent::__construct($phpArrayFile, $fallbackPool); $this->validatorBuilder = $validatorBuilder; - $this->phpArrayFile = $phpArrayFile; - if (!$fallbackPool instanceof AdapterInterface) { - $fallbackPool = new ProxyAdapter($fallbackPool); - } - $this->fallbackPool = $fallbackPool; } /** * {@inheritdoc} */ - public function warmUp($cacheDir) + protected function doWarmUp($cacheDir, ArrayAdapter $arrayAdapter) { if (!method_exists($this->validatorBuilder, 'getLoaders')) { - return; + return false; } - $adapter = new PhpArrayAdapter($this->phpArrayFile, $this->fallbackPool); - $arrayPool = new ArrayAdapter(0, false); - $loaders = $this->validatorBuilder->getLoaders(); - $metadataFactory = new LazyLoadingMetadataFactory(new LoaderChain($loaders), new Psr6Cache($arrayPool)); + $metadataFactory = new LazyLoadingMetadataFactory(new LoaderChain($loaders), new Psr6Cache($arrayAdapter)); - spl_autoload_register(array($adapter, 'throwOnRequiredClass')); - try { - foreach ($this->extractSupportedLoaders($loaders) as $loader) { - foreach ($loader->getMappedClasses() as $mappedClass) { - try { - if ($metadataFactory->hasMetadataFor($mappedClass)) { - $metadataFactory->getMetadataFor($mappedClass); - } - } catch (\ReflectionException $e) { - // ignore failing reflection - } catch (AnnotationException $e) { - // ignore failing annotations + foreach ($this->extractSupportedLoaders($loaders) as $loader) { + foreach ($loader->getMappedClasses() as $mappedClass) { + try { + if ($metadataFactory->hasMetadataFor($mappedClass)) { + $metadataFactory->getMetadataFor($mappedClass); } + } catch (\ReflectionException $e) { + // ignore failing reflection + } catch (AnnotationException $e) { + // ignore failing annotations } } - } finally { - spl_autoload_unregister(array($adapter, 'throwOnRequiredClass')); } - $values = $arrayPool->getValues(); - $adapter->warmUp(array_filter($values)); - - foreach ($values as $k => $v) { - $item = $this->fallbackPool->getItem($k); - $this->fallbackPool->saveDeferred($item->set($v)); - } - $this->fallbackPool->commit(); + return true; } - /** - * {@inheritdoc} - */ - public function isOptional() + protected function warmUpPhpArrayAdapter(PhpArrayAdapter $phpArrayAdapter, array $values) { - return true; + // make sure we don't cache null values + parent::warmUpPhpArrayAdapter($phpArrayAdapter, array_filter($values)); } /** diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterDebugCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterDebugCommandTest.php index 597082485a0b6..a8ef3cd421c9c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterDebugCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterDebugCommandTest.php @@ -71,10 +71,6 @@ private function getKernel() ->will($this->returnValue($routeCollection)) ; - $loader = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Routing\DelegatingLoader') - ->disableOriginalConstructor() - ->getMock(); - $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); $container ->expects($this->once()) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterMatchCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterMatchCommandTest.php index 384bd7ca53079..fe77fa5703465 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterMatchCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterMatchCommandTest.php @@ -70,10 +70,6 @@ private function getKernel() ->will($this->returnValue($requestContext)) ; - $loader = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Routing\DelegatingLoader') - ->disableOriginalConstructor() - ->getMock(); - $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); $container ->expects($this->atLeastOnce()) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDebugCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDebugCommandTest.php index 5b40325e08eb9..a98879938d13e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDebugCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDebugCommandTest.php @@ -61,7 +61,7 @@ public function testParametersValuesAreResolved() public function testDumpUndefinedBundleOption() { $tester = $this->createCommandTester(); - $ret = $tester->execute(array('name' => 'TestBundle', 'path' => 'foo')); + $tester->execute(array('name' => 'TestBundle', 'path' => 'foo')); $this->assertContains('Unable to find configuration for "test.foo"', $tester->getDisplay()); } diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.css.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.css.twig index 862b7f43c6ec6..f07713473155c 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.css.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.css.twig @@ -369,13 +369,12 @@ 100% { background: #222; } } -.sf-toolbar-block.sf-toolbar-block-dump { - position: static; -} - .sf-toolbar-block.sf-toolbar-block-dump .sf-toolbar-info { max-width: none; - right: 0; + width: 100%; + position: fixed; + box-sizing: border-box; + left: 0; } .sf-toolbar-block-dump pre.sf-dump { diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index 3d91357778e47..1e447fa20a239 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -190,7 +190,12 @@ public function doRun(InputInterface $input, OutputInterface $output) if (!$name) { $name = $this->defaultCommand; - $input = new ArrayInput(array('command' => $this->defaultCommand)); + $this->definition->setArguments(array_merge( + $this->definition->getArguments(), + array( + 'command' => new InputArgument('command', InputArgument::OPTIONAL, $this->definition->getArgument('command')->getDescription(), $name), + ) + )); } $this->runningCommand = null; diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index 1ef77a654a2af..3f682465b329a 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -39,6 +39,7 @@ public static function setUpBeforeClass() { self::$fixturesPath = realpath(__DIR__.'/Fixtures/'); require_once self::$fixturesPath.'/FooCommand.php'; + require_once self::$fixturesPath.'/FooOptCommand.php'; require_once self::$fixturesPath.'/Foo1Command.php'; require_once self::$fixturesPath.'/Foo2Command.php'; require_once self::$fixturesPath.'/Foo3Command.php'; @@ -1168,16 +1169,31 @@ public function testSetRunCustomDefaultCommand() $application->setDefaultCommand($command->getName()); $tester = new ApplicationTester($application); - $tester->run(array()); - $this->assertEquals('interact called'.PHP_EOL.'called'.PHP_EOL, $tester->getDisplay(), 'Application runs the default set command if different from \'list\' command'); + $tester->run(array(), array('interactive' => false)); + $this->assertEquals('called'.PHP_EOL, $tester->getDisplay(), 'Application runs the default set command if different from \'list\' command'); $application = new CustomDefaultCommandApplication(); $application->setAutoExit(false); $tester = new ApplicationTester($application); - $tester->run(array()); + $tester->run(array(), array('interactive' => false)); + + $this->assertEquals('called'.PHP_EOL, $tester->getDisplay(), 'Application runs the default set command if different from \'list\' command'); + } + + public function testSetRunCustomDefaultCommandWithOption() + { + $command = new \FooOptCommand(); + + $application = new Application(); + $application->setAutoExit(false); + $application->add($command); + $application->setDefaultCommand($command->getName()); + + $tester = new ApplicationTester($application); + $tester->run(array('--fooopt' => 'opt'), array('interactive' => false)); - $this->assertEquals('interact called'.PHP_EOL.'called'.PHP_EOL, $tester->getDisplay(), 'Application runs the default set command if different from \'list\' command'); + $this->assertEquals('called'.PHP_EOL.'opt'.PHP_EOL, $tester->getDisplay(), 'Application runs the default set command if different from \'list\' command'); } public function testSetRunCustomSingleCommand() diff --git a/src/Symfony/Component/Console/Tests/Fixtures/FooOptCommand.php b/src/Symfony/Component/Console/Tests/Fixtures/FooOptCommand.php new file mode 100644 index 0000000000000..9043aa483c20f --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/FooOptCommand.php @@ -0,0 +1,36 @@ +setName('foo:bar') + ->setDescription('The foo:bar command') + ->setAliases(array('afoobar')) + ->addOption('fooopt', 'fo', InputOption::VALUE_OPTIONAL, 'fooopt description') + ; + } + + protected function interact(InputInterface $input, OutputInterface $output) + { + $output->writeln('interact called'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $this->input = $input; + $this->output = $output; + + $output->writeln('called'); + $output->writeln($this->input->getOption('fooopt')); + } +} diff --git a/src/Symfony/Component/Debug/ExceptionHandler.php b/src/Symfony/Component/Debug/ExceptionHandler.php index f2ae4b102e13d..ee247ada4f0b8 100644 --- a/src/Symfony/Component/Debug/ExceptionHandler.php +++ b/src/Symfony/Component/Debug/ExceptionHandler.php @@ -386,7 +386,7 @@ private function formatArgs(array $args) $formattedValue = str_replace("\n", '', $this->escapeHtml(var_export($item[1], true))); } - $result[] = is_int($key) ? $formattedValue : sprintf("'%s' => %s", $key, $formattedValue); + $result[] = is_int($key) ? $formattedValue : sprintf("'%s' => %s", $this->escapeHtml($key), $formattedValue); } return implode(', ', $result); diff --git a/src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php b/src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php index 717fc378e498e..68b2a0217263c 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php @@ -12,8 +12,10 @@ namespace Symfony\Component\DependencyInjection\Compiler; use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\ExpressionLanguage; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\ExpressionLanguage\Expression; /** * Run this pass before passes that need to know more about the relation of @@ -32,6 +34,7 @@ class AnalyzeServiceReferencesPass implements RepeatablePassInterface private $currentDefinition; private $repeatedPass; private $onlyConstructorArguments; + private $expressionLanguage; /** * @param bool $onlyConstructorArguments Sets this Service Reference pass to ignore method calls @@ -97,6 +100,8 @@ private function processArguments(array $arguments) foreach ($arguments as $argument) { if (is_array($argument)) { $this->processArguments($argument); + } elseif ($argument instanceof Expression) { + $this->getExpressionLanguage()->compile((string) $argument, array('this' => 'container')); } elseif ($argument instanceof Reference) { $this->graph->connect( $this->currentId, @@ -143,4 +148,27 @@ private function getDefinitionId($id) return $id; } + + private function getExpressionLanguage() + { + if (null === $this->expressionLanguage) { + $providers = $this->container->getExpressionLanguageProviders(); + $this->expressionLanguage = new ExpressionLanguage(null, $providers, function ($arg) { + if ('""' === substr_replace($arg, '', 1, -1)) { + $id = stripcslashes(substr($arg, 1, -1)); + + $this->graph->connect( + $this->currentId, + $this->currentDefinition, + $this->getDefinitionId($id), + $this->getDefinition($id) + ); + } + + return sprintf('$this->get(%s)', $arg); + }); + } + + return $this->expressionLanguage; + } } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php b/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php index 64c041e93f3a7..04e6cc67a55d9 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php @@ -26,7 +26,7 @@ trait PriorityTaggedServiceTrait * * The order of additions must be respected for services having the same priority, * and knowing that the \SplPriorityQueue class does not respect the FIFO method, - * we should not use this class. + * we should not use that class. * * @see https://bugs.php.net/bug.php?id=53710 * @see https://bugs.php.net/bug.php?id=60926 diff --git a/src/Symfony/Component/DependencyInjection/Container.php b/src/Symfony/Component/DependencyInjection/Container.php index 1ed239b939747..6e156919a1b39 100644 --- a/src/Symfony/Component/DependencyInjection/Container.php +++ b/src/Symfony/Component/DependencyInjection/Container.php @@ -56,10 +56,14 @@ class Container implements ResettableContainerInterface protected $services = array(); protected $methodMap = array(); - protected $privates = array(); protected $aliases = array(); protected $loading = array(); + /** + * @internal + */ + protected $privates = array(); + private $underscoreMap = array('_' => '', '.' => '_', '\\' => '_'); private $envCache = array(); @@ -249,9 +253,6 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE if (isset($this->privates[$id])) { @trigger_error(sprintf('Requesting the "%s" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED); } - if ('service_container' === $id) { - return $this; - } if (isset($this->aliases[$id])) { $id = $this->aliases[$id]; } @@ -260,6 +261,9 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE if (isset($this->services[$id])) { return $this->services[$id]; } + if ('service_container' === $id) { + return $this; + } if (isset($this->loading[$id])) { throw new ServiceCircularReferenceException($id, array_keys($this->loading)); @@ -322,14 +326,14 @@ public function initialized($id) { $id = strtolower($id); - if ('service_container' === $id) { - return false; - } - if (isset($this->aliases[$id])) { $id = $this->aliases[$id]; } + if ('service_container' === $id) { + return false; + } + return isset($this->services[$id]); } diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index 2b7d0b2a6a3fe..4aee93dec5037 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -267,12 +267,11 @@ private function addProxyClasses() /** * Generates the require_once statement for service includes. * - * @param string $id The service id * @param Definition $definition * * @return string */ - private function addServiceInclude($id, $definition) + private function addServiceInclude($definition) { $template = " require_once %s;\n"; $code = ''; @@ -347,9 +346,9 @@ private function addServiceInlinedDefinitions($id, $definition) $code .= $this->addNewInstance($sDefinition, '$'.$name, ' = ', $id); if (!$this->hasReference($id, $sDefinition->getMethodCalls(), true) && !$this->hasReference($id, $sDefinition->getProperties(), true)) { - $code .= $this->addServiceProperties(null, $sDefinition, $name); - $code .= $this->addServiceMethodCalls(null, $sDefinition, $name); - $code .= $this->addServiceConfigurator(null, $sDefinition, $name); + $code .= $this->addServiceProperties($sDefinition, $name); + $code .= $this->addServiceMethodCalls($sDefinition, $name); + $code .= $this->addServiceConfigurator($sDefinition, $name); } $code .= "\n"; @@ -447,13 +446,12 @@ private function isSimpleInstance($id, Definition $definition) /** * Adds method calls to a service definition. * - * @param string $id * @param Definition $definition * @param string $variableName * * @return string */ - private function addServiceMethodCalls($id, Definition $definition, $variableName = 'instance') + private function addServiceMethodCalls(Definition $definition, $variableName = 'instance') { $calls = ''; foreach ($definition->getMethodCalls() as $call) { @@ -468,7 +466,7 @@ private function addServiceMethodCalls($id, Definition $definition, $variableNam return $calls; } - private function addServiceProperties($id, Definition $definition, $variableName = 'instance') + private function addServiceProperties(Definition $definition, $variableName = 'instance') { $code = ''; foreach ($definition->getProperties() as $name => $value) { @@ -511,9 +509,9 @@ private function addServiceInlinedDefinitionsSetup($id, Definition $definition) } $name = (string) $this->definitionVariables->offsetGet($iDefinition); - $code .= $this->addServiceProperties(null, $iDefinition, $name); - $code .= $this->addServiceMethodCalls(null, $iDefinition, $name); - $code .= $this->addServiceConfigurator(null, $iDefinition, $name); + $code .= $this->addServiceProperties($iDefinition, $name); + $code .= $this->addServiceMethodCalls($iDefinition, $name); + $code .= $this->addServiceConfigurator($iDefinition, $name); } if ('' !== $code) { @@ -526,13 +524,12 @@ private function addServiceInlinedDefinitionsSetup($id, Definition $definition) /** * Adds configurator definition. * - * @param string $id * @param Definition $definition * @param string $variableName * * @return string */ - private function addServiceConfigurator($id, Definition $definition, $variableName = 'instance') + private function addServiceConfigurator(Definition $definition, $variableName = 'instance') { if (!$callable = $definition->getConfigurator()) { return ''; @@ -580,7 +577,7 @@ private function addService($id, Definition $definition) $return[] = '@throws RuntimeException always since this service is expected to be injected dynamically'; } elseif ($class = $definition->getClass()) { $class = $this->container->resolveEnvPlaceholders($class); - $return[] = sprintf('@return %s A %s instance', 0 === strpos($class, '%') ? 'object' : '\\'.ltrim($class, '\\'), ltrim($class, '\\')); + $return[] = sprintf(0 === strpos($class, '%') ? '@return object A %1$s instance' : '@return \%s', ltrim($class, '\\')); } elseif ($definition->getFactory()) { $factory = $definition->getFactory(); if (is_string($factory)) { @@ -605,40 +602,14 @@ private function addService($id, Definition $definition) $return = str_replace("\n * \n", "\n *\n", implode("\n * ", $return)); $return = $this->container->resolveEnvPlaceholders($return); - $doc = ''; - if ($definition->isShared()) { - $doc .= <<<'EOF' - - * - * This service is shared. - * This method always returns the same instance of the service. -EOF; - } - - if (!$definition->isPublic()) { - $doc .= <<<'EOF' - - * - * This service is private. - * If you want to be able to request this service from the container directly, - * make it public, otherwise you might end up with broken code. -EOF; - } - - if ($definition->isAutowired()) { - $doc .= <<isShared() ? ' shared' : ''; + $public = $definition->isPublic() ? 'public' : 'private'; + $autowired = $definition->isAutowired() ? ' autowired' : ''; if ($definition->isLazy()) { $lazyInitialization = '$lazyLoad = true'; - $lazyInitializationDoc = "\n * @param bool \$lazyLoad whether to try lazy-loading the service with a proxy\n *"; } else { $lazyInitialization = ''; - $lazyInitializationDoc = ''; } // with proxies, for 5.3.3 compatibility, the getter must be public to be accessible to the initializer @@ -648,8 +619,8 @@ private function addService($id, Definition $definition) $code = <<docStar} - * Gets the '$id' service.$doc - *$lazyInitializationDoc + * Gets the $public '$id'$shared$autowired service. + * * $return */ {$visibility} function {$methodName}($lazyInitialization) @@ -667,14 +638,14 @@ private function addService($id, Definition $definition) } $code .= - $this->addServiceInclude($id, $definition). + $this->addServiceInclude($definition). $this->addServiceLocalTempVariables($id, $definition). $this->addServiceInlinedDefinitions($id, $definition). $this->addServiceInstance($id, $definition). $this->addServiceInlinedDefinitionsSetup($id, $definition). - $this->addServiceProperties($id, $definition). - $this->addServiceMethodCalls($id, $definition). - $this->addServiceConfigurator($id, $definition). + $this->addServiceProperties($definition). + $this->addServiceMethodCalls($definition). + $this->addServiceConfigurator($definition). $this->addServiceReturn($id, $definition) ; } @@ -1482,6 +1453,10 @@ private function dumpParameter($name) */ private function getServiceCall($id, Reference $reference = null) { + while ($this->container->hasAlias($id)) { + $id = (string) $this->container->getAlias($id); + } + if ('service_container' === $id) { return '$this'; } @@ -1495,10 +1470,6 @@ private function getServiceCall($id, Reference $reference = null) return sprintf('$this->get(\'%s\', ContainerInterface::NULL_ON_INVALID_REFERENCE)', $id); } - if ($this->container->hasAlias($id)) { - $id = (string) $this->container->getAlias($id); - } - return sprintf('$this->get(\'%s\')', $id); } @@ -1597,7 +1568,15 @@ private function getExpressionLanguage() throw new RuntimeException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.'); } $providers = $this->container->getExpressionLanguageProviders(); - $this->expressionLanguage = new ExpressionLanguage(null, $providers); + $this->expressionLanguage = new ExpressionLanguage(null, $providers, function ($arg) { + $id = '""' === substr_replace($arg, '', 1, -1) ? stripcslashes(substr($arg, 1, -1)) : null; + + if (null !== $id && ($this->container->hasAlias($id) || $this->container->hasDefinition($id))) { + return $this->getServiceCall($id); + } + + return sprintf('$this->get(%s)', $arg); + }); if ($this->container->isTrackingResources()) { foreach ($providers as $provider) { diff --git a/src/Symfony/Component/DependencyInjection/ExpressionLanguage.php b/src/Symfony/Component/DependencyInjection/ExpressionLanguage.php index d80985fa670e5..051d41b84ba4b 100644 --- a/src/Symfony/Component/DependencyInjection/ExpressionLanguage.php +++ b/src/Symfony/Component/DependencyInjection/ExpressionLanguage.php @@ -25,10 +25,10 @@ class ExpressionLanguage extends BaseExpressionLanguage /** * {@inheritdoc} */ - public function __construct($cache = null, array $providers = array()) + public function __construct($cache = null, array $providers = array(), callable $serviceCompiler = null) { // prepend the default provider to let users override it easily - array_unshift($providers, new ExpressionLanguageProvider()); + array_unshift($providers, new ExpressionLanguageProvider($serviceCompiler)); parent::__construct($cache, $providers); } diff --git a/src/Symfony/Component/DependencyInjection/ExpressionLanguageProvider.php b/src/Symfony/Component/DependencyInjection/ExpressionLanguageProvider.php index ce6d69522e191..e2084aa85da6d 100644 --- a/src/Symfony/Component/DependencyInjection/ExpressionLanguageProvider.php +++ b/src/Symfony/Component/DependencyInjection/ExpressionLanguageProvider.php @@ -24,10 +24,17 @@ */ class ExpressionLanguageProvider implements ExpressionFunctionProviderInterface { + private $serviceCompiler; + + public function __construct(callable $serviceCompiler = null) + { + $this->serviceCompiler = $serviceCompiler; + } + public function getFunctions() { return array( - new ExpressionFunction('service', function ($arg) { + new ExpressionFunction('service', $this->serviceCompiler ?: function ($arg) { return sprintf('$this->get(%s)', $arg); }, function (array $variables, $value) { return $variables['container']->get($value); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php index 2ff01d120b169..eb491d9435b2d 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php @@ -122,13 +122,13 @@ public function testAddService() // without compilation $container = include self::$fixturesPath.'/containers/container9.php'; $dumper = new PhpDumper($container); - $this->assertEquals(str_replace('%path%', str_replace('\\', '\\\\', self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR), file_get_contents(self::$fixturesPath.'/php/services9.php')), $dumper->dump(), '->dump() dumps services'); + $this->assertStringEqualsFile(self::$fixturesPath.'/php/services9.php', str_replace(str_replace('\\', '\\\\', self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR), '%path%', $dumper->dump()), '->dump() dumps services'); // with compilation $container = include self::$fixturesPath.'/containers/container9.php'; $container->compile(); $dumper = new PhpDumper($container); - $this->assertEquals(str_replace('%path%', str_replace('\\', '\\\\', self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR), file_get_contents(self::$fixturesPath.'/php/services9_compiled.php')), $dumper->dump(), '->dump() dumps services'); + $this->assertStringEqualsFile(self::$fixturesPath.'/php/services9_compiled.php', str_replace(str_replace('\\', '\\\\', self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR), '%path%', $dumper->dump()), '->dump() dumps services'); $dumper = new PhpDumper($container = new ContainerBuilder()); $container->register('foo', 'FooClass')->addArgument(new \stdClass()); @@ -425,6 +425,22 @@ public function testPrivateWithIgnoreOnInvalidReference() $this->assertInstanceOf('BazClass', $container->get('bar')->getBaz()); } + public function testExpressionReferencingPrivateService() + { + $container = new ContainerBuilder(); + $container->register('private_bar', 'stdClass') + ->setPublic(false); + $container->register('private_foo', 'stdClass') + ->setPublic(false); + $container->register('public_foo', 'stdClass') + ->addArgument(new Expression('service("private_foo")')); + + $container->compile(); + $dumper = new PhpDumper($container); + + $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_private_in_expression.php', $dumper->dump()); + } + public function testDumpHandlesLiteralClassWithRootNamespace() { $container = new ContainerBuilder(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php index c300e5a4c49f0..e0a0c49542b4d 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php @@ -50,12 +50,9 @@ public function isFrozen() } /** - * Gets the 'test' service. + * Gets the public 'test' shared service. * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \stdClass A stdClass instance + * @return \stdClass */ protected function getTestService() { diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php index 5c299f55d69c1..f0c765218c8ce 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php @@ -54,12 +54,9 @@ public function isFrozen() } /** - * Gets the 'test' service. + * Gets the public 'test' shared service. * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \stdClass A stdClass instance + * @return \stdClass */ protected function getTestService() { diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services13.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services13.php index 58052966744ee..852e5a2f3c6b2 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services13.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services13.php @@ -48,12 +48,9 @@ public function isFrozen() } /** - * Gets the 'bar' service. + * Gets the public 'bar' shared service. * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \stdClass A stdClass instance + * @return \stdClass */ protected function getBarService() { diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services19.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services19.php index e89c3c8f8e22b..da8135e32b6e8 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services19.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services19.php @@ -31,12 +31,9 @@ public function __construct() } /** - * Gets the 'service_from_anonymous_factory' service. + * Gets the public 'service_from_anonymous_factory' shared service. * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \Bar\FooClass A Bar\FooClass instance + * @return \Bar\FooClass */ protected function getServiceFromAnonymousFactoryService() { @@ -44,12 +41,9 @@ protected function getServiceFromAnonymousFactoryService() } /** - * Gets the 'service_with_method_call_and_factory' service. - * - * This service is shared. - * This method always returns the same instance of the service. + * Gets the public 'service_with_method_call_and_factory' shared service. * - * @return \Bar\FooClass A Bar\FooClass instance + * @return \Bar\FooClass */ protected function getServiceWithMethodCallAndFactoryService() { diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services24.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services24.php index 00f11e925e17d..aa920e7c77bd1 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services24.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services24.php @@ -30,14 +30,9 @@ public function __construct() } /** - * Gets the 'foo' service. + * Gets the public 'foo' shared autowired service. * - * This service is shared. - * This method always returns the same instance of the service. - * - * This service is autowired. - * - * @return \Foo A Foo instance + * @return \Foo */ protected function getFooService() { diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services26.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services26.php index d834ae2865dae..84eb66deaca9f 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services26.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services26.php @@ -50,10 +50,7 @@ public function isFrozen() } /** - * Gets the 'test' service. - * - * This service is shared. - * This method always returns the same instance of the service. + * Gets the public 'test' shared service. * * @return object A %env(FOO)% instance */ diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php index 306375d1b5541..0100b8f585f50 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php @@ -63,12 +63,9 @@ public function __construct() } /** - * Gets the 'bar' service. + * Gets the public 'bar' shared service. * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \Bar\FooClass A Bar\FooClass instance + * @return \Bar\FooClass */ protected function getBarService() { @@ -82,12 +79,9 @@ protected function getBarService() } /** - * Gets the 'baz' service. - * - * This service is shared. - * This method always returns the same instance of the service. + * Gets the public 'baz' shared service. * - * @return \Baz A Baz instance + * @return \Baz */ protected function getBazService() { @@ -99,12 +93,9 @@ protected function getBazService() } /** - * Gets the 'configured_service' service. + * Gets the public 'configured_service' shared service. * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \stdClass A stdClass instance + * @return \stdClass */ protected function getConfiguredServiceService() { @@ -116,12 +107,9 @@ protected function getConfiguredServiceService() } /** - * Gets the 'configured_service_simple' service. - * - * This service is shared. - * This method always returns the same instance of the service. + * Gets the public 'configured_service_simple' shared service. * - * @return \stdClass A stdClass instance + * @return \stdClass */ protected function getConfiguredServiceSimpleService() { @@ -133,12 +121,9 @@ protected function getConfiguredServiceSimpleService() } /** - * Gets the 'decorated' service. + * Gets the public 'decorated' shared service. * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \stdClass A stdClass instance + * @return \stdClass */ protected function getDecoratedService() { @@ -146,12 +131,9 @@ protected function getDecoratedService() } /** - * Gets the 'decorator_service' service. - * - * This service is shared. - * This method always returns the same instance of the service. + * Gets the public 'decorator_service' shared service. * - * @return \stdClass A stdClass instance + * @return \stdClass */ protected function getDecoratorServiceService() { @@ -159,12 +141,9 @@ protected function getDecoratorServiceService() } /** - * Gets the 'decorator_service_with_name' service. - * - * This service is shared. - * This method always returns the same instance of the service. + * Gets the public 'decorator_service_with_name' shared service. * - * @return \stdClass A stdClass instance + * @return \stdClass */ protected function getDecoratorServiceWithNameService() { @@ -172,12 +151,9 @@ protected function getDecoratorServiceWithNameService() } /** - * Gets the 'deprecated_service' service. + * Gets the public 'deprecated_service' shared service. * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \stdClass A stdClass instance + * @return \stdClass * * @deprecated The "deprecated_service" service is deprecated. You should stop using it, as it will soon be removed. */ @@ -189,12 +165,9 @@ protected function getDeprecatedServiceService() } /** - * Gets the 'factory_service' service. - * - * This service is shared. - * This method always returns the same instance of the service. + * Gets the public 'factory_service' shared service. * - * @return \Bar A Bar instance + * @return \Bar */ protected function getFactoryServiceService() { @@ -202,12 +175,9 @@ protected function getFactoryServiceService() } /** - * Gets the 'factory_service_simple' service. + * Gets the public 'factory_service_simple' shared service. * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \Bar A Bar instance + * @return \Bar */ protected function getFactoryServiceSimpleService() { @@ -215,12 +185,9 @@ protected function getFactoryServiceSimpleService() } /** - * Gets the 'foo' service. - * - * This service is shared. - * This method always returns the same instance of the service. + * Gets the public 'foo' shared service. * - * @return \Bar\FooClass A Bar\FooClass instance + * @return \Bar\FooClass */ protected function getFooService() { @@ -239,10 +206,7 @@ protected function getFooService() } /** - * Gets the 'foo.baz' service. - * - * This service is shared. - * This method always returns the same instance of the service. + * Gets the public 'foo.baz' shared service. * * @return object A %baz_class% instance */ @@ -256,7 +220,7 @@ protected function getFoo_BazService() } /** - * Gets the 'foo_bar' service. + * Gets the public 'foo_bar' service. * * @return object A %foo_class% instance */ @@ -268,12 +232,9 @@ protected function getFooBarService() } /** - * Gets the 'foo_with_inline' service. - * - * This service is shared. - * This method always returns the same instance of the service. + * Gets the public 'foo_with_inline' shared service. * - * @return \Foo A Foo instance + * @return \Foo */ protected function getFooWithInlineService() { @@ -285,12 +246,9 @@ protected function getFooWithInlineService() } /** - * Gets the 'method_call1' service. - * - * This service is shared. - * This method always returns the same instance of the service. + * Gets the public 'method_call1' shared service. * - * @return \Bar\FooClass A Bar\FooClass instance + * @return \Bar\FooClass */ protected function getMethodCall1Service() { @@ -306,18 +264,15 @@ protected function getMethodCall1Service() if ($this->has('foobaz')) { $instance->setBar($this->get('foobaz', ContainerInterface::NULL_ON_INVALID_REFERENCE)); } - $instance->setBar(($this->get("foo")->foo() . (($this->hasParameter("foo")) ? ($this->getParameter("foo")) : ("default")))); + $instance->setBar(($this->get('foo')->foo() . (($this->hasParameter("foo")) ? ($this->getParameter("foo")) : ("default")))); return $instance; } /** - * Gets the 'new_factory_service' service. + * Gets the public 'new_factory_service' shared service. * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \FooBarBaz A FooBarBaz instance + * @return \FooBarBaz */ protected function getNewFactoryServiceService() { @@ -329,10 +284,7 @@ protected function getNewFactoryServiceService() } /** - * Gets the 'request' service. - * - * This service is shared. - * This method always returns the same instance of the service. + * Gets the public 'request' shared service. * * @throws RuntimeException always since this service is expected to be injected dynamically */ @@ -342,12 +294,9 @@ protected function getRequestService() } /** - * Gets the 'service_from_static_method' service. + * Gets the public 'service_from_static_method' shared service. * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \Bar\FooClass A Bar\FooClass instance + * @return \Bar\FooClass */ protected function getServiceFromStaticMethodService() { @@ -355,16 +304,9 @@ protected function getServiceFromStaticMethodService() } /** - * Gets the 'configurator_service' service. - * - * This service is shared. - * This method always returns the same instance of the service. + * Gets the private 'configurator_service' shared service. * - * This service is private. - * If you want to be able to request this service from the container directly, - * make it public, otherwise you might end up with broken code. - * - * @return \ConfClass A ConfClass instance + * @return \ConfClass */ protected function getConfiguratorServiceService() { @@ -376,16 +318,9 @@ protected function getConfiguratorServiceService() } /** - * Gets the 'configurator_service_simple' service. - * - * This service is shared. - * This method always returns the same instance of the service. - * - * This service is private. - * If you want to be able to request this service from the container directly, - * make it public, otherwise you might end up with broken code. + * Gets the private 'configurator_service_simple' shared service. * - * @return \ConfClass A ConfClass instance + * @return \ConfClass */ protected function getConfiguratorServiceSimpleService() { @@ -393,16 +328,9 @@ protected function getConfiguratorServiceSimpleService() } /** - * Gets the 'factory_simple' service. + * Gets the private 'factory_simple' shared service. * - * This service is shared. - * This method always returns the same instance of the service. - * - * This service is private. - * If you want to be able to request this service from the container directly, - * make it public, otherwise you might end up with broken code. - * - * @return \SimpleFactoryClass A SimpleFactoryClass instance + * @return \SimpleFactoryClass */ protected function getFactorySimpleService() { @@ -410,16 +338,9 @@ protected function getFactorySimpleService() } /** - * Gets the 'inlined' service. - * - * This service is shared. - * This method always returns the same instance of the service. + * Gets the private 'inlined' shared service. * - * This service is private. - * If you want to be able to request this service from the container directly, - * make it public, otherwise you might end up with broken code. - * - * @return \Bar A Bar instance + * @return \Bar */ protected function getInlinedService() { @@ -432,16 +353,9 @@ protected function getInlinedService() } /** - * Gets the 'new_factory' service. - * - * This service is shared. - * This method always returns the same instance of the service. - * - * This service is private. - * If you want to be able to request this service from the container directly, - * make it public, otherwise you might end up with broken code. + * Gets the private 'new_factory' shared service. * - * @return \FactoryClass A FactoryClass instance + * @return \FactoryClass */ protected function getNewFactoryService() { diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php index f8b263c2a01f3..4680b6e853b9c 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php @@ -69,12 +69,9 @@ public function isFrozen() } /** - * Gets the 'bar' service. + * Gets the public 'bar' shared service. * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \Bar\FooClass A Bar\FooClass instance + * @return \Bar\FooClass */ protected function getBarService() { @@ -88,12 +85,9 @@ protected function getBarService() } /** - * Gets the 'baz' service. - * - * This service is shared. - * This method always returns the same instance of the service. + * Gets the public 'baz' shared service. * - * @return \Baz A Baz instance + * @return \Baz */ protected function getBazService() { @@ -105,12 +99,9 @@ protected function getBazService() } /** - * Gets the 'configured_service' service. + * Gets the public 'configured_service' shared service. * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \stdClass A stdClass instance + * @return \stdClass */ protected function getConfiguredServiceService() { @@ -125,12 +116,9 @@ protected function getConfiguredServiceService() } /** - * Gets the 'configured_service_simple' service. - * - * This service is shared. - * This method always returns the same instance of the service. + * Gets the public 'configured_service_simple' shared service. * - * @return \stdClass A stdClass instance + * @return \stdClass */ protected function getConfiguredServiceSimpleService() { @@ -142,12 +130,9 @@ protected function getConfiguredServiceSimpleService() } /** - * Gets the 'decorator_service' service. + * Gets the public 'decorator_service' shared service. * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \stdClass A stdClass instance + * @return \stdClass */ protected function getDecoratorServiceService() { @@ -155,12 +140,9 @@ protected function getDecoratorServiceService() } /** - * Gets the 'decorator_service_with_name' service. - * - * This service is shared. - * This method always returns the same instance of the service. + * Gets the public 'decorator_service_with_name' shared service. * - * @return \stdClass A stdClass instance + * @return \stdClass */ protected function getDecoratorServiceWithNameService() { @@ -168,12 +150,9 @@ protected function getDecoratorServiceWithNameService() } /** - * Gets the 'deprecated_service' service. + * Gets the public 'deprecated_service' shared service. * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \stdClass A stdClass instance + * @return \stdClass * * @deprecated The "deprecated_service" service is deprecated. You should stop using it, as it will soon be removed. */ @@ -185,12 +164,9 @@ protected function getDeprecatedServiceService() } /** - * Gets the 'factory_service' service. - * - * This service is shared. - * This method always returns the same instance of the service. + * Gets the public 'factory_service' shared service. * - * @return \Bar A Bar instance + * @return \Bar */ protected function getFactoryServiceService() { @@ -198,12 +174,9 @@ protected function getFactoryServiceService() } /** - * Gets the 'factory_service_simple' service. + * Gets the public 'factory_service_simple' shared service. * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \Bar A Bar instance + * @return \Bar */ protected function getFactoryServiceSimpleService() { @@ -211,12 +184,9 @@ protected function getFactoryServiceSimpleService() } /** - * Gets the 'foo' service. - * - * This service is shared. - * This method always returns the same instance of the service. + * Gets the public 'foo' shared service. * - * @return \Bar\FooClass A Bar\FooClass instance + * @return \Bar\FooClass */ protected function getFooService() { @@ -235,12 +205,9 @@ protected function getFooService() } /** - * Gets the 'foo.baz' service. + * Gets the public 'foo.baz' shared service. * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \BazClass A BazClass instance + * @return \BazClass */ protected function getFoo_BazService() { @@ -252,9 +219,9 @@ protected function getFoo_BazService() } /** - * Gets the 'foo_bar' service. + * Gets the public 'foo_bar' service. * - * @return \Bar\FooClass A Bar\FooClass instance + * @return \Bar\FooClass */ protected function getFooBarService() { @@ -262,12 +229,9 @@ protected function getFooBarService() } /** - * Gets the 'foo_with_inline' service. - * - * This service is shared. - * This method always returns the same instance of the service. + * Gets the public 'foo_with_inline' shared service. * - * @return \Foo A Foo instance + * @return \Foo */ protected function getFooWithInlineService() { @@ -284,12 +248,9 @@ protected function getFooWithInlineService() } /** - * Gets the 'method_call1' service. + * Gets the public 'method_call1' shared service. * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \Bar\FooClass A Bar\FooClass instance + * @return \Bar\FooClass */ protected function getMethodCall1Service() { @@ -299,18 +260,15 @@ protected function getMethodCall1Service() $instance->setBar($this->get('foo')); $instance->setBar(NULL); - $instance->setBar(($this->get("foo")->foo() . (($this->hasParameter("foo")) ? ($this->getParameter("foo")) : ("default")))); + $instance->setBar(($this->get('foo')->foo() . (($this->hasParameter("foo")) ? ($this->getParameter("foo")) : ("default")))); return $instance; } /** - * Gets the 'new_factory_service' service. - * - * This service is shared. - * This method always returns the same instance of the service. + * Gets the public 'new_factory_service' shared service. * - * @return \FooBarBaz A FooBarBaz instance + * @return \FooBarBaz */ protected function getNewFactoryServiceService() { @@ -325,10 +283,7 @@ protected function getNewFactoryServiceService() } /** - * Gets the 'request' service. - * - * This service is shared. - * This method always returns the same instance of the service. + * Gets the public 'request' shared service. * * @throws RuntimeException always since this service is expected to be injected dynamically */ @@ -338,12 +293,9 @@ protected function getRequestService() } /** - * Gets the 'service_from_static_method' service. - * - * This service is shared. - * This method always returns the same instance of the service. + * Gets the public 'service_from_static_method' shared service. * - * @return \Bar\FooClass A Bar\FooClass instance + * @return \Bar\FooClass */ protected function getServiceFromStaticMethodService() { diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_private_frozen.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_private_frozen.php index f14141b8d1b2c..998418fc8da60 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_private_frozen.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_private_frozen.php @@ -53,12 +53,9 @@ public function isFrozen() } /** - * Gets the 'bar_service' service. + * Gets the public 'bar_service' shared service. * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \stdClass A stdClass instance + * @return \stdClass */ protected function getBarServiceService() { @@ -66,12 +63,9 @@ protected function getBarServiceService() } /** - * Gets the 'foo_service' service. - * - * This service is shared. - * This method always returns the same instance of the service. + * Gets the public 'foo_service' shared service. * - * @return \stdClass A stdClass instance + * @return \stdClass */ protected function getFooServiceService() { @@ -79,16 +73,9 @@ protected function getFooServiceService() } /** - * Gets the 'baz_service' service. - * - * This service is shared. - * This method always returns the same instance of the service. - * - * This service is private. - * If you want to be able to request this service from the container directly, - * make it public, otherwise you might end up with broken code. + * Gets the private 'baz_service' shared service. * - * @return \stdClass A stdClass instance + * @return \stdClass */ protected function getBazServiceService() { diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_private_in_expression.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_private_in_expression.php new file mode 100644 index 0000000000000..3ac7e1c46c7ae --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_private_in_expression.php @@ -0,0 +1,73 @@ +services = array(); + $this->methodMap = array( + 'private_foo' => 'getPrivateFooService', + 'public_foo' => 'getPublicFooService', + ); + $this->privates = array( + 'private_foo' => true, + ); + + $this->aliases = array(); + } + + /** + * {@inheritdoc} + */ + public function compile() + { + throw new LogicException('You cannot compile a dumped frozen container.'); + } + + /** + * {@inheritdoc} + */ + public function isFrozen() + { + return true; + } + + /** + * Gets the public 'public_foo' shared service. + * + * @return \stdClass + */ + protected function getPublicFooService() + { + return $this->services['public_foo'] = new \stdClass(${($_ = isset($this->services['private_foo']) ? $this->services['private_foo'] : $this->getPrivateFooService()) && false ?: '_'}); + } + + /** + * Gets the private 'private_foo' shared service. + * + * @return \stdClass + */ + protected function getPrivateFooService() + { + return $this->services['private_foo'] = new \stdClass(); + } +} diff --git a/src/Symfony/Component/Form/Extension/Core/EventListener/ResizeFormListener.php b/src/Symfony/Component/Form/Extension/Core/EventListener/ResizeFormListener.php index c3218ae4ec1cf..85d0fc4c03a39 100644 --- a/src/Symfony/Component/Form/Extension/Core/EventListener/ResizeFormListener.php +++ b/src/Symfony/Component/Form/Extension/Core/EventListener/ResizeFormListener.php @@ -15,6 +15,7 @@ use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\Exception\UnexpectedTypeException; use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\Form\FormInterface; /** * Resize a collection form element based on the data sent from the client. @@ -150,6 +151,7 @@ public function onSubmit(FormEvent $event) if ($this->deleteEmpty) { $previousData = $event->getForm()->getData(); + /** @var FormInterface $child */ foreach ($form as $name => $child) { $isNew = !isset($previousData[$name]); diff --git a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php index 25bb52f2903c6..8bd79419e65ed 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php @@ -116,6 +116,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) // Reconstruct the data as mapping from child names to values $data = array(); + /** @var FormInterface $child */ foreach ($form as $child) { $value = $child->getConfig()->getOption('value'); diff --git a/src/Symfony/Component/Form/Extension/Core/Type/TimezoneType.php b/src/Symfony/Component/Form/Extension/Core/Type/TimezoneType.php index beb83dde4f0cf..486f0a28e40ff 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/TimezoneType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/TimezoneType.php @@ -66,7 +66,7 @@ public function loadChoiceList($value = null) return $this->choiceList; } - return $this->choiceList = new ArrayChoiceList($this->getTimezones(), $value); + return $this->choiceList = new ArrayChoiceList(self::getTimezones(), $value); } /** diff --git a/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php b/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php index 93d5188d9ddc8..4cde5e2b58e05 100644 --- a/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php +++ b/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php @@ -78,6 +78,7 @@ public function validate($form, Constraint $constraint) } else { $childrenSynchronized = true; + /** @var FormInterface $child */ foreach ($form as $child) { if (!$child->isSynchronized()) { $childrenSynchronized = false; diff --git a/src/Symfony/Component/Form/Extension/Validator/ValidatorTypeGuesser.php b/src/Symfony/Component/Form/Extension/Validator/ValidatorTypeGuesser.php index c90443a9dcfad..4a5ed4d69e5da 100644 --- a/src/Symfony/Component/Form/Extension/Validator/ValidatorTypeGuesser.php +++ b/src/Symfony/Component/Form/Extension/Validator/ValidatorTypeGuesser.php @@ -151,8 +151,6 @@ public function guessTypeForConstraint(Constraint $constraint) case 'Symfony\Component\Validator\Constraints\Count': return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\CollectionType', array(), Guess::LOW_CONFIDENCE); - case 'Symfony\Component\Validator\Constraints\True': - case 'Symfony\Component\Validator\Constraints\False': case 'Symfony\Component\Validator\Constraints\IsTrue': case 'Symfony\Component\Validator\Constraints\IsFalse': return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\CheckboxType', array(), Guess::MEDIUM_CONFIDENCE); @@ -171,7 +169,6 @@ public function guessRequiredForConstraint(Constraint $constraint) switch (get_class($constraint)) { case 'Symfony\Component\Validator\Constraints\NotNull': case 'Symfony\Component\Validator\Constraints\NotBlank': - case 'Symfony\Component\Validator\Constraints\True': case 'Symfony\Component\Validator\Constraints\IsTrue': return new ValueGuess(true, Guess::HIGH_CONFIDENCE); } diff --git a/src/Symfony/Component/HttpFoundation/Cookie.php b/src/Symfony/Component/HttpFoundation/Cookie.php index 492c6fbe75193..5ea881c6e3670 100644 --- a/src/Symfony/Component/HttpFoundation/Cookie.php +++ b/src/Symfony/Component/HttpFoundation/Cookie.php @@ -77,6 +77,10 @@ public function __construct($name, $value = null, $expire = 0, $path = '/', $dom $this->httpOnly = (bool) $httpOnly; $this->raw = (bool) $raw; + if (null !== $sameSite) { + $sameSite = strtolower($sameSite); + } + if (!in_array($sameSite, array(self::SAMESITE_LAX, self::SAMESITE_STRICT, null), true)) { throw new \InvalidArgumentException('The "sameSite" parameter value is not valid.'); } diff --git a/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php b/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php index 3986a7e8f8796..ad6d3f508c1ed 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php @@ -180,4 +180,10 @@ public function testRawCookie() $this->assertTrue($cookie->isRaw()); $this->assertEquals('foo=b+a+r; path=/', (string) $cookie); } + + public function testSameSiteAttributeIsCaseInsensitive() + { + $cookie = new Cookie('foo', 'bar', 0, '/', null, false, true, false, 'Lax'); + $this->assertEquals('lax', $cookie->getSameSite()); + } } diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index d0acb4af856a4..3b3d87814b6ab 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -58,11 +58,11 @@ abstract class Kernel implements KernelInterface, TerminableInterface protected $startTime; protected $loadClassCache; - const VERSION = '3.2.12'; - const VERSION_ID = 30212; + const VERSION = '3.2.13'; + const VERSION_ID = 30213; const MAJOR_VERSION = 3; const MINOR_VERSION = 2; - const RELEASE_VERSION = 12; + const RELEASE_VERSION = 13; const EXTRA_VERSION = ''; const END_OF_MAINTENANCE = '07/2017'; diff --git a/src/Symfony/Component/PropertyInfo/PropertyInfoCacheExtractor.php b/src/Symfony/Component/PropertyInfo/PropertyInfoCacheExtractor.php index 69ade35dfeeea..269b90810e217 100644 --- a/src/Symfony/Component/PropertyInfo/PropertyInfoCacheExtractor.php +++ b/src/Symfony/Component/PropertyInfo/PropertyInfoCacheExtractor.php @@ -106,7 +106,8 @@ private function extract($method, array $arguments) return call_user_func_array(array($this->propertyInfoExtractor, $method), $arguments); } - $key = $this->escape($method.'.'.$serializedArguments); + // Calling rawurlencode escapes special characters not allowed in PSR-6's keys + $key = rawurlencode($method.'.'.$serializedArguments); if (array_key_exists($key, $this->arrayCache)) { return $this->arrayCache[$key]; @@ -124,29 +125,4 @@ private function extract($method, array $arguments) return $this->arrayCache[$key] = $value; } - - /** - * Escapes a key according to PSR-6. - * - * Replaces characters forbidden by PSR-6 and the _ char by the _ char followed by the ASCII - * code of the escaped char. - * - * @param string $key - * - * @return string - */ - private function escape($key) - { - return strtr($key, array( - '{' => '_123', - '}' => '_125', - '(' => '_40', - ')' => '_41', - '/' => '_47', - '\\' => '_92', - '@' => '_64', - ':' => '_58', - '_' => '_95', - )); - } } diff --git a/src/Symfony/Component/PropertyInfo/Tests/PropertyInfoCacheExtractorTest.php b/src/Symfony/Component/PropertyInfo/Tests/PropertyInfoCacheExtractorTest.php index 455d39fa96c22..d31a7bd51ddde 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/PropertyInfoCacheExtractorTest.php +++ b/src/Symfony/Component/PropertyInfo/Tests/PropertyInfoCacheExtractorTest.php @@ -61,29 +61,4 @@ public function testGetProperties() parent::testGetProperties(); parent::testGetProperties(); } - - /** - * @dataProvider escapeDataProvider - */ - public function testEscape($toEscape, $expected) - { - $reflectionMethod = new \ReflectionMethod($this->propertyInfo, 'escape'); - $reflectionMethod->setAccessible(true); - - $this->assertSame($expected, $reflectionMethod->invoke($this->propertyInfo, $toEscape)); - } - - public function escapeDataProvider() - { - return array( - array('foo_bar', 'foo_95bar'), - array('foo_95bar', 'foo_9595bar'), - array('foo{bar}', 'foo_123bar_125'), - array('foo(bar)', 'foo_40bar_41'), - array('foo/bar', 'foo_47bar'), - array('foo\bar', 'foo_92bar'), - array('foo@bar', 'foo_64bar'), - array('foo:bar', 'foo_58bar'), - ); - } } diff --git a/src/Symfony/Component/Security/Core/Exception/AuthenticationExpiredException.php b/src/Symfony/Component/Security/Core/Exception/AuthenticationExpiredException.php index caf2e6cc38601..7bc174f05ce82 100644 --- a/src/Symfony/Component/Security/Core/Exception/AuthenticationExpiredException.php +++ b/src/Symfony/Component/Security/Core/Exception/AuthenticationExpiredException.php @@ -12,7 +12,7 @@ namespace Symfony\Component\Security\Core\Exception; /** - * AuthenticationServiceException is thrown when an authenticated token becomes un-authentcated between requests. + * AuthenticationServiceException is thrown when an authenticated token becomes un-authenticated between requests. * * In practice, this is due to the User changing between requests (e.g. password changes), * causes the token to become un-authenticated. diff --git a/src/Symfony/Component/Security/Core/Tests/Encoder/BCryptPasswordEncoderTest.php b/src/Symfony/Component/Security/Core/Tests/Encoder/BCryptPasswordEncoderTest.php index b6b6ab8c8015d..0977d7350736a 100644 --- a/src/Symfony/Component/Security/Core/Tests/Encoder/BCryptPasswordEncoderTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Encoder/BCryptPasswordEncoderTest.php @@ -20,7 +20,6 @@ class BCryptPasswordEncoderTest extends TestCase { const PASSWORD = 'password'; - const BYTES = '0123456789abcdef'; const VALID_COST = '04'; /** diff --git a/src/Symfony/Component/Security/Http/Authentication/DefaultAuthenticationSuccessHandler.php b/src/Symfony/Component/Security/Http/Authentication/DefaultAuthenticationSuccessHandler.php index 4cb4bb68287fa..79f806404b591 100644 --- a/src/Symfony/Component/Security/Http/Authentication/DefaultAuthenticationSuccessHandler.php +++ b/src/Symfony/Component/Security/Http/Authentication/DefaultAuthenticationSuccessHandler.php @@ -122,8 +122,14 @@ protected function determineTargetUrl(Request $request) return $targetUrl; } - if ($this->options['use_referer'] && ($targetUrl = $request->headers->get('Referer')) && $targetUrl !== $this->httpUtils->generateUri($request, $this->options['login_path'])) { - return $targetUrl; + if ($this->options['use_referer']) { + $targetUrl = $request->headers->get('Referer'); + if (false !== $pos = strpos($targetUrl, '?')) { + $targetUrl = substr($targetUrl, 0, $pos); + } + if ($targetUrl !== $this->httpUtils->generateUri($request, $this->options['login_path'])) { + return $targetUrl; + } } return $this->options['default_target_path']; diff --git a/src/Symfony/Component/Security/Http/HttpUtils.php b/src/Symfony/Component/Security/Http/HttpUtils.php index ed737a2f61695..56add79926d3e 100644 --- a/src/Symfony/Component/Security/Http/HttpUtils.php +++ b/src/Symfony/Component/Security/Http/HttpUtils.php @@ -108,7 +108,7 @@ public function checkRequestPath(Request $request, $path) $parameters = $this->urlMatcher->match($request->getPathInfo()); } - return $path === $parameters['_route']; + return isset($parameters['_route']) && $path === $parameters['_route']; } catch (MethodNotAllowedException $e) { return false; } catch (ResourceNotFoundException $e) { diff --git a/src/Symfony/Component/Security/Http/Tests/Authentication/DefaultAuthenticationSuccessHandlerTest.php b/src/Symfony/Component/Security/Http/Tests/Authentication/DefaultAuthenticationSuccessHandlerTest.php index 52cd00432dc46..b42f840358e03 100644 --- a/src/Symfony/Component/Security/Http/Tests/Authentication/DefaultAuthenticationSuccessHandlerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Authentication/DefaultAuthenticationSuccessHandlerTest.php @@ -12,173 +12,92 @@ namespace Symfony\Component\Security\Http\Tests\Authentication; use PHPUnit\Framework\TestCase; -use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler; +use Symfony\Component\Security\Http\HttpUtils; class DefaultAuthenticationSuccessHandlerTest extends TestCase { - private $httpUtils = null; - - private $request = null; - - private $token = null; - - protected function setUp() + /** + * @dataProvider getRequestRedirections + */ + public function testRequestRedirections(Request $request, $options, $redirectedUrl) { - $this->httpUtils = $this->getMockBuilder('Symfony\Component\Security\Http\HttpUtils')->getMock(); - $this->request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock(); - $this->request->headers = $this->getMockBuilder('Symfony\Component\HttpFoundation\HeaderBag')->getMock(); - $this->token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock(); + $urlGenerator = $this->getMockBuilder('Symfony\Component\Routing\Generator\UrlGeneratorInterface')->getMock(); + $urlGenerator->expects($this->any())->method('generate')->will($this->returnValue('http://localhost/login')); + $httpUtils = new HttpUtils($urlGenerator); + $token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock(); + $handler = new DefaultAuthenticationSuccessHandler($httpUtils, $options); + if ($request->hasSession()) { + $handler->setProviderKey('admin'); + } + $this->assertSame('http://localhost'.$redirectedUrl, $handler->onAuthenticationSuccess($request, $token)->getTargetUrl()); } - public function testRequestIsRedirected() - { - $response = $this->expectRedirectResponse('/'); - - $handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, array()); - $result = $handler->onAuthenticationSuccess($this->request, $this->token); - - $this->assertSame($response, $result); - } - - public function testDefaultTargetPathCanBeForced() - { - $options = array( - 'always_use_default_target_path' => true, - 'default_target_path' => '/dashboard', - ); - - $response = $this->expectRedirectResponse('/dashboard'); - - $handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, $options); - $result = $handler->onAuthenticationSuccess($this->request, $this->token); - - $this->assertSame($response, $result); - } - - public function testTargetPathIsPassedWithRequest() - { - $this->request->expects($this->once()) - ->method('get')->with('_target_path') - ->will($this->returnValue('/dashboard')); - - $response = $this->expectRedirectResponse('/dashboard'); - - $handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, array()); - $result = $handler->onAuthenticationSuccess($this->request, $this->token); - - $this->assertSame($response, $result); - } - - public function testTargetPathIsPassedAsNestedParameterWithRequest() - { - $this->request->expects($this->once()) - ->method('get')->with('_target_path') - ->will($this->returnValue(array('value' => '/dashboard'))); - - $response = $this->expectRedirectResponse('/dashboard'); - - $handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, array('target_path_parameter' => '_target_path[value]')); - $result = $handler->onAuthenticationSuccess($this->request, $this->token); - - $this->assertSame($response, $result); - } - - public function testTargetPathParameterIsCustomised() - { - $options = array('target_path_parameter' => '_my_target_path'); - - $this->request->expects($this->once()) - ->method('get')->with('_my_target_path') - ->will($this->returnValue('/dashboard')); - - $response = $this->expectRedirectResponse('/dashboard'); - - $handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, $options); - $result = $handler->onAuthenticationSuccess($this->request, $this->token); - - $this->assertSame($response, $result); - } - - public function testTargetPathIsTakenFromTheSession() + public function getRequestRedirections() { $session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock(); - $session->expects($this->once()) - ->method('get')->with('_security.admin.target_path') - ->will($this->returnValue('/admin/dashboard')); - $session->expects($this->once()) - ->method('remove')->with('_security.admin.target_path'); - - $this->request->expects($this->any()) - ->method('getSession') - ->will($this->returnValue($session)); - - $response = $this->expectRedirectResponse('/admin/dashboard'); - - $handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, array()); - $handler->setProviderKey('admin'); - - $result = $handler->onAuthenticationSuccess($this->request, $this->token); - - $this->assertSame($response, $result); - } - - public function testTargetPathIsPassedAsReferer() - { - $options = array('use_referer' => true); - - $this->request->headers->expects($this->once()) - ->method('get')->with('Referer') - ->will($this->returnValue('/dashboard')); - - $response = $this->expectRedirectResponse('/dashboard'); - - $handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, $options); - $result = $handler->onAuthenticationSuccess($this->request, $this->token); - - $this->assertSame($response, $result); - } - - public function testRefererHasToBeDifferentThatLoginUrl() - { - $options = array('use_referer' => true); - - $this->request->headers->expects($this->any()) - ->method('get')->with('Referer') - ->will($this->returnValue('/login')); - - $this->httpUtils->expects($this->once()) - ->method('generateUri')->with($this->request, '/login') - ->will($this->returnValue('/login')); - - $response = $this->expectRedirectResponse('/'); - - $handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, $options); - $result = $handler->onAuthenticationSuccess($this->request, $this->token); - - $this->assertSame($response, $result); - } - - public function testRefererTargetPathIsIgnoredByDefault() - { - $this->request->headers->expects($this->never())->method('get'); - - $response = $this->expectRedirectResponse('/'); - - $handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, array()); - $result = $handler->onAuthenticationSuccess($this->request, $this->token); - - $this->assertSame($response, $result); - } - - private function expectRedirectResponse($path) - { - $response = new Response(); - $this->httpUtils->expects($this->once()) - ->method('createRedirectResponse') - ->with($this->request, $path) - ->will($this->returnValue($response)); - - return $response; + $session->expects($this->once())->method('get')->with('_security.admin.target_path')->will($this->returnValue('/admin/dashboard')); + $session->expects($this->once())->method('remove')->with('_security.admin.target_path'); + $requestWithSession = Request::create('/'); + $requestWithSession->setSession($session); + + return array( + 'default' => array( + Request::create('/'), + array(), + '/', + ), + 'forced target path' => array( + Request::create('/'), + array('always_use_default_target_path' => true, 'default_target_path' => '/dashboard'), + '/dashboard', + ), + 'target path as query string' => array( + Request::create('/?_target_path=/dashboard'), + array(), + '/dashboard', + ), + 'target path name as query string is customized' => array( + Request::create('/?_my_target_path=/dashboard'), + array('target_path_parameter' => '_my_target_path'), + '/dashboard', + ), + 'target path name as query string is customized and nested' => array( + Request::create('/?_target_path[value]=/dashboard'), + array('target_path_parameter' => '_target_path[value]'), + '/dashboard', + ), + 'target path in session' => array( + $requestWithSession, + array(), + '/admin/dashboard', + ), + 'target path as referer' => array( + Request::create('/', 'GET', array(), array(), array(), array('HTTP_REFERER' => 'http://localhost/dashboard')), + array('use_referer' => true), + '/dashboard', + ), + 'target path as referer is ignored if not configured' => array( + Request::create('/', 'GET', array(), array(), array(), array('HTTP_REFERER' => 'http://localhost/dashboard')), + array(), + '/', + ), + 'target path should be different than login URL' => array( + Request::create('/', 'GET', array(), array(), array(), array('HTTP_REFERER' => 'http://localhost/login')), + array('use_referer' => true, 'login_path' => '/login'), + '/', + ), + 'target path should be different than login URL (query string does not matter)' => array( + Request::create('/', 'GET', array(), array(), array(), array('HTTP_REFERER' => 'http://localhost/login?t=1&p=2')), + array('use_referer' => true, 'login_path' => '/login'), + '/', + ), + 'target path should be different than login URL (login_path as a route)' => array( + Request::create('/', 'GET', array(), array(), array(), array('HTTP_REFERER' => 'http://localhost/login?t=1&p=2')), + array('use_referer' => true, 'login_path' => 'login_route'), + '/', + ), + ); } } diff --git a/src/Symfony/Component/Security/Http/Tests/HttpUtilsTest.php b/src/Symfony/Component/Security/Http/Tests/HttpUtilsTest.php index 3d0e63b6fe1b9..b508012665e87 100644 --- a/src/Symfony/Component/Security/Http/Tests/HttpUtilsTest.php +++ b/src/Symfony/Component/Security/Http/Tests/HttpUtilsTest.php @@ -221,6 +221,19 @@ public function testCheckRequestPathWithUrlMatcherLoadingException() $utils->checkRequestPath($this->getRequest(), 'foobar'); } + public function testCheckPathWithoutRouteParam() + { + $urlMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\UrlMatcherInterface')->getMock(); + $urlMatcher + ->expects($this->any()) + ->method('match') + ->willReturn(array('_controller' => 'PathController')) + ; + + $utils = new HttpUtils(null, $urlMatcher); + $this->assertFalse($utils->checkRequestPath($this->getRequest(), 'path/index.html')); + } + /** * @expectedException \InvalidArgumentException * @expectedExceptionMessage Matcher must either implement UrlMatcherInterface or RequestMatcherInterface diff --git a/src/Symfony/Component/Validator/Constraints/IbanValidator.php b/src/Symfony/Component/Validator/Constraints/IbanValidator.php index 541c7161bccd0..e31ea61a85c96 100644 --- a/src/Symfony/Component/Validator/Constraints/IbanValidator.php +++ b/src/Symfony/Component/Validator/Constraints/IbanValidator.php @@ -33,7 +33,7 @@ class IbanValidator extends ConstraintValidator * a BBAN (Basic Bank Account Number) which has a fixed length per country and, * included within it, a bank identifier with a fixed position and a fixed length per country * - * @see http://www.swift.com/dsp/resources/documents/IBAN_Registry.pdf + * @see https://www.swift.com/sites/default/files/resources/iban_registry.pdf * * @var array */ @@ -129,7 +129,7 @@ class IbanValidator extends ConstraintValidator 'TL' => 'TL\d{2}\d{3}\d{14}\d{2}', // Timor-Leste 'TN' => 'TN59\d{2}\d{3}\d{13}\d{2}', // Tunisia 'TR' => 'TR\d{2}\d{5}[\dA-Z]{1}[\dA-Z]{16}', // Turkey - 'UA' => 'UA\d{2}[A-Z]{6}[\dA-Z]{19}', // Ukraine + 'UA' => 'UA\d{2}\d{6}[\dA-Z]{19}', // Ukraine 'VG' => 'VG\d{2}[A-Z]{4}\d{16}', // Virgin Islands, British 'WF' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // Wallis and Futuna Islands 'XK' => 'XK\d{2}\d{4}\d{10}\d{2}', // Republic of Kosovo diff --git a/src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php index b9ad5af1db4a1..74c37cd924d4c 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php @@ -113,7 +113,7 @@ public function getValidIbans() //Extended country list //http://www.nordea.com/Our+services/International+products+and+services/Cash+Management/IBAN+countries/908462.html - // http://www.swift.com/dsp/resources/documents/IBAN_Registry.pdf + // https://www.swift.com/sites/default/files/resources/iban_registry.pdf array('AO06000600000100037131174'), //Angola array('AZ21NABZ00000000137010001944'), //Azerbaijan array('BH29BMAG1299123456BH00'), //Bahrain @@ -151,6 +151,7 @@ public function getValidIbans() array('TL380080012345678910157'), //Timor-Leste array('TN5914207207100707129648'), //Tunisia array('TR330006100519786457841326'), //Turkey + array('UA213223130000026007233566001'), //Ukraine array('AE260211000000230064016'), //United Arab Emirates ); } @@ -263,6 +264,7 @@ public function getIbansWithInvalidFormat() array('TL3800800123456789101571'), //Timor-Leste array('TN59142072071007071296481'), //Tunisia array('TR3300061005197864578413261'), //Turkey + array('UA21AAAA1300000260072335660012'), //Ukraine array('AE2602110000002300640161'), //United Arab Emirates ); } @@ -372,6 +374,7 @@ public function getIbansWithValidFormatButIncorrectChecksum() array('TL380080012345678910158'), //Timor-Leste array('TN5914207207100707129649'), //Tunisia array('TR330006100519786457841327'), //Turkey + array('UA213223130000026007233566002'), //Ukraine array('AE260211000000230064017'), //United Arab Emirates ); } diff --git a/src/Symfony/Component/VarDumper/Caster/Caster.php b/src/Symfony/Component/VarDumper/Caster/Caster.php index 5749e0762a684..7c7fe00ece49d 100644 --- a/src/Symfony/Component/VarDumper/Caster/Caster.php +++ b/src/Symfony/Component/VarDumper/Caster/Caster.php @@ -60,7 +60,7 @@ public static function castObject($obj, \ReflectionClass $reflector) $combine = false; $p = array_keys($a); foreach ($p as $i => $k) { - if (isset($k[0]) && "\0" !== $k[0] && !$reflector->hasProperty($k)) { + if (isset($k[0]) ? "\0" !== $k[0] && !$reflector->hasProperty($k) : \PHP_VERSION_ID >= 70200) { $combine = true; $p[$i] = self::PREFIX_DYNAMIC.$k; } elseif (isset($k[16]) && "\0" === $k[16] && 0 === strpos($k, "\0class@anonymous\0")) { diff --git a/src/Symfony/Component/VarDumper/Dumper/AbstractDumper.php b/src/Symfony/Component/VarDumper/Dumper/AbstractDumper.php index 9cc0979b7fc75..12f835b1ffac6 100644 --- a/src/Symfony/Component/VarDumper/Dumper/AbstractDumper.php +++ b/src/Symfony/Component/VarDumper/Dumper/AbstractDumper.php @@ -44,8 +44,8 @@ public function __construct($output = null, $charset = null, $flags = 0) { $this->flags = (int) $flags; $this->setCharset($charset ?: ini_get('php.output_encoding') ?: ini_get('default_charset') ?: 'UTF-8'); - $this->decimalPoint = (string) 0.5; - $this->decimalPoint = $this->decimalPoint[1]; + $this->decimalPoint = localeconv(); + $this->decimalPoint = $this->decimalPoint['decimal_point']; $this->setOutput($output ?: static::$defaultOutput); if (!$output && is_string(static::$defaultOutput)) { static::$defaultOutput = $this->outputStream; @@ -121,6 +121,9 @@ public function setIndentPad($pad) */ public function dump(Data $data, $output = null) { + $this->decimalPoint = localeconv(); + $this->decimalPoint = $this->decimalPoint['decimal_point']; + if ($returnDump = true === $output) { $output = fopen('php://memory', 'r+b'); } diff --git a/src/Symfony/Component/VarDumper/Tests/CliDumperTest.php b/src/Symfony/Component/VarDumper/Tests/CliDumperTest.php index feaf85da24fd2..1e0809c1fbdba 100644 --- a/src/Symfony/Component/VarDumper/Tests/CliDumperTest.php +++ b/src/Symfony/Component/VarDumper/Tests/CliDumperTest.php @@ -139,8 +139,22 @@ public function testJsonCast() $var[] = &$v; $var[''] = 2; - $this->assertDumpMatchesFormat( - <<<'EOTXT' + if (\PHP_VERSION_ID >= 70200) { + $this->assertDumpMatchesFormat( + <<<'EOTXT' +array:4 [ + 0 => {} + 1 => &1 null + 2 => &1 null + "" => 2 +] +EOTXT + , + $var + ); + } else { + $this->assertDumpMatchesFormat( + <<<'EOTXT' array:4 [ "0" => {} "1" => &1 null @@ -148,9 +162,10 @@ public function testJsonCast() "" => 2 ] EOTXT - , - $var - ); + , + $var + ); + } } public function testObjectCast() @@ -158,16 +173,28 @@ public function testObjectCast() $var = (object) array(1 => 1); $var->{1} = 2; - $this->assertDumpMatchesFormat( - <<<'EOTXT' + if (\PHP_VERSION_ID >= 70200) { + $this->assertDumpMatchesFormat( + <<<'EOTXT' +{ + +"1": 2 +} +EOTXT + , + $var + ); + } else { + $this->assertDumpMatchesFormat( + <<<'EOTXT' { +1: 1 +"1": 2 } EOTXT - , - $var - ); + , + $var + ); + } } public function testClosedResource() diff --git a/src/Symfony/Component/VarDumper/Tests/VarClonerTest.php b/src/Symfony/Component/VarDumper/Tests/VarClonerTest.php index 273be61121bce..2181905e4a304 100644 --- a/src/Symfony/Component/VarDumper/Tests/VarClonerTest.php +++ b/src/Symfony/Component/VarDumper/Tests/VarClonerTest.php @@ -233,7 +233,7 @@ public function testJsonCast() EOTXT; ob_start(); var_dump($clone); - $this->assertStringMatchesFormat($expected, ob_get_clean()); + $this->assertStringMatchesFormat(\PHP_VERSION_ID >= 70200 ? str_replace('"1"', '1', $expected) : $expected, ob_get_clean()); } public function testCaster()