From e7436af7a6f8915b6a1562255c3ca1516beeebfa Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 29 May 2017 12:04:03 -0700 Subject: [PATCH 01/57] updated CHANGELOG for 2.7.28 --- CHANGELOG-2.7.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CHANGELOG-2.7.md b/CHANGELOG-2.7.md index 1d1f0984f1988..fb402c9aaf2ca 100644 --- a/CHANGELOG-2.7.md +++ b/CHANGELOG-2.7.md @@ -7,6 +7,20 @@ in 2.7 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/v2.7.0...v2.7.1 +* 2.7.28 (2017-05-29) + + * bug #22847 [Console] ChoiceQuestion must have choices (ro0NL) + * bug #22900 [FrameworkBundle][Console] Fix the override of a command registered by the kernel (aaa2000) + * bug #22910 [Filesystem] improve error handling in lock() (xabbuh) + * bug #22718 [Console] Fixed different behaviour of key and value user inputs in multiple choice question (borNfreee) + * bug #22901 Fix missing abstract key in XmlDumper (weaverryan) + * bug #22817 [PhpUnitBridge] optional error handler arguments (xabbuh) + * bug #22647 [VarDumper] Fix dumping of non-nested stubs (nicolas-grekas) + * bug #22584 [Security] Avoid unnecessary route lookup for empty logout path (ro0NL) + * bug #22690 [Console] Fix errors not rethrown even if not handled by console.error listeners (chalasr) + * bug #22669 [FrameworkBundle] AbstractConfigCommand: do not try registering bundles twice (ogizanagi) + * bug #22676 [FrameworkBundle] Adding the extension XML (flug) + * 2.7.27 (2017-05-01) * bug #22528 [Asset] Starting slash should indicate no basePath wanted (weaverryan) From 1d51bbd3849b9bd645016f6bde37c50da263bfe5 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 29 May 2017 12:04:10 -0700 Subject: [PATCH 02/57] update CONTRIBUTORS for 2.7.28 --- CONTRIBUTORS.md | 51 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 9fe1d4c7e9d50..66212cf3bf4c4 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -24,20 +24,20 @@ Symfony is the result of the work of many people who made the code better - Wouter De Jong (wouterj) - Romain Neutron (romain) - Grégoire Pineau (lyrixx) + - Robin Chalas (chalas_r) - Joseph Bielawski (stloyd) + - Maxime Steinhausser (ogizanagi) - Karma Dordrak (drak) - - Robin Chalas (chalas_r) - Lukas Kahwe Smith (lsmith) - Martin Hasoň (hason) - - Maxime Steinhausser (ogizanagi) - Jeremy Mikola (jmikola) - Jean-François Simon (jfsimon) - Benjamin Eberlei (beberlei) - Igor Wiedler (igorw) - Eriksen Costa (eriksencosta) - Jules Pietri (heah) - - Sarah Khalil (saro0h) - Roland Franssen (ro0) + - Sarah Khalil (saro0h) - Jonathan Wage (jwage) - Guilhem Niot (energetick) - Diego Saint Esteben (dosten) @@ -49,10 +49,10 @@ Symfony is the result of the work of many people who made the code better - Alexander Mols (asm89) - Bulat Shakirzyanov (avalanche123) - Peter Rehm (rpet) + - Iltar van der Berg (kjarli) - Saša Stamenković (umpirsky) - Henrik Bjørnskov (henrikbjorn) - Miha Vrhovnik - - Iltar van der Berg (kjarli) - Diego Saint Esteben (dii3g0) - Konstantin Kudryashov (everzet) - Bilal Amarni (bamarni) @@ -64,8 +64,8 @@ Symfony is the result of the work of many people who made the code better - Michel Weimerskirch (mweimerskirch) - Eric Clemmons (ericclemmons) - Charles Sarrazin (csarrazi) - - Pierre du Plessis (pierredup) - Christian Raue + - Pierre du Plessis (pierredup) - Arnout Boks (aboks) - Deni - Henrik Westphal (snc) @@ -77,12 +77,12 @@ Symfony is the result of the work of many people who made the code better - Lee McDermott - Brandon Turner - Luis Cordova (cordoval) + - Jérémy DERUSSÉ (jderusse) - Graham Campbell (graham) - Daniel Holmes (dholmes) - Toni Uebernickel (havvg) - Bart van den Burg (burgov) - Jordan Alliot (jalliot) - - Jérémy DERUSSÉ (jderusse) - John Wards (johnwards) - Dariusz Ruminski - Fran Moreno (franmomu) @@ -92,8 +92,8 @@ Symfony is the result of the work of many people who made the code better - Arnaud Le Blanc (arnaud-lb) - Maxime STEINHAUSSER - Michal Piotrowski (eventhorizon) - - Tim Nagel (merk) - Issei Murasawa (issei_m) + - Tim Nagel (merk) - Brice BERNARD (brikou) - Alexander M. Turek (derrabus) - Baptiste Clavié (talus) @@ -115,6 +115,7 @@ Symfony is the result of the work of many people who made the code better - Fabien Pennequin (fabienpennequin) - Gordon Franke (gimler) - Eric GELOEN (gelo) + - Yonel Ceruto González (yonelceruto) - Daniel Wehner (dawehner) - Tugdual Saunier (tucksaun) - Théo FIDRY (theofidry) @@ -122,7 +123,6 @@ Symfony is the result of the work of many people who made the code better - Florian Lonqueu-Brochard (florianlb) - Sebastiaan Stok (sstok) - Stefano Sala (stefano.sala) - - Yonel Ceruto González (yonelceruto) - Evgeniy (ewgraf) - Juti Noppornpitak (shiroyuki) - Tigran Azatyan (tigranazatyan) @@ -157,6 +157,7 @@ Symfony is the result of the work of many people who made the code better - Amal Raghav (kertz) - Jonathan Ingram (jonathaningram) - Artur Kotyrba + - David Maicher (dmaicher) - jeremyFreeAgent (Jérémy Romey) (jeremyfreeagent) - James Halsall (jaitsu) - Warnar Boekkooi (boekkooi) @@ -166,6 +167,7 @@ Symfony is the result of the work of many people who made the code better - Possum - Dorian Villet (gnutix) - Richard Miller (mr_r_miller) + - Julien Falque (julienfalque) - Mario A. Alvarez Garcia (nomack84) - Dennis Benkert (denderello) - Benjamin Dulau (dbenjamin) @@ -179,7 +181,6 @@ Symfony is the result of the work of many people who made the code better - Daniel Espendiller - sun (sun) - Larry Garfield (crell) - - Julien Falque (julienfalque) - Martin Schuhfuß (usefulthink) - apetitpa - Matthieu Bontemps (mbontemps) @@ -202,6 +203,7 @@ Symfony is the result of the work of many people who made the code better - Tom Van Looy (tvlooy) - Sven Paulus (subsven) - Rui Marinho (ruimarinho) + - Marek Štípek (maryo) - SpacePossum - Eugene Wissner - Julien Brochet (mewt) @@ -215,7 +217,6 @@ Symfony is the result of the work of many people who made the code better - julien pauli (jpauli) - Lorenz Schori - Sébastien Lavoie (lavoiesl) - - David Maicher (dmaicher) - Francois Zaninotto - Alexander Kotynia (olden) - Daniel Tschinder @@ -252,6 +253,7 @@ Symfony is the result of the work of many people who made the code better - Albert Casademont (acasademont) - Jhonny Lidfors (jhonne) - Diego Agulló (aeoris) + - Andreas Schempp (aschempp) - jdhoek - Pavel Batanov (scaytrase) - Nikita Konstantinov @@ -270,8 +272,8 @@ Symfony is the result of the work of many people who made the code better - Michael Holm (hollo) - Marc Weistroff (futurecat) - Christian Schmidt - - Marek Štípek (maryo) - Hidde Wieringa (hiddewie) + - Chad Sikorra (chadsikorra) - Jordan Samouh (jordansamouh) - Chris Smith (cs278) - Florian Klein (docteurklein) @@ -301,10 +303,10 @@ Symfony is the result of the work of many people who made the code better - Francesc Rosàs (frosas) - Massimiliano Arione (garak) - Julien Galenski (ruian) - - Andreas Schempp (aschempp) - Bongiraud Dominique - janschoenherr - Thomas Schulz (king2500) + - Dariusz Rumiński - Berny Cantos (xphere81) - Ricard Clau (ricardclau) - Mark Challoner (markchalloner) @@ -383,7 +385,6 @@ Symfony is the result of the work of many people who made the code better - Christophe L. (christophelau) - Anthon Pang (robocoder) - Emanuele Gaspari (inmarelibero) - - Dariusz Rumiński - Sébastien Santoro (dereckson) - Brian King - Michel Salib (michelsalib) @@ -400,6 +401,7 @@ Symfony is the result of the work of many people who made the code better - Jan Rosier (rosier) - Thomas Royer (cydonia7) - Josip Kruslin + - Asmir Mustafic (goetas) - vagrant - EdgarPE - Florian Pfitzer (marmelatze) @@ -418,7 +420,6 @@ Symfony is the result of the work of many people who made the code better - Marcin Sikoń (marphi) - Dominik Zogg (dominik.zogg) - Marek Pietrzak - - Chad Sikorra (chadsikorra) - franek (franek) - Christian Wahler - Gintautas Miselis @@ -542,7 +543,6 @@ Symfony is the result of the work of many people who made the code better - Andre Rømcke (andrerom) - Nahuel Cuesta (ncuesta) - Chris Boden (cboden) - - Asmir Mustafic (goetas) - Stefan Gehrig (sgehrig) - Hany el-Kerdany - Wang Jingyu @@ -580,6 +580,7 @@ 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 @@ -627,6 +628,7 @@ Symfony is the result of the work of many people who made the code better - twifty - Indra Gunawan (guind) - Peter Ward + - insekticid - Julien DIDIER (juliendidier) - Dominik Ritter (dritter) - Sebastian Grodzicki (sgrodzicki) @@ -743,6 +745,7 @@ Symfony is the result of the work of many people who made the code better - Jan Kramer (jankramer) - abdul malik ikhsan (samsonasik) - Henry Snoek (snoek09) + - Jérémy M (th3mouk) - Simone Di Maulo (toretto460) - Christian Morgan - Alexander Miehe (engerim) @@ -759,6 +762,7 @@ Symfony is the result of the work of many people who made the code better - Douglas Reith (douglas_reith) - Harry Walter (haswalt) - Johnson Page (jwpage) + - Ruben Gonzalez (rubenruateltek) - Michael Roterman (wtfzdotnet) - Arno Geurts - Adán Lobato (adanlobato) @@ -884,6 +888,7 @@ Symfony is the result of the work of many people who made the code better - Eddie Jaoude - Antanas Arvasevicius - Haritz Iturbe (hizai) + - Baptiste Meyer (meyerbaptiste) - Nerijus Arlauskas (nercury) - SPolischook - Diego Sapriza @@ -912,6 +917,7 @@ Symfony is the result of the work of many people who made the code better - Jeremy Bush - wizhippo - Viacheslav Sychov + - Tyson Andre - Carlos Ortega Huetos - rpg600 - Péter Buri (burci) @@ -1012,6 +1018,7 @@ Symfony is the result of the work of many people who made the code better - Conrad Kleinespel - Sebastian Utz - Adrien Gallou (agallou) + - Maks Rafalko (bornfree) - Karol Sójko (karolsojko) - Grzegorz Zdanowski (kiler129) - sl_toto (sl_toto) @@ -1046,7 +1053,6 @@ Symfony is the result of the work of many people who made the code better - Kim Laï Trinh - Jason Desrosiers - m.chwedziak - - insekticid - Philip Frank - Lance McNearney - Giorgio Premi @@ -1056,6 +1062,7 @@ Symfony is the result of the work of many people who made the code better - Alberto Pirovano (geezmo) - Pete Mitchell (peterjmit) - Tom Corrigan (tomcorrigan) + - adev - Luis Galeas - Martin Pärtel - George Mponos (gmponos) @@ -1224,6 +1231,7 @@ Symfony is the result of the work of many people who made the code better - Romain Dorgueil - Grayson Koonce (breerly) - Fabien LUCAS (flucas2) + - Indra Gunawan (indragunawan) - Karim Cassam Chenaï (ka) - Nicolas Bastien (nicolas_bastien) - Denis (yethee) @@ -1271,6 +1279,7 @@ Symfony is the result of the work of many people who made the code better - Daan van Renterghem - Nicole Cordes - Bram Van der Sype (brammm) + - Christopher Hertel (chertel) - Guile (guile) - Julien Moulin (lizjulien) - Mauro Foti (skler) @@ -1289,6 +1298,7 @@ Symfony is the result of the work of many people who made the code better - Johann Pardanaud - Trevor Suarez - gedrox + - Alan Bondarchuk - dropfen - Andrey Chernykh - Edvinas Klovas @@ -1301,6 +1311,7 @@ Symfony is the result of the work of many people who made the code better - bertillon - Bertalan Attila - Yannick Bensacq (cibou) + - Gawain Lynch (gawain) - Luca Genuzio (genuzio) - Hans Nilsson (hansnilsson) - Andrew Marcinkevičius (ifdattic) @@ -1310,7 +1321,6 @@ Symfony is the result of the work of many people who made the code better - Dan Patrick (mdpatrick) - Rares Vlaseanu (raresvla) - tante kinast (tante) - - Jérémy M (th3mouk) - Vincent LEFORT (vlefort) - Sadicov Vladimir (xtech) - Kevin EMO (zarcox) @@ -1334,7 +1344,6 @@ Symfony is the result of the work of many people who made the code better - Jonny Schmid (schmidjon) - Götz Gottwald - Veres Lajos - - Michael Babker - grifx - Robert Campbell - Matt Lehner @@ -1413,9 +1422,11 @@ Symfony is the result of the work of many people who made the code better - Yanick Witschi - Ondrej Mirtes - akimsko + - Ben Scott - Youpie - srsbiz - Taylan Kasap + - Michael Orlitzky - Nicolas A. Bérard-Nault - Saem Ghani - Stefan Oderbolz @@ -1428,6 +1439,7 @@ Symfony is the result of the work of many people who made the code better - Ben - Evgeniy Tetenchuk - dasmfm + - Mathias Geat - Arnaud Buathier (arnapou) - chesteroni (chesteroni) - Mauricio Lopez (diaspar) @@ -1514,6 +1526,7 @@ Symfony is the result of the work of many people who made the code better - Abdulkadir N. A. - Yevgen Kovalienia - Lebnik + - Ondřej Führer - Sema - Elan Ruusamäe - Thorsten Hallwas @@ -1566,6 +1579,7 @@ Symfony is the result of the work of many people who made the code better - Bill Hance (billhance) - Bernd Matzner (bmatzner) - Bram Tweedegolf (bram_tweedegolf) + - Brandon Kelly (brandonkelly) - Choong Wei Tjeng (choonge) - Kousuke Ebihara (co3k) - Loïc Vernet (coil) @@ -1673,6 +1687,7 @@ Symfony is the result of the work of many people who made the code better - Andrew Carter (andrewcarteruk) - Adam Elsodaney (archfizz) - Daniel Kolvik (dkvk) + - Marc Lemay (flug) - Jeroen De Dauw (jeroendedauw) - Maxime COLIN (maximecolin) - Muharrem Demirci (mdemirci) From a13a17ad0444bab920122c2cb2e54b12173f2227 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 29 May 2017 12:04:18 -0700 Subject: [PATCH 03/57] updated VERSION for 2.7.28 --- src/Symfony/Component/HttpKernel/Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 1c1928825025c..05f6dc29223ce 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -58,12 +58,12 @@ abstract class Kernel implements KernelInterface, TerminableInterface protected $startTime; protected $loadClassCache; - const VERSION = '2.7.28-DEV'; + const VERSION = '2.7.28'; const VERSION_ID = 20728; const MAJOR_VERSION = 2; const MINOR_VERSION = 7; const RELEASE_VERSION = 28; - const EXTRA_VERSION = 'DEV'; + const EXTRA_VERSION = ''; const END_OF_MAINTENANCE = '05/2018'; const END_OF_LIFE = '05/2019'; From aa04f35092de3ebecbf75963adf2dfd9aeead80a Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 29 May 2017 12:14:01 -0700 Subject: [PATCH 04/57] bumped Symfony version to 2.7.29 --- src/Symfony/Component/HttpKernel/Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 05f6dc29223ce..4bbd67b1e5ef3 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -58,12 +58,12 @@ abstract class Kernel implements KernelInterface, TerminableInterface protected $startTime; protected $loadClassCache; - const VERSION = '2.7.28'; - const VERSION_ID = 20728; + const VERSION = '2.7.29-DEV'; + const VERSION_ID = 20729; const MAJOR_VERSION = 2; const MINOR_VERSION = 7; - const RELEASE_VERSION = 28; - const EXTRA_VERSION = ''; + const RELEASE_VERSION = 29; + const EXTRA_VERSION = 'DEV'; const END_OF_MAINTENANCE = '05/2018'; const END_OF_LIFE = '05/2019'; From 1140ae19308c87610e1686db8dbe5384860328d6 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 29 May 2017 12:14:50 -0700 Subject: [PATCH 05/57] updated CHANGELOG for 2.8.21 --- CHANGELOG-2.8.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CHANGELOG-2.8.md b/CHANGELOG-2.8.md index 52328ef28f5c3..b73a0f1a2b18b 100644 --- a/CHANGELOG-2.8.md +++ b/CHANGELOG-2.8.md @@ -7,6 +7,21 @@ in 2.8 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/v2.8.0...v2.8.1 +* 2.8.21 (2017-05-29) + + * bug #22847 [Console] ChoiceQuestion must have choices (ro0NL) + * bug #22900 [FrameworkBundle][Console] Fix the override of a command registered by the kernel (aaa2000) + * bug #22910 [Filesystem] improve error handling in lock() (xabbuh) + * bug #22718 [Console] Fixed different behaviour of key and value user inputs in multiple choice question (borNfreee) + * bug #22901 Fix missing abstract key in XmlDumper (weaverryan) + * bug #22817 [PhpUnitBridge] optional error handler arguments (xabbuh) + * bug #22752 Improved how profiler errors are displayed on small screens (javiereguiluz) + * bug #22647 [VarDumper] Fix dumping of non-nested stubs (nicolas-grekas) + * bug #22584 [Security] Avoid unnecessary route lookup for empty logout path (ro0NL) + * bug #22690 [Console] Fix errors not rethrown even if not handled by console.error listeners (chalasr) + * bug #22669 [FrameworkBundle] AbstractConfigCommand: do not try registering bundles twice (ogizanagi) + * bug #22676 [FrameworkBundle] Adding the extension XML (flug) + * 2.8.20 (2017-05-01) * bug #22550 Allow Upper Case property names in ObjectNormalizer (insekticid) From ecf57807c8110681f4a599bc2e3b028d38a6b336 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 29 May 2017 12:14:58 -0700 Subject: [PATCH 06/57] updated VERSION for 2.8.21 --- src/Symfony/Component/HttpKernel/Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 51417f5dcbf32..86be16e14e70e 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -59,12 +59,12 @@ abstract class Kernel implements KernelInterface, TerminableInterface protected $startTime; protected $loadClassCache; - const VERSION = '2.8.21-DEV'; + const VERSION = '2.8.21'; const VERSION_ID = 20821; const MAJOR_VERSION = 2; const MINOR_VERSION = 8; const RELEASE_VERSION = 21; - const EXTRA_VERSION = 'DEV'; + const EXTRA_VERSION = ''; const END_OF_MAINTENANCE = '11/2018'; const END_OF_LIFE = '11/2019'; From af6b25b28c0b6d9cd528503ae3f8d845b3028052 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 29 May 2017 12:30:05 -0700 Subject: [PATCH 07/57] bumped Symfony version to 2.8.22 --- src/Symfony/Component/HttpKernel/Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 86be16e14e70e..545c27b0366dc 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -59,12 +59,12 @@ abstract class Kernel implements KernelInterface, TerminableInterface protected $startTime; protected $loadClassCache; - const VERSION = '2.8.21'; - const VERSION_ID = 20821; + const VERSION = '2.8.22-DEV'; + const VERSION_ID = 20822; const MAJOR_VERSION = 2; const MINOR_VERSION = 8; - const RELEASE_VERSION = 21; - const EXTRA_VERSION = ''; + const RELEASE_VERSION = 22; + const EXTRA_VERSION = 'DEV'; const END_OF_MAINTENANCE = '11/2018'; const END_OF_LIFE = '11/2019'; From 17fd48cdfe73e83b499ad82c9cb13422074d1e30 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 29 May 2017 12:31:58 -0700 Subject: [PATCH 08/57] updated CHANGELOG for 3.2.9 --- CHANGELOG-3.2.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/CHANGELOG-3.2.md b/CHANGELOG-3.2.md index c76c8add66003..de1e0fd980928 100644 --- a/CHANGELOG-3.2.md +++ b/CHANGELOG-3.2.md @@ -7,6 +7,29 @@ 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.9 (2017-05-29) + + * bug #22847 [Console] ChoiceQuestion must have choices (ro0NL) + * bug #22900 [FrameworkBundle][Console] Fix the override of a command registered by the kernel (aaa2000) + * bug #22910 [Filesystem] improve error handling in lock() (xabbuh) + * bug #22924 [Cache] Dont use pipelining with RedisCluster (nicolas-grekas) + * bug #22718 [Console] Fixed different behaviour of key and value user inputs in multiple choice question (borNfreee) + * bug #22829 [Yaml] fix colon without space deprecation (xabbuh) + * bug #22901 Fix missing abstract key in XmlDumper (weaverryan) + * bug #22912 [DI] Avoid private call to Container::has() (ro0NL) + * bug #22866 [DI] Check for privates before shared services (ro0NL) + * bug #22874 [WebProfilerBundle] Fix sub-requests display in time profiler panel (nicolas-grekas) + * bug #22817 [PhpUnitBridge] optional error handler arguments (xabbuh) + * bug #22752 Improved how profiler errors are displayed on small screens (javiereguiluz) + * bug #22715 [FrameworkBundle] remove Security deps from the require section (xabbuh) + * bug #22647 [VarDumper] Fix dumping of non-nested stubs (nicolas-grekas) + * bug #22409 [Yaml] respect inline level when dumping objects as maps (goetas, xabbuh) + * bug #22584 [Security] Avoid unnecessary route lookup for empty logout path (ro0NL) + * bug #22690 [Console] Fix errors not rethrown even if not handled by console.error listeners (chalasr) + * bug #22669 [FrameworkBundle] AbstractConfigCommand: do not try registering bundles twice (ogizanagi) + * bug #22676 [FrameworkBundle] Adding the extension XML (flug) + * bug #22652 [Workflow] Move twig extension registration to twig bundle (ogizanagi) + * 3.2.8 (2017-05-01) * bug #22550 Allow Upper Case property names in ObjectNormalizer (insekticid) From a948880ecbd2660a73bb17c7ec0e7374ffca5df9 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 29 May 2017 12:32:04 -0700 Subject: [PATCH 09/57] updated VERSION for 3.2.9 --- src/Symfony/Component/HttpKernel/Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index ddfe322cc2853..af4fcaa4f30eb 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -58,12 +58,12 @@ abstract class Kernel implements KernelInterface, TerminableInterface protected $startTime; protected $loadClassCache; - const VERSION = '3.2.9-DEV'; + const VERSION = '3.2.9'; const VERSION_ID = 30209; const MAJOR_VERSION = 3; const MINOR_VERSION = 2; const RELEASE_VERSION = 9; - const EXTRA_VERSION = 'DEV'; + const EXTRA_VERSION = ''; const END_OF_MAINTENANCE = '07/2017'; const END_OF_LIFE = '01/2018'; From 17deeaf42e9809a563947d7a1c709b8e10035d6c Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 29 May 2017 13:10:37 -0700 Subject: [PATCH 10/57] bumped Symfony version to 3.2.10 --- src/Symfony/Component/HttpKernel/Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index af4fcaa4f30eb..4b849b8133062 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -58,12 +58,12 @@ abstract class Kernel implements KernelInterface, TerminableInterface protected $startTime; protected $loadClassCache; - const VERSION = '3.2.9'; - const VERSION_ID = 30209; + const VERSION = '3.2.10-DEV'; + const VERSION_ID = 30210; const MAJOR_VERSION = 3; const MINOR_VERSION = 2; - const RELEASE_VERSION = 9; - const EXTRA_VERSION = ''; + const RELEASE_VERSION = 10; + const EXTRA_VERSION = 'DEV'; const END_OF_MAINTENANCE = '07/2017'; const END_OF_LIFE = '01/2018'; From adc39a2f57fcfd85ed46b8938c6ea2a4f4c1f129 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 29 May 2017 14:23:02 -0700 Subject: [PATCH 11/57] bumped Symfony version to 3.3.1 --- src/Symfony/Component/HttpKernel/Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index e2f1df0351ad0..c9724c61f9ab9 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -61,12 +61,12 @@ abstract class Kernel implements KernelInterface, TerminableInterface private $projectDir; - const VERSION = '3.3.0'; - const VERSION_ID = 30300; + const VERSION = '3.3.1-DEV'; + const VERSION_ID = 30301; const MAJOR_VERSION = 3; const MINOR_VERSION = 3; - const RELEASE_VERSION = 0; - const EXTRA_VERSION = ''; + const RELEASE_VERSION = 1; + const EXTRA_VERSION = 'DEV'; const END_OF_MAINTENANCE = '01/2018'; const END_OF_LIFE = '07/2018'; From ff6151b15f69b5b519cf10d675a9cc6b085af97b Mon Sep 17 00:00:00 2001 From: Maxime Steinhausser Date: Tue, 30 May 2017 18:27:31 +0200 Subject: [PATCH 12/57] [Profiler] Fix text selection on exception pages --- .../Bundle/TwigBundle/Resources/views/base_js.html.twig | 5 +++++ .../Bundle/TwigBundle/Resources/views/exception.css.twig | 1 - .../Resources/views/Profiler/base_js.html.twig | 5 +++++ src/Symfony/Component/Debug/ExceptionHandler.php | 1 - 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/TwigBundle/Resources/views/base_js.html.twig b/src/Symfony/Bundle/TwigBundle/Resources/views/base_js.html.twig index d85d2e0ea32ae..337c40898697f 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/views/base_js.html.twig +++ b/src/Symfony/Bundle/TwigBundle/Resources/views/base_js.html.twig @@ -478,6 +478,11 @@ addEventListener(toggles[i], 'click', function(e) { e.preventDefault(); + if ('' !== window.getSelection().toString()) { + /* Don't do anything on text selection */ + return; + } + var toggle = e.target || e.srcElement; /* needed because when the toggle contains HTML contents, user can click */ diff --git a/src/Symfony/Bundle/TwigBundle/Resources/views/exception.css.twig b/src/Symfony/Bundle/TwigBundle/Resources/views/exception.css.twig index 4f553f20df5e9..1c8c76e78db4a 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/views/exception.css.twig +++ b/src/Symfony/Bundle/TwigBundle/Resources/views/exception.css.twig @@ -89,7 +89,6 @@ header .container { display: flex; justify-content: space-between; } .exception-illustration { flex-basis: 111px; flex-shrink: 0; height: 66px; margin-left: 15px; opacity: .7; } .trace + .trace { margin-top: 30px; } -.trace-head { -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .trace-head .trace-class { color: #222; font-size: 18px; font-weight: bold; line-height: 1.3; margin: 0; position: relative; } .trace-head .trace-namespace { color: #999; display: block; font-size: 13px; } .trace-head .icon { position: absolute; right: 0; top: 0; } diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig index 79da38a230f01..abdf19d0fa5f6 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig @@ -478,6 +478,11 @@ addEventListener(toggles[i], 'click', function(e) { e.preventDefault(); + if ('' !== window.getSelection().toString()) { + /* Don't do anything on text selection */ + return; + } + var toggle = e.target || e.srcElement; /* needed because when the toggle contains HTML contents, user can click */ diff --git a/src/Symfony/Component/Debug/ExceptionHandler.php b/src/Symfony/Component/Debug/ExceptionHandler.php index 1fe60d9f31e69..5c399ef089e3b 100644 --- a/src/Symfony/Component/Debug/ExceptionHandler.php +++ b/src/Symfony/Component/Debug/ExceptionHandler.php @@ -316,7 +316,6 @@ public function getStylesheet(FlattenException $exception) .exception-illustration { flex-basis: 111px; flex-shrink: 0; height: 66px; margin-left: 15px; opacity: .7; } .trace + .trace { margin-top: 30px; } - .trace-head { -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .trace-head .trace-class { color: #222; font-size: 18px; font-weight: bold; line-height: 1.3; margin: 0; position: relative; } .trace-message { font-size: 14px; font-weight: normal; margin: .5em 0 0; } From 8618399e4264d810aecb33e33edbf628a71cf913 Mon Sep 17 00:00:00 2001 From: Maxime Steinhausser Date: Wed, 31 May 2017 01:27:40 +0200 Subject: [PATCH 13/57] [Profiler] Fix clicking on links inside toggle --- .../Bundle/TwigBundle/Resources/views/base_js.html.twig | 8 ++++++++ .../Resources/views/Profiler/base_js.html.twig | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/Symfony/Bundle/TwigBundle/Resources/views/base_js.html.twig b/src/Symfony/Bundle/TwigBundle/Resources/views/base_js.html.twig index 337c40898697f..4ce8013c4463a 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/views/base_js.html.twig +++ b/src/Symfony/Bundle/TwigBundle/Resources/views/base_js.html.twig @@ -512,6 +512,14 @@ var altContent = toggle.getAttribute('data-toggle-alt-content'); toggle.innerHTML = currentContent !== altContent ? altContent : originalContent; }); + + /* Prevents from disallowing clicks on links inside toggles */ + var toggleLinks = document.querySelectorAll('.sf-toggle a'); + for (var i = 0; i < toggleLinks.length; i++) { + addEventListener(toggleLinks[i], 'click', function(e) { + e.stopPropagation(); + }); + } } } }; diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig index abdf19d0fa5f6..b5f08f869168d 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig @@ -513,6 +513,14 @@ toggle.innerHTML = currentContent !== altContent ? altContent : originalContent; }); } + + /* Prevents from disallowing clicks on links inside toggles */ + var toggleLinks = document.querySelectorAll('.sf-toggle a'); + for (var i = 0; i < toggleLinks.length; i++) { + addEventListener(toggleLinks[i], 'click', function(e) { + e.stopPropagation(); + }); + } } }; })(); From 28e615a656548cbedcdd3760423d7948e6fe656e Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Tue, 30 May 2017 14:30:58 +0200 Subject: [PATCH 14/57] Fix decorating TagAware adapters in dev --- .../Compiler/CacheCollectorPass.php | 7 ++-- .../Cache/Adapter/TraceableAdapter.php | 4 +-- .../Adapter/TraceableTagAwareAdapter.php | 36 +++++++++++++++++++ .../Adapter/TraceableTagAwareAdapterTest.php | 34 ++++++++++++++++++ 4 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 src/Symfony/Component/Cache/Adapter/TraceableTagAwareAdapter.php create mode 100644 src/Symfony/Component/Cache/Tests/Adapter/TraceableTagAwareAdapterTest.php diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CacheCollectorPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CacheCollectorPass.php index 3d1908bf9bc92..a4b89144ef717 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CacheCollectorPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CacheCollectorPass.php @@ -11,7 +11,9 @@ namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler; +use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface; use Symfony\Component\Cache\Adapter\TraceableAdapter; +use Symfony\Component\Cache\Adapter\TraceableTagAwareAdapter; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; @@ -34,11 +36,12 @@ public function process(ContainerBuilder $container) $collectorDefinition = $container->getDefinition('data_collector.cache'); foreach ($container->findTaggedServiceIds('cache.pool') as $id => $attributes) { - if ($container->getDefinition($id)->isAbstract()) { + $definition = $container->getDefinition($id); + if ($definition->isAbstract()) { continue; } - $container->register($id.'.recorder', TraceableAdapter::class) + $container->register($id.'.recorder', is_subclass_of($definition->getClass(), TagAwareAdapterInterface::class) ? TraceableTagAwareAdapter::class : TraceableAdapter::class) ->setDecoratedService($id) ->addArgument(new Reference($id.'.recorder.inner')) ->setPublic(false); diff --git a/src/Symfony/Component/Cache/Adapter/TraceableAdapter.php b/src/Symfony/Component/Cache/Adapter/TraceableAdapter.php index d813c61ad9038..1ddf65b3015e2 100644 --- a/src/Symfony/Component/Cache/Adapter/TraceableAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/TraceableAdapter.php @@ -22,7 +22,7 @@ */ class TraceableAdapter implements AdapterInterface { - private $pool; + protected $pool; private $calls = array(); public function __construct(AdapterInterface $pool) @@ -177,7 +177,7 @@ public function getCalls() } } - private function start($name) + protected function start($name) { $this->calls[] = $event = new TraceableAdapterEvent(); $event->name = $name; diff --git a/src/Symfony/Component/Cache/Adapter/TraceableTagAwareAdapter.php b/src/Symfony/Component/Cache/Adapter/TraceableTagAwareAdapter.php new file mode 100644 index 0000000000000..de68955d8e56d --- /dev/null +++ b/src/Symfony/Component/Cache/Adapter/TraceableTagAwareAdapter.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\Component\Cache\Adapter; + +/** + * @author Robin Chalas + */ +class TraceableTagAwareAdapter extends TraceableAdapter implements TagAwareAdapterInterface +{ + public function __construct(TagAwareAdapterInterface $pool) + { + parent::__construct($pool); + } + + /** + * {@inheritdoc} + */ + public function invalidateTags(array $tags) + { + $event = $this->start(__FUNCTION__); + try { + return $event->result = $this->pool->invalidateTags($tags); + } finally { + $event->end = microtime(true); + } + } +} diff --git a/src/Symfony/Component/Cache/Tests/Adapter/TraceableTagAwareAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/TraceableTagAwareAdapterTest.php new file mode 100644 index 0000000000000..38f3c6c087dfc --- /dev/null +++ b/src/Symfony/Component/Cache/Tests/Adapter/TraceableTagAwareAdapterTest.php @@ -0,0 +1,34 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Cache\Tests\Adapter; + +use Symfony\Component\Cache\Adapter\FilesystemAdapter; +use Symfony\Component\Cache\Adapter\TagAwareAdapter; +use Symfony\Component\Cache\Adapter\TraceableTagAwareAdapter; + +class TraceableTagAwareAdapterTest extends TraceableAdapterTest +{ + public function testInvalidateTags() + { + $pool = new TraceableTagAwareAdapter(new TagAwareAdapter(new FilesystemAdapter())); + $pool->invalidateTags(array('foo')); + $calls = $pool->getCalls(); + $this->assertCount(1, $calls); + + $call = $calls[0]; + $this->assertSame('invalidateTags', $call->name); + $this->assertSame(0, $call->hits); + $this->assertSame(0, $call->misses); + $this->assertNotEmpty($call->start); + $this->assertNotEmpty($call->end); + } +} From c5b9c1a8c81d36bffec8a957de9aa58bcb2f52c0 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 31 May 2017 10:22:24 +0200 Subject: [PATCH 15/57] [Config] Allow empty globs --- .../Component/Config/Loader/FileLoader.php | 17 +++++++++++------ .../Config/Tests/Loader/FileLoaderTest.php | 16 ++++++++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Config/Loader/FileLoader.php b/src/Symfony/Component/Config/Loader/FileLoader.php index d3fe0eacfc0d9..02aa811fc5497 100644 --- a/src/Symfony/Component/Config/Loader/FileLoader.php +++ b/src/Symfony/Component/Config/Loader/FileLoader.php @@ -83,13 +83,18 @@ public function getLocator() */ public function import($resource, $type = null, $ignoreErrors = false, $sourceResource = null) { - if (is_string($resource) && false !== strpbrk($resource, '*?{[')) { + if (is_string($resource) && strlen($resource) !== $i = strcspn($resource, '*?{[')) { $ret = array(); - foreach ($this->glob($resource, false, $_, true) as $path => $info) { - $ret[] = $this->doImport($path, $type, $ignoreErrors, $sourceResource); + $isSubpath = 0 !== $i && false !== strpos(substr($resource, 0, $i), '/'); + foreach ($this->glob($resource, false, $_, $ignoreErrors || !$isSubpath) as $path => $info) { + if (null !== $res = $this->doImport($path, $type, $ignoreErrors, $sourceResource)) { + $ret[] = $res; + } + $isSubpath = true; } - if ($ret) { - return count($ret) > 1 ? $ret : $ret[0]; + + if ($isSubpath) { + return isset($ret[1]) ? $ret : (isset($ret[0]) ? $ret[0] : null); } } @@ -104,7 +109,7 @@ protected function glob($pattern, $recursive, &$resource = null, $ignoreErrors = if (strlen($pattern) === $i = strcspn($pattern, '*?{[')) { $prefix = $pattern; $pattern = ''; - } elseif (0 === $i) { + } elseif (0 === $i || false === strpos(substr($pattern, 0, $i), '/')) { $prefix = '.'; $pattern = '/'.$pattern; } else { diff --git a/src/Symfony/Component/Config/Tests/Loader/FileLoaderTest.php b/src/Symfony/Component/Config/Tests/Loader/FileLoaderTest.php index 59b625525bff1..c6e283c74919b 100644 --- a/src/Symfony/Component/Config/Tests/Loader/FileLoaderTest.php +++ b/src/Symfony/Component/Config/Tests/Loader/FileLoaderTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Config\Tests\Loader; use PHPUnit\Framework\TestCase; +use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\Loader\FileLoader; use Symfony\Component\Config\Loader\LoaderResolver; @@ -74,6 +75,21 @@ public function testImportWithGlobLikeResource() $this->assertSame('[foo]', $loader->import('[foo]')); } + + public function testImportWithNoGlobMatch() + { + $locatorMock = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock(); + $loader = new TestFileLoader($locatorMock); + + $this->assertNull($loader->import('./*.abc')); + } + + public function testImportWithSimpleGlob() + { + $loader = new TestFileLoader(new FileLocator(__DIR__)); + + $this->assertSame(__FILE__, strtr($loader->import('FileLoaderTest.*'), '/', DIRECTORY_SEPARATOR)); + } } class TestFileLoader extends FileLoader From 8c3c0fe65e3d61379e14f2dd1f63f6a951d528b6 Mon Sep 17 00:00:00 2001 From: Dariusz Date: Wed, 31 May 2017 11:30:46 +0200 Subject: [PATCH 16/57] CS: adjust chaining indentation --- .../DoctrineDataCollectorTest.php | 12 ++--- .../Constraints/UniqueEntityValidatorTest.php | 12 ++--- .../Tests/Command/RouterDebugCommandTest.php | 4 +- .../Tests/Command/RouterMatchCommandTest.php | 4 +- .../Console/Tests/ApplicationTest.php | 8 ++-- .../Compiler/AutoAliasServicePassTest.php | 10 ++-- .../Form/Tests/AbstractDivLayoutTest.php | 4 +- .../DataTransformerChainTest.php | 24 +++++----- .../Extension/Core/Type/FormTypeTest.php | 12 ++--- .../LegacySessionCsrfProviderTest.php | 12 ++--- .../Component/Form/Tests/FormFactoryTest.php | 48 +++++++++---------- .../EventListener/RouterListenerTest.php | 16 +++---- .../Acl/Tests/Domain/AuditLoggerTest.php | 10 ++-- .../SecurityIdentityRetrievalStrategyTest.php | 8 ++-- .../Tests/Domain/UserSecurityIdentityTest.php | 4 +- .../Validator/Constraints/UrlValidator.php | 8 ++-- .../Tests/Mapping/Loader/LoaderChainTest.php | 24 +++++----- 17 files changed, 110 insertions(+), 110 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php b/src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php index 3059f8aba00a3..7557390bc6ab6 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php @@ -142,13 +142,13 @@ private function createCollector($queries) $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock(); $registry - ->expects($this->any()) - ->method('getConnectionNames') - ->will($this->returnValue(array('default' => 'doctrine.dbal.default_connection'))); + ->expects($this->any()) + ->method('getConnectionNames') + ->will($this->returnValue(array('default' => 'doctrine.dbal.default_connection'))); $registry - ->expects($this->any()) - ->method('getManagerNames') - ->will($this->returnValue(array('default' => 'doctrine.orm.default_entity_manager'))); + ->expects($this->any()) + ->method('getManagerNames') + ->will($this->returnValue(array('default' => 'doctrine.orm.default_entity_manager'))); $registry->expects($this->any()) ->method('getConnection') ->will($this->returnValue($connection)); diff --git a/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php b/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php index 115da8cba0008..61131e47045aa 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php @@ -89,8 +89,8 @@ protected function createEntityManagerMock($repositoryMock) ->getMock() ; $em->expects($this->any()) - ->method('getRepository') - ->will($this->returnValue($repositoryMock)) + ->method('getRepository') + ->will($this->returnValue($repositoryMock)) ; $classMetadata = $this->getMockBuilder('Doctrine\Common\Persistence\Mapping\ClassMetadata')->getMock(); @@ -115,8 +115,8 @@ protected function createEntityManagerMock($repositoryMock) ; $classMetadata->reflFields = array('name' => $refl); $em->expects($this->any()) - ->method('getClassMetadata') - ->will($this->returnValue($classMetadata)) + ->method('getClassMetadata') + ->will($this->returnValue($classMetadata)) ; return $em; @@ -333,8 +333,8 @@ public function testValidateUniquenessUsingCustomRepositoryMethod() $repository = $this->createRepositoryMock(); $repository->expects($this->once()) - ->method('findByCustom') - ->will($this->returnValue(array())) + ->method('findByCustom') + ->will($this->returnValue(array())) ; $this->em = $this->createEntityManagerMock($repository); $this->registry = $this->createRegistryMock($this->em); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterDebugCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterDebugCommandTest.php index 9060af4d8260e..1a9e87e1ceeb8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterDebugCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterDebugCommandTest.php @@ -72,8 +72,8 @@ private function getContainer() ; $loader = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Routing\DelegatingLoader') - ->disableOriginalConstructor() - ->getMock(); + ->disableOriginalConstructor() + ->getMock(); $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); $container diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterMatchCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterMatchCommandTest.php index 6e9b5debe2f59..82a33b46d56da 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterMatchCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterMatchCommandTest.php @@ -76,8 +76,8 @@ private function getContainer() ; $loader = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Routing\DelegatingLoader') - ->disableOriginalConstructor() - ->getMock(); + ->disableOriginalConstructor() + ->getMock(); $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); $container diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index a955ee44c9fb4..c521cfd29148f 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -735,8 +735,8 @@ public function testRunReturnsIntegerExitCode() $application = $this->getMockBuilder('Symfony\Component\Console\Application')->setMethods(array('doRun'))->getMock(); $application->setAutoExit(false); $application->expects($this->once()) - ->method('doRun') - ->will($this->throwException($exception)); + ->method('doRun') + ->will($this->throwException($exception)); $exitCode = $application->run(new ArrayInput(array()), new NullOutput()); @@ -750,8 +750,8 @@ public function testRunReturnsExitCodeOneForExceptionCodeZero() $application = $this->getMockBuilder('Symfony\Component\Console\Application')->setMethods(array('doRun'))->getMock(); $application->setAutoExit(false); $application->expects($this->once()) - ->method('doRun') - ->will($this->throwException($exception)); + ->method('doRun') + ->will($this->throwException($exception)); $exitCode = $application->run(new ArrayInput(array()), new NullOutput()); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutoAliasServicePassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutoAliasServicePassTest.php index f8199b8c9f791..281634225acaa 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutoAliasServicePassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutoAliasServicePassTest.php @@ -25,7 +25,7 @@ public function testProcessWithMissingParameter() $container = new ContainerBuilder(); $container->register('example') - ->addTag('auto_alias', array('format' => '%non_existing%.example')); + ->addTag('auto_alias', array('format' => '%non_existing%.example')); $pass = new AutoAliasServicePass(); $pass->process($container); @@ -39,7 +39,7 @@ public function testProcessWithMissingFormat() $container = new ContainerBuilder(); $container->register('example') - ->addTag('auto_alias', array()); + ->addTag('auto_alias', array()); $container->setParameter('existing', 'mysql'); $pass = new AutoAliasServicePass(); @@ -51,7 +51,7 @@ public function testProcessWithNonExistingAlias() $container = new ContainerBuilder(); $container->register('example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassDefault') - ->addTag('auto_alias', array('format' => '%existing%.example')); + ->addTag('auto_alias', array('format' => '%existing%.example')); $container->setParameter('existing', 'mysql'); $pass = new AutoAliasServicePass(); @@ -66,7 +66,7 @@ public function testProcessWithExistingAlias() $container = new ContainerBuilder(); $container->register('example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassDefault') - ->addTag('auto_alias', array('format' => '%existing%.example')); + ->addTag('auto_alias', array('format' => '%existing%.example')); $container->register('mysql.example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassMysql'); $container->setParameter('existing', 'mysql'); @@ -84,7 +84,7 @@ public function testProcessWithManualAlias() $container = new ContainerBuilder(); $container->register('example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassDefault') - ->addTag('auto_alias', array('format' => '%existing%.example')); + ->addTag('auto_alias', array('format' => '%existing%.example')); $container->register('mysql.example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassMysql'); $container->register('mariadb.example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassMariadb'); diff --git a/src/Symfony/Component/Form/Tests/AbstractDivLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractDivLayoutTest.php index 511c7f138cc7f..bd4121c5b64c3 100644 --- a/src/Symfony/Component/Form/Tests/AbstractDivLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractDivLayoutTest.php @@ -346,8 +346,8 @@ public function testCollectionRow() ); $form = $this->factory->createNamedBuilder('form', 'form') - ->add($collection) - ->getForm(); + ->add($collection) + ->getForm(); $this->assertWidgetMatchesXpath($form->createView(), array(), '/div diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DataTransformerChainTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DataTransformerChainTest.php index fc9f85e3c752e..16302b3483692 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DataTransformerChainTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DataTransformerChainTest.php @@ -20,14 +20,14 @@ public function testTransform() { $transformer1 = $this->getMockBuilder('Symfony\Component\Form\DataTransformerInterface')->getMock(); $transformer1->expects($this->once()) - ->method('transform') - ->with($this->identicalTo('foo')) - ->will($this->returnValue('bar')); + ->method('transform') + ->with($this->identicalTo('foo')) + ->will($this->returnValue('bar')); $transformer2 = $this->getMockBuilder('Symfony\Component\Form\DataTransformerInterface')->getMock(); $transformer2->expects($this->once()) - ->method('transform') - ->with($this->identicalTo('bar')) - ->will($this->returnValue('baz')); + ->method('transform') + ->with($this->identicalTo('bar')) + ->will($this->returnValue('baz')); $chain = new DataTransformerChain(array($transformer1, $transformer2)); @@ -38,14 +38,14 @@ public function testReverseTransform() { $transformer2 = $this->getMockBuilder('Symfony\Component\Form\DataTransformerInterface')->getMock(); $transformer2->expects($this->once()) - ->method('reverseTransform') - ->with($this->identicalTo('foo')) - ->will($this->returnValue('bar')); + ->method('reverseTransform') + ->with($this->identicalTo('foo')) + ->will($this->returnValue('bar')); $transformer1 = $this->getMockBuilder('Symfony\Component\Form\DataTransformerInterface')->getMock(); $transformer1->expects($this->once()) - ->method('reverseTransform') - ->with($this->identicalTo('bar')) - ->will($this->returnValue('baz')); + ->method('reverseTransform') + ->with($this->identicalTo('bar')) + ->will($this->returnValue('baz')); $chain = new DataTransformerChain(array($transformer1, $transformer2)); diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php index 1ff4057d5f373..bd772a4e59fd9 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php @@ -124,9 +124,9 @@ public function testReadOnlyFormWithNonReadOnlyParentIsReadOnly() public function testNonReadOnlyFormWithNonReadOnlyParentIsNotReadOnly() { $view = $this->factory->createNamedBuilder('parent', static::TESTED_TYPE) - ->add('child', static::TESTED_TYPE) - ->getForm() - ->createView(); + ->add('child', static::TESTED_TYPE) + ->getForm() + ->createView(); $this->assertFalse($view['child']->vars['read_only']); } @@ -478,9 +478,9 @@ public function testPassMultipartTrueIfAnyChildIsMultipartToView() public function testViewIsNotRenderedByDefault() { $view = $this->factory->createBuilder(static::TESTED_TYPE) - ->add('foo', static::TESTED_TYPE) - ->getForm() - ->createView(); + ->add('foo', static::TESTED_TYPE) + ->getForm() + ->createView(); $this->assertFalse($view->isRendered()); } diff --git a/src/Symfony/Component/Form/Tests/Extension/Csrf/CsrfProvider/LegacySessionCsrfProviderTest.php b/src/Symfony/Component/Form/Tests/Extension/Csrf/CsrfProvider/LegacySessionCsrfProviderTest.php index bd87d9cc8c577..8bf4183d61e84 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Csrf/CsrfProvider/LegacySessionCsrfProviderTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Csrf/CsrfProvider/LegacySessionCsrfProviderTest.php @@ -37,8 +37,8 @@ protected function tearDown() public function testGenerateCsrfToken() { $this->session->expects($this->once()) - ->method('getId') - ->will($this->returnValue('ABCDEF')); + ->method('getId') + ->will($this->returnValue('ABCDEF')); $token = $this->provider->generateCsrfToken('foo'); @@ -48,8 +48,8 @@ public function testGenerateCsrfToken() public function testIsCsrfTokenValidSucceeds() { $this->session->expects($this->once()) - ->method('getId') - ->will($this->returnValue('ABCDEF')); + ->method('getId') + ->will($this->returnValue('ABCDEF')); $token = sha1('SECRET'.'foo'.'ABCDEF'); @@ -59,8 +59,8 @@ public function testIsCsrfTokenValidSucceeds() public function testIsCsrfTokenValidFails() { $this->session->expects($this->once()) - ->method('getId') - ->will($this->returnValue('ABCDEF')); + ->method('getId') + ->will($this->returnValue('ABCDEF')); $token = sha1('SECRET'.'bar'.'ABCDEF'); diff --git a/src/Symfony/Component/Form/Tests/FormFactoryTest.php b/src/Symfony/Component/Form/Tests/FormFactoryTest.php index 4185a4a0025d2..29d5be7d55991 100644 --- a/src/Symfony/Component/Form/Tests/FormFactoryTest.php +++ b/src/Symfony/Component/Form/Tests/FormFactoryTest.php @@ -427,9 +427,9 @@ public function testCreateBuilderForPropertyCreatesFormWithHighestConfidence() public function testCreateBuilderCreatesTextFormIfNoGuess() { $this->guesser1->expects($this->once()) - ->method('guessType') - ->with('Application\Author', 'firstName') - ->will($this->returnValue(null)); + ->method('guessType') + ->with('Application\Author', 'firstName') + ->will($this->returnValue(null)); $factory = $this->getMockFactory(array('createNamedBuilder')); @@ -446,9 +446,9 @@ public function testCreateBuilderCreatesTextFormIfNoGuess() public function testOptionsCanBeOverridden() { $this->guesser1->expects($this->once()) - ->method('guessType') - ->with('Application\Author', 'firstName') - ->will($this->returnValue(new TypeGuess( + ->method('guessType') + ->with('Application\Author', 'firstName') + ->will($this->returnValue(new TypeGuess( 'text', array('attr' => array('maxlength' => 10)), Guess::MEDIUM_CONFIDENCE @@ -474,17 +474,17 @@ public function testOptionsCanBeOverridden() public function testCreateBuilderUsesMaxLengthIfFound() { $this->guesser1->expects($this->once()) - ->method('guessMaxLength') - ->with('Application\Author', 'firstName') - ->will($this->returnValue(new ValueGuess( + ->method('guessMaxLength') + ->with('Application\Author', 'firstName') + ->will($this->returnValue(new ValueGuess( 15, Guess::MEDIUM_CONFIDENCE ))); $this->guesser2->expects($this->once()) - ->method('guessMaxLength') - ->with('Application\Author', 'firstName') - ->will($this->returnValue(new ValueGuess( + ->method('guessMaxLength') + ->with('Application\Author', 'firstName') + ->will($this->returnValue(new ValueGuess( 20, Guess::HIGH_CONFIDENCE ))); @@ -542,17 +542,17 @@ public function testCreateBuilderUsesMaxLengthAndPattern() public function testCreateBuilderUsesRequiredSettingWithHighestConfidence() { $this->guesser1->expects($this->once()) - ->method('guessRequired') - ->with('Application\Author', 'firstName') - ->will($this->returnValue(new ValueGuess( + ->method('guessRequired') + ->with('Application\Author', 'firstName') + ->will($this->returnValue(new ValueGuess( true, Guess::MEDIUM_CONFIDENCE ))); $this->guesser2->expects($this->once()) - ->method('guessRequired') - ->with('Application\Author', 'firstName') - ->will($this->returnValue(new ValueGuess( + ->method('guessRequired') + ->with('Application\Author', 'firstName') + ->will($this->returnValue(new ValueGuess( false, Guess::HIGH_CONFIDENCE ))); @@ -575,17 +575,17 @@ public function testCreateBuilderUsesRequiredSettingWithHighestConfidence() public function testCreateBuilderUsesPatternIfFound() { $this->guesser1->expects($this->once()) - ->method('guessPattern') - ->with('Application\Author', 'firstName') - ->will($this->returnValue(new ValueGuess( + ->method('guessPattern') + ->with('Application\Author', 'firstName') + ->will($this->returnValue(new ValueGuess( '[a-z]', Guess::MEDIUM_CONFIDENCE ))); $this->guesser2->expects($this->once()) - ->method('guessPattern') - ->with('Application\Author', 'firstName') - ->will($this->returnValue(new ValueGuess( + ->method('guessPattern') + ->with('Application\Author', 'firstName') + ->will($this->returnValue(new ValueGuess( '[a-zA-Z]', Guess::HIGH_CONFIDENCE ))); diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php index 40636fa684d5c..8376ba8f6fd18 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php @@ -33,14 +33,14 @@ protected function setUp() public function testPort($defaultHttpPort, $defaultHttpsPort, $uri, $expectedHttpPort, $expectedHttpsPort) { $urlMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\UrlMatcherInterface') - ->disableOriginalConstructor() - ->getMock(); + ->disableOriginalConstructor() + ->getMock(); $context = new RequestContext(); $context->setHttpPort($defaultHttpPort); $context->setHttpsPort($defaultHttpsPort); $urlMatcher->expects($this->any()) - ->method('getContext') - ->will($this->returnValue($context)); + ->method('getContext') + ->will($this->returnValue($context)); $listener = new RouterListener($urlMatcher, null, null, $this->requestStack); $event = $this->createGetResponseEventForUri($uri); @@ -133,13 +133,13 @@ public function testLoggingParameter($parameter, $log) { $requestMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\RequestMatcherInterface')->getMock(); $requestMatcher->expects($this->once()) - ->method('matchRequest') - ->will($this->returnValue($parameter)); + ->method('matchRequest') + ->will($this->returnValue($parameter)); $logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock(); $logger->expects($this->once()) - ->method('info') - ->with($this->equalTo($log)); + ->method('info') + ->with($this->equalTo($log)); $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); $request = Request::create('http://localhost/'); diff --git a/src/Symfony/Component/Security/Acl/Tests/Domain/AuditLoggerTest.php b/src/Symfony/Component/Security/Acl/Tests/Domain/AuditLoggerTest.php index 630d217558ac7..d7d1f6b1ad090 100644 --- a/src/Symfony/Component/Security/Acl/Tests/Domain/AuditLoggerTest.php +++ b/src/Symfony/Component/Security/Acl/Tests/Domain/AuditLoggerTest.php @@ -31,8 +31,8 @@ public function testLogIfNeeded($granting, $audit) ; $ace - ->expects($this->never()) - ->method('isAuditFailure') + ->expects($this->never()) + ->method('isAuditFailure') ; } else { $ace @@ -49,9 +49,9 @@ public function testLogIfNeeded($granting, $audit) if (true === $audit) { $logger - ->expects($this->once()) - ->method('doLog') - ->with($this->equalTo($granting), $this->equalTo($ace)) + ->expects($this->once()) + ->method('doLog') + ->with($this->equalTo($granting), $this->equalTo($ace)) ; } else { $logger diff --git a/src/Symfony/Component/Security/Acl/Tests/Domain/SecurityIdentityRetrievalStrategyTest.php b/src/Symfony/Component/Security/Acl/Tests/Domain/SecurityIdentityRetrievalStrategyTest.php index 2b5e35ecb7c3b..3bc0bde13dae9 100644 --- a/src/Symfony/Component/Security/Acl/Tests/Domain/SecurityIdentityRetrievalStrategyTest.php +++ b/src/Symfony/Component/Security/Acl/Tests/Domain/SecurityIdentityRetrievalStrategyTest.php @@ -27,8 +27,8 @@ public function testGetSecurityIdentities($user, array $roles, $authenticationSt if ('anonymous' === $authenticationStatus) { $token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\AnonymousToken') - ->disableOriginalConstructor() - ->getMock(); + ->disableOriginalConstructor() + ->getMock(); } else { $class = ''; if (is_string($user)) { @@ -36,8 +36,8 @@ public function testGetSecurityIdentities($user, array $roles, $authenticationSt } $token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface') - ->setMockClassName($class) - ->getMock(); + ->setMockClassName($class) + ->getMock(); } $token ->expects($this->once()) diff --git a/src/Symfony/Component/Security/Acl/Tests/Domain/UserSecurityIdentityTest.php b/src/Symfony/Component/Security/Acl/Tests/Domain/UserSecurityIdentityTest.php index 613de22ada017..672b5788e4581 100644 --- a/src/Symfony/Component/Security/Acl/Tests/Domain/UserSecurityIdentityTest.php +++ b/src/Symfony/Component/Security/Acl/Tests/Domain/UserSecurityIdentityTest.php @@ -45,8 +45,8 @@ public function testEquals($id1, $id2, $equal) public function getCompareData() { $account = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface') - ->setMockClassName('USI_AccountImpl') - ->getMock(); + ->setMockClassName('USI_AccountImpl') + ->getMock(); $account ->expects($this->any()) ->method('getUsername') diff --git a/src/Symfony/Component/Validator/Constraints/UrlValidator.php b/src/Symfony/Component/Validator/Constraints/UrlValidator.php index a12dc14979b47..5cb126d8fe2fe 100644 --- a/src/Symfony/Component/Validator/Constraints/UrlValidator.php +++ b/src/Symfony/Component/Validator/Constraints/UrlValidator.php @@ -83,12 +83,12 @@ public function validate($value, Constraint $constraint) if (!is_string($host) || !checkdnsrr($host, 'ANY')) { if ($this->context instanceof ExecutionContextInterface) { $this->context->buildViolation($constraint->dnsMessage) - ->setParameter('{{ value }}', $this->formatValue($host)) - ->addViolation(); + ->setParameter('{{ value }}', $this->formatValue($host)) + ->addViolation(); } else { $this->buildViolation($constraint->dnsMessage) - ->setParameter('{{ value }}', $this->formatValue($host)) - ->addViolation(); + ->setParameter('{{ value }}', $this->formatValue($host)) + ->addViolation(); } } } diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Loader/LoaderChainTest.php b/src/Symfony/Component/Validator/Tests/Mapping/Loader/LoaderChainTest.php index 49a8b5256d0b6..0d28b0a399e48 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/Loader/LoaderChainTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/Loader/LoaderChainTest.php @@ -23,13 +23,13 @@ public function testAllLoadersAreCalled() $loader1 = $this->getMockBuilder('Symfony\Component\Validator\Mapping\Loader\LoaderInterface')->getMock(); $loader1->expects($this->once()) - ->method('loadClassMetadata') - ->with($this->equalTo($metadata)); + ->method('loadClassMetadata') + ->with($this->equalTo($metadata)); $loader2 = $this->getMockBuilder('Symfony\Component\Validator\Mapping\Loader\LoaderInterface')->getMock(); $loader2->expects($this->once()) - ->method('loadClassMetadata') - ->with($this->equalTo($metadata)); + ->method('loadClassMetadata') + ->with($this->equalTo($metadata)); $chain = new LoaderChain(array( $loader1, @@ -45,13 +45,13 @@ public function testReturnsTrueIfAnyLoaderReturnedTrue() $loader1 = $this->getMockBuilder('Symfony\Component\Validator\Mapping\Loader\LoaderInterface')->getMock(); $loader1->expects($this->any()) - ->method('loadClassMetadata') - ->will($this->returnValue(true)); + ->method('loadClassMetadata') + ->will($this->returnValue(true)); $loader2 = $this->getMockBuilder('Symfony\Component\Validator\Mapping\Loader\LoaderInterface')->getMock(); $loader2->expects($this->any()) - ->method('loadClassMetadata') - ->will($this->returnValue(false)); + ->method('loadClassMetadata') + ->will($this->returnValue(false)); $chain = new LoaderChain(array( $loader1, @@ -67,13 +67,13 @@ public function testReturnsFalseIfNoLoaderReturnedTrue() $loader1 = $this->getMockBuilder('Symfony\Component\Validator\Mapping\Loader\LoaderInterface')->getMock(); $loader1->expects($this->any()) - ->method('loadClassMetadata') - ->will($this->returnValue(false)); + ->method('loadClassMetadata') + ->will($this->returnValue(false)); $loader2 = $this->getMockBuilder('Symfony\Component\Validator\Mapping\Loader\LoaderInterface')->getMock(); $loader2->expects($this->any()) - ->method('loadClassMetadata') - ->will($this->returnValue(false)); + ->method('loadClassMetadata') + ->will($this->returnValue(false)); $chain = new LoaderChain(array( $loader1, From a8dfbb11807539fd0f49baccfb088787e82a0d4a Mon Sep 17 00:00:00 2001 From: Iltar van der Berg Date: Tue, 30 May 2017 15:00:50 +0200 Subject: [PATCH 17/57] Support unknown compiler log format --- .../DataCollector/LoggerDataCollector.php | 3 +++ .../Tests/DataCollector/Compiler.log | 4 ++++ .../DataCollector/LoggerDataCollectorTest.php | 21 +++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 src/Symfony/Component/HttpKernel/Tests/DataCollector/Compiler.log diff --git a/src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php index d32c581cb6b28..7ae1fbbd61537 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php @@ -138,6 +138,9 @@ private function getContainerCompilerLogs() $logs = array(); foreach (file($file, FILE_IGNORE_NEW_LINES) as $log) { $log = explode(': ', $log, 2); + if (!isset($log[1]) || !preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)++$/', $log[0])) { + $log = array('Unknown Compiler Pass', implode(': ', $log)); + } $logs[$log[0]][] = array('message' => $log[1]); } diff --git a/src/Symfony/Component/HttpKernel/Tests/DataCollector/Compiler.log b/src/Symfony/Component/HttpKernel/Tests/DataCollector/Compiler.log new file mode 100644 index 0000000000000..88b6840eae8e9 --- /dev/null +++ b/src/Symfony/Component/HttpKernel/Tests/DataCollector/Compiler.log @@ -0,0 +1,4 @@ +Symfony\Component\DependencyInjection\Compiler\RemovePrivateAliasesPass: Removed service "Psr\Container\ContainerInterface"; reason: private alias. +Symfony\Component\DependencyInjection\Compiler\RemovePrivateAliasesPass: Removed service "Symfony\Component\DependencyInjection\ContainerInterface"; reason: private alias. +Some custom logging message +With ending : diff --git a/src/Symfony/Component/HttpKernel/Tests/DataCollector/LoggerDataCollectorTest.php b/src/Symfony/Component/HttpKernel/Tests/DataCollector/LoggerDataCollectorTest.php index 5a01ee88161e9..62bf2c00c7586 100644 --- a/src/Symfony/Component/HttpKernel/Tests/DataCollector/LoggerDataCollectorTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/DataCollector/LoggerDataCollectorTest.php @@ -17,6 +17,27 @@ class LoggerDataCollectorTest extends TestCase { + public function testCollectWithUnexpectedFormat() + { + $logger = $this->getMockBuilder('Symfony\Component\HttpKernel\Log\DebugLoggerInterface')->getMock(); + $logger->expects($this->once())->method('countErrors')->will($this->returnValue('foo')); + $logger->expects($this->exactly(2))->method('getLogs')->will($this->returnValue(array())); + + $c = new LoggerDataCollector($logger, __DIR__.'/'); + $c->lateCollect(); + $compilerLogs = $c->getCompilerLogs()->getValue('message'); + + $this->assertSame(array( + array('message' => 'Removed service "Psr\Container\ContainerInterface"; reason: private alias.'), + array('message' => 'Removed service "Symfony\Component\DependencyInjection\ContainerInterface"; reason: private alias.'), + ), $compilerLogs['Symfony\Component\DependencyInjection\Compiler\RemovePrivateAliasesPass']); + + $this->assertSame(array( + array('message' => 'Some custom logging message'), + array('message' => 'With ending :'), + ), $compilerLogs['Unknown Compiler Pass']); + } + /** * @dataProvider getCollectTestData */ From 47d5e6b82c91a4f6093f70e6a01255e66d4cd172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Wed, 31 May 2017 12:58:03 +0200 Subject: [PATCH 18/57] [PropertyInfo][DoctrineBridge] The bigint Doctrine's type must be converted to string --- .../Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php | 5 +---- .../Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php | 2 ++ .../Doctrine/Tests/PropertyInfo/Fixtures/DoctrineDummy.php | 6 ++++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php b/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php index aba31792f99ee..e07c7b0bc2cba 100644 --- a/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php +++ b/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php @@ -174,13 +174,13 @@ private function getPhpType($doctrineType) { switch ($doctrineType) { case DBALType::SMALLINT: - case DBALType::BIGINT: case DBALType::INTEGER: return Type::BUILTIN_TYPE_INT; case DBALType::FLOAT: return Type::BUILTIN_TYPE_FLOAT; + case DBALType::BIGINT: case DBALType::STRING: case DBALType::TEXT: case DBALType::GUID: @@ -196,9 +196,6 @@ private function getPhpType($doctrineType) case DBALType::OBJECT: return Type::BUILTIN_TYPE_OBJECT; - - default: - return; } } } diff --git a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php index 277922daefd51..48822d5888fbc 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php @@ -55,6 +55,7 @@ public function testGetProperties() 'bool', 'binary', 'customFoo', + 'bigint', 'foo', 'bar', 'indexedBar', @@ -76,6 +77,7 @@ public function typesProvider() return array( array('id', array(new Type(Type::BUILTIN_TYPE_INT))), array('guid', array(new Type(Type::BUILTIN_TYPE_STRING))), + array('bigint', array(new Type(Type::BUILTIN_TYPE_STRING))), array('float', array(new Type(Type::BUILTIN_TYPE_FLOAT))), array('decimal', array(new Type(Type::BUILTIN_TYPE_STRING))), array('bool', array(new Type(Type::BUILTIN_TYPE_BOOL))), diff --git a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineDummy.php b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineDummy.php index ad3b7b9227652..9ceae5150c7ab 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineDummy.php +++ b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineDummy.php @@ -11,6 +11,7 @@ namespace Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures; +use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping\Column; use Doctrine\ORM\Mapping\Entity; use Doctrine\ORM\Mapping\Id; @@ -90,5 +91,10 @@ class DoctrineDummy */ private $customFoo; + /** + * @Column(type="bigint") + */ + private $bigint; + public $notMapped; } From a3793198fa33c410489627a03fbb1ac8c7ecafe8 Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Wed, 31 May 2017 13:48:12 +0200 Subject: [PATCH 19/57] Remove extra arg in call to TraceableAdapter::start() --- src/Symfony/Component/Cache/Adapter/TraceableAdapter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Cache/Adapter/TraceableAdapter.php b/src/Symfony/Component/Cache/Adapter/TraceableAdapter.php index 1ddf65b3015e2..9959199f67ccc 100644 --- a/src/Symfony/Component/Cache/Adapter/TraceableAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/TraceableAdapter.php @@ -107,7 +107,7 @@ public function saveDeferred(CacheItemInterface $item) */ public function getItems(array $keys = array()) { - $event = $this->start(__FUNCTION__, $keys); + $event = $this->start(__FUNCTION__); try { $result = $this->pool->getItems($keys); } finally { From 2d3e44e11ea053d2506408e49191e9b1797a9c14 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Wed, 31 May 2017 09:45:25 -0400 Subject: [PATCH 20/57] Fixing a bug where an autowiring exception was thrown even when that service was removed The specific report was for a service with a private constructor. This also clarifies that the AutowirePass throws AutowiringFailedException for all situations. And a bug was fixed in the constructor of AutowiringFailedException --- .../Compiler/AutowirePass.php | 10 +++- .../Exception/AutowiringFailedException.php | 2 +- .../Tests/Compiler/AutowirePassTest.php | 49 +++++++++++++------ 3 files changed, 44 insertions(+), 17 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php index b79a656aa8eaf..bf7fc844c732b 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php @@ -133,7 +133,13 @@ private function doProcessValue($value, $isRoot = false) $autowiredMethods = $this->getMethodsToAutowire($reflectionClass); $methodCalls = $value->getMethodCalls(); - if ($constructor = $this->getConstructor($value, false)) { + try { + $constructor = $this->getConstructor($value, false); + } catch (RuntimeException $e) { + throw new AutowiringFailedException($this->currentId, $e->getMessage(), 0, $e); + } + + if ($constructor) { array_unshift($methodCalls, array($constructor, $value->getArguments())); } @@ -242,7 +248,7 @@ private function autowireCalls(\ReflectionClass $reflectionClass, array $methodC * * @return array The autowired arguments * - * @throws RuntimeException + * @throws AutowiringFailedException */ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, array $arguments) { diff --git a/src/Symfony/Component/DependencyInjection/Exception/AutowiringFailedException.php b/src/Symfony/Component/DependencyInjection/Exception/AutowiringFailedException.php index f5c50d4dee336..145cd8cbdcf24 100644 --- a/src/Symfony/Component/DependencyInjection/Exception/AutowiringFailedException.php +++ b/src/Symfony/Component/DependencyInjection/Exception/AutowiringFailedException.php @@ -18,7 +18,7 @@ class AutowiringFailedException extends RuntimeException { private $serviceId; - public function __construct($serviceId, $message = '', $code = 0, Exception $previous = null) + public function __construct($serviceId, $message = '', $code = 0, \Exception $previous = null) { $this->serviceId = $serviceId; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php index e2ba9ec4e4b97..ca297f217495d 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php @@ -151,7 +151,21 @@ public function testExceptionsAreStored() } /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException + * @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException + * @expectedExceptionMessage Unable to resolve service "private_service": constructor of class "Symfony\Component\DependencyInjection\Tests\Compiler\PrivateConstructor" must be public. + */ + public function testPrivateConstructorThrowsAutowireException() + { + $container = new ContainerBuilder(); + + $container->autowire('private_service', __NAMESPACE__.'\PrivateConstructor'); + + $pass = new AutowirePass(true); + $pass->process($container); + } + + /** + * @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException * @expectedExceptionMessage Cannot autowire service "a": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\CannotBeAutowired::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" but no such service exists. You should maybe alias this interface to one of these existing services: "c1", "c2", "c3". */ public function testTypeCollision() @@ -169,7 +183,7 @@ public function testTypeCollision() } /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException + * @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException * @expectedExceptionMessage Cannot autowire service "a": argument "$k" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotGuessableArgument::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" but no such service exists. You should maybe alias this class to one of these existing services: "a1", "a2". */ public function testTypeNotGuessable() @@ -186,7 +200,7 @@ public function testTypeNotGuessable() } /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException + * @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException * @expectedExceptionMessage Cannot autowire service "a": argument "$k" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotGuessableArgumentForSubclass::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\A" but no such service exists. You should maybe alias this class to one of these existing services: "a1", "a2". */ public function testTypeNotGuessableWithSubclass() @@ -203,7 +217,7 @@ public function testTypeNotGuessableWithSubclass() } /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException + * @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException * @expectedExceptionMessage Cannot autowire service "a": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\CannotBeAutowired::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" but no such service exists. */ public function testTypeNotGuessableNoServicesFound() @@ -322,7 +336,7 @@ public function testDontTriggerAutowiring() } /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException + * @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException * @expectedExceptionMessage Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotARealClass" but this class does not exist. */ public function testClassNotFoundThrowsException() @@ -337,7 +351,7 @@ public function testClassNotFoundThrowsException() } /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException + * @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException * @expectedExceptionMessage Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadParentTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\OptionalServiceClass" but this class does not exist. */ public function testParentClassNotFoundThrowsException() @@ -354,7 +368,7 @@ public function testParentClassNotFoundThrowsException() /** * @group legacy * @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. You should rename (or alias) the "foo" service to "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" instead. - * @expectedExceptionInSymfony4 \Symfony\Component\DependencyInjection\Exception\RuntimeException + * @expectedExceptionInSymfony4 \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException * @expectedExceptionMessageInSymfony4 Cannot autowire service "bar": argument "$foo" of method "Symfony\Component\DependencyInjection\Tests\Compiler\Bar::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" but this service is abstract. You should maybe alias this class to the existing "foo" service. */ public function testDontUseAbstractServices() @@ -399,7 +413,7 @@ public function testSomeSpecificArgumentsAreSet() } /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException + * @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException * @expectedExceptionMessage Cannot autowire service "arg_no_type_hint": argument "$foo" of method "Symfony\Component\DependencyInjection\Tests\Compiler\MultipleArguments::__construct()" must have a type-hint or be given a value explicitly. */ public function testScalarArgsCannotBeAutowired() @@ -607,7 +621,7 @@ public function testIgnoreServiceWithClassNotExisting() } /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException + * @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException * @expectedExceptionMessage Cannot autowire service "setter_injection_collision": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\SetterInjectionCollision::setMultipleInstancesForOneArg()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" but no such service exists. You should maybe alias this interface to one of these existing services: "c1", "c2". */ public function testSetterInjectionCollisionThrowsException() @@ -626,7 +640,7 @@ public function testSetterInjectionCollisionThrowsException() /** * @group legacy * @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. You should rename (or alias) the "foo" service to "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" instead. - * @expectedExceptionInSymfony4 \Symfony\Component\DependencyInjection\Exception\RuntimeException + * @expectedExceptionInSymfony4 \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException * @expectedExceptionMessageInSymfony4 Cannot autowire service "bar": argument "$foo" of method "Symfony\Component\DependencyInjection\Tests\Compiler\Bar::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" but no such service exists. You should maybe alias this class to the existing "foo" service. */ public function testProcessDoesNotTriggerDeprecations() @@ -677,7 +691,7 @@ public function testWithFactory() /** * @dataProvider provideNotWireableCalls - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException + * @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException */ public function testNotWireableCalls($method, $expectedMsg) { @@ -717,7 +731,7 @@ public function provideNotWireableCalls() /** * @group legacy * @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. You should rename (or alias) the "i" service to "Symfony\Component\DependencyInjection\Tests\Compiler\I" instead. - * @expectedExceptionInSymfony4 \Symfony\Component\DependencyInjection\Exception\RuntimeException + * @expectedExceptionInSymfony4 \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException * @expectedExceptionMessageInSymfony4 Cannot autowire service "j": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\I" but no such service exists. Try changing the type-hint to "Symfony\Component\DependencyInjection\Tests\Compiler\IInterface" instead. */ public function testByIdAlternative() @@ -734,7 +748,7 @@ public function testByIdAlternative() } /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException + * @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException * @expectedExceptionMessage Cannot autowire service "j": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\I" but no such service exists. Try changing the type-hint to "Symfony\Component\DependencyInjection\Tests\Compiler\IInterface" instead. */ public function testExceptionWhenAliasExists() @@ -754,7 +768,7 @@ public function testExceptionWhenAliasExists() } /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException + * @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException * @expectedExceptionMessage Cannot autowire service "j": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\I" but no such service exists. You should maybe alias this class to one of these existing services: "i", "i2". */ public function testExceptionWhenAliasDoesNotExist() @@ -1091,3 +1105,10 @@ protected function setProtectedMethod(A $a) { } } + +class PrivateConstructor +{ + private function __construct() + { + } +} From 63a8aff2c887a4358529ebe7adb851725515e4eb Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Wed, 31 May 2017 17:20:46 +0200 Subject: [PATCH 21/57] Harden the debugging of Twig filters and functions Removing the environment and context arguments is now based on Twig metadata rather than on some wild guessing which might go wrong. --- .../Bridge/Twig/Command/DebugCommand.php | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Command/DebugCommand.php b/src/Symfony/Bridge/Twig/Command/DebugCommand.php index 349a8b81b83c1..7473221277c81 100644 --- a/src/Symfony/Bridge/Twig/Command/DebugCommand.php +++ b/src/Symfony/Bridge/Twig/Command/DebugCommand.php @@ -159,14 +159,20 @@ private function getMetadata($type, $entity) throw new \UnexpectedValueException('Unsupported callback type'); } + $args = $refl->getParameters(); + // filter out context/environment args - $args = array_filter($refl->getParameters(), function ($param) use ($entity) { - if ($entity->needsContext() && $param->getName() === 'context') { - return false; - } + if ($entity->needsEnvironment()) { + array_shift($args); + } + if ($entity->needsContext()) { + array_shift($args); + } - return !$param->getClass() || $param->getClass()->getName() !== 'Twig_Environment'; - }); + if ($type === 'filters') { + // remove the value the filter is applied on + array_shift($args); + } // format args $args = array_map(function ($param) { @@ -177,11 +183,6 @@ private function getMetadata($type, $entity) return $param->getName(); }, $args); - if ($type === 'filters') { - // remove the value the filter is applied on - array_shift($args); - } - return $args; } } From a990d5c558f195235b5390b27cb06ad4c00ba052 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Fri, 5 May 2017 07:31:04 -0400 Subject: [PATCH 22/57] Improving deprecation message when hitting the "deprecated type" lookup, but an alias is available --- .../Compiler/AutowirePass.php | 62 ++++++++++++------- .../Tests/Compiler/AutowirePassTest.php | 49 ++++++++++++++- 2 files changed, 86 insertions(+), 25 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php index bf7fc844c732b..49138f91bea34 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php @@ -114,7 +114,7 @@ protected function processValue($value, $isRoot = false) private function doProcessValue($value, $isRoot = false) { if ($value instanceof TypedReference) { - if ($ref = $this->getAutowiredReference($value)) { + if ($ref = $this->getAutowiredReference($value, $value->getRequiringClass() ? sprintf('for "%s" in "%s"', $value->getType(), $value->getRequiringClass()) : '')) { return $ref; } $this->container->log($this, $this->createTypeNotFoundMessage($value, 'it')); @@ -282,7 +282,7 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a continue; } - if (!$value = $this->getAutowiredReference($ref = new TypedReference($type, $type, !$parameter->isOptional() ? $class : ''))) { + if (!$value = $this->getAutowiredReference($ref = new TypedReference($type, $type, !$parameter->isOptional() ? $class : ''), 'for '.sprintf('argument "$%s" of method "%s()"', $parameter->name, $class.'::'.$method))) { $failureMessage = $this->createTypeNotFoundMessage($ref, sprintf('argument "$%s" of method "%s()"', $parameter->name, $class !== $this->currentId ? $class.'::'.$method : $method)); if ($parameter->isDefaultValueAvailable()) { @@ -316,7 +316,7 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a /** * @return TypedReference|null A reference to the service matching the given type, if any */ - private function getAutowiredReference(TypedReference $reference) + private function getAutowiredReference(TypedReference $reference, $deprecationMessage) { $this->lastFailure = null; $type = $reference->getType(); @@ -334,7 +334,14 @@ private function getAutowiredReference(TypedReference $reference) } if (isset($this->types[$type])) { - @trigger_error(sprintf('Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won\'t be supported in version 4.0. You should %s the "%s" service to "%s" instead.', isset($this->types[$this->types[$type]]) ? 'alias' : 'rename (or alias)', $this->types[$type], $type), E_USER_DEPRECATED); + $message = 'Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won\'t be supported in version 4.0.'; + if ($aliasSuggestion = $this->getAliasesSuggestionForType($type = $reference->getType(), $deprecationMessage)) { + $message .= ' '.$aliasSuggestion; + } else { + $message .= sprintf(' You should %s the "%s" service to "%s" instead.', isset($this->types[$this->types[$type]]) ? 'alias' : 'rename (or alias)', $this->types[$type], $type); + } + + @trigger_error($message, E_USER_DEPRECATED); return new TypedReference($this->types[$type], $type); } @@ -490,25 +497,9 @@ private function createTypeNotFoundMessage(TypedReference $reference, $label) private function createTypeAlternatives(TypedReference $reference) { - $type = $reference->getType(); - $aliases = array(); - foreach (class_parents($type) + class_implements($type) as $parent) { - if ($this->container->has($parent) && !$this->container->findDefinition($parent)->isAbstract()) { - $aliases[] = $parent; - } - } - - if (1 < $len = count($aliases)) { - $message = ' Try changing the type-hint to one of its parents: '; - for ($i = 0, --$len; $i < $len; ++$i) { - $message .= sprintf('%s "%s", ', class_exists($aliases[$i], false) ? 'class' : 'interface', $aliases[$i]); - } - $message .= sprintf('or %s "%s".', class_exists($aliases[$i], false) ? 'class' : 'interface', $aliases[$i]); - - return $message; - } - if ($aliases) { - return sprintf(' Try changing the type-hint to "%s" instead.', $aliases[0]); + // try suggesting available aliases first + if ($message = $this->getAliasesSuggestionForType($type = $reference->getType())) { + return ' '.$message; } if (isset($this->ambiguousServiceTypes[$type])) { @@ -548,4 +539,29 @@ private static function getResourceMetadataForMethod(\ReflectionMethod $method) return $methodArgumentsMetadata; } + + private function getAliasesSuggestionForType($type, $extraContext = null) + { + $aliases = array(); + foreach (class_parents($type) + class_implements($type) as $parent) { + if ($this->container->has($parent) && !$this->container->findDefinition($parent)->isAbstract()) { + $aliases[] = $parent; + } + } + + $extraContext = $extraContext ? ' '.$extraContext : ''; + if (1 < $len = count($aliases)) { + $message = sprintf('Try changing the type-hint%s to one of its parents: ', $extraContext); + for ($i = 0, --$len; $i < $len; ++$i) { + $message .= sprintf('%s "%s", ', class_exists($aliases[$i], false) ? 'class' : 'interface', $aliases[$i]); + } + $message .= sprintf('or %s "%s".', class_exists($aliases[$i], false) ? 'class' : 'interface', $aliases[$i]); + + return $message; + } + + if ($aliases) { + return sprintf('Try changing the type-hint%s to "%s" instead.', $extraContext, $aliases[0]); + } + } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php index ca297f217495d..41ad5634132c0 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php @@ -78,6 +78,28 @@ public function testProcessAutowireParent() $this->assertEquals(B::class, (string) $container->getDefinition('c')->getArgument(0)); } + /** + * @group legacy + * @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. Try changing the type-hint for argument "$a" of method "Symfony\Component\DependencyInjection\Tests\Compiler\C::__construct()" to "Symfony\Component\DependencyInjection\Tests\Compiler\AInterface" instead. + * @expectedExceptionInSymfony4 \Symfony\Component\DependencyInjection\Exception\RuntimeException + * @expectedExceptionMessageInSymfony4 Cannot autowire service "c": argument "$a" of method "Symfony\Component\DependencyInjection\Tests\Compiler\C::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\A" but no such service exists. You should maybe alias this class to the existing "Symfony\Component\DependencyInjection\Tests\Compiler\B" service. + */ + public function testProcessLegacyAutowireWithAvailableInterface() + { + $container = new ContainerBuilder(); + + $container->setAlias(AInterface::class, B::class); + $container->register(B::class); + $cDefinition = $container->register('c', __NAMESPACE__.'\C'); + $cDefinition->setAutowired(true); + + (new ResolveClassPass())->process($container); + (new AutowirePass())->process($container); + + $this->assertCount(1, $container->getDefinition('c')->getArguments()); + $this->assertEquals(B::class, (string) $container->getDefinition('c')->getArgument(0)); + } + /** * @group legacy * @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. You should alias the "Symfony\Component\DependencyInjection\Tests\Compiler\F" service to "Symfony\Component\DependencyInjection\Tests\Compiler\DInterface" instead. @@ -730,7 +752,7 @@ public function provideNotWireableCalls() /** * @group legacy - * @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. You should rename (or alias) the "i" service to "Symfony\Component\DependencyInjection\Tests\Compiler\I" instead. + * @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. Try changing the type-hint for argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" to "Symfony\Component\DependencyInjection\Tests\Compiler\IInterface" instead. * @expectedExceptionInSymfony4 \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException * @expectedExceptionMessageInSymfony4 Cannot autowire service "j": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\I" but no such service exists. Try changing the type-hint to "Symfony\Component\DependencyInjection\Tests\Compiler\IInterface" instead. */ @@ -747,6 +769,25 @@ public function testByIdAlternative() $pass->process($container); } + /** + * @group legacy + * @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. Try changing the type-hint for "Symfony\Component\DependencyInjection\Tests\Compiler\A" in "Symfony\Component\DependencyInjection\Tests\Compiler\Bar" to "Symfony\Component\DependencyInjection\Tests\Compiler\AInterface" instead. + */ + public function testTypedReferenceDeprecationNotice() + { + $container = new ContainerBuilder(); + + $container->register('aClass', A::class); + $container->setAlias(AInterface::class, 'aClass'); + $container + ->register('bar', Bar::class) + ->setProperty('a', array(new TypedReference(A::class, A::class, Bar::class))) + ; + + $pass = new AutowirePass(); + $pass->process($container); + } + /** * @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException * @expectedExceptionMessage Cannot autowire service "j": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\I" but no such service exists. Try changing the type-hint to "Symfony\Component\DependencyInjection\Tests\Compiler\IInterface" instead. @@ -798,7 +839,11 @@ public function __construct(Foo $foo) } } -class A +interface AInterface +{ +} + +class A implements AInterface { public static function create(Foo $foo) { From 793b9a001f5fa09a501322aa4dcb8a3506fb6da2 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Wed, 31 May 2017 10:32:39 -0400 Subject: [PATCH 23/57] [DI] Autowiring exception thrown when inlined service is removed --- .../Compiler/AutowireExceptionPass.php | 16 ++++++- .../Compiler/InlineServiceDefinitionsPass.php | 6 ++- .../Compiler/AutowireExceptionPassTest.php | 43 +++++++++++++++++-- .../InlineServiceDefinitionsPassTest.php | 6 +-- 4 files changed, 62 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/AutowireExceptionPass.php b/src/Symfony/Component/DependencyInjection/Compiler/AutowireExceptionPass.php index 2ee9427a15098..a1ed422f7336d 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/AutowireExceptionPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/AutowireExceptionPass.php @@ -44,9 +44,23 @@ public function process(ContainerBuilder $container) $this->inlineServicePass = null; foreach ($exceptions as $exception) { - if ($container->hasDefinition($exception->getServiceId()) || in_array($exception->getServiceId(), $inlinedIds)) { + if ($this->doesServiceExistInTheContainer($exception->getServiceId(), $container, $inlinedIds)) { throw $exception; } } } + + private function doesServiceExistInTheContainer($serviceId, ContainerBuilder $container, array $inlinedIds) + { + if ($container->hasDefinition($serviceId)) { + return true; + } + + // was the service inlined? Of so, does its parent service exist? + if (isset($inlinedIds[$serviceId])) { + return $this->doesServiceExistInTheContainer($inlinedIds[$serviceId], $container, $inlinedIds); + } + + return false; + } } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php index b084d7e4dce28..a2eb511c643d7 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php @@ -36,7 +36,9 @@ public function setRepeatedPass(RepeatedPass $repeatedPass) /** * Returns an array of all services inlined by this pass. * - * @return array Service id strings + * The key is the inlined service id and its value is the service it was inlined into. + * + * @return array */ public function getInlinedServiceIds() { @@ -57,7 +59,7 @@ protected function processValue($value, $isRoot = false) if ($this->isInlineableDefinition($id, $definition, $this->container->getCompiler()->getServiceReferenceGraph())) { $this->container->log($this, sprintf('Inlined service "%s" to "%s".', $id, $this->currentId)); - $this->inlinedServiceIds[] = $id; + $this->inlinedServiceIds[$id] = $this->currentId; if ($definition->isShared()) { return $definition; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowireExceptionPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowireExceptionPassTest.php index 092b6401c48ef..8cd03f578ac02 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowireExceptionPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowireExceptionPassTest.php @@ -54,7 +54,7 @@ public function testThrowExceptionIfServiceInlined() $autowirePass = $this->getMockBuilder(AutowirePass::class) ->getMock(); - $autowireException = new AutowiringFailedException('foo_service_id', 'An autowiring exception message'); + $autowireException = new AutowiringFailedException('a_service', 'An autowiring exception message'); $autowirePass->expects($this->any()) ->method('getAutowiringExceptions') ->will($this->returnValue(array($autowireException))); @@ -63,10 +63,16 @@ public function testThrowExceptionIfServiceInlined() ->getMock(); $inlinePass->expects($this->any()) ->method('getInlinedServiceIds') - ->will($this->returnValue(array('foo_service_id'))); + ->will($this->returnValue(array( + // a_service inlined into b_service + 'a_service' => 'b_service', + // b_service inlined into c_service + 'b_service' => 'c_service', + ))); - // don't register the foo_service_id service $container = new ContainerBuilder(); + // ONLY register c_service in the final container + $container->register('c_service', 'stdClass'); $pass = new AutowireExceptionPass($autowirePass, $inlinePass); @@ -78,6 +84,37 @@ public function testThrowExceptionIfServiceInlined() } } + public function testDoNotThrowExceptionIfServiceInlinedButRemoved() + { + $autowirePass = $this->getMockBuilder(AutowirePass::class) + ->getMock(); + + $autowireException = new AutowiringFailedException('a_service', 'An autowiring exception message'); + $autowirePass->expects($this->any()) + ->method('getAutowiringExceptions') + ->will($this->returnValue(array($autowireException))); + + $inlinePass = $this->getMockBuilder(InlineServiceDefinitionsPass::class) + ->getMock(); + $inlinePass->expects($this->any()) + ->method('getInlinedServiceIds') + ->will($this->returnValue(array( + // a_service inlined into b_service + 'a_service' => 'b_service', + // b_service inlined into c_service + 'b_service' => 'c_service', + ))); + + // do NOT register c_service in the container + $container = new ContainerBuilder(); + + $pass = new AutowireExceptionPass($autowirePass, $inlinePass); + + $pass->process($container); + // mark the test as passed + $this->assertTrue(true); + } + public function testNoExceptionIfServiceRemoved() { $autowirePass = $this->getMockBuilder(AutowirePass::class) diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php index d241758b04425..0eaea411f114f 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php @@ -252,7 +252,7 @@ public function testProcessDoesNotSetLazyArgumentValuesAfterInlining() $this->assertSame('inline', (string) $values[0]); } - public function testGetInlinedServiceIds() + public function testGetInlinedServiceIdData() { $container = new ContainerBuilder(); $container @@ -265,7 +265,7 @@ public function testGetInlinedServiceIds() ; $container - ->register('service') + ->register('other_service') ->setArguments(array(new Reference('inlinable.service'))) ; @@ -273,7 +273,7 @@ public function testGetInlinedServiceIds() $repeatedPass = new RepeatedPass(array(new AnalyzeServiceReferencesPass(), $inlinePass)); $repeatedPass->process($container); - $this->assertEquals(array('inlinable.service'), $inlinePass->getInlinedServiceIds()); + $this->assertEquals(array('inlinable.service' => 'other_service'), $inlinePass->getInlinedServiceIds()); } protected function process(ContainerBuilder $container) From e8f70c75b98fe709b2890829b5bc12d47b90fec6 Mon Sep 17 00:00:00 2001 From: Roland Franssen Date: Tue, 30 May 2017 16:55:30 +0200 Subject: [PATCH 24/57] [Cache] Ignore missing annotations.php --- src/Symfony/Component/Cache/Traits/PhpArrayTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Cache/Traits/PhpArrayTrait.php b/src/Symfony/Component/Cache/Traits/PhpArrayTrait.php index 2b0ae50f6a1ac..2d2c7db3d014f 100644 --- a/src/Symfony/Component/Cache/Traits/PhpArrayTrait.php +++ b/src/Symfony/Component/Cache/Traits/PhpArrayTrait.php @@ -126,6 +126,6 @@ public function clear() */ private function initialize() { - $this->values = @(include $this->file) ?: array(); + $this->values = file_exists($this->file) ? (include $this->file ?: array()) : array(); } } From 996698d996801f64cb6241cec1e1b3d5d77eacf3 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 1 Jun 2017 08:27:51 +0200 Subject: [PATCH 25/57] [DI] Deal with inlined non-shared services --- .../Compiler/AutowireExceptionPass.php | 6 +++++- .../Compiler/InlineServiceDefinitionsPass.php | 4 ++-- .../Tests/Compiler/AutowireExceptionPassTest.php | 8 ++++---- .../Tests/Compiler/InlineServiceDefinitionsPassTest.php | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/AutowireExceptionPass.php b/src/Symfony/Component/DependencyInjection/Compiler/AutowireExceptionPass.php index a1ed422f7336d..12be3d915fd10 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/AutowireExceptionPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/AutowireExceptionPass.php @@ -58,7 +58,11 @@ private function doesServiceExistInTheContainer($serviceId, ContainerBuilder $co // was the service inlined? Of so, does its parent service exist? if (isset($inlinedIds[$serviceId])) { - return $this->doesServiceExistInTheContainer($inlinedIds[$serviceId], $container, $inlinedIds); + foreach ($inlinedIds[$serviceId] as $parentId) { + if ($this->doesServiceExistInTheContainer($parentId, $container, $inlinedIds)) { + return true; + } + } } return false; diff --git a/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php index a2eb511c643d7..7a5da70d09567 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php @@ -36,7 +36,7 @@ public function setRepeatedPass(RepeatedPass $repeatedPass) /** * Returns an array of all services inlined by this pass. * - * The key is the inlined service id and its value is the service it was inlined into. + * The key is the inlined service id and its value is the list of services it was inlined into. * * @return array */ @@ -59,7 +59,7 @@ protected function processValue($value, $isRoot = false) if ($this->isInlineableDefinition($id, $definition, $this->container->getCompiler()->getServiceReferenceGraph())) { $this->container->log($this, sprintf('Inlined service "%s" to "%s".', $id, $this->currentId)); - $this->inlinedServiceIds[$id] = $this->currentId; + $this->inlinedServiceIds[$id][] = $this->currentId; if ($definition->isShared()) { return $definition; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowireExceptionPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowireExceptionPassTest.php index 8cd03f578ac02..4f0b3d6c2566c 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowireExceptionPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowireExceptionPassTest.php @@ -65,9 +65,9 @@ public function testThrowExceptionIfServiceInlined() ->method('getInlinedServiceIds') ->will($this->returnValue(array( // a_service inlined into b_service - 'a_service' => 'b_service', + 'a_service' => array('b_service'), // b_service inlined into c_service - 'b_service' => 'c_service', + 'b_service' => array('c_service'), ))); $container = new ContainerBuilder(); @@ -100,9 +100,9 @@ public function testDoNotThrowExceptionIfServiceInlinedButRemoved() ->method('getInlinedServiceIds') ->will($this->returnValue(array( // a_service inlined into b_service - 'a_service' => 'b_service', + 'a_service' => array('b_service'), // b_service inlined into c_service - 'b_service' => 'c_service', + 'b_service' => array('c_service'), ))); // do NOT register c_service in the container diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php index 0eaea411f114f..f0dd7fe74dc4c 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php @@ -273,7 +273,7 @@ public function testGetInlinedServiceIdData() $repeatedPass = new RepeatedPass(array(new AnalyzeServiceReferencesPass(), $inlinePass)); $repeatedPass->process($container); - $this->assertEquals(array('inlinable.service' => 'other_service'), $inlinePass->getInlinedServiceIds()); + $this->assertEquals(array('inlinable.service' => array('other_service')), $inlinePass->getInlinedServiceIds()); } protected function process(ContainerBuilder $container) From 71d4e366a9bcea717fc418b41e5fe5821d677635 Mon Sep 17 00:00:00 2001 From: Frank de Jonge Date: Thu, 1 Jun 2017 11:46:06 +0200 Subject: [PATCH 26/57] [Routing] Allow GET requests to be redirected. Fixes #23004 --- .../Matcher/Dumper/PhpMatcherDumper.php | 2 +- .../Tests/Fixtures/dumper/url_matcher6.php | 204 ++++++++++++++++ .../Tests/Fixtures/dumper/url_matcher7.php | 228 ++++++++++++++++++ .../Matcher/Dumper/PhpMatcherDumperTest.php | 21 ++ 4 files changed, 454 insertions(+), 1 deletion(-) create mode 100644 src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher6.php create mode 100644 src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher7.php diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php index 7f0d0520b938f..8eae68c4c280e 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php @@ -238,7 +238,7 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren $hostMatches = false; $methods = $route->getMethods(); - $supportsTrailingSlash = $supportsRedirections && (!$methods || in_array('HEAD', $methods)); + $supportsTrailingSlash = $supportsRedirections && (!$methods || in_array('HEAD', $methods) || in_array('GET', $methods)); $regex = $compiledRoute->getRegex(); if (!count($compiledRoute->getPathVariables()) && false !== preg_match('#^(.)\^(?P.*?)\$\1#'.(substr($regex, -1) === 'u' ? 'u' : ''), $regex, $m)) { diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher6.php b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher6.php new file mode 100644 index 0000000000000..c7645521f5a6e --- /dev/null +++ b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher6.php @@ -0,0 +1,204 @@ +context = $context; + } + + public function match($pathinfo) + { + $allow = array(); + $pathinfo = rawurldecode($pathinfo); + $trimmedPathinfo = rtrim($pathinfo, '/'); + $context = $this->context; + $request = $this->request; + $requestMethod = $canonicalMethod = $context->getMethod(); + $scheme = $context->getScheme(); + + if ('HEAD' === $requestMethod) { + $canonicalMethod = 'GET'; + } + + + if (0 === strpos($pathinfo, '/trailing/simple')) { + // simple_trailing_slash_no_methods + if ('/trailing/simple/no-methods/' === $pathinfo) { + return array('_route' => 'simple_trailing_slash_no_methods'); + } + + // simple_trailing_slash_GET_method + if ('/trailing/simple/get-method/' === $pathinfo) { + if ('GET' !== $canonicalMethod) { + $allow[] = 'GET'; + goto not_simple_trailing_slash_GET_method; + } + + return array('_route' => 'simple_trailing_slash_GET_method'); + } + not_simple_trailing_slash_GET_method: + + // simple_trailing_slash_HEAD_method + if ('/trailing/simple/head-method/' === $pathinfo) { + if ('HEAD' !== $requestMethod) { + $allow[] = 'HEAD'; + goto not_simple_trailing_slash_HEAD_method; + } + + return array('_route' => 'simple_trailing_slash_HEAD_method'); + } + not_simple_trailing_slash_HEAD_method: + + // simple_trailing_slash_POST_method + if ('/trailing/simple/post-method/' === $pathinfo) { + if ('POST' !== $canonicalMethod) { + $allow[] = 'POST'; + goto not_simple_trailing_slash_POST_method; + } + + return array('_route' => 'simple_trailing_slash_POST_method'); + } + not_simple_trailing_slash_POST_method: + + } + + elseif (0 === strpos($pathinfo, '/trailing/regex')) { + // regex_trailing_slash_no_methods + if (0 === strpos($pathinfo, '/trailing/regex/no-methods') && preg_match('#^/trailing/regex/no\\-methods/(?P[^/]++)/$#s', $pathinfo, $matches)) { + return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_no_methods')), array ()); + } + + // regex_trailing_slash_GET_method + if (0 === strpos($pathinfo, '/trailing/regex/get-method') && preg_match('#^/trailing/regex/get\\-method/(?P[^/]++)/$#s', $pathinfo, $matches)) { + if ('GET' !== $canonicalMethod) { + $allow[] = 'GET'; + goto not_regex_trailing_slash_GET_method; + } + + return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_GET_method')), array ()); + } + not_regex_trailing_slash_GET_method: + + // regex_trailing_slash_HEAD_method + if (0 === strpos($pathinfo, '/trailing/regex/head-method') && preg_match('#^/trailing/regex/head\\-method/(?P[^/]++)/$#s', $pathinfo, $matches)) { + if ('HEAD' !== $requestMethod) { + $allow[] = 'HEAD'; + goto not_regex_trailing_slash_HEAD_method; + } + + return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_HEAD_method')), array ()); + } + not_regex_trailing_slash_HEAD_method: + + // regex_trailing_slash_POST_method + if (0 === strpos($pathinfo, '/trailing/regex/post-method') && preg_match('#^/trailing/regex/post\\-method/(?P[^/]++)/$#s', $pathinfo, $matches)) { + if ('POST' !== $canonicalMethod) { + $allow[] = 'POST'; + goto not_regex_trailing_slash_POST_method; + } + + return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_POST_method')), array ()); + } + not_regex_trailing_slash_POST_method: + + } + + elseif (0 === strpos($pathinfo, '/not-trailing/simple')) { + // simple_not_trailing_slash_no_methods + if ('/not-trailing/simple/no-methods' === $pathinfo) { + return array('_route' => 'simple_not_trailing_slash_no_methods'); + } + + // simple_not_trailing_slash_GET_method + if ('/not-trailing/simple/get-method' === $pathinfo) { + if ('GET' !== $canonicalMethod) { + $allow[] = 'GET'; + goto not_simple_not_trailing_slash_GET_method; + } + + return array('_route' => 'simple_not_trailing_slash_GET_method'); + } + not_simple_not_trailing_slash_GET_method: + + // simple_not_trailing_slash_HEAD_method + if ('/not-trailing/simple/head-method' === $pathinfo) { + if ('HEAD' !== $requestMethod) { + $allow[] = 'HEAD'; + goto not_simple_not_trailing_slash_HEAD_method; + } + + return array('_route' => 'simple_not_trailing_slash_HEAD_method'); + } + not_simple_not_trailing_slash_HEAD_method: + + // simple_not_trailing_slash_POST_method + if ('/not-trailing/simple/post-method' === $pathinfo) { + if ('POST' !== $canonicalMethod) { + $allow[] = 'POST'; + goto not_simple_not_trailing_slash_POST_method; + } + + return array('_route' => 'simple_not_trailing_slash_POST_method'); + } + not_simple_not_trailing_slash_POST_method: + + } + + elseif (0 === strpos($pathinfo, '/not-trailing/regex')) { + // regex_not_trailing_slash_no_methods + if (0 === strpos($pathinfo, '/not-trailing/regex/no-methods') && preg_match('#^/not\\-trailing/regex/no\\-methods/(?P[^/]++)$#s', $pathinfo, $matches)) { + return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_no_methods')), array ()); + } + + // regex_not_trailing_slash_GET_method + if (0 === strpos($pathinfo, '/not-trailing/regex/get-method') && preg_match('#^/not\\-trailing/regex/get\\-method/(?P[^/]++)$#s', $pathinfo, $matches)) { + if ('GET' !== $canonicalMethod) { + $allow[] = 'GET'; + goto not_regex_not_trailing_slash_GET_method; + } + + return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_GET_method')), array ()); + } + not_regex_not_trailing_slash_GET_method: + + // regex_not_trailing_slash_HEAD_method + if (0 === strpos($pathinfo, '/not-trailing/regex/head-method') && preg_match('#^/not\\-trailing/regex/head\\-method/(?P[^/]++)$#s', $pathinfo, $matches)) { + if ('HEAD' !== $requestMethod) { + $allow[] = 'HEAD'; + goto not_regex_not_trailing_slash_HEAD_method; + } + + return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_HEAD_method')), array ()); + } + not_regex_not_trailing_slash_HEAD_method: + + // regex_not_trailing_slash_POST_method + if (0 === strpos($pathinfo, '/not-trailing/regex/post-method') && preg_match('#^/not\\-trailing/regex/post\\-method/(?P[^/]++)$#s', $pathinfo, $matches)) { + if ('POST' !== $canonicalMethod) { + $allow[] = 'POST'; + goto not_regex_not_trailing_slash_POST_method; + } + + return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_POST_method')), array ()); + } + not_regex_not_trailing_slash_POST_method: + + } + + throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException(); + } +} diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher7.php b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher7.php new file mode 100644 index 0000000000000..876a90f2da468 --- /dev/null +++ b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher7.php @@ -0,0 +1,228 @@ +context = $context; + } + + public function match($pathinfo) + { + $allow = array(); + $pathinfo = rawurldecode($pathinfo); + $trimmedPathinfo = rtrim($pathinfo, '/'); + $context = $this->context; + $request = $this->request; + $requestMethod = $canonicalMethod = $context->getMethod(); + $scheme = $context->getScheme(); + + if ('HEAD' === $requestMethod) { + $canonicalMethod = 'GET'; + } + + + if (0 === strpos($pathinfo, '/trailing/simple')) { + // simple_trailing_slash_no_methods + if ('/trailing/simple/no-methods' === $trimmedPathinfo) { + if (substr($pathinfo, -1) !== '/') { + return $this->redirect($pathinfo.'/', 'simple_trailing_slash_no_methods'); + } + + return array('_route' => 'simple_trailing_slash_no_methods'); + } + + // simple_trailing_slash_GET_method + if ('/trailing/simple/get-method' === $trimmedPathinfo) { + if ('GET' !== $canonicalMethod) { + $allow[] = 'GET'; + goto not_simple_trailing_slash_GET_method; + } + + if (substr($pathinfo, -1) !== '/') { + return $this->redirect($pathinfo.'/', 'simple_trailing_slash_GET_method'); + } + + return array('_route' => 'simple_trailing_slash_GET_method'); + } + not_simple_trailing_slash_GET_method: + + // simple_trailing_slash_HEAD_method + if ('/trailing/simple/head-method' === $trimmedPathinfo) { + if ('HEAD' !== $requestMethod) { + $allow[] = 'HEAD'; + goto not_simple_trailing_slash_HEAD_method; + } + + if (substr($pathinfo, -1) !== '/') { + return $this->redirect($pathinfo.'/', 'simple_trailing_slash_HEAD_method'); + } + + return array('_route' => 'simple_trailing_slash_HEAD_method'); + } + not_simple_trailing_slash_HEAD_method: + + // simple_trailing_slash_POST_method + if ('/trailing/simple/post-method/' === $pathinfo) { + if ('POST' !== $canonicalMethod) { + $allow[] = 'POST'; + goto not_simple_trailing_slash_POST_method; + } + + return array('_route' => 'simple_trailing_slash_POST_method'); + } + not_simple_trailing_slash_POST_method: + + } + + elseif (0 === strpos($pathinfo, '/trailing/regex')) { + // regex_trailing_slash_no_methods + if (0 === strpos($pathinfo, '/trailing/regex/no-methods') && preg_match('#^/trailing/regex/no\\-methods/(?P[^/]++)/?$#s', $pathinfo, $matches)) { + if (substr($pathinfo, -1) !== '/') { + return $this->redirect($pathinfo.'/', 'regex_trailing_slash_no_methods'); + } + + return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_no_methods')), array ()); + } + + // regex_trailing_slash_GET_method + if (0 === strpos($pathinfo, '/trailing/regex/get-method') && preg_match('#^/trailing/regex/get\\-method/(?P[^/]++)/?$#s', $pathinfo, $matches)) { + if ('GET' !== $canonicalMethod) { + $allow[] = 'GET'; + goto not_regex_trailing_slash_GET_method; + } + + if (substr($pathinfo, -1) !== '/') { + return $this->redirect($pathinfo.'/', 'regex_trailing_slash_GET_method'); + } + + return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_GET_method')), array ()); + } + not_regex_trailing_slash_GET_method: + + // regex_trailing_slash_HEAD_method + if (0 === strpos($pathinfo, '/trailing/regex/head-method') && preg_match('#^/trailing/regex/head\\-method/(?P[^/]++)/?$#s', $pathinfo, $matches)) { + if ('HEAD' !== $requestMethod) { + $allow[] = 'HEAD'; + goto not_regex_trailing_slash_HEAD_method; + } + + if (substr($pathinfo, -1) !== '/') { + return $this->redirect($pathinfo.'/', 'regex_trailing_slash_HEAD_method'); + } + + return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_HEAD_method')), array ()); + } + not_regex_trailing_slash_HEAD_method: + + // regex_trailing_slash_POST_method + if (0 === strpos($pathinfo, '/trailing/regex/post-method') && preg_match('#^/trailing/regex/post\\-method/(?P[^/]++)/$#s', $pathinfo, $matches)) { + if ('POST' !== $canonicalMethod) { + $allow[] = 'POST'; + goto not_regex_trailing_slash_POST_method; + } + + return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_POST_method')), array ()); + } + not_regex_trailing_slash_POST_method: + + } + + elseif (0 === strpos($pathinfo, '/not-trailing/simple')) { + // simple_not_trailing_slash_no_methods + if ('/not-trailing/simple/no-methods' === $pathinfo) { + return array('_route' => 'simple_not_trailing_slash_no_methods'); + } + + // simple_not_trailing_slash_GET_method + if ('/not-trailing/simple/get-method' === $pathinfo) { + if ('GET' !== $canonicalMethod) { + $allow[] = 'GET'; + goto not_simple_not_trailing_slash_GET_method; + } + + return array('_route' => 'simple_not_trailing_slash_GET_method'); + } + not_simple_not_trailing_slash_GET_method: + + // simple_not_trailing_slash_HEAD_method + if ('/not-trailing/simple/head-method' === $pathinfo) { + if ('HEAD' !== $requestMethod) { + $allow[] = 'HEAD'; + goto not_simple_not_trailing_slash_HEAD_method; + } + + return array('_route' => 'simple_not_trailing_slash_HEAD_method'); + } + not_simple_not_trailing_slash_HEAD_method: + + // simple_not_trailing_slash_POST_method + if ('/not-trailing/simple/post-method' === $pathinfo) { + if ('POST' !== $canonicalMethod) { + $allow[] = 'POST'; + goto not_simple_not_trailing_slash_POST_method; + } + + return array('_route' => 'simple_not_trailing_slash_POST_method'); + } + not_simple_not_trailing_slash_POST_method: + + } + + elseif (0 === strpos($pathinfo, '/not-trailing/regex')) { + // regex_not_trailing_slash_no_methods + if (0 === strpos($pathinfo, '/not-trailing/regex/no-methods') && preg_match('#^/not\\-trailing/regex/no\\-methods/(?P[^/]++)$#s', $pathinfo, $matches)) { + return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_no_methods')), array ()); + } + + // regex_not_trailing_slash_GET_method + if (0 === strpos($pathinfo, '/not-trailing/regex/get-method') && preg_match('#^/not\\-trailing/regex/get\\-method/(?P[^/]++)$#s', $pathinfo, $matches)) { + if ('GET' !== $canonicalMethod) { + $allow[] = 'GET'; + goto not_regex_not_trailing_slash_GET_method; + } + + return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_GET_method')), array ()); + } + not_regex_not_trailing_slash_GET_method: + + // regex_not_trailing_slash_HEAD_method + if (0 === strpos($pathinfo, '/not-trailing/regex/head-method') && preg_match('#^/not\\-trailing/regex/head\\-method/(?P[^/]++)$#s', $pathinfo, $matches)) { + if ('HEAD' !== $requestMethod) { + $allow[] = 'HEAD'; + goto not_regex_not_trailing_slash_HEAD_method; + } + + return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_HEAD_method')), array ()); + } + not_regex_not_trailing_slash_HEAD_method: + + // regex_not_trailing_slash_POST_method + if (0 === strpos($pathinfo, '/not-trailing/regex/post-method') && preg_match('#^/not\\-trailing/regex/post\\-method/(?P[^/]++)$#s', $pathinfo, $matches)) { + if ('POST' !== $canonicalMethod) { + $allow[] = 'POST'; + goto not_regex_not_trailing_slash_POST_method; + } + + return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_POST_method')), array ()); + } + not_regex_not_trailing_slash_POST_method: + + } + + throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException(); + } +} diff --git a/src/Symfony/Component/Routing/Tests/Matcher/Dumper/PhpMatcherDumperTest.php b/src/Symfony/Component/Routing/Tests/Matcher/Dumper/PhpMatcherDumperTest.php index e26b48e78d1f5..9d4f086be7702 100644 --- a/src/Symfony/Component/Routing/Tests/Matcher/Dumper/PhpMatcherDumperTest.php +++ b/src/Symfony/Component/Routing/Tests/Matcher/Dumper/PhpMatcherDumperTest.php @@ -345,12 +345,33 @@ public function getRouteCollections() $groupOptimisedCollection->add('slashed_b', new Route('/slashed/group/b/')); $groupOptimisedCollection->add('slashed_c', new Route('/slashed/group/c/')); + $trailingSlashCollection = new RouteCollection(); + $trailingSlashCollection->add('simple_trailing_slash_no_methods', new Route('/trailing/simple/no-methods/', array(), array(), array(), '', array(), array())); + $trailingSlashCollection->add('simple_trailing_slash_GET_method', new Route('/trailing/simple/get-method/', array(), array(), array(), '', array(), array('GET'))); + $trailingSlashCollection->add('simple_trailing_slash_HEAD_method', new Route('/trailing/simple/head-method/', array(), array(), array(), '', array(), array('HEAD'))); + $trailingSlashCollection->add('simple_trailing_slash_POST_method', new Route('/trailing/simple/post-method/', array(), array(), array(), '', array(), array('POST'))); + $trailingSlashCollection->add('regex_trailing_slash_no_methods', new Route('/trailing/regex/no-methods/{param}/', array(), array(), array(), '', array(), array())); + $trailingSlashCollection->add('regex_trailing_slash_GET_method', new Route('/trailing/regex/get-method/{param}/', array(), array(), array(), '', array(), array('GET'))); + $trailingSlashCollection->add('regex_trailing_slash_HEAD_method', new Route('/trailing/regex/head-method/{param}/', array(), array(), array(), '', array(), array('HEAD'))); + $trailingSlashCollection->add('regex_trailing_slash_POST_method', new Route('/trailing/regex/post-method/{param}/', array(), array(), array(), '', array(), array('POST'))); + + $trailingSlashCollection->add('simple_not_trailing_slash_no_methods', new Route('/not-trailing/simple/no-methods', array(), array(), array(), '', array(), array())); + $trailingSlashCollection->add('simple_not_trailing_slash_GET_method', new Route('/not-trailing/simple/get-method', array(), array(), array(), '', array(), array('GET'))); + $trailingSlashCollection->add('simple_not_trailing_slash_HEAD_method', new Route('/not-trailing/simple/head-method', array(), array(), array(), '', array(), array('HEAD'))); + $trailingSlashCollection->add('simple_not_trailing_slash_POST_method', new Route('/not-trailing/simple/post-method', array(), array(), array(), '', array(), array('POST'))); + $trailingSlashCollection->add('regex_not_trailing_slash_no_methods', new Route('/not-trailing/regex/no-methods/{param}', array(), array(), array(), '', array(), array())); + $trailingSlashCollection->add('regex_not_trailing_slash_GET_method', new Route('/not-trailing/regex/get-method/{param}', array(), array(), array(), '', array(), array('GET'))); + $trailingSlashCollection->add('regex_not_trailing_slash_HEAD_method', new Route('/not-trailing/regex/head-method/{param}', array(), array(), array(), '', array(), array('HEAD'))); + $trailingSlashCollection->add('regex_not_trailing_slash_POST_method', new Route('/not-trailing/regex/post-method/{param}', array(), array(), array(), '', array(), array('POST'))); + return array( array($collection, 'url_matcher1.php', array()), array($redirectCollection, 'url_matcher2.php', array('base_class' => 'Symfony\Component\Routing\Tests\Fixtures\RedirectableUrlMatcher')), array($rootprefixCollection, 'url_matcher3.php', array()), array($headMatchCasesCollection, 'url_matcher4.php', array()), array($groupOptimisedCollection, 'url_matcher5.php', array('base_class' => 'Symfony\Component\Routing\Tests\Fixtures\RedirectableUrlMatcher')), + array($trailingSlashCollection, 'url_matcher6.php', array()), + array($trailingSlashCollection, 'url_matcher7.php', array('base_class' => 'Symfony\Component\Routing\Tests\Fixtures\RedirectableUrlMatcher')), ); } } From f42c73f213b85ce173401dd416691a275a06f860 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Wed, 31 May 2017 17:48:21 +0200 Subject: [PATCH 27/57] [Form] Fix \IntlDateFormatter timezone parameter usage to bypass PHP bug #66323 --- .../DataTransformer/DateTimeToLocalizedStringTransformer.php | 4 ++++ src/Symfony/Component/Form/Extension/Core/Type/DateType.php | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.php index 9411de82b4393..e1db36bda663d 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.php @@ -163,6 +163,10 @@ protected function getIntlDateFormatter($ignoreTimezone = false) $dateFormat = $this->dateFormat; $timeFormat = $this->timeFormat; $timezone = $ignoreTimezone ? 'UTC' : $this->outputTimezone; + if (class_exists('IntlTimeZone', false)) { + // see https://bugs.php.net/bug.php?id=66323 + $timezone = \IntlTimeZone::createTimeZone($timezone); + } $calendar = $this->calendar; $pattern = $this->pattern; diff --git a/src/Symfony/Component/Form/Extension/Core/Type/DateType.php b/src/Symfony/Component/Form/Extension/Core/Type/DateType.php index 2bc433f8414f2..fdb7ff59e7022 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/DateType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/DateType.php @@ -77,7 +77,8 @@ public function buildForm(FormBuilderInterface $builder, array $options) \Locale::getDefault(), $dateFormat, $timeFormat, - null, + // see https://bugs.php.net/bug.php?id=66323 + class_exists('IntlTimeZone', false) ? \IntlTimeZone::createDefault() : null, $calendar, $pattern ); From 9578fd3eb6c3e9ab8cccd5a64cb12275f53c9b38 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Thu, 1 Jun 2017 06:36:44 -0400 Subject: [PATCH 28/57] Adding a new event subscriber that "parses" the _controller attribute in the FW --- .../ResolveControllerNameSubscriber.php | 48 +++++++++++++++++ .../FrameworkBundle/Resources/config/web.xml | 5 ++ .../ResolveControllerNameSubscriberTest.php | 54 +++++++++++++++++++ .../SubRequestServiceResolutionController.php | 38 +++++++++++++ .../Tests/Functional/SubRequestsTest.php | 8 +++ .../ControllerServiceResolution/bundles.php | 18 +++++++ .../ControllerServiceResolution/config.yml | 10 ++++ .../ControllerServiceResolution/routing.yml | 4 ++ 8 files changed, 185 insertions(+) create mode 100644 src/Symfony/Bundle/FrameworkBundle/EventListener/ResolveControllerNameSubscriber.php create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/ResolveControllerNameSubscriberTest.php create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/SubRequestServiceResolutionController.php create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/ControllerServiceResolution/bundles.php create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/ControllerServiceResolution/config.yml create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/ControllerServiceResolution/routing.yml diff --git a/src/Symfony/Bundle/FrameworkBundle/EventListener/ResolveControllerNameSubscriber.php b/src/Symfony/Bundle/FrameworkBundle/EventListener/ResolveControllerNameSubscriber.php new file mode 100644 index 0000000000000..b083bb7ba8723 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/EventListener/ResolveControllerNameSubscriber.php @@ -0,0 +1,48 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\EventListener; + +use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\KernelEvents; + +/** + * Guarantees that the _controller key is parsed into its final format. + * + * @author Ryan Weaver + */ +class ResolveControllerNameSubscriber implements EventSubscriberInterface +{ + private $parser; + + public function __construct(ControllerNameParser $parser) + { + $this->parser = $parser; + } + + public function onKernelRequest(GetResponseEvent $event) + { + $controller = $event->getRequest()->attributes->get('_controller'); + if ($controller && false === strpos($controller, '::') && 2 === substr_count($controller, ':')) { + // controller in the a:b:c notation then + $event->getRequest()->attributes->set('_controller', $this->parser->parse($controller)); + } + } + + public static function getSubscribedEvents() + { + return array( + KernelEvents::REQUEST => array('onKernelRequest', 24), + ); + } +} diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml index 0203bf048bc2f..1eed0e92f6c21 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml @@ -70,5 +70,10 @@ + + + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/ResolveControllerNameSubscriberTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/ResolveControllerNameSubscriberTest.php new file mode 100644 index 0000000000000..e5cc6d28a4e9d --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/ResolveControllerNameSubscriberTest.php @@ -0,0 +1,54 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\Tests\EventListener; + +use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser; +use Symfony\Bundle\FrameworkBundle\EventListener\ResolveControllerNameSubscriber; +use Symfony\Bundle\FrameworkBundle\Tests\TestCase; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\HttpKernelInterface; + +class ResolveControllerNameSubscriberTest extends TestCase +{ + public function testReplacesControllerAttribute() + { + $parser = $this->getMockBuilder(ControllerNameParser::class)->disableOriginalConstructor()->getMock(); + $parser->expects($this->any()) + ->method('parse') + ->with('AppBundle:Starting:format') + ->willReturn('App\\Final\\Format::methodName'); + $httpKernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + + $request = new Request(); + $request->attributes->set('_controller', 'AppBundle:Starting:format'); + + $subscriber = new ResolveControllerNameSubscriber($parser); + $subscriber->onKernelRequest(new GetResponseEvent($httpKernel, $request, HttpKernelInterface::MASTER_REQUEST)); + $this->assertEquals('App\\Final\\Format::methodName', $request->attributes->get('_controller')); + } + + public function testSkipsOtherControllerFormats() + { + $parser = $this->getMockBuilder(ControllerNameParser::class)->disableOriginalConstructor()->getMock(); + $parser->expects($this->never()) + ->method('parse'); + $httpKernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + + $request = new Request(); + $request->attributes->set('_controller', 'Other:format'); + + $subscriber = new ResolveControllerNameSubscriber($parser); + $subscriber->onKernelRequest(new GetResponseEvent($httpKernel, $request, HttpKernelInterface::MASTER_REQUEST)); + $this->assertEquals('Other:format', $request->attributes->get('_controller')); + } +} diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/SubRequestServiceResolutionController.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/SubRequestServiceResolutionController.php new file mode 100644 index 0000000000000..ae17f605a40f1 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/SubRequestServiceResolutionController.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller; + +use Psr\Log\LoggerInterface; +use Symfony\Component\DependencyInjection\ContainerAwareInterface; +use Symfony\Component\DependencyInjection\ContainerAwareTrait; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\HttpKernelInterface; + +class SubRequestServiceResolutionController implements ContainerAwareInterface +{ + use ContainerAwareTrait; + + public function indexAction() + { + $request = $this->container->get('request_stack')->getCurrentRequest(); + $path['_forwarded'] = $request->attributes; + $path['_controller'] = 'TestBundle:SubRequestServiceResolution:fragment'; + $subRequest = $request->duplicate(array(), null, $path); + + return $this->container->get('http_kernel')->handle($subRequest, HttpKernelInterface::SUB_REQUEST); + } + + public function fragmentAction(LoggerInterface $logger) + { + return new Response('---'); + } +} diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SubRequestsTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SubRequestsTest.php index 2aaeb220f7189..1a87ff928a6e4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SubRequestsTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SubRequestsTest.php @@ -20,4 +20,12 @@ public function testStateAfterSubRequest() $this->assertEquals('--fr/json--en/html--fr/json--http://localhost/subrequest/fragment/en', $client->getResponse()->getContent()); } + + public function testSubRequestControllerServicesAreResolved() + { + $client = $this->createClient(array('test_case' => 'ControllerServiceResolution', 'root_config' => 'config.yml')); + $client->request('GET', 'https://localhost/subrequest'); + + $this->assertEquals('---', $client->getResponse()->getContent()); + } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/ControllerServiceResolution/bundles.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/ControllerServiceResolution/bundles.php new file mode 100644 index 0000000000000..a73987bcc986a --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/ControllerServiceResolution/bundles.php @@ -0,0 +1,18 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestBundle; +use Symfony\Bundle\FrameworkBundle\FrameworkBundle; + +return array( + new FrameworkBundle(), + new TestBundle(), +); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/ControllerServiceResolution/config.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/ControllerServiceResolution/config.yml new file mode 100644 index 0000000000000..d196ce950921a --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/ControllerServiceResolution/config.yml @@ -0,0 +1,10 @@ +imports: + - { resource: ../config/default.yml } + +services: + Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\SubRequestServiceResolutionController: + public: true + tags: [controller.service_arguments] + + logger: { class: Psr\Log\NullLogger } + Psr\Log\LoggerInterface: '@logger' diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/ControllerServiceResolution/routing.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/ControllerServiceResolution/routing.yml new file mode 100644 index 0000000000000..ffd9471525a6c --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/ControllerServiceResolution/routing.yml @@ -0,0 +1,4 @@ +sub_request_page: + path: /subrequest + defaults: + _controller: 'TestBundle:SubRequestServiceResolution:index' From dfb5549f63ec274c8ebfec1ff4e94c5b5dd4f1a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1chym=20Tou=C5=A1ek?= Date: Thu, 1 Jun 2017 15:50:35 +0200 Subject: [PATCH 29/57] [PhpUnitBridge] Fix detection of PHPUnit 5 --- src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php | 2 +- src/Symfony/Bridge/PhpUnit/TextUI/Command.php | 2 +- src/Symfony/Bridge/PhpUnit/TextUI/TestRunner.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php b/src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php index f85dbb367ca9c..2dad6ef0095bc 100644 --- a/src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php +++ b/src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php @@ -16,7 +16,7 @@ use PHPUnit\Framework\TestSuite; use PHPUnit\Framework\Warning; -if (class_exists('PHPUnit_Framework_BaseTestListener')) { +if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) { class_alias('Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListener', 'Symfony\Bridge\PhpUnit\SymfonyTestsListener'); return; diff --git a/src/Symfony/Bridge/PhpUnit/TextUI/Command.php b/src/Symfony/Bridge/PhpUnit/TextUI/Command.php index 77b617fdcc269..408533292a656 100644 --- a/src/Symfony/Bridge/PhpUnit/TextUI/Command.php +++ b/src/Symfony/Bridge/PhpUnit/TextUI/Command.php @@ -13,7 +13,7 @@ use PHPUnit\TextUI\Command as BaseCommand; -if (class_exists('PHPUnit_TextUI_Command')) { +if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) { class_alias('Symfony\Bridge\PhpUnit\Legacy\Command', 'Symfony\Bridge\PhpUnit\TextUI\Command'); return; diff --git a/src/Symfony/Bridge/PhpUnit/TextUI/TestRunner.php b/src/Symfony/Bridge/PhpUnit/TextUI/TestRunner.php index 2d18b4f9afa2b..07fe2d165b627 100644 --- a/src/Symfony/Bridge/PhpUnit/TextUI/TestRunner.php +++ b/src/Symfony/Bridge/PhpUnit/TextUI/TestRunner.php @@ -14,7 +14,7 @@ use PHPUnit\TextUI\TestRunner as BaseRunner; use Symfony\Bridge\PhpUnit\SymfonyTestsListener; -if (class_exists('PHPUnit_TextUI_Command')) { +if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) { class_alias('Symfony\Bridge\PhpUnit\Legacy\TestRunner', 'Symfony\Bridge\PhpUnit\TextUI\TestRunner'); return; From 28b253ab40620dbf74df16f4ee8705d557fdd5d2 Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Thu, 1 Jun 2017 17:20:33 +0200 Subject: [PATCH 30/57] Fix CacheCollectorPass priority --- .../Compiler/CacheCollectorPass.php | 21 ++++++-- .../FrameworkBundle/FrameworkBundle.php | 2 +- .../Resources/config/cache_debug.xml | 4 +- .../Compiler/CacheCollectorPassTest.php | 49 +++++++++++++++++++ 4 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CacheCollectorPassTest.php diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CacheCollectorPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CacheCollectorPass.php index a4b89144ef717..05e8a00a7925a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CacheCollectorPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CacheCollectorPass.php @@ -16,6 +16,7 @@ use Symfony\Component\Cache\Adapter\TraceableTagAwareAdapter; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; /** @@ -41,13 +42,25 @@ public function process(ContainerBuilder $container) continue; } - $container->register($id.'.recorder', is_subclass_of($definition->getClass(), TagAwareAdapterInterface::class) ? TraceableTagAwareAdapter::class : TraceableAdapter::class) - ->setDecoratedService($id) - ->addArgument(new Reference($id.'.recorder.inner')) - ->setPublic(false); + $recorder = new Definition(is_subclass_of($definition->getClass(), TagAwareAdapterInterface::class) ? TraceableTagAwareAdapter::class : TraceableAdapter::class); + $recorder->setTags($definition->getTags()); + $recorder->setPublic($definition->isPublic()); + $recorder->setArguments(array(new Reference($innerId = $id.'.recorder_inner'))); + + $definition->setTags(array()); + $definition->setPublic(false); + + if ($types = $definition->getAutowiringTypes(false)) { + $recorder->setAutowiringTypes($types); + $definition->setAutowiringTypes(array()); + } + + $container->setDefinition($innerId, $definition); + $container->setDefinition($id, $recorder); // Tell the collector to add the new instance $collectorDefinition->addMethodCall('addInstance', array($id, new Reference($id))); + $collectorDefinition->setPublic(false); } } } diff --git a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php index 1844f9b4a4391..99ab06b337772 100644 --- a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php +++ b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php @@ -115,7 +115,7 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new UnusedTagsPass(), PassConfig::TYPE_AFTER_REMOVING); $container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_BEFORE_REMOVING, -255); $this->addCompilerPassIfExists($container, ConfigCachePass::class); - $container->addCompilerPass(new CacheCollectorPass()); + $container->addCompilerPass(new CacheCollectorPass(), PassConfig::TYPE_BEFORE_REMOVING); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache_debug.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache_debug.xml index 9356d66769c1e..1b9b4077c0dd8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache_debug.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache_debug.xml @@ -7,8 +7,8 @@ - - + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CacheCollectorPassTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CacheCollectorPassTest.php new file mode 100644 index 0000000000000..6a9438ecbd7c8 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CacheCollectorPassTest.php @@ -0,0 +1,49 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler; + +use PHPUnit\Framework\TestCase; +use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CacheCollectorPass; +use Symfony\Component\Cache\Adapter\FilesystemAdapter; +use Symfony\Component\Cache\Adapter\TagAwareAdapter; +use Symfony\Component\Cache\Adapter\TraceableAdapter; +use Symfony\Component\Cache\Adapter\TraceableTagAwareAdapter; +use Symfony\Component\Cache\DataCollector\CacheDataCollector; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Reference; + +class CacheCollectorPassTest extends TestCase +{ + public function testProcess() + { + $container = new ContainerBuilder(); + $container + ->register('fs', FilesystemAdapter::class) + ->addTag('cache.pool'); + $container + ->register('tagged_fs', TagAwareAdapter::class) + ->addArgument(new Reference('fs')) + ->addTag('cache.pool'); + + $collector = $container->register('data_collector.cache', CacheDataCollector::class); + (new CacheCollectorPass())->process($container); + + $this->assertEquals(array( + array('addInstance', array('fs', new Reference('fs'))), + array('addInstance', array('tagged_fs', new Reference('tagged_fs'))), + ), $collector->getMethodCalls()); + + $this->assertSame(TraceableAdapter::class, $container->findDefinition('fs')->getClass()); + $this->assertSame(TraceableTagAwareAdapter::class, $container->getDefinition('tagged_fs')->getClass()); + $this->assertFalse($collector->isPublic(), 'The "data_collector.cache" should be private after processing'); + } +} From c17a009d666007150b9fdeba61521d0760cf4ab6 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 1 Jun 2017 11:24:09 +0200 Subject: [PATCH 31/57] [EventDispatcher] Handle laziness internally instead of relying on ClosureProxyArgument --- .../ContainerAwareEventDispatcher.php | 2 +- .../RegisterListenersPass.php | 7 +- .../EventDispatcher/EventDispatcher.php | 66 +++++++++++++++--- .../Tests/AbstractEventDispatcherTest.php | 67 +++++++++++++++++++ .../RegisterListenersPassTest.php | 9 +-- 5 files changed, 134 insertions(+), 17 deletions(-) diff --git a/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php b/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php index 195acf2e0b6e6..72eca3deb0490 100644 --- a/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php +++ b/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php @@ -116,7 +116,7 @@ public function removeListener($eventName, $listener) public function hasListeners($eventName = null) { if (null === $eventName) { - return (bool) count($this->listenerIds) || (bool) count($this->listeners); + return count($this->listenerIds) || count($this->listeners) || parent::hasListeners(); } if (isset($this->listenerIds[$eventName])) { diff --git a/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php b/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php index 8b2df3ea0f639..50e466a3983c6 100644 --- a/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php +++ b/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php @@ -11,10 +11,11 @@ namespace Symfony\Component\EventDispatcher\DependencyInjection; -use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument; +use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; +use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -78,7 +79,7 @@ public function process(ContainerBuilder $container) $event['method'] = preg_replace('/[^a-z0-9]/i', '', $event['method']); } - $definition->addMethodCall('addListener', array($event['event'], new ClosureProxyArgument($id, $event['method']), $priority)); + $definition->addMethodCall('addListener', array($event['event'], array(new ServiceClosureArgument(new Reference($id)), $event['method']), $priority)); } } @@ -103,7 +104,7 @@ public function process(ContainerBuilder $container) ExtractingEventDispatcher::$subscriber = $class; $extractingDispatcher->addSubscriber($extractingDispatcher); foreach ($extractingDispatcher->listeners as $args) { - $args[1] = new ClosureProxyArgument($id, $args[1]); + $args[1] = array(new ServiceClosureArgument(new Reference($id)), $args[1]); $definition->addMethodCall('addListener', $args); } $extractingDispatcher->listeners = array(); diff --git a/src/Symfony/Component/EventDispatcher/EventDispatcher.php b/src/Symfony/Component/EventDispatcher/EventDispatcher.php index 01bfc0066ea25..4630b01cd8644 100644 --- a/src/Symfony/Component/EventDispatcher/EventDispatcher.php +++ b/src/Symfony/Component/EventDispatcher/EventDispatcher.php @@ -24,6 +24,7 @@ * @author Fabien Potencier * @author Jordi Boggiano * @author Jordan Alliot + * @author Nicolas Grekas */ class EventDispatcher implements EventDispatcherInterface { @@ -52,7 +53,7 @@ public function dispatch($eventName, Event $event = null) public function getListeners($eventName = null) { if (null !== $eventName) { - if (!isset($this->listeners[$eventName])) { + if (empty($this->listeners[$eventName])) { return array(); } @@ -77,13 +78,23 @@ public function getListeners($eventName = null) */ public function getListenerPriority($eventName, $listener) { - if (!isset($this->listeners[$eventName])) { + if (empty($this->listeners[$eventName])) { return; } + if (is_array($listener) && isset($listener[0]) && $listener[0] instanceof \Closure) { + $listener[0] = $listener[0](); + } + foreach ($this->listeners[$eventName] as $priority => $listeners) { - if (false !== in_array($listener, $listeners, true)) { - return $priority; + foreach ($listeners as $k => $v) { + if ($v !== $listener && is_array($v) && isset($v[0]) && $v[0] instanceof \Closure) { + $v[0] = $v[0](); + $this->listeners[$eventName][$priority][$k] = $v; + } + if ($v === $listener) { + return $priority; + } } } } @@ -93,7 +104,17 @@ public function getListenerPriority($eventName, $listener) */ public function hasListeners($eventName = null) { - return (bool) $this->getListeners($eventName); + if (null !== $eventName) { + return !empty($this->listeners[$eventName]); + } + + foreach ($this->listeners as $eventListeners) { + if ($eventListeners) { + return true; + } + } + + return false; } /** @@ -110,13 +131,30 @@ public function addListener($eventName, $listener, $priority = 0) */ public function removeListener($eventName, $listener) { - if (!isset($this->listeners[$eventName])) { + if (empty($this->listeners[$eventName])) { return; } + if (is_array($listener) && isset($listener[0]) && $listener[0] instanceof \Closure) { + $listener[0] = $listener[0](); + } + foreach ($this->listeners[$eventName] as $priority => $listeners) { - if (false !== ($key = array_search($listener, $listeners, true))) { - unset($this->listeners[$eventName][$priority][$key], $this->sorted[$eventName]); + foreach ($listeners as $k => $v) { + if ($v !== $listener && is_array($v) && isset($v[0]) && $v[0] instanceof \Closure) { + $v[0] = $v[0](); + } + if ($v === $listener) { + unset($listeners[$k], $this->sorted[$eventName]); + } else { + $listeners[$k] = $v; + } + } + + if ($listeners) { + $this->listeners[$eventName][$priority] = $listeners; + } else { + unset($this->listeners[$eventName][$priority]); } } } @@ -183,6 +221,16 @@ protected function doDispatch($listeners, $eventName, Event $event) private function sortListeners($eventName) { krsort($this->listeners[$eventName]); - $this->sorted[$eventName] = call_user_func_array('array_merge', $this->listeners[$eventName]); + $this->sorted[$eventName] = array(); + + foreach ($this->listeners[$eventName] as $priority => $listeners) { + foreach ($listeners as $k => $listener) { + if (is_array($listener) && isset($listener[0]) && $listener[0] instanceof \Closure) { + $listener[0] = $listener[0](); + $this->listeners[$eventName][$priority][$k] = $listener; + } + $this->sorted[$eventName][] = $listener; + } + } } } diff --git a/src/Symfony/Component/EventDispatcher/Tests/AbstractEventDispatcherTest.php b/src/Symfony/Component/EventDispatcher/Tests/AbstractEventDispatcherTest.php index 5943039c9e6de..b3fd66927f2b5 100644 --- a/src/Symfony/Component/EventDispatcher/Tests/AbstractEventDispatcherTest.php +++ b/src/Symfony/Component/EventDispatcher/Tests/AbstractEventDispatcherTest.php @@ -302,6 +302,73 @@ public function testHasListenersWithoutEventsReturnsFalseAfterHasListenersWithEv $this->assertFalse($this->dispatcher->hasListeners('foo')); $this->assertFalse($this->dispatcher->hasListeners()); } + + public function testHasListenersIsLazy() + { + $called = 0; + $listener = array(function () use (&$called) { ++$called; }, 'onFoo'); + $this->dispatcher->addListener('foo', $listener); + $this->assertTrue($this->dispatcher->hasListeners()); + $this->assertTrue($this->dispatcher->hasListeners('foo')); + $this->assertSame(0, $called); + } + + public function testDispatchLazyListener() + { + $called = 0; + $factory = function () use (&$called) { + ++$called; + + return new TestWithDispatcher(); + }; + $this->dispatcher->addListener('foo', array($factory, 'foo')); + $this->assertSame(0, $called); + $this->dispatcher->dispatch('foo', new Event()); + $this->dispatcher->dispatch('foo', new Event()); + $this->assertSame(1, $called); + } + + public function testRemoveFindsLazyListeners() + { + $test = new TestWithDispatcher(); + $factory = function () use ($test) { return $test; }; + + $this->dispatcher->addListener('foo', array($factory, 'foo')); + $this->assertTrue($this->dispatcher->hasListeners('foo')); + $this->dispatcher->removeListener('foo', array($test, 'foo')); + $this->assertFalse($this->dispatcher->hasListeners('foo')); + + $this->dispatcher->addListener('foo', array($test, 'foo')); + $this->assertTrue($this->dispatcher->hasListeners('foo')); + $this->dispatcher->removeListener('foo', array($factory, 'foo')); + $this->assertFalse($this->dispatcher->hasListeners('foo')); + } + + public function testPriorityFindsLazyListeners() + { + $test = new TestWithDispatcher(); + $factory = function () use ($test) { return $test; }; + + $this->dispatcher->addListener('foo', array($factory, 'foo'), 3); + $this->assertSame(3, $this->dispatcher->getListenerPriority('foo', array($test, 'foo'))); + $this->dispatcher->removeListener('foo', array($factory, 'foo')); + + $this->dispatcher->addListener('foo', array($test, 'foo'), 5); + $this->assertSame(5, $this->dispatcher->getListenerPriority('foo', array($factory, 'foo'))); + } + + public function testGetLazyListeners() + { + $test = new TestWithDispatcher(); + $factory = function () use ($test) { return $test; }; + + $this->dispatcher->addListener('foo', array($factory, 'foo'), 3); + $this->assertSame(array(array($test, 'foo')), $this->dispatcher->getListeners('foo')); + + $this->dispatcher->removeListener('foo', array($test, 'foo')); + $this->dispatcher->addListener('bar', array($factory, 'foo'), 3); + $this->assertSame(array('bar' => array(array($test, 'foo'))), $this->dispatcher->getListeners()); + } } class CallableClass diff --git a/src/Symfony/Component/EventDispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php b/src/Symfony/Component/EventDispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php index f583cd04cf9a7..d46d8c591195f 100644 --- a/src/Symfony/Component/EventDispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php +++ b/src/Symfony/Component/EventDispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php @@ -12,8 +12,9 @@ namespace Symfony\Component\EventDispatcher\Tests\DependencyInjection; use PHPUnit\Framework\TestCase; -use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument; +use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass; class RegisterListenersPassTest extends TestCase @@ -127,17 +128,17 @@ public function testEventSubscriberResolvableClassName() $registerListenersPass->process($container); $definition = $container->getDefinition('event_dispatcher'); - $expected_calls = array( + $expectedCalls = array( array( 'addListener', array( 'event', - new ClosureProxyArgument('foo', 'onEvent'), + array(new ServiceClosureArgument(new Reference('foo')), 'onEvent'), 0, ), ), ); - $this->assertEquals($expected_calls, $definition->getMethodCalls()); + $this->assertEquals($expectedCalls, $definition->getMethodCalls()); } /** From f91a020b842ed05f26656f4957e2dbc87e8fe1c8 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 1 Jun 2017 10:56:34 -0700 Subject: [PATCH 32/57] Using FQ name for PHP_VERSION_ID --- .github/build-packages.php | 2 +- phpunit | 2 +- .../Bridge/Twig/Extension/CodeExtension.php | 2 +- .../Bridge/Twig/Tests/Node/DumpNodeTest.php | 8 +++---- .../Bridge/Twig/Tests/Node/FormThemeTest.php | 4 ++-- .../Node/SearchAndRenderBlockNodeTest.php | 4 ++-- .../Bridge/Twig/Tests/Node/TransNodeTest.php | 8 +++---- .../FrameworkBundle/Command/ServerCommand.php | 2 +- .../Templating/Helper/CodeHelper.php | 2 +- .../Translation/PhpExtractor.php | 2 +- .../ClassLoader/ClassCollectionLoader.php | 2 +- .../ClassLoader/ClassMapGenerator.php | 4 ++-- .../Tests/ClassMapGeneratorTest.php | 4 ++-- .../Console/Descriptor/TextDescriptor.php | 2 +- src/Symfony/Component/Debug/ErrorHandler.php | 2 +- .../Component/Debug/ExceptionHandler.php | 4 ++-- .../Debug/Tests/DebugClassLoaderTest.php | 6 ++--- .../Component/ExpressionLanguage/Parser.php | 2 +- .../Finder/Iterator/FilterIterator.php | 2 +- .../Iterator/RecursiveDirectoryIterator.php | 2 +- .../Form/Extension/Core/Type/DateType.php | 2 +- .../Csrf/CsrfProvider/DefaultCsrfProvider.php | 2 +- .../Validator/ValidatorTypeGuesserTest.php | 2 +- .../Component/HttpFoundation/JsonResponse.php | 10 ++++---- .../Component/HttpFoundation/Request.php | 2 +- .../Storage/Handler/NativeSessionHandler.php | 2 +- .../Session/Storage/NativeSessionStorage.php | 14 +++++------ .../Session/Storage/Proxy/AbstractProxy.php | 4 ++-- .../HttpFoundation/Tests/RequestTest.php | 2 +- .../Handler/NativeFileSessionHandlerTest.php | 2 +- .../Handler/NativeSessionHandlerTest.php | 2 +- .../Storage/NativeSessionStorageTest.php | 4 ++-- .../Storage/PhpBridgeSessionStorageTest.php | 2 +- .../Storage/Proxy/AbstractProxyTest.php | 8 +++---- .../Storage/Proxy/SessionHandlerProxyTest.php | 2 +- .../DataCollector/DumpDataCollector.php | 4 ++-- .../Fragment/HIncludeFragmentRenderer.php | 2 +- src/Symfony/Component/HttpKernel/Kernel.php | 2 +- .../Controller/ControllerResolverTest.php | 2 +- .../DataCollector/DumpDataCollectorTest.php | 6 ++--- .../Data/Bundle/Writer/JsonBundleWriter.php | 2 +- .../Intl/DateFormatter/IntlDateFormatter.php | 8 +++---- .../Intl/NumberFormatter/NumberFormatter.php | 4 ++-- .../Bundle/Reader/IntlBundleReaderTest.php | 4 ++-- .../Bundle/Writer/JsonBundleWriterTest.php | 2 +- .../Bundle/Writer/PhpBundleWriterTest.php | 2 +- .../AbstractIntlDateFormatterTest.php | 24 +++++++++---------- .../AbstractNumberFormatterTest.php | 6 ++--- .../PropertyAccess/PropertyAccessor.php | 4 ++-- .../Routing/Loader/AnnotationFileLoader.php | 2 +- .../NativeSessionTokenStorage.php | 2 +- .../Session/SessionAuthenticationStrategy.php | 2 +- .../SessionAuthenticationStrategyTest.php | 4 ++-- .../Serializer/Encoder/JsonDecode.php | 2 +- .../Component/Templating/PhpEngine.php | 2 +- .../Tests/Dumper/JsonFileDumperTest.php | 2 +- .../AbstractComparisonValidatorTestCase.php | 4 ++-- .../Constraints/IdenticalToValidatorTest.php | 2 +- .../Tests/Constraints/RangeValidatorTest.php | 6 ++--- .../Component/VarDumper/Cloner/VarCloner.php | 2 +- .../VarDumper/Tests/CliDumperTest.php | 4 ++-- .../VarDumper/Tests/HtmlDumperTest.php | 2 +- .../Tests/Test/VarDumperTestTraitTest.php | 2 +- .../Yaml/Exception/ParseException.php | 2 +- .../Yaml/Tests/ParseExceptionTest.php | 4 ++-- 65 files changed, 121 insertions(+), 121 deletions(-) diff --git a/.github/build-packages.php b/.github/build-packages.php index 02a2239732be2..56112b753ad32 100644 --- a/.github/build-packages.php +++ b/.github/build-packages.php @@ -11,7 +11,7 @@ $mergeBase = trim(shell_exec(sprintf('git merge-base %s HEAD', array_shift($dirs)))); $packages = array(); -$flags = PHP_VERSION_ID >= 50400 ? JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE : 0; +$flags = \PHP_VERSION_ID >= 50400 ? JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE : 0; foreach ($dirs as $k => $dir) { if (!system("git diff --name-only $mergeBase -- $dir", $exitStatus)) { diff --git a/phpunit b/phpunit index 559660b1df25f..53e1a8dc31dbf 100755 --- a/phpunit +++ b/phpunit @@ -7,7 +7,7 @@ if (!file_exists(__DIR__.'/vendor/symfony/phpunit-bridge/bin/simple-phpunit')) { echo "Unable to find the `simple-phpunit` script in `vendor/symfony/phpunit-bridge/bin/`.\nPlease run `composer update` before running this command.\n"; exit(1); } -if (PHP_VERSION_ID >= 70000 && !getenv('SYMFONY_PHPUNIT_VERSION')) { +if (\PHP_VERSION_ID >= 70000 && !getenv('SYMFONY_PHPUNIT_VERSION')) { putenv('SYMFONY_PHPUNIT_VERSION=6.0'); } putenv('SYMFONY_PHPUNIT_DIR='.__DIR__.'/.phpunit'); diff --git a/src/Symfony/Bridge/Twig/Extension/CodeExtension.php b/src/Symfony/Bridge/Twig/Extension/CodeExtension.php index 59dbeec7e995b..4b25d62198341 100644 --- a/src/Symfony/Bridge/Twig/Extension/CodeExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/CodeExtension.php @@ -174,7 +174,7 @@ public function formatFile($file, $line, $text = null) $text = "$text at line $line"; if (false !== $link = $this->getFileLink($file, $line)) { - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { $flags = ENT_QUOTES | ENT_SUBSTITUTE; } else { $flags = ENT_QUOTES; diff --git a/src/Symfony/Bridge/Twig/Tests/Node/DumpNodeTest.php b/src/Symfony/Bridge/Twig/Tests/Node/DumpNodeTest.php index 93c8433c2894e..e38d9c728283b 100644 --- a/src/Symfony/Bridge/Twig/Tests/Node/DumpNodeTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Node/DumpNodeTest.php @@ -81,9 +81,9 @@ public function testOneVar() } EOTXT; - if (PHP_VERSION_ID >= 70000) { + if (\PHP_VERSION_ID >= 70000) { $expected = preg_replace('/%(.*?)%/', '($context["$1"] ?? null)', $expected); - } elseif (PHP_VERSION_ID >= 50400) { + } elseif (\PHP_VERSION_ID >= 50400) { $expected = preg_replace('/%(.*?)%/', '(isset($context["$1"]) ? $context["$1"] : null)', $expected); } else { $expected = preg_replace('/%(.*?)%/', '$this->getContext($context, "$1")', $expected); @@ -114,9 +114,9 @@ public function testMultiVars() EOTXT; - if (PHP_VERSION_ID >= 70000) { + if (\PHP_VERSION_ID >= 70000) { $expected = preg_replace('/%(.*?)%/', '($context["$1"] ?? null)', $expected); - } elseif (PHP_VERSION_ID >= 50400) { + } elseif (\PHP_VERSION_ID >= 50400) { $expected = preg_replace('/%(.*?)%/', '(isset($context["$1"]) ? $context["$1"] : null)', $expected); } else { $expected = preg_replace('/%(.*?)%/', '$this->getContext($context, "$1")', $expected); diff --git a/src/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php b/src/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php index 4202355594745..923c20ff35d5f 100644 --- a/src/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php @@ -67,11 +67,11 @@ public function testCompile() protected function getVariableGetter($name) { - if (PHP_VERSION_ID >= 70000) { + if (\PHP_VERSION_ID >= 70000) { return sprintf('($context["%s"] ?? null)', $name, $name); } - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name); } diff --git a/src/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php b/src/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php index 69b987e83297f..e29f66ea3c56b 100644 --- a/src/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php @@ -264,11 +264,11 @@ public function testCompileLabelWithLabelThatEvaluatesToNullAndAttributes() protected function getVariableGetter($name) { - if (PHP_VERSION_ID >= 70000) { + if (\PHP_VERSION_ID >= 70000) { return sprintf('($context["%s"] ?? null)', $name, $name); } - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name); } diff --git a/src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php b/src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php index 683d47af27aea..aabd813e5c5ac 100644 --- a/src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php @@ -40,11 +40,11 @@ public function testCompileStrict() protected function getVariableGetterWithoutStrictCheck($name) { - if (PHP_VERSION_ID >= 70000) { + if (\PHP_VERSION_ID >= 70000) { return sprintf('($context["%s"] ?? null)', $name, $name); } - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name); } @@ -57,11 +57,11 @@ protected function getVariableGetterWithStrictCheck($name) return sprintf('(isset($context["%s"]) || array_key_exists("%s", $context) ? $context["%s"] : (function () { throw new Twig_Error_Runtime(\'Variable "%s" does not exist.\', 0, $this->getSourceContext()); })())', $name, $name, $name, $name); } - if (PHP_VERSION_ID >= 70000) { + if (\PHP_VERSION_ID >= 70000) { return sprintf('($context["%s"] ?? $this->getContext($context, "%s"))', $name, $name, $name); } - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { return sprintf('(isset($context["%s"]) ? $context["%s"] : $this->getContext($context, "%s"))', $name, $name, $name); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ServerCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ServerCommand.php index 3e1c324f00203..c5f9ee0ecd21d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ServerCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ServerCommand.php @@ -23,7 +23,7 @@ abstract class ServerCommand extends ContainerAwareCommand */ public function isEnabled() { - if (PHP_VERSION_ID < 50400 || defined('HHVM_VERSION')) { + if (\PHP_VERSION_ID < 50400 || defined('HHVM_VERSION')) { return false; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php index cdf19e3ada807..06071e51b276c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php @@ -154,7 +154,7 @@ public function fileExcerpt($file, $line) */ public function formatFile($file, $line, $text = null) { - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { $flags = ENT_QUOTES | ENT_SUBSTITUTE; } else { $flags = ENT_QUOTES; diff --git a/src/Symfony/Bundle/FrameworkBundle/Translation/PhpExtractor.php b/src/Symfony/Bundle/FrameworkBundle/Translation/PhpExtractor.php index 97c94fdd14bf9..70658f67232d3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Translation/PhpExtractor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Translation/PhpExtractor.php @@ -85,7 +85,7 @@ public function extract($resource, MessageCatalogue $catalog) foreach ($files as $file) { $this->parseTokens(token_get_all(file_get_contents($file)), $catalog); - if (PHP_VERSION_ID >= 70000) { + if (\PHP_VERSION_ID >= 70000) { // PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098 gc_mem_caches(); } diff --git a/src/Symfony/Component/ClassLoader/ClassCollectionLoader.php b/src/Symfony/Component/ClassLoader/ClassCollectionLoader.php index 6f88286de0ff5..cd3c433ed200a 100644 --- a/src/Symfony/Component/ClassLoader/ClassCollectionLoader.php +++ b/src/Symfony/Component/ClassLoader/ClassCollectionLoader.php @@ -232,7 +232,7 @@ public static function fixNamespaceDeclarations($source) $output .= self::compressCode($rawChunk); - if (PHP_VERSION_ID >= 70000) { + if (\PHP_VERSION_ID >= 70000) { // PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098 unset($tokens, $rawChunk); gc_mem_caches(); diff --git a/src/Symfony/Component/ClassLoader/ClassMapGenerator.php b/src/Symfony/Component/ClassLoader/ClassMapGenerator.php index 2976eb81c09cf..a35c90ca10d8b 100644 --- a/src/Symfony/Component/ClassLoader/ClassMapGenerator.php +++ b/src/Symfony/Component/ClassLoader/ClassMapGenerator.php @@ -12,7 +12,7 @@ namespace Symfony\Component\ClassLoader; if (!defined('SYMFONY_TRAIT')) { - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { define('SYMFONY_TRAIT', T_TRAIT); } else { define('SYMFONY_TRAIT', 0); @@ -72,7 +72,7 @@ public static function createMap($dir) $classes = self::findClasses($path); - if (PHP_VERSION_ID >= 70000) { + if (\PHP_VERSION_ID >= 70000) { // PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098 gc_mem_caches(); } diff --git a/src/Symfony/Component/ClassLoader/Tests/ClassMapGeneratorTest.php b/src/Symfony/Component/ClassLoader/Tests/ClassMapGeneratorTest.php index db7fb962cedde..c12182497a01b 100644 --- a/src/Symfony/Component/ClassLoader/Tests/ClassMapGeneratorTest.php +++ b/src/Symfony/Component/ClassLoader/Tests/ClassMapGeneratorTest.php @@ -108,7 +108,7 @@ public function getTestCreateMapTests() )), ); - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { $data[] = array(__DIR__.'/Fixtures/php5.4', array( 'TFoo' => __DIR__.'/Fixtures/php5.4/traits.php', 'CFoo' => __DIR__.'/Fixtures/php5.4/traits.php', @@ -119,7 +119,7 @@ public function getTestCreateMapTests() )); } - if (PHP_VERSION_ID >= 50500) { + if (\PHP_VERSION_ID >= 50500) { $data[] = array(__DIR__.'/Fixtures/php5.5', array( 'ClassCons\\Foo' => __DIR__.'/Fixtures/php5.5/class_cons.php', )); diff --git a/src/Symfony/Component/Console/Descriptor/TextDescriptor.php b/src/Symfony/Component/Console/Descriptor/TextDescriptor.php index b49b64d5acfa8..c0dd4830c3d2d 100644 --- a/src/Symfony/Component/Console/Descriptor/TextDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/TextDescriptor.php @@ -247,7 +247,7 @@ private function formatDefaultValue($default) } } - if (PHP_VERSION_ID < 50400) { + if (\PHP_VERSION_ID < 50400) { return str_replace(array('\/', '\\\\'), array('/', '\\'), json_encode($default)); } diff --git a/src/Symfony/Component/Debug/ErrorHandler.php b/src/Symfony/Component/Debug/ErrorHandler.php index 46bcc33f67f57..7624d1213f711 100644 --- a/src/Symfony/Component/Debug/ErrorHandler.php +++ b/src/Symfony/Component/Debug/ErrorHandler.php @@ -404,7 +404,7 @@ public function handleError($type, $message, $file, $line) $throw = new \ErrorException($this->levels[$type].': '.$message, 0, $type, $file, $line); } - if (PHP_VERSION_ID <= 50407 && (PHP_VERSION_ID >= 50400 || PHP_VERSION_ID <= 50317)) { + if (\PHP_VERSION_ID <= 50407 && (\PHP_VERSION_ID >= 50400 || \PHP_VERSION_ID <= 50317)) { // Exceptions thrown from error handlers are sometimes not caught by the exception // handler and shutdown handlers are bypassed before 5.4.8/5.3.18. // We temporarily re-enable display_errors to prevent any blank page related to this bug. diff --git a/src/Symfony/Component/Debug/ExceptionHandler.php b/src/Symfony/Component/Debug/ExceptionHandler.php index 23929b3946c0f..e0d7a0580cb70 100644 --- a/src/Symfony/Component/Debug/ExceptionHandler.php +++ b/src/Symfony/Component/Debug/ExceptionHandler.php @@ -434,7 +434,7 @@ protected static function utf8Htmlize($str) { @trigger_error('The '.__METHOD__.' method is deprecated since version 2.7 and will be removed in 3.0.', E_USER_DEPRECATED); - return htmlspecialchars($str, ENT_QUOTES | (PHP_VERSION_ID >= 50400 ? ENT_SUBSTITUTE : 0), 'UTF-8'); + return htmlspecialchars($str, ENT_QUOTES | (\PHP_VERSION_ID >= 50400 ? ENT_SUBSTITUTE : 0), 'UTF-8'); } /** @@ -442,7 +442,7 @@ protected static function utf8Htmlize($str) */ private function escapeHtml($str) { - return htmlspecialchars($str, ENT_QUOTES | (PHP_VERSION_ID >= 50400 ? ENT_SUBSTITUTE : 0), $this->charset); + return htmlspecialchars($str, ENT_QUOTES | (\PHP_VERSION_ID >= 50400 ? ENT_SUBSTITUTE : 0), $this->charset); } /** diff --git a/src/Symfony/Component/Debug/Tests/DebugClassLoaderTest.php b/src/Symfony/Component/Debug/Tests/DebugClassLoaderTest.php index 8d0a027346b38..133ca28e546b7 100644 --- a/src/Symfony/Component/Debug/Tests/DebugClassLoaderTest.php +++ b/src/Symfony/Component/Debug/Tests/DebugClassLoaderTest.php @@ -61,7 +61,7 @@ public function testIdempotence() public function testUnsilencing() { - if (PHP_VERSION_ID >= 70000) { + if (\PHP_VERSION_ID >= 70000) { $this->markTestSkipped('PHP7 throws exceptions, unsilencing is not required anymore.'); } if (defined('HHVM_VERSION')) { @@ -111,7 +111,7 @@ class ChildTestingStacking extends TestingStacking { function foo($bar) {} } restore_error_handler(); restore_exception_handler(); $this->assertStringStartsWith(__FILE__, $exception->getFile()); - if (PHP_VERSION_ID < 70000) { + if (\PHP_VERSION_ID < 70000) { $this->assertRegExp('/^Runtime Notice: Declaration/', $exception->getMessage()); $this->assertEquals(E_STRICT, $exception->getSeverity()); } else { @@ -227,7 +227,7 @@ class_exists('Symfony\Bridge\Debug\Tests\Fixtures\ExtendsDeprecatedParent', true public function testReservedForPhp7() { - if (PHP_VERSION_ID >= 70000) { + if (\PHP_VERSION_ID >= 70000) { $this->markTestSkipped('PHP7 already prevents using reserved names.'); } diff --git a/src/Symfony/Component/ExpressionLanguage/Parser.php b/src/Symfony/Component/ExpressionLanguage/Parser.php index 6f90451522290..d847dfa4b03bc 100644 --- a/src/Symfony/Component/ExpressionLanguage/Parser.php +++ b/src/Symfony/Component/ExpressionLanguage/Parser.php @@ -344,7 +344,7 @@ public function parsePostfixExpression($node) $node = new Node\GetAttrNode($node, $arg, $arguments, $type); } elseif ('[' === $token->value) { - if ($node instanceof Node\GetAttrNode && Node\GetAttrNode::METHOD_CALL === $node->attributes['type'] && PHP_VERSION_ID < 50400) { + if ($node instanceof Node\GetAttrNode && Node\GetAttrNode::METHOD_CALL === $node->attributes['type'] && \PHP_VERSION_ID < 50400) { throw new SyntaxError('Array calls on a method call is only supported on PHP 5.4+', $token->cursor, $this->stream->getExpression()); } diff --git a/src/Symfony/Component/Finder/Iterator/FilterIterator.php b/src/Symfony/Component/Finder/Iterator/FilterIterator.php index 3c3c3fbec0218..acb98361c9643 100644 --- a/src/Symfony/Component/Finder/Iterator/FilterIterator.php +++ b/src/Symfony/Component/Finder/Iterator/FilterIterator.php @@ -29,7 +29,7 @@ abstract class FilterIterator extends \FilterIterator */ public function rewind() { - if (PHP_VERSION_ID > 50607 || (PHP_VERSION_ID > 50523 && PHP_VERSION_ID < 50600)) { + if (\PHP_VERSION_ID > 50607 || (\PHP_VERSION_ID > 50523 && \PHP_VERSION_ID < 50600)) { parent::rewind(); return; diff --git a/src/Symfony/Component/Finder/Iterator/RecursiveDirectoryIterator.php b/src/Symfony/Component/Finder/Iterator/RecursiveDirectoryIterator.php index 1df2f5014f622..c87096fc87e23 100644 --- a/src/Symfony/Component/Finder/Iterator/RecursiveDirectoryIterator.php +++ b/src/Symfony/Component/Finder/Iterator/RecursiveDirectoryIterator.php @@ -119,7 +119,7 @@ public function rewind() } // @see https://bugs.php.net/68557 - if (PHP_VERSION_ID < 50523 || PHP_VERSION_ID >= 50600 && PHP_VERSION_ID < 50607) { + if (\PHP_VERSION_ID < 50523 || \PHP_VERSION_ID >= 50600 && \PHP_VERSION_ID < 50607) { parent::next(); } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/DateType.php b/src/Symfony/Component/Form/Extension/Core/Type/DateType.php index fdb7ff59e7022..d77cdc8e70335 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/DateType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/DateType.php @@ -272,7 +272,7 @@ private function formatTimestamps(\IntlDateFormatter $formatter, $regex, array $ $timezone = $formatter->getTimezoneId(); $formattedTimestamps = array(); - if ($setTimeZone = PHP_VERSION_ID >= 50500 || method_exists($formatter, 'setTimeZone')) { + if ($setTimeZone = \PHP_VERSION_ID >= 50500 || method_exists($formatter, 'setTimeZone')) { $formatter->setTimeZone('UTC'); } else { $formatter->setTimeZoneId('UTC'); diff --git a/src/Symfony/Component/Form/Extension/Csrf/CsrfProvider/DefaultCsrfProvider.php b/src/Symfony/Component/Form/Extension/Csrf/CsrfProvider/DefaultCsrfProvider.php index 7e25a122c6f74..387f4ccf355cb 100644 --- a/src/Symfony/Component/Form/Extension/Csrf/CsrfProvider/DefaultCsrfProvider.php +++ b/src/Symfony/Component/Form/Extension/Csrf/CsrfProvider/DefaultCsrfProvider.php @@ -85,7 +85,7 @@ public function isCsrfTokenValid($intention, $token) */ protected function getSessionId() { - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { if (PHP_SESSION_NONE === session_status()) { session_start(); } diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/ValidatorTypeGuesserTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/ValidatorTypeGuesserTest.php index 6ddac337afea0..2f2d5676a9bd7 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/ValidatorTypeGuesserTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/ValidatorTypeGuesserTest.php @@ -90,7 +90,7 @@ public function testGuessRequired($constraint, $guess) */ public function testLegacyGuessRequired() { - if (PHP_VERSION_ID >= 70000) { + if (\PHP_VERSION_ID >= 70000) { $this->markTestSkipped('Cannot use a class called True on PHP 7 or higher.'); } $true = 'Symfony\Component\Validator\Constraints\True'; diff --git a/src/Symfony/Component/HttpFoundation/JsonResponse.php b/src/Symfony/Component/HttpFoundation/JsonResponse.php index b20e2e28ba3c1..c6e0ba6541061 100644 --- a/src/Symfony/Component/HttpFoundation/JsonResponse.php +++ b/src/Symfony/Component/HttpFoundation/JsonResponse.php @@ -121,7 +121,7 @@ public function setData($data = array()) $data = json_encode($data, $this->encodingOptions); } else { try { - if (PHP_VERSION_ID < 50400) { + if (\PHP_VERSION_ID < 50400) { // PHP 5.3 triggers annoying warnings for some // types that can't be serialized as JSON (INF, resources, etc.) // but doesn't provide the JsonSerializable interface. @@ -131,7 +131,7 @@ public function setData($data = array()) // PHP 5.4 and up wrap exceptions thrown by JsonSerializable // objects in a new exception that needs to be removed. // Fortunately, PHP 5.5 and up do not trigger any warning anymore. - if (PHP_VERSION_ID < 50500) { + if (\PHP_VERSION_ID < 50500) { // Clear json_last_error() json_encode(null); $errorHandler = set_error_handler('var_dump'); @@ -146,14 +146,14 @@ public function setData($data = array()) $data = json_encode($data, $this->encodingOptions); } - if (PHP_VERSION_ID < 50500) { + if (\PHP_VERSION_ID < 50500) { restore_error_handler(); } } catch (\Exception $e) { - if (PHP_VERSION_ID < 50500) { + if (\PHP_VERSION_ID < 50500) { restore_error_handler(); } - if (PHP_VERSION_ID >= 50400 && 'Exception' === get_class($e) && 0 === strpos($e->getMessage(), 'Failed calling ')) { + if (\PHP_VERSION_ID >= 50400 && 'Exception' === get_class($e) && 0 === strpos($e->getMessage(), 'Failed calling ')) { throw $e->getPrevious() ?: $e; } throw $e; diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 0291f9f671aaa..0c11adab6a92e 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -1502,7 +1502,7 @@ public function isMethodCacheable() public function getContent($asResource = false) { $currentContentIsResource = is_resource($this->content); - if (PHP_VERSION_ID < 50600 && false === $this->content) { + if (\PHP_VERSION_ID < 50600 && false === $this->content) { throw new \LogicException('getContent() can only be called once when using the resource return type and PHP below 5.6.'); } diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/NativeSessionHandler.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/NativeSessionHandler.php index 95d5cdbf56310..03acbd94ee343 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/NativeSessionHandler.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/NativeSessionHandler.php @@ -13,7 +13,7 @@ // Adds SessionHandler functionality if available. // @see http://php.net/sessionhandler -if (PHP_VERSION_ID >= 50400) { +if (\PHP_VERSION_ID >= 50400) { class NativeSessionHandler extends \SessionHandler { } diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php index 4deb58eca2ede..36a20550b07cf 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php @@ -102,7 +102,7 @@ public function __construct(array $options = array(), $handler = null, MetadataB session_cache_limiter(''); // disable by default because it's managed by HeaderBag (if used) ini_set('session.use_cookies', 1); - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { session_register_shutdown(); } else { register_shutdown_function('session_write_close'); @@ -132,11 +132,11 @@ public function start() return true; } - if (PHP_VERSION_ID >= 50400 && \PHP_SESSION_ACTIVE === session_status()) { + if (\PHP_VERSION_ID >= 50400 && \PHP_SESSION_ACTIVE === session_status()) { throw new \RuntimeException('Failed to start the session: already started by PHP.'); } - if (PHP_VERSION_ID < 50400 && !$this->closed && isset($_SESSION) && session_id()) { + if (\PHP_VERSION_ID < 50400 && !$this->closed && isset($_SESSION) && session_id()) { // not 100% fool-proof, but is the most reliable way to determine if a session is active in PHP 5.3 throw new \RuntimeException('Failed to start the session: already started by PHP ($_SESSION is set).'); } @@ -197,12 +197,12 @@ public function setName($name) public function regenerate($destroy = false, $lifetime = null) { // Cannot regenerate the session ID for non-active sessions. - if (PHP_VERSION_ID >= 50400 && \PHP_SESSION_ACTIVE !== session_status()) { + if (\PHP_VERSION_ID >= 50400 && \PHP_SESSION_ACTIVE !== session_status()) { return false; } // Check if session ID exists in PHP 5.3 - if (PHP_VERSION_ID < 50400 && '' === session_id()) { + if (\PHP_VERSION_ID < 50400 && '' === session_id()) { return false; } @@ -384,13 +384,13 @@ public function setSaveHandler($saveHandler = null) if (!$saveHandler instanceof AbstractProxy && $saveHandler instanceof \SessionHandlerInterface) { $saveHandler = new SessionHandlerProxy($saveHandler); } elseif (!$saveHandler instanceof AbstractProxy) { - $saveHandler = PHP_VERSION_ID >= 50400 ? + $saveHandler = \PHP_VERSION_ID >= 50400 ? new SessionHandlerProxy(new \SessionHandler()) : new NativeProxy(); } $this->saveHandler = $saveHandler; if ($this->saveHandler instanceof \SessionHandlerInterface) { - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { session_set_save_handler($this->saveHandler, false); } else { session_set_save_handler( diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/AbstractProxy.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/AbstractProxy.php index 463677b55acfe..405e60b2fdfb3 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/AbstractProxy.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/AbstractProxy.php @@ -72,7 +72,7 @@ public function isWrapper() */ public function isActive() { - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { return $this->active = \PHP_SESSION_ACTIVE === session_status(); } @@ -93,7 +93,7 @@ public function isActive() */ public function setActive($flag) { - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { throw new \LogicException('This method is disabled in PHP 5.4.0+'); } diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index 6f9d76b4835e0..bb7a3f4800cd6 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -1029,7 +1029,7 @@ public function testContentAsResource() */ public function testGetContentCantBeCalledTwiceWithResources($first, $second) { - if (PHP_VERSION_ID >= 50600) { + if (\PHP_VERSION_ID >= 50600) { $this->markTestSkipped('PHP >= 5.6 allows to open php://input several times.'); } diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php index 947502f7b1660..67336f68dc45a 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php @@ -29,7 +29,7 @@ public function testConstruct() { $storage = new NativeSessionStorage(array('name' => 'TESTING'), new NativeFileSessionHandler(sys_get_temp_dir())); - if (PHP_VERSION_ID < 50400) { + if (\PHP_VERSION_ID < 50400) { $this->assertEquals('files', $storage->getSaveHandler()->getSaveHandlerName()); $this->assertEquals('files', ini_get('session.save_handler')); } else { diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/NativeSessionHandlerTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/NativeSessionHandlerTest.php index bd335b3b4cf71..021d8c0f9e3a0 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/NativeSessionHandlerTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/NativeSessionHandlerTest.php @@ -30,7 +30,7 @@ public function testConstruct() // note for PHPUnit optimisers - the use of assertTrue/False // here is deliberate since the tests do not require the classes to exist - drak - if (PHP_VERSION_ID < 50400) { + if (\PHP_VERSION_ID < 50400) { $this->assertFalse($handler instanceof \SessionHandler); $this->assertTrue($handler instanceof NativeSessionHandler); } else { diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php index 4da9a1bc515cb..20f9ca060bc3c 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php @@ -196,7 +196,7 @@ public function testSetSaveHandlerException() public function testSetSaveHandler53() { - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { $this->markTestSkipped('Test skipped, for PHP 5.3 only.'); } @@ -249,7 +249,7 @@ public function testStartedOutside() session_start(); $this->assertTrue(isset($_SESSION)); - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { // this only works in PHP >= 5.4 where session_status is available $this->assertTrue($storage->getSaveHandler()->isActive()); } diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/PhpBridgeSessionStorageTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/PhpBridgeSessionStorageTest.php index 99491ce86ac25..5cfb328d3095c 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/PhpBridgeSessionStorageTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/PhpBridgeSessionStorageTest.php @@ -62,7 +62,7 @@ protected function getStorage() public function testPhpSession53() { - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { $this->markTestSkipped('Test skipped, for PHP 5.3 only.'); } diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Proxy/AbstractProxyTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Proxy/AbstractProxyTest.php index efd8d80d35c57..f21bcc9632be2 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Proxy/AbstractProxyTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Proxy/AbstractProxyTest.php @@ -88,7 +88,7 @@ public function testIsWrapper() public function testIsActivePhp53() { - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { $this->markTestSkipped('Test skipped, for PHP 5.3 only.'); } @@ -109,7 +109,7 @@ public function testIsActivePhp54() public function testSetActivePhp53() { - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { $this->markTestSkipped('Test skipped, for PHP 5.3 only.'); } @@ -147,7 +147,7 @@ public function testName() */ public function testNameExceptionPhp53() { - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { $this->markTestSkipped('Test skipped, for PHP 5.3 only.'); } @@ -184,7 +184,7 @@ public function testId() */ public function testIdExceptionPhp53() { - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { $this->markTestSkipped('Test skipped, for PHP 5.3 only.'); } diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php index 243f850b5ebdf..df277ac5a8def 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php @@ -54,7 +54,7 @@ public function testOpen() $this->assertFalse($this->proxy->isActive()); $this->proxy->open('name', 'id'); - if (PHP_VERSION_ID < 50400) { + if (\PHP_VERSION_ID < 50400) { $this->assertTrue($this->proxy->isActive()); } else { $this->assertFalse($this->proxy->isActive()); diff --git a/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php index 78fc74f2d3f4a..9448ad180b4f3 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php @@ -71,7 +71,7 @@ public function dump(Data $data) } $trace = DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS; - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { $trace = debug_backtrace($trace, 7); } else { $trace = debug_backtrace($trace); @@ -263,7 +263,7 @@ public function __destruct() private function doDump($data, $name, $file, $line) { - if (PHP_VERSION_ID >= 50400 && $this->dumper instanceof CliDumper) { + if (\PHP_VERSION_ID >= 50400 && $this->dumper instanceof CliDumper) { $contextDumper = function ($name, $file, $line, $fileLinkFormat) { if ($this instanceof HtmlDumper) { if ('' !== $file) { diff --git a/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php b/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php index 27051cfb772ee..09f84ec3b8e01 100644 --- a/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php +++ b/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php @@ -107,7 +107,7 @@ public function render($uri, Request $request, array $options = array()) } $renderedAttributes = ''; if (count($attributes) > 0) { - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { $flags = ENT_QUOTES | ENT_SUBSTITUTE; } else { $flags = ENT_QUOTES; diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 4bbd67b1e5ef3..d20b6e2a16aed 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -753,7 +753,7 @@ public static function stripComments($source) $output .= $rawChunk; - if (PHP_VERSION_ID >= 70000) { + if (\PHP_VERSION_ID >= 70000) { // PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098 unset($tokens, $rawChunk); gc_mem_caches(); diff --git a/src/Symfony/Component/HttpKernel/Tests/Controller/ControllerResolverTest.php b/src/Symfony/Component/HttpKernel/Tests/Controller/ControllerResolverTest.php index 046b71ac01170..58ca07fc5361b 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Controller/ControllerResolverTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Controller/ControllerResolverTest.php @@ -184,7 +184,7 @@ public function testGetArguments() $request->attributes->set('foobar', 'foobar'); $controller = array(new self(), 'controllerMethod3'); - if (PHP_VERSION_ID === 50316) { + if (\PHP_VERSION_ID === 50316) { $this->markTestSkipped('PHP 5.3.16 has a major bug in the Reflection sub-system'); } else { try { diff --git a/src/Symfony/Component/HttpKernel/Tests/DataCollector/DumpDataCollectorTest.php b/src/Symfony/Component/HttpKernel/Tests/DataCollector/DumpDataCollectorTest.php index 48b46efad0551..91f4b2e6f25e0 100644 --- a/src/Symfony/Component/HttpKernel/Tests/DataCollector/DumpDataCollectorTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/DataCollector/DumpDataCollectorTest.php @@ -68,7 +68,7 @@ public function testCollectDefault() $collector->collect(new Request(), new Response()); $output = ob_get_clean(); - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { $this->assertSame("DumpDataCollectorTest.php on line {$line}:\n123\n", $output); } else { $this->assertSame("\"DumpDataCollectorTest.php on line {$line}:\"\n123\n", $output); @@ -86,7 +86,7 @@ public function testCollectHtml() $collector->dump($data); $line = __LINE__ - 1; $file = __FILE__; - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { $xOutput = <<DumpDataCollectorTest.php on line {$line}: 123 @@ -124,7 +124,7 @@ public function testFlush() ob_start(); $collector->__destruct(); - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { $this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", ob_get_clean()); } else { $this->assertSame("\"DumpDataCollectorTest.php on line {$line}:\"\n456\n", ob_get_clean()); diff --git a/src/Symfony/Component/Intl/Data/Bundle/Writer/JsonBundleWriter.php b/src/Symfony/Component/Intl/Data/Bundle/Writer/JsonBundleWriter.php index 6a79340c695e4..1a5f07f0a1b31 100644 --- a/src/Symfony/Component/Intl/Data/Bundle/Writer/JsonBundleWriter.php +++ b/src/Symfony/Component/Intl/Data/Bundle/Writer/JsonBundleWriter.php @@ -35,7 +35,7 @@ public function write($path, $locale, $data) } }); - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { // Use JSON_PRETTY_PRINT so that we can see what changed in Git diffs file_put_contents( $path.'/'.$locale.'.json', diff --git a/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php b/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php index 908afc8acec01..438b4d73e943b 100644 --- a/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php +++ b/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php @@ -209,7 +209,7 @@ public function format($timestamp) $argumentError = null; if (!is_int($timestamp) && !$timestamp instanceof \DateTime) { $argumentError = 'datefmt_format: takes either an array or an integer timestamp value or a DateTime object'; - if (PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) { + if (\PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) { $argumentError = sprintf('datefmt_format: string \'%s\' is not numeric, which would be required for it to be a valid date', $timestamp); } } @@ -371,7 +371,7 @@ public function getTimeZoneId() } // In PHP 5.5 default timezone depends on `date_default_timezone_get()` method - if (PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) { + if (\PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) { return date_default_timezone_get(); } } @@ -536,7 +536,7 @@ public function setTimeZoneId($timeZoneId) { if (null === $timeZoneId) { // In PHP 5.5 if $timeZoneId is null it fallbacks to `date_default_timezone_get()` method - if (PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) { + if (\PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) { $timeZoneId = date_default_timezone_get(); } else { // TODO: changes were made to ext/intl in PHP 5.4.4 release that need to be investigated since it will @@ -567,7 +567,7 @@ public function setTimeZoneId($timeZoneId) $timeZone = $this->getTimeZoneId(); } } catch (\Exception $e) { - if (PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) { + if (\PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) { $timeZoneId = $timeZone = $this->getTimeZoneId(); } else { $timeZoneId = 'UTC'; diff --git a/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php b/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php index f93147c593ba2..50ee30a217da1 100644 --- a/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php +++ b/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php @@ -854,7 +854,7 @@ private function getInt64Value($value) // The negative PHP_INT_MAX was being converted to float if ( $value == -self::$int32Max - 1 && - ((PHP_VERSION_ID < 50400 && PHP_VERSION_ID >= 50314) || PHP_VERSION_ID >= 50404 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) + ((\PHP_VERSION_ID < 50400 && \PHP_VERSION_ID >= 50314) || \PHP_VERSION_ID >= 50404 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) ) { return (int) $value; } @@ -867,7 +867,7 @@ private function getInt64Value($value) // A 32 bit integer was being generated instead of a 64 bit integer if ( ($value > self::$int32Max || $value < -self::$int32Max - 1) && - (PHP_VERSION_ID < 50314 || (PHP_VERSION_ID >= 50400 && PHP_VERSION_ID < 50404)) && + (\PHP_VERSION_ID < 50314 || (\PHP_VERSION_ID >= 50400 && \PHP_VERSION_ID < 50404)) && !(extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone')) ) { $value = (-2147483648 - ($value % -2147483648)) * ($value / abs($value)); diff --git a/src/Symfony/Component/Intl/Tests/Data/Bundle/Reader/IntlBundleReaderTest.php b/src/Symfony/Component/Intl/Tests/Data/Bundle/Reader/IntlBundleReaderTest.php index 88e6974bf2954..76543d3f0aa99 100644 --- a/src/Symfony/Component/Intl/Tests/Data/Bundle/Reader/IntlBundleReaderTest.php +++ b/src/Symfony/Component/Intl/Tests/Data/Bundle/Reader/IntlBundleReaderTest.php @@ -51,7 +51,7 @@ public function testReadFollowsAlias() public function testReadDoesNotFollowFallback() { - if (PHP_VERSION_ID < 50307 || PHP_VERSION_ID === 50400) { + if (\PHP_VERSION_ID < 50307 || \PHP_VERSION_ID === 50400) { $this->markTestSkipped('ResourceBundle handles disabling fallback properly only as of PHP 5.3.7 and 5.4.1.'); } @@ -71,7 +71,7 @@ public function testReadDoesNotFollowFallback() public function testReadDoesNotFollowFallbackAlias() { - if (PHP_VERSION_ID < 50307 || PHP_VERSION_ID === 50400) { + if (\PHP_VERSION_ID < 50307 || \PHP_VERSION_ID === 50400) { $this->markTestSkipped('ResourceBundle handles disabling fallback properly only as of PHP 5.3.7 and 5.4.1.'); } diff --git a/src/Symfony/Component/Intl/Tests/Data/Bundle/Writer/JsonBundleWriterTest.php b/src/Symfony/Component/Intl/Tests/Data/Bundle/Writer/JsonBundleWriterTest.php index b8610334d5a7a..d18968c9c95f2 100644 --- a/src/Symfony/Component/Intl/Tests/Data/Bundle/Writer/JsonBundleWriterTest.php +++ b/src/Symfony/Component/Intl/Tests/Data/Bundle/Writer/JsonBundleWriterTest.php @@ -44,7 +44,7 @@ protected function setUp() protected function tearDown() { - if (PHP_VERSION_ID < 50400) { + if (\PHP_VERSION_ID < 50400) { return; } diff --git a/src/Symfony/Component/Intl/Tests/Data/Bundle/Writer/PhpBundleWriterTest.php b/src/Symfony/Component/Intl/Tests/Data/Bundle/Writer/PhpBundleWriterTest.php index a4c0330e0d5e9..05bb9aad4f238 100644 --- a/src/Symfony/Component/Intl/Tests/Data/Bundle/Writer/PhpBundleWriterTest.php +++ b/src/Symfony/Component/Intl/Tests/Data/Bundle/Writer/PhpBundleWriterTest.php @@ -69,7 +69,7 @@ public function testWrite() */ public function testWriteResourceBundle() { - if (PHP_VERSION_ID < 50315 || (PHP_VERSION_ID >= 50400 && PHP_VERSION_ID < 50404)) { + if (\PHP_VERSION_ID < 50315 || (\PHP_VERSION_ID >= 50400 && \PHP_VERSION_ID < 50404)) { $this->markTestSkipped('ResourceBundle implements Traversable only as of PHP 5.3.15 and 5.4.4'); } diff --git a/src/Symfony/Component/Intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php b/src/Symfony/Component/Intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php index 43001a74fc6cb..669365c567b0a 100644 --- a/src/Symfony/Component/Intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php +++ b/src/Symfony/Component/Intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php @@ -37,7 +37,7 @@ public function testConstructorDefaultTimeZone() $formatter = $this->getDateFormatter('en', IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT); // In PHP 5.5 default timezone depends on `date_default_timezone_get()` method - if (PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) { + if (\PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) { $this->assertEquals(date_default_timezone_get(), $formatter->getTimeZoneId()); } else { $this->assertNull($formatter->getTimeZoneId()); @@ -277,7 +277,7 @@ public function testFormatIllegalArgumentError($pattern, $timestamp, $errorMessa public function formatErrorProvider() { // With PHP 5.5 IntlDateFormatter accepts empty values ('0') - if (PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) { + if (\PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) { return array( array('y-M-d', 'foobar', 'datefmt_format: string \'foobar\' is not numeric, which would be required for it to be a valid date: U_ILLEGAL_ARGUMENT_ERROR'), ); @@ -330,7 +330,7 @@ public function formatWithTimezoneProvider() ); // As of PHP 5.5, intl ext no longer fallbacks invalid time zones to UTC - if (PHP_VERSION_ID < 50500 && !(extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) { + if (\PHP_VERSION_ID < 50500 && !(extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) { // When time zone not exists, uses UTC by default $data[] = array(0, 'Foo/Bar', '1970-01-01 00:00:00'); $data[] = array(0, 'UTC+04:30', '1970-01-01 00:00:00'); @@ -413,7 +413,7 @@ public function testFormatWithGmtTimezone() { $formatter = $this->getDefaultDateFormatter('zzzz'); - if (PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) { + if (\PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) { $formatter->setTimeZone('GMT+03:00'); } else { $formatter->setTimeZoneId('GMT+03:00'); @@ -426,7 +426,7 @@ public function testFormatWithGmtTimeZoneAndMinutesOffset() { $formatter = $this->getDefaultDateFormatter('zzzz'); - if (PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) { + if (\PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) { $formatter->setTimeZone('GMT+00:30'); } else { $formatter->setTimeZoneId('GMT+00:30'); @@ -439,7 +439,7 @@ public function testFormatWithNonStandardTimezone() { $formatter = $this->getDefaultDateFormatter('zzzz'); - if (PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) { + if (\PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) { $formatter->setTimeZone('Pacific/Fiji'); } else { $formatter->setTimeZoneId('Pacific/Fiji'); @@ -471,7 +471,7 @@ public function testFormatWithDateTimeZoneGmt() public function testFormatWithDateTimeZoneGmtOffset() { - if (defined('HHVM_VERSION_ID') || PHP_VERSION_ID <= 50509) { + if (defined('HHVM_VERSION_ID') || \PHP_VERSION_ID <= 50509) { $this->markTestSkipped('DateTimeZone GMT offsets are supported since 5.5.10. See https://github.com/facebook/hhvm/issues/5875 for HHVM.'); } @@ -485,7 +485,7 @@ public function testFormatWithIntlTimeZone() if (!extension_loaded('intl')) { $this->markTestSkipped('Extension intl is required.'); } - if (PHP_VERSION_ID < 50500 && !method_exists('IntlDateFormatter', 'setTimeZone')) { + if (\PHP_VERSION_ID < 50500 && !method_exists('IntlDateFormatter', 'setTimeZone')) { $this->markTestSkipped('Only in PHP 5.5+ IntlDateFormatter allows to use DateTimeZone objects.'); } @@ -496,7 +496,7 @@ public function testFormatWithIntlTimeZone() public function testFormatWithTimezoneFromEnvironmentVariable() { - if (PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) { + if (\PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) { $this->markTestSkipped('IntlDateFormatter in PHP 5.5 no longer depends on TZ environment.'); } @@ -519,7 +519,7 @@ public function testFormatWithTimezoneFromEnvironmentVariable() public function testFormatWithTimezoneFromPhp() { - if (PHP_VERSION_ID < 50500 && !(extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) { + if (\PHP_VERSION_ID < 50500 && !(extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) { $this->markTestSkipped('Only in PHP 5.5 IntlDateFormatter depends on default timezone (`date_default_timezone_get()`).'); } @@ -949,7 +949,7 @@ public function testSetTimeZoneId($timeZoneId, $expectedTimeZoneId) { $formatter = $this->getDefaultDateFormatter(); - if (PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) { + if (\PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) { $formatter->setTimeZone($timeZoneId); } else { $formatter->setTimeZoneId($timeZoneId); @@ -960,7 +960,7 @@ public function testSetTimeZoneId($timeZoneId, $expectedTimeZoneId) public function setTimeZoneIdProvider() { - $isPhp55 = PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone')); + $isPhp55 = \PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone')); return array( array('UTC', 'UTC'), diff --git a/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php b/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php index d91f9a292afce..a3f86e2b5144a 100644 --- a/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php +++ b/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php @@ -701,7 +701,7 @@ public function testParseTypeInt64With32BitIntegerInPhp32Bit() // Bug #59597 was fixed on PHP 5.3.14 and 5.4.4 // The negative PHP_INT_MAX was being converted to float - if ((PHP_VERSION_ID < 50400 && PHP_VERSION_ID >= 50314) || PHP_VERSION_ID >= 50404 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) { + if ((\PHP_VERSION_ID < 50400 && \PHP_VERSION_ID >= 50314) || \PHP_VERSION_ID >= 50404 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) { $this->assertInternalType('int', $parsedValue); } else { $this->assertInternalType('float', $parsedValue); @@ -758,7 +758,7 @@ public function testParseTypeInt64With64BitIntegerInPhp64Bit() // Bug #59597 was fixed on PHP 5.3.14 and 5.4.4 // A 32 bit integer was being generated instead of a 64 bit integer - if (PHP_VERSION_ID < 50314 || (PHP_VERSION_ID >= 50400 && PHP_VERSION_ID < 50404)) { + if (\PHP_VERSION_ID < 50314 || (\PHP_VERSION_ID >= 50400 && \PHP_VERSION_ID < 50404)) { $this->assertEquals(-2147483648, $parsedValue, '->parse() TYPE_INT64 does not use true 64 bit integers, using only the 32 bit range (PHP < 5.3.14 and PHP < 5.4.4).'); } else { $this->assertEquals(2147483648, $parsedValue, '->parse() TYPE_INT64 uses true 64 bit integers (PHP >= 5.3.14 and PHP >= 5.4.4).'); @@ -769,7 +769,7 @@ public function testParseTypeInt64With64BitIntegerInPhp64Bit() // Bug #59597 was fixed on PHP 5.3.14 and 5.4.4 // A 32 bit integer was being generated instead of a 64 bit integer - if (PHP_VERSION_ID < 50314 || (PHP_VERSION_ID >= 50400 && PHP_VERSION_ID < 50404)) { + if (\PHP_VERSION_ID < 50314 || (\PHP_VERSION_ID >= 50400 && \PHP_VERSION_ID < 50404)) { $this->assertEquals(2147483647, $parsedValue, '->parse() TYPE_INT64 does not use true 64 bit integers, using only the 32 bit range (PHP < 5.3.14 and PHP < 5.4.4).'); } else { $this->assertEquals(-2147483649, $parsedValue, '->parse() TYPE_INT64 uses true 64 bit integers (PHP >= 5.3.14 and PHP >= 5.4.4).'); diff --git a/src/Symfony/Component/PropertyAccess/PropertyAccessor.php b/src/Symfony/Component/PropertyAccess/PropertyAccessor.php index d7ccc46438675..cdb075c84621f 100644 --- a/src/Symfony/Component/PropertyAccess/PropertyAccessor.php +++ b/src/Symfony/Component/PropertyAccess/PropertyAccessor.php @@ -166,7 +166,7 @@ public function setValue(&$objectOrArray, $propertyPath, $value) $overwrite = true; try { - if (PHP_VERSION_ID < 70000 && false === self::$previousErrorHandler) { + if (\PHP_VERSION_ID < 70000 && false === self::$previousErrorHandler) { self::$previousErrorHandler = set_error_handler(self::$errorHandler); } @@ -222,7 +222,7 @@ public function setValue(&$objectOrArray, $propertyPath, $value) } catch (\Throwable $e) { } - if (PHP_VERSION_ID < 70000 && false !== self::$previousErrorHandler) { + if (\PHP_VERSION_ID < 70000 && false !== self::$previousErrorHandler) { restore_error_handler(); self::$previousErrorHandler = false; } diff --git a/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php index b8fc03615f968..d98e024640366 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php @@ -64,7 +64,7 @@ public function load($file, $type = null) $collection->addResource(new FileResource($path)); $collection->addCollection($this->loader->load($class, $type)); } - if (PHP_VERSION_ID >= 70000) { + if (\PHP_VERSION_ID >= 70000) { // PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098 gc_mem_caches(); } diff --git a/src/Symfony/Component/Security/Csrf/TokenStorage/NativeSessionTokenStorage.php b/src/Symfony/Component/Security/Csrf/TokenStorage/NativeSessionTokenStorage.php index 71151fa831813..4923576e7c9b7 100644 --- a/src/Symfony/Component/Security/Csrf/TokenStorage/NativeSessionTokenStorage.php +++ b/src/Symfony/Component/Security/Csrf/TokenStorage/NativeSessionTokenStorage.php @@ -108,7 +108,7 @@ public function removeToken($tokenId) private function startSession() { - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { if (PHP_SESSION_NONE === session_status()) { session_start(); } diff --git a/src/Symfony/Component/Security/Http/Session/SessionAuthenticationStrategy.php b/src/Symfony/Component/Security/Http/Session/SessionAuthenticationStrategy.php index ccfa6ba67a492..b431289392561 100644 --- a/src/Symfony/Component/Security/Http/Session/SessionAuthenticationStrategy.php +++ b/src/Symfony/Component/Security/Http/Session/SessionAuthenticationStrategy.php @@ -49,7 +49,7 @@ public function onAuthentication(Request $request, TokenInterface $token) case self::MIGRATE: // Destroying the old session is broken in php 5.4.0 - 5.4.10 // See php bug #63379 - $destroy = PHP_VERSION_ID < 50400 || PHP_VERSION_ID >= 50411; + $destroy = \PHP_VERSION_ID < 50400 || \PHP_VERSION_ID >= 50411; $request->getSession()->migrate($destroy); return; diff --git a/src/Symfony/Component/Security/Http/Tests/Session/SessionAuthenticationStrategyTest.php b/src/Symfony/Component/Security/Http/Tests/Session/SessionAuthenticationStrategyTest.php index 601c3375887cf..d18c1c3ee7075 100644 --- a/src/Symfony/Component/Security/Http/Tests/Session/SessionAuthenticationStrategyTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Session/SessionAuthenticationStrategyTest.php @@ -40,7 +40,7 @@ public function testUnsupportedStrategy() public function testSessionIsMigrated() { - if (PHP_VERSION_ID >= 50400 && PHP_VERSION_ID < 50411) { + if (\PHP_VERSION_ID >= 50400 && \PHP_VERSION_ID < 50411) { $this->markTestSkipped('We cannot destroy the old session on PHP 5.4.0 - 5.4.10.'); } @@ -53,7 +53,7 @@ public function testSessionIsMigrated() public function testSessionIsMigratedWithPhp54Workaround() { - if (PHP_VERSION_ID < 50400 || PHP_VERSION_ID >= 50411) { + if (\PHP_VERSION_ID < 50400 || \PHP_VERSION_ID >= 50411) { $this->markTestSkipped('This PHP version is not affected.'); } diff --git a/src/Symfony/Component/Serializer/Encoder/JsonDecode.php b/src/Symfony/Component/Serializer/Encoder/JsonDecode.php index 5f5f2899f5fff..a7a11caf2e7f0 100644 --- a/src/Symfony/Component/Serializer/Encoder/JsonDecode.php +++ b/src/Symfony/Component/Serializer/Encoder/JsonDecode.php @@ -101,7 +101,7 @@ public function decode($data, $format, array $context = array()) $recursionDepth = $context['json_decode_recursion_depth']; $options = $context['json_decode_options']; - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { $decodedData = json_decode($data, $associative, $recursionDepth, $options); } else { $decodedData = json_decode($data, $associative, $recursionDepth); diff --git a/src/Symfony/Component/Templating/PhpEngine.php b/src/Symfony/Component/Templating/PhpEngine.php index 75846455b9ee4..de243d35e09bf 100644 --- a/src/Symfony/Component/Templating/PhpEngine.php +++ b/src/Symfony/Component/Templating/PhpEngine.php @@ -417,7 +417,7 @@ public function getGlobals() protected function initializeEscapers() { $that = $this; - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { $flags = ENT_QUOTES | ENT_SUBSTITUTE; } else { $flags = ENT_QUOTES; diff --git a/src/Symfony/Component/Translation/Tests/Dumper/JsonFileDumperTest.php b/src/Symfony/Component/Translation/Tests/Dumper/JsonFileDumperTest.php index f54768418ca68..74d1c27b6407f 100644 --- a/src/Symfony/Component/Translation/Tests/Dumper/JsonFileDumperTest.php +++ b/src/Symfony/Component/Translation/Tests/Dumper/JsonFileDumperTest.php @@ -19,7 +19,7 @@ class JsonFileDumperTest extends TestCase { public function testDump() { - if (PHP_VERSION_ID < 50400) { + if (\PHP_VERSION_ID < 50400) { $this->markTestIncomplete('PHP below 5.4 doesn\'t support JSON pretty printing'); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php b/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php index 856e49d6c56a1..9c8ce50fc3dd1 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php @@ -36,7 +36,7 @@ abstract class AbstractComparisonValidatorTestCase extends AbstractConstraintVal { protected static function addPhp5Dot5Comparisons(array $comparisons) { - if (PHP_VERSION_ID < 50500) { + if (\PHP_VERSION_ID < 50500) { return $comparisons; } @@ -130,7 +130,7 @@ public function testInvalidComparisonToValue($dirtyValue, $dirtyValueAsString, $ if ($dirtyValue instanceof \DateTime || $dirtyValue instanceof \DateTimeInterface) { IntlTestHelper::requireIntl($this, '57.1'); - if (PHP_VERSION_ID < 50304 && !(extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) { + if (\PHP_VERSION_ID < 50304 && !(extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) { $this->markTestSkipped('Intl supports formatting DateTime objects since 5.3.4'); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/IdenticalToValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/IdenticalToValidatorTest.php index 1acb41a66ccd7..0b6a4e411af9f 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/IdenticalToValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/IdenticalToValidatorTest.php @@ -64,7 +64,7 @@ public function provideValidComparisons() array(null, 1), ); - if (PHP_VERSION_ID >= 50500) { + if (\PHP_VERSION_ID >= 50500) { $immutableDate = new \DateTimeImmutable('2000-01-01'); $comparisons[] = array($immutableDate, $immutableDate); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/RangeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/RangeValidatorTest.php index ecee65cd81e27..b977a7e19c95b 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/RangeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/RangeValidatorTest.php @@ -194,7 +194,7 @@ public function getTenthToTwentiethMarch2014() array(new \DateTime('March 20, 2014')), ); - if (PHP_VERSION_ID >= 50500) { + if (\PHP_VERSION_ID >= 50500) { $tests[] = array(new \DateTimeImmutable('March 10, 2014')); $tests[] = array(new \DateTimeImmutable('March 15, 2014')); $tests[] = array(new \DateTimeImmutable('March 20, 2014')); @@ -216,7 +216,7 @@ public function getSoonerThanTenthMarch2014() array(new \DateTime('March 9, 2014'), 'Mar 9, 2014, 12:00 AM'), ); - if (PHP_VERSION_ID >= 50500) { + if (\PHP_VERSION_ID >= 50500) { $tests[] = array(new \DateTimeImmutable('March 20, 2013'), 'Mar 20, 2013, 12:00 AM'); $tests[] = array(new \DateTimeImmutable('March 9, 2014'), 'Mar 9, 2014, 12:00 AM'); } @@ -237,7 +237,7 @@ public function getLaterThanTwentiethMarch2014() array(new \DateTime('March 9, 2015'), 'Mar 9, 2015, 12:00 AM'), ); - if (PHP_VERSION_ID >= 50500) { + if (\PHP_VERSION_ID >= 50500) { $tests[] = array(new \DateTimeImmutable('March 21, 2014'), 'Mar 21, 2014, 12:00 AM'); $tests[] = array(new \DateTimeImmutable('March 9, 2015'), 'Mar 9, 2015, 12:00 AM'); } diff --git a/src/Symfony/Component/VarDumper/Cloner/VarCloner.php b/src/Symfony/Component/VarDumper/Cloner/VarCloner.php index af467056a5d97..6c9ede3ed55da 100644 --- a/src/Symfony/Component/VarDumper/Cloner/VarCloner.php +++ b/src/Symfony/Component/VarDumper/Cloner/VarCloner.php @@ -308,7 +308,7 @@ private static function initHashMask() } else { // check if we are nested in an output buffering handler to prevent a fatal error with ob_start() below $obFuncs = array('ob_clean', 'ob_end_clean', 'ob_flush', 'ob_end_flush', 'ob_get_contents', 'ob_get_flush'); - foreach (debug_backtrace(PHP_VERSION_ID >= 50400 ? DEBUG_BACKTRACE_IGNORE_ARGS : false) as $frame) { + foreach (debug_backtrace(\PHP_VERSION_ID >= 50400 ? DEBUG_BACKTRACE_IGNORE_ARGS : false) as $frame) { if (isset($frame['function'][0]) && !isset($frame['class']) && 'o' === $frame['function'][0] && in_array($frame['function'], $obFuncs)) { $frame['line'] = 0; break; diff --git a/src/Symfony/Component/VarDumper/Tests/CliDumperTest.php b/src/Symfony/Component/VarDumper/Tests/CliDumperTest.php index 519e6a126b7dc..f8acf0d562438 100644 --- a/src/Symfony/Component/VarDumper/Tests/CliDumperTest.php +++ b/src/Symfony/Component/VarDumper/Tests/CliDumperTest.php @@ -45,7 +45,7 @@ public function testGet() $closure54 = ''; $r = defined('HHVM_VERSION') ? '' : '#%d'; - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { $closure54 = <<= 50600) { + if (\PHP_VERSION_ID >= 50600) { $this->markTestSkipped('PHP 5.6 fixed refs counting'); } diff --git a/src/Symfony/Component/VarDumper/Tests/HtmlDumperTest.php b/src/Symfony/Component/VarDumper/Tests/HtmlDumperTest.php index c3a8e1a6c948c..6ba68c5c80c0e 100644 --- a/src/Symfony/Component/VarDumper/Tests/HtmlDumperTest.php +++ b/src/Symfony/Component/VarDumper/Tests/HtmlDumperTest.php @@ -49,7 +49,7 @@ public function testGet() $closure54 = ''; $r = defined('HHVM_VERSION') ? '' : '#%d'; - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { $closure54 = <<class: "Symfony\Component\VarDumper\Tests\HtmlDumperTest" diff --git a/src/Symfony/Component/VarDumper/Tests/Test/VarDumperTestTraitTest.php b/src/Symfony/Component/VarDumper/Tests/Test/VarDumperTestTraitTest.php index a87476be75217..81d1a0cf1b592 100644 --- a/src/Symfony/Component/VarDumper/Tests/Test/VarDumperTestTraitTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Test/VarDumperTestTraitTest.php @@ -10,6 +10,6 @@ */ // Skipping trait tests for PHP < 5.4 -if (PHP_VERSION_ID >= 50400) { +if (\PHP_VERSION_ID >= 50400) { require __DIR__.'/VarDumperTestTraitRequire54.php'; } diff --git a/src/Symfony/Component/Yaml/Exception/ParseException.php b/src/Symfony/Component/Yaml/Exception/ParseException.php index 74548df1f85e1..ef36cfbadd35c 100644 --- a/src/Symfony/Component/Yaml/Exception/ParseException.php +++ b/src/Symfony/Component/Yaml/Exception/ParseException.php @@ -123,7 +123,7 @@ private function updateRepr() } if (null !== $this->parsedFile) { - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { $jsonOptions = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE; } else { $jsonOptions = 0; diff --git a/src/Symfony/Component/Yaml/Tests/ParseExceptionTest.php b/src/Symfony/Component/Yaml/Tests/ParseExceptionTest.php index 4f01ab938e504..b7797fb7f32b1 100644 --- a/src/Symfony/Component/Yaml/Tests/ParseExceptionTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParseExceptionTest.php @@ -19,7 +19,7 @@ class ParseExceptionTest extends TestCase public function testGetMessage() { $exception = new ParseException('Error message', 42, 'foo: bar', '/var/www/app/config.yml'); - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { $message = 'Error message in "/var/www/app/config.yml" at line 42 (near "foo: bar")'; } else { $message = 'Error message in "\\/var\\/www\\/app\\/config.yml" at line 42 (near "foo: bar")'; @@ -31,7 +31,7 @@ public function testGetMessage() public function testGetMessageWithUnicodeInFilename() { $exception = new ParseException('Error message', 42, 'foo: bar', 'äöü.yml'); - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { $message = 'Error message in "äöü.yml" at line 42 (near "foo: bar")'; } else { $message = 'Error message in "\u00e4\u00f6\u00fc.yml" at line 42 (near "foo: bar")'; From 57daadbf67f3090f8bcd32e6cf70e9266dad9d3e Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 1 Jun 2017 22:30:09 +0200 Subject: [PATCH 33/57] [Di] Remove closure-proxy arguments --- UPGRADE-3.3.md | 2 +- UPGRADE-4.0.md | 2 +- .../Console/Descriptor/Descriptor.php | 4 - .../Console/Descriptor/TextDescriptor.php | 4 - .../Console/Descriptor/XmlDescriptor.php | 6 -- .../Console/Descriptor/ObjectsProvider.php | 2 - .../Descriptor/builder_1_arguments.json | 7 -- .../Descriptor/builder_1_arguments.xml | 1 - .../Descriptor/definition_arguments_1.json | 7 -- .../Descriptor/definition_arguments_1.txt | 43 ++++---- .../Descriptor/definition_arguments_1.xml | 1 - .../Argument/ClosureProxyArgument.php | 50 ---------- .../DependencyInjection/CHANGELOG.md | 1 - .../DependencyInjection/ContainerBuilder.php | 26 ----- .../DependencyInjection/Dumper/PhpDumper.php | 32 ------ .../DependencyInjection/Dumper/XmlDumper.php | 6 -- .../DependencyInjection/Dumper/YamlDumper.php | 3 - .../LazyProxy/ProxyHelper.php | 48 --------- .../Loader/XmlFileLoader.php | 10 -- .../Loader/YamlFileLoader.php | 16 --- .../schema/dic/services/services-1.0.xsd | 2 - .../InlineServiceDefinitionsPassTest.php | 8 +- .../Tests/ContainerBuilderTest.php | 62 ------------ .../Tests/Dumper/PhpDumperTest.php | 40 -------- .../Tests/Fixtures/containers/container31.php | 37 ------- .../Tests/Fixtures/containers/container32.php | 37 ------- .../Tests/Fixtures/containers/container33.php | 1 - .../Tests/Fixtures/containers/container9.php | 5 - ...ainer_dump_proxy_with_void_return_type.php | 27 ----- .../Tests/Fixtures/graphviz/services9.dot | 2 - .../Tests/Fixtures/php/services31.php | 23 ----- .../Tests/Fixtures/php/services32.php | 99 ------------------- .../Tests/Fixtures/php/services9.php | 16 --- .../Tests/Fixtures/php/services9_compiled.php | 16 --- ...vices_dump_proxy_with_void_return_type.php | 95 ------------------ .../Tests/Fixtures/xml/services9.xml | 3 - .../Tests/Fixtures/yaml/services9.yml | 3 - .../Component/EventDispatcher/CHANGELOG.md | 2 +- .../ContainerAwareEventDispatcher.php | 2 +- .../EventDispatcher/Debug/WrappedListener.php | 8 +- .../Component/VarDumper/Caster/ClassStub.php | 4 - 41 files changed, 30 insertions(+), 733 deletions(-) delete mode 100644 src/Symfony/Component/DependencyInjection/Argument/ClosureProxyArgument.php delete mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container31.php delete mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container32.php delete mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container_dump_proxy_with_void_return_type.php delete mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services32.php delete mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_dump_proxy_with_void_return_type.php diff --git a/UPGRADE-3.3.md b/UPGRADE-3.3.md index 05f44e549e11b..b8d2524654386 100644 --- a/UPGRADE-3.3.md +++ b/UPGRADE-3.3.md @@ -127,7 +127,7 @@ EventDispatcher --------------- * The `ContainerAwareEventDispatcher` class has been deprecated. - Use `EventDispatcher` with closure-proxy injection instead. + Use `EventDispatcher` with closure factories instead. Finder ------ diff --git a/UPGRADE-4.0.md b/UPGRADE-4.0.md index 6c10190c7c502..b06145202e7cd 100644 --- a/UPGRADE-4.0.md +++ b/UPGRADE-4.0.md @@ -132,7 +132,7 @@ EventDispatcher --------------- * The `ContainerAwareEventDispatcher` class has been removed. - Use `EventDispatcher` with closure-proxy injection instead. + Use `EventDispatcher` with closure factories instead. ExpressionLanguage ------------------ diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php index 268a7818979cb..acaec0bf5dbab 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php @@ -312,10 +312,6 @@ protected function formatClosure(\Closure $closure) { $r = new \ReflectionFunction($closure); - if (preg_match('#^/\*\* @closure-proxy ([^: ]++)::([^: ]++) \*/$#', $r->getDocComment(), $m)) { - return sprintf('%s::%s', $m[1], $m[2]); - } - return 'closure'; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php index 64c38cdff759f..06a404080d32d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php @@ -14,7 +14,6 @@ use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\DependencyInjection\Alias; -use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -343,9 +342,6 @@ protected function describeContainerDefinition(Definition $definition, array $op $argumentsInformation[] = sprintf('Service(%s)', (string) $argument); } elseif ($argument instanceof IteratorArgument) { $argumentsInformation[] = sprintf('Iterator (%d element(s))', count($argument->getValues())); - } elseif ($argument instanceof ClosureProxyArgument) { - list($reference, $method) = $argument->getValues(); - $argumentsInformation[] = sprintf('ClosureProxy(Service(%s)::%s())', $reference, $method); } elseif ($argument instanceof Definition) { $argumentsInformation[] = 'Inlined Service'; } else { diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php index c1e586cf927f5..f1770d8c3c453 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php @@ -12,7 +12,6 @@ namespace Symfony\Bundle\FrameworkBundle\Console\Descriptor; use Symfony\Component\DependencyInjection\Alias; -use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -444,11 +443,6 @@ private function getArgumentNodes(array $arguments, \DOMDocument $dom) foreach ($this->getArgumentNodes($argument->getValues(), $dom) as $childArgumentXML) { $argumentXML->appendChild($childArgumentXML); } - } elseif ($argument instanceof ClosureProxyArgument) { - list($reference, $method) = $argument->getValues(); - $argumentXML->setAttribute('type', 'closure-proxy'); - $argumentXML->setAttribute('id', (string) $reference); - $argumentXML->setAttribute('method', $method); } elseif ($argument instanceof Definition) { $argumentXML->appendChild($dom->importNode($this->getContainerDefinitionDocument($argument, null, false, true)->childNodes->item(0), true)); } elseif (is_array($argument)) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php index 0c0363c482bab..9eb2e874d63d5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php @@ -12,7 +12,6 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor; use Symfony\Component\DependencyInjection\Alias; -use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; @@ -119,7 +118,6 @@ public static function getContainerDefinitions() new Reference('definition_1'), new Reference('definition_2'), ))) - ->addArgument(new ClosureProxyArgument('definition1', 'get')) ->setFactory(array('Full\\Qualified\\FactoryClass', 'get')), 'definition_2' => $definition2 ->setPublic(false) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.json b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.json index dd3f81f1768e4..e2ab628937760 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.json +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.json @@ -60,13 +60,6 @@ "type": "service", "id": "definition_2" } - ], - [ - { - "type": "service", - "id": "definition1" - }, - "get" ] ], "file": null, diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.xml index 91b292da50248..b016ae382a908 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.xml @@ -22,7 +22,6 @@ - diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_1.json b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_1.json index 0590d3f76a611..5074d4fba6170 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_1.json +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_1.json @@ -58,13 +58,6 @@ "type": "service", "id": "definition_2" } - ], - [ - { - "type": "service", - "id": "definition1" - }, - "get" ] ], "file": null, diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_1.txt b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_1.txt index 0bb95302f8315..989f96ee1369f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_1.txt +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_1.txt @@ -1,23 +1,22 @@ - ---------------- ------------------------------------------- -  Option   Value  - ---------------- ------------------------------------------- - Service ID - - Class Full\Qualified\Class1 - Tags - - Public yes - Synthetic no - Lazy yes - Shared yes - Abstract yes - Autowired no - Autoconfigured no - Factory Class Full\Qualified\FactoryClass - Factory Method get - Arguments Service(definition2)  - %parameter%  - Inlined Service  - Array (3 element(s))  - Iterator (2 element(s))  - ClosureProxy(Service(definition1)::get()) - ---------------- ------------------------------------------- + ---------------- ----------------------------- +  Option   Value  + ---------------- ----------------------------- + Service ID - + Class Full\Qualified\Class1 + Tags - + Public yes + Synthetic no + Lazy yes + Shared yes + Abstract yes + Autowired no + Autoconfigured no + Factory Class Full\Qualified\FactoryClass + Factory Method get + Arguments Service(definition2)  + %parameter%  + Inlined Service  + Array (3 element(s))  + Iterator (2 element(s)) + ---------------- ----------------------------- diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_1.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_1.xml index 6d3cb8eea40be..732f99f7839a1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_1.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_1.xml @@ -20,5 +20,4 @@ - diff --git a/src/Symfony/Component/DependencyInjection/Argument/ClosureProxyArgument.php b/src/Symfony/Component/DependencyInjection/Argument/ClosureProxyArgument.php deleted file mode 100644 index 94ba13241a108..0000000000000 --- a/src/Symfony/Component/DependencyInjection/Argument/ClosureProxyArgument.php +++ /dev/null @@ -1,50 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\DependencyInjection\Argument; - -use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; -use Symfony\Component\DependencyInjection\Reference; - -/** - * @author Nicolas Grekas - */ -class ClosureProxyArgument implements ArgumentInterface -{ - private $reference; - private $method; - - public function __construct($id, $method, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE) - { - $this->reference = new Reference($id, $invalidBehavior); - $this->method = $method; - } - - /** - * {@inheritdoc} - */ - public function getValues() - { - return array($this->reference, $this->method); - } - - /** - * {@inheritdoc} - */ - public function setValues(array $values) - { - if (!$values[0] instanceof Reference) { - throw new InvalidArgumentException(sprintf('A ClosureProxyArgument must hold a Reference, "%s" given.', is_object($values[0]) ? get_class($values[0]) : gettype($values[0]))); - } - list($this->reference, $this->method) = $values; - } -} diff --git a/src/Symfony/Component/DependencyInjection/CHANGELOG.md b/src/Symfony/Component/DependencyInjection/CHANGELOG.md index b591c5958dae7..457e22413ea5f 100644 --- a/src/Symfony/Component/DependencyInjection/CHANGELOG.md +++ b/src/Symfony/Component/DependencyInjection/CHANGELOG.md @@ -20,7 +20,6 @@ CHANGELOG * added support for omitting the factory class name in a service definition if the definition class is set * deprecated case insensitivity of service identifiers * added "iterator" argument type for lazy iteration over a set of values and services - * added "closure-proxy" argument type for turning services' methods into lazy callables * added file-wide configurable defaults for service attributes "public", "tags", "autowire" and "autoconfigure" * made the "class" attribute optional, using the "id" as fallback diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index 0675dd6f58071..3887e56fc244a 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection; use Psr\Container\ContainerInterface as PsrContainerInterface; -use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\Argument\RewindableGenerator; use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; @@ -1161,31 +1160,6 @@ public function resolveServices($value) return $count; }); - } elseif ($value instanceof ClosureProxyArgument) { - $parameterBag = $this->getParameterBag(); - list($reference, $method) = $value->getValues(); - if ('service_container' === $id = (string) $reference) { - $class = parent::class; - } elseif (!$this->hasDefinition($id) && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $reference->getInvalidBehavior()) { - return; - } else { - $class = $parameterBag->resolveValue($this->findDefinition($id)->getClass()); - } - if (!method_exists($class, $method = $parameterBag->resolveValue($method))) { - throw new InvalidArgumentException(sprintf('Cannot create closure-proxy for service "%s": method "%s::%s" does not exist.', $id, $class, $method)); - } - $r = new \ReflectionMethod($class, $method); - if (!$r->isPublic()) { - throw new RuntimeException(sprintf('Cannot create closure-proxy for service "%s": method "%s::%s" must be public.', $id, $class, $method)); - } - foreach ($r->getParameters() as $p) { - if ($p->isPassedByReference()) { - throw new RuntimeException(sprintf('Cannot create closure-proxy for service "%s": parameter "$%s" of method "%s::%s" must not be passed by reference.', $id, $p->name, $class, $method)); - } - } - $value = function () use ($id, $method) { - return call_user_func_array(array($this->get($id), $method), func_get_args()); - }; } elseif ($value instanceof Reference) { $value = $this->get((string) $value, $value->getInvalidBehavior()); } elseif ($value instanceof Definition) { diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index a1fb8950e0871..840b670f165f5 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Dumper; use Symfony\Component\DependencyInjection\Argument\ArgumentInterface; -use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; use Symfony\Component\DependencyInjection\Variable; @@ -27,7 +26,6 @@ use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException; -use Symfony\Component\DependencyInjection\LazyProxy\ProxyHelper; use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface as ProxyDumper; use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\NullDumper; use Symfony\Component\DependencyInjection\ExpressionLanguage; @@ -67,7 +65,6 @@ class PhpDumper extends Dumper private $docStar; private $serviceIdToMethodNameMap; private $usedMethodNames; - private $baseClass; /** * @var \Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface @@ -125,7 +122,6 @@ public function dump(array $options = array()) $this->classResources = array(); $this->initializeMethodNamesMap($options['base_class']); - $this->baseClass = $options['base_class']; $this->docStar = $options['debug'] ? '*' : ''; @@ -1465,34 +1461,6 @@ private function dumpValue($value, $interpolate = true) return implode("\n", $code); } - - if ($value instanceof ClosureProxyArgument) { - list($reference, $method) = $value->getValues(); - $method = substr($this->dumpLiteralClass($this->dumpValue($method)), 1); - - if ('service_container' === (string) $reference) { - $class = $this->baseClass; - } elseif (!$this->container->hasDefinition((string) $reference) && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $reference->getInvalidBehavior()) { - return 'null'; - } else { - $class = substr($this->dumpLiteralClass($this->dumpValue($this->container->findDefinition((string) $reference)->getClass())), 1); - } - if (false !== strpos($class, '$') || false !== strpos($method, '$')) { - throw new RuntimeException(sprintf('Cannot dump definition for service "%s": dynamic class names or methods, and closure-proxies are incompatible with each other.', $reference)); - } - if (!method_exists($class, $method)) { - throw new InvalidArgumentException(sprintf('Cannot create closure-proxy for service "%s": method "%s::%s" does not exist.', $reference, $class, $method)); - } - $r = $this->container->getReflectionClass($class)->getMethod($method); - if (!$r->isPublic()) { - throw new InvalidArgumentException(sprintf('Cannot create closure-proxy for service "%s": method "%s::%s" must be public.', $reference, $class, $method)); - } - $signature = preg_replace('/^(&?)[^(]*/', '$1', ProxyHelper::getSignature($r, $call)); - - $return = 'void' !== ProxyHelper::getTypeHint($r); - - return sprintf("/** @closure-proxy %s::%s */ function %s {\n %s%s->%s;\n }", $class, $method, $signature, $return ? 'return ' : '', $this->dumpValue($reference), $call); - } } finally { list($this->definitionVariables, $this->referenceVariables, $this->variableCount) = $scope; } diff --git a/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php index 61978dcd28971..c6b3be06a1402 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php @@ -11,7 +11,6 @@ namespace Symfony\Component\DependencyInjection\Dumper; -use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -302,11 +301,6 @@ private function convertParameters(array $parameters, $type, \DOMElement $parent } elseif ($value instanceof IteratorArgument) { $element->setAttribute('type', 'iterator'); $this->convertParameters($value->getValues(), $type, $element, 'key'); - } elseif ($value instanceof ClosureProxyArgument) { - list($reference, $method) = $value->getValues(); - $element->setAttribute('type', 'closure-proxy'); - $element->setAttribute('id', (string) $reference); - $element->setAttribute('method', $method); } elseif ($value instanceof Reference) { $element->setAttribute('type', 'service'); $element->setAttribute('id', (string) $value); diff --git a/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php index 81951fe536699..e71df2af24c14 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php @@ -15,7 +15,6 @@ use Symfony\Component\Yaml\Tag\TaggedValue; use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\Argument\ArgumentInterface; -use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -256,8 +255,6 @@ private function dumpValue($value) if ($value instanceof ArgumentInterface) { if ($value instanceof IteratorArgument) { $tag = 'iterator'; - } elseif ($value instanceof ClosureProxyArgument) { - $tag = 'closure_proxy'; } else { throw new RuntimeException(sprintf('Unspecified Yaml tag for type "%s".', get_class($value))); } diff --git a/src/Symfony/Component/DependencyInjection/LazyProxy/ProxyHelper.php b/src/Symfony/Component/DependencyInjection/LazyProxy/ProxyHelper.php index 5f0c8772fef43..84686efff5d6a 100644 --- a/src/Symfony/Component/DependencyInjection/LazyProxy/ProxyHelper.php +++ b/src/Symfony/Component/DependencyInjection/LazyProxy/ProxyHelper.php @@ -18,54 +18,6 @@ */ class ProxyHelper { - /** - * @return string The signature of the passed function, return type and function/method name included if any - */ - public static function getSignature(\ReflectionFunctionAbstract $r, &$call = null) - { - $signature = array(); - $call = array(); - - foreach ($r->getParameters() as $i => $p) { - $k = '$'.$p->name; - if (method_exists($p, 'isVariadic') && $p->isVariadic()) { - $k = '...'.$k; - } - $call[] = $k; - - if ($p->isPassedByReference()) { - $k = '&'.$k; - } - if ($type = self::getTypeHint($r, $p)) { - $k = $type.' '.$k; - } - if ($type && $p->allowsNull()) { - $k = '?'.$k; - } - - try { - $k .= ' = '.self::export($p->getDefaultValue()); - if ($type && $p->allowsNull() && null === $p->getDefaultValue()) { - $k = substr($k, 1); - } - } catch (\ReflectionException $e) { - if ($type && $p->allowsNull() && !class_exists('ReflectionNamedType', false)) { - $k .= ' = null'; - $k = substr($k, 1); - } - } - - $signature[] = $k; - } - $call = ($r->isClosure() ? '' : $r->name).'('.implode(', ', $call).')'; - - if ($type = self::getTypeHint($r)) { - $type = ': '.($r->getReturnType()->allowsNull() ? '?' : '').$type; - } - - return ($r->returnsReference() ? '&' : '').($r->isClosure() ? '' : $r->name).'('.implode(', ', $signature).')'.$type; - } - /** * @return string|null The FQCN or builtin name of the type hint, or null when the type hint references an invalid self|parent context */ diff --git a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php index 79c8fbf9677ab..4b07e5c58581e 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php @@ -14,7 +14,6 @@ use Symfony\Component\Config\Util\XmlUtils; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Alias; -use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\ChildDefinition; @@ -493,15 +492,6 @@ private function getArgumentsAsPhp(\DOMElement $node, $name, $file, $lowercase = case 'expression': $arguments[$key] = new Expression($arg->nodeValue); break; - case 'closure-proxy': - if (!$arg->getAttribute('id')) { - throw new InvalidArgumentException(sprintf('Tag "<%s>" with type="closure-proxy" has no or empty "id" attribute in "%s".', $name, $file)); - } - if (!$arg->getAttribute('method')) { - throw new InvalidArgumentException(sprintf('Tag "<%s>" with type="closure-proxy" has no or empty "method" attribute in "%s".', $name, $file)); - } - $arguments[$key] = new ClosureProxyArgument($arg->getAttribute('id'), $arg->getAttribute('method'), $invalidBehavior); - break; case 'collection': $arguments[$key] = $this->getArgumentsAsPhp($arg, $name, $file, false); break; diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index c3e697c1b5207..7a0123ba21bf5 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -13,7 +13,6 @@ use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\Argument\ArgumentInterface; -use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -679,21 +678,6 @@ private function resolveServices($value, $file, $isParameter = false) throw new InvalidArgumentException(sprintf('"!iterator" tag only accepts arrays of "@service" references in "%s".', $file)); } } - if ('closure_proxy' === $value->getTag()) { - if (!is_array($argument) || array(0, 1) !== array_keys($argument) || !is_string($argument[0]) || !is_string($argument[1]) || 0 !== strpos($argument[0], '@') || 0 === strpos($argument[0], '@@')) { - throw new InvalidArgumentException(sprintf('"!closure_proxy" tagged values must be arrays of [@service, method] in "%s".', $file)); - } - - if (0 === strpos($argument[0], '@?')) { - $argument[0] = substr($argument[0], 2); - $invalidBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE; - } else { - $argument[0] = substr($argument[0], 1); - $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE; - } - - return new ClosureProxyArgument($argument[0], $argument[1], $invalidBehavior); - } if ('service' === $value->getTag()) { if ($isParameter) { throw new InvalidArgumentException(sprintf('Using an anonymous service in a parameter is not allowed in "%s".', $file)); diff --git a/src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd b/src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd index 2de786bdb7cba..6f5c8ccc543d3 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd +++ b/src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd @@ -218,7 +218,6 @@ - @@ -244,7 +243,6 @@ - diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php index f0dd7fe74dc4c..26b24fa713242 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php @@ -18,7 +18,7 @@ use Symfony\Component\DependencyInjection\Compiler\InlineServiceDefinitionsPass; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument; +use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; class InlineServiceDefinitionsPassTest extends TestCase @@ -233,8 +233,8 @@ public function testProcessDoesNotSetLazyArgumentValuesAfterInlining() ->setShared(false) ; $container - ->register('closure-proxy') - ->setArguments(array(new ClosureProxyArgument('inline', 'method'))) + ->register('service-closure') + ->setArguments(array(new ServiceClosureArgument(new Reference('inline')))) ; $container ->register('iterator') @@ -243,7 +243,7 @@ public function testProcessDoesNotSetLazyArgumentValuesAfterInlining() $this->process($container); - $values = $container->getDefinition('closure-proxy')->getArgument(0)->getValues(); + $values = $container->getDefinition('service-closure')->getArgument(0)->getValues(); $this->assertInstanceOf(Reference::class, $values[0]); $this->assertSame('inline', (string) $values[0]); diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php index 3558c7bd226e1..51f7001491a19 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php @@ -20,7 +20,6 @@ use Symfony\Component\Config\Resource\ResourceInterface; use Symfony\Component\Config\Resource\DirectoryResource; use Symfony\Component\DependencyInjection\Alias; -use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\Argument\RewindableGenerator; use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; @@ -1008,63 +1007,6 @@ public function testAutowiring() $this->assertEquals(A::class, (string) $container->getDefinition('b')->getArgument(0)); } - public function testClosureProxy() - { - $container = new ContainerBuilder(); - - $container->register('foo', 'stdClass') - ->setProperty('foo', new ClosureProxyArgument('bar', 'c')) - ; - $container->register('bar', A::class); - - $foo = $container->get('foo'); - - $this->assertInstanceOf('Closure', $foo->foo); - $this->assertSame(123, call_user_func($foo->foo)); - } - - public function testClosureProxyContainer() - { - $container = new ContainerBuilder(); - - $container->register('foo', 'stdClass') - ->setProperty('foo', new ClosureProxyArgument('service_container', 'get')) - ; - - $foo = $container->get('foo'); - - $this->assertInstanceOf('Closure', $foo->foo); - $this->assertSame($foo, call_user_func($foo->foo, 'foo')); - } - - public function testClosureProxyOnInvalidNull() - { - $container = new ContainerBuilder(); - - $container->register('foo', 'stdClass') - ->setProperty('foo', new ClosureProxyArgument('bar', 'c', ContainerInterface::NULL_ON_INVALID_REFERENCE)) - ; - - $foo = $container->get('foo'); - - $this->assertNull($foo->foo); - } - - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException - * @expectedExceptionMessage You have requested a non-existent service "bar". - */ - public function testClosureProxyOnInvalidException() - { - $container = new ContainerBuilder(); - - $container->register('foo', 'stdClass') - ->setProperty('foo', new ClosureProxyArgument('bar', 'c')) - ; - - $container->get('foo'); - } - public function testClassFromId() { $container = new ContainerBuilder(); @@ -1148,10 +1090,6 @@ class FooClass class A { - public function c() - { - return 123; - } } class B diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php index b11201111c1f5..fe53b941006de 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php @@ -472,46 +472,6 @@ public function testLazyArgumentProvideGenerator() $this->assertEmpty(iterator_to_array($lazyContext->lazyEmptyValues)); } - public function testClosureProxy() - { - $container = include self::$fixturesPath.'/containers/container31.php'; - $container->compile(); - $dumper = new PhpDumper($container); - - $this->assertStringEqualsFile(self::$fixturesPath.'/php/services31.php', $dumper->dump()); - $res = $container->getResources(); - $this->assertSame('reflection.Symfony\Component\DependencyInjection\Tests\Fixtures\Container31\Foo', (string) array_pop($res)); - } - - /** - * @requires PHP 7.1 - */ - public function testClosureProxyWithVoidReturnType() - { - $container = include self::$fixturesPath.'/containers/container_dump_proxy_with_void_return_type.php'; - - $container->compile(); - $dumper = new PhpDumper($container); - - $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_dump_proxy_with_void_return_type.php', $dumper->dump()); - $res = $container->getResources(); - $this->assertSame('reflection.Symfony\Component\DependencyInjection\Tests\Fixtures\ContainerVoid\Foo', (string) array_pop($res)); - } - - /** - * @requires PHP 7.1 - */ - public function testClosureProxyPhp71() - { - $container = include self::$fixturesPath.'/containers/container32.php'; - $container->compile(); - $dumper = new PhpDumper($container); - - $this->assertStringEqualsFile(self::$fixturesPath.'/php/services32.php', $dumper->dump()); - $res = $container->getResources(); - $this->assertSame('reflection.Symfony\Component\DependencyInjection\Tests\Fixtures\Container32\Foo', (string) array_pop($res)); - } - public function testNormalizedId() { $container = include self::$fixturesPath.'/containers/container33.php'; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container31.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container31.php deleted file mode 100644 index e8493ad02cdf6..0000000000000 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container31.php +++ /dev/null @@ -1,37 +0,0 @@ -register('foo', Foo::class); - -$container->register('bar', 'stdClass') - ->setProperty('foo', array( - new ClosureProxyArgument('foo', 'withNoArgs'), - new ClosureProxyArgument('foo', 'withArgs'), - new ClosureProxyArgument('foo', 'withRefs'), - )) -; - -return $container; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container32.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container32.php deleted file mode 100644 index 00d5654a5b464..0000000000000 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container32.php +++ /dev/null @@ -1,37 +0,0 @@ -register('foo', Foo::class); - -$container->register('bar', 'stdClass') - ->setProperty('foo', array( - new ClosureProxyArgument('foo', 'withVariadic'), - new ClosureProxyArgument('foo', 'withNullable'), - new ClosureProxyArgument('foo', 'withReturnType'), - )) -; - -return $container; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container33.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container33.php index 482558cb0d352..6deb52d170af8 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container33.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container33.php @@ -2,7 +2,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Container33; -use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument; use Symfony\Component\DependencyInjection\ContainerBuilder; if (!class_exists(Foo::class, false)) { diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php index 2a31ec6d76e47..13b45fda07a70 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php @@ -3,7 +3,6 @@ require_once __DIR__.'/../includes/classes.php'; require_once __DIR__.'/../includes/foo.php'; -use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -140,9 +139,5 @@ ->register('lazy_context_ignore_invalid_ref', 'LazyContext') ->setArguments(array(new IteratorArgument(array(new Reference('foo.baz'), new Reference('invalid', ContainerInterface::IGNORE_ON_INVALID_REFERENCE))), new IteratorArgument(array()))) ; -$container - ->register('closure_proxy', 'BarClass') - ->setArguments(array(new ClosureProxyArgument('closure_proxy', 'getBaz'))) -; return $container; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container_dump_proxy_with_void_return_type.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container_dump_proxy_with_void_return_type.php deleted file mode 100644 index ef9cb92a6c141..0000000000000 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container_dump_proxy_with_void_return_type.php +++ /dev/null @@ -1,27 +0,0 @@ -register('foo', Foo::class); - -$container->register('bar', 'stdClass') - ->setProperty('foo', array( - new ClosureProxyArgument('foo', 'withVoid'), - )) -; - -return $container; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services9.dot b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services9.dot index ac6a9c38d1d51..b316b93c1576b 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services9.dot +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services9.dot @@ -29,7 +29,6 @@ digraph sc { node_factory_service_simple [label="factory_service_simple\nBar\n", shape=record, fillcolor="#eeeeee", style="filled"]; node_lazy_context [label="lazy_context\nLazyContext\n", shape=record, fillcolor="#eeeeee", style="filled"]; node_lazy_context_ignore_invalid_ref [label="lazy_context_ignore_invalid_ref\nLazyContext\n", shape=record, fillcolor="#eeeeee", style="filled"]; - node_closure_proxy [label="closure_proxy\nBarClass\n", shape=record, fillcolor="#eeeeee", style="filled"]; node_foo2 [label="foo2\n\n", shape=record, fillcolor="#ff9999", style="filled"]; node_foo3 [label="foo3\n\n", shape=record, fillcolor="#ff9999", style="filled"]; node_foobaz [label="foobaz\n\n", shape=record, fillcolor="#ff9999", style="filled"]; @@ -51,5 +50,4 @@ digraph sc { node_lazy_context -> node_service_container [label="" style="filled" color="#9999ff"]; node_lazy_context_ignore_invalid_ref -> node_foo_baz [label="" style="filled" color="#9999ff"]; node_lazy_context_ignore_invalid_ref -> node_invalid [label="" style="filled" color="#9999ff"]; - node_closure_proxy -> node_closure_proxy [label="" style="filled" color="#9999ff"]; } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services31.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services31.php index d22a130cd0514..daf0ed5d60a19 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services31.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services31.php @@ -61,29 +61,6 @@ public function isFrozen() return true; } - /** - * Gets the 'bar' service. - * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \stdClass A stdClass instance - */ - protected function getBarService() - { - $this->services['bar'] = $instance = new \stdClass(); - - $instance->foo = array(0 => /** @closure-proxy Symfony\Component\DependencyInjection\Tests\Fixtures\Container31\Foo::withNoArgs */ function () { - return ${($_ = isset($this->services['foo']) ? $this->services['foo'] : $this->get('foo')) && false ?: '_'}->withNoArgs(); - }, 1 => /** @closure-proxy Symfony\Component\DependencyInjection\Tests\Fixtures\Container31\Foo::withArgs */ function ($a, \Symfony\Component\DependencyInjection\Tests\Fixtures\Container31\Foo $b = NULL, $c = array(0 => 123)) { - return ${($_ = isset($this->services['foo']) ? $this->services['foo'] : $this->get('foo')) && false ?: '_'}->withArgs($a, $b, $c); - }, 2 => /** @closure-proxy Symfony\Component\DependencyInjection\Tests\Fixtures\Container31\Foo::withRefs */ function &(&$a = NULL, &$b) { - return ${($_ = isset($this->services['foo']) ? $this->services['foo'] : $this->get('foo')) && false ?: '_'}->withRefs($a, $b); - }); - - return $instance; - } - /** * Gets the 'foo' service. * diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services32.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services32.php deleted file mode 100644 index 08ca63092a6a6..0000000000000 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services32.php +++ /dev/null @@ -1,99 +0,0 @@ -services = array(); - $this->methodMap = array( - 'bar' => 'getBarService', - 'foo' => 'getFooService', - ); - - $this->aliases = array(); - } - - /** - * {@inheritdoc} - */ - public function compile() - { - throw new LogicException('You cannot compile a dumped container that was already compiled.'); - } - - /** - * {@inheritdoc} - */ - public function isCompiled() - { - return true; - } - - /** - * {@inheritdoc} - */ - public function isFrozen() - { - @trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0. Use the isCompiled() method instead.', __METHOD__), E_USER_DEPRECATED); - - return true; - } - - /** - * Gets the 'bar' service. - * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \stdClass A stdClass instance - */ - protected function getBarService() - { - $this->services['bar'] = $instance = new \stdClass(); - - $instance->foo = array(0 => /** @closure-proxy Symfony\Component\DependencyInjection\Tests\Fixtures\Container32\Foo::withVariadic */ function ($a, &...$c) { - return ${($_ = isset($this->services['foo']) ? $this->services['foo'] : $this->get('foo')) && false ?: '_'}->withVariadic($a, ...$c); - }, 1 => /** @closure-proxy Symfony\Component\DependencyInjection\Tests\Fixtures\Container32\Foo::withNullable */ function (?int $a) { - return ${($_ = isset($this->services['foo']) ? $this->services['foo'] : $this->get('foo')) && false ?: '_'}->withNullable($a); - }, 2 => /** @closure-proxy Symfony\Component\DependencyInjection\Tests\Fixtures\Container32\Foo::withReturnType */ function (): \Bar { - return ${($_ = isset($this->services['foo']) ? $this->services['foo'] : $this->get('foo')) && false ?: '_'}->withReturnType(); - }); - - return $instance; - } - - /** - * Gets the 'foo' service. - * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \Symfony\Component\DependencyInjection\Tests\Fixtures\Container32\Foo A Symfony\Component\DependencyInjection\Tests\Fixtures\Container32\Foo instance - */ - protected function getFooService() - { - return $this->services['foo'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\Container32\Foo(); - } -} diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php index b8d5aeafacf24..2f8de5c8c0eb1 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php @@ -34,7 +34,6 @@ public function __construct() $this->methodMap = array( 'bar' => 'getBarService', 'baz' => 'getBazService', - 'closure_proxy' => 'getClosureProxyService', 'configurator_service' => 'getConfiguratorServiceService', 'configurator_service_simple' => 'getConfiguratorServiceSimpleService', 'configured_service' => 'getConfiguredServiceService', @@ -109,21 +108,6 @@ protected function getBazService() return $instance; } - /** - * Gets the 'closure_proxy' service. - * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \BarClass A BarClass instance - */ - protected function getClosureProxyService() - { - return $this->services['closure_proxy'] = new \BarClass(/** @closure-proxy BarClass::getBaz */ function () { - return ${($_ = isset($this->services['closure_proxy']) ? $this->services['closure_proxy'] : $this->get('closure_proxy')) && false ?: '_'}->getBaz(); - }); - } - /** * Gets the 'configured_service' service. * 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 a519cece6e297..08707b3b692c1 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php @@ -32,7 +32,6 @@ public function __construct() $this->methodMap = array( 'bar' => 'getBarService', 'baz' => 'getBazService', - 'closure_proxy' => 'getClosureProxyService', 'configured_service' => 'getConfiguredServiceService', 'configured_service_simple' => 'getConfiguredServiceSimpleService', 'decorator_service' => 'getDecoratorServiceService', @@ -119,21 +118,6 @@ protected function getBazService() return $instance; } - /** - * Gets the 'closure_proxy' service. - * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \BarClass A BarClass instance - */ - protected function getClosureProxyService() - { - return $this->services['closure_proxy'] = new \BarClass(/** @closure-proxy BarClass::getBaz */ function () { - return ${($_ = isset($this->services['closure_proxy']) ? $this->services['closure_proxy'] : $this->get('closure_proxy')) && false ?: '_'}->getBaz(); - }); - } - /** * Gets the 'configured_service' service. * diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_dump_proxy_with_void_return_type.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_dump_proxy_with_void_return_type.php deleted file mode 100644 index ec6af7fc2c8c5..0000000000000 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_dump_proxy_with_void_return_type.php +++ /dev/null @@ -1,95 +0,0 @@ -services = array(); - $this->methodMap = array( - 'bar' => 'getBarService', - 'foo' => 'getFooService', - ); - - $this->aliases = array(); - } - - /** - * {@inheritdoc} - */ - public function compile() - { - throw new LogicException('You cannot compile a dumped container that was already compiled.'); - } - - /** - * {@inheritdoc} - */ - public function isCompiled() - { - return true; - } - - /** - * {@inheritdoc} - */ - public function isFrozen() - { - @trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0. Use the isCompiled() method instead.', __METHOD__), E_USER_DEPRECATED); - - return true; - } - - /** - * Gets the 'bar' service. - * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \stdClass A stdClass instance - */ - protected function getBarService() - { - $this->services['bar'] = $instance = new \stdClass(); - - $instance->foo = array(0 => /** @closure-proxy Symfony\Component\DependencyInjection\Tests\Fixtures\ContainerVoid\Foo::withVoid */ function (): void { - ${($_ = isset($this->services['foo']) ? $this->services['foo'] : $this->get('foo')) && false ?: '_'}->withVoid(); - }); - - return $instance; - } - - /** - * Gets the 'foo' service. - * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \Symfony\Component\DependencyInjection\Tests\Fixtures\ContainerVoid\Foo A Symfony\Component\DependencyInjection\Tests\Fixtures\ContainerVoid\Foo instance - */ - protected function getFooService() - { - return $this->services['foo'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\ContainerVoid\Foo(); - } -} diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml index 79fdff4c4e2d0..100a23a9c5b7e 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml @@ -130,9 +130,6 @@ - - - diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml index bfee29fb605e5..a7a9cc28fd61b 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml @@ -116,9 +116,6 @@ services: lazy_context_ignore_invalid_ref: class: LazyContext arguments: [!iterator ['@foo.baz', '@?invalid'], !iterator []] - closure_proxy: - class: BarClass - arguments: [!closure_proxy ['@closure_proxy', getBaz]] alias_for_foo: '@foo' alias_for_alias: '@foo' Psr\Container\ContainerInterface: diff --git a/src/Symfony/Component/EventDispatcher/CHANGELOG.md b/src/Symfony/Component/EventDispatcher/CHANGELOG.md index 51c1d919bb4df..736bd84903b4b 100644 --- a/src/Symfony/Component/EventDispatcher/CHANGELOG.md +++ b/src/Symfony/Component/EventDispatcher/CHANGELOG.md @@ -4,7 +4,7 @@ CHANGELOG 3.3.0 ----- - * The ContainerAwareEventDispatcher class has been deprecated. Use EventDispatcher with closure-proxy injection instead. + * The ContainerAwareEventDispatcher class has been deprecated. Use EventDispatcher with closure factories instead. 3.0.0 ----- diff --git a/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php b/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php index 72eca3deb0490..f9e51b1a8b864 100644 --- a/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php +++ b/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php @@ -160,7 +160,7 @@ public function getListenerPriority($eventName, $listener) */ public function addSubscriberService($serviceId, $class) { - @trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use EventDispatcher with closure-proxy injection instead.', __CLASS__), E_USER_DEPRECATED); + @trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.', __CLASS__), E_USER_DEPRECATED); foreach ($class::getSubscribedEvents() as $eventName => $params) { if (is_string($params)) { diff --git a/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php b/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php index 130cc54d343bd..4029883dd98c7 100644 --- a/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php +++ b/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php @@ -46,13 +46,7 @@ public function __construct($listener, $name, Stopwatch $stopwatch, EventDispatc $this->name = is_object($listener[0]) ? get_class($listener[0]) : $listener[0]; $this->pretty = $this->name.'::'.$listener[1]; } elseif ($listener instanceof \Closure) { - $r = new \ReflectionFunction($listener); - if (preg_match('#^/\*\* @closure-proxy ([^: ]++)::([^: ]++) \*/$#', $r->getDocComment(), $m)) { - $this->name = $m[1]; - $this->pretty = $m[1].'::'.$m[2]; - } else { - $this->pretty = $this->name = 'closure'; - } + $this->pretty = $this->name = 'closure'; } elseif (is_string($listener)) { $this->pretty = $this->name = $listener; } else { diff --git a/src/Symfony/Component/VarDumper/Caster/ClassStub.php b/src/Symfony/Component/VarDumper/Caster/ClassStub.php index 51990bc356c0d..4765174d08670 100644 --- a/src/Symfony/Component/VarDumper/Caster/ClassStub.php +++ b/src/Symfony/Component/VarDumper/Caster/ClassStub.php @@ -38,10 +38,6 @@ public function __construct($identifier, $callable = null) if (null !== $callable) { if ($callable instanceof \Closure) { $r = new \ReflectionFunction($callable); - - if (preg_match('#^/\*\* @closure-proxy ([^: ]++)::([^: ]++) \*/$#', $r->getDocComment(), $m)) { - $r = array($m[1], $m[2]); - } } elseif (is_object($callable)) { $r = array($callable, '__invoke'); } elseif (is_array($callable)) { From c3d1262208783fa103e7bb9fe5b3cddb1096dcfd Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 30 May 2017 12:15:38 +0200 Subject: [PATCH 34/57] Use namespaced Twig --- composer.json | 2 +- .../Bridge/Twig/Command/DebugCommand.php | 10 +- .../Bridge/Twig/Command/LintCommand.php | 25 ++-- .../Twig/DataCollector/TwigDataCollector.php | 11 +- .../Bridge/Twig/Extension/AssetExtension.php | 10 +- .../Bridge/Twig/Extension/CodeExtension.php | 21 +-- .../Bridge/Twig/Extension/DumpExtension.php | 12 +- .../Twig/Extension/ExpressionExtension.php | 6 +- .../Bridge/Twig/Extension/FormExtension.php | 34 +++-- .../Extension/HttpFoundationExtension.php | 8 +- .../Twig/Extension/HttpKernelExtension.php | 10 +- .../Twig/Extension/LogoutUrlExtension.php | 8 +- .../Twig/Extension/ProfilerExtension.php | 10 +- .../Twig/Extension/RoutingExtension.php | 19 ++- .../Twig/Extension/SecurityExtension.php | 6 +- .../Twig/Extension/StopwatchExtension.php | 3 +- .../Twig/Extension/TranslationExtension.php | 14 +- .../Bridge/Twig/Extension/YamlExtension.php | 8 +- src/Symfony/Bridge/Twig/Form/TwigRenderer.php | 3 +- .../Bridge/Twig/Form/TwigRendererEngine.php | 14 +- .../Twig/Form/TwigRendererEngineInterface.php | 11 +- .../Twig/Form/TwigRendererInterface.php | 11 +- src/Symfony/Bridge/Twig/Node/DumpNode.php | 11 +- .../Bridge/Twig/Node/FormThemeNode.php | 14 +- .../Bridge/Twig/Node/RenderBlockNode.php | 7 +- .../Twig/Node/SearchAndRenderBlockNode.php | 15 ++- .../Bridge/Twig/Node/StopwatchNode.php | 10 +- .../Twig/Node/TransDefaultDomainNode.php | 15 +-- src/Symfony/Bridge/Twig/Node/TransNode.php | 38 +++--- .../TranslationDefaultDomainNodeVisitor.php | 31 +++-- .../NodeVisitor/TranslationNodeVisitor.php | 31 +++-- .../Twig/Tests/Command/LintCommandTest.php | 4 +- .../Tests/Extension/DumpExtensionTest.php | 6 +- .../Extension/ExpressionExtensionTest.php | 4 +- .../Fixtures/StubFilesystemLoader.php | 4 +- ...xtensionBootstrap3HorizontalLayoutTest.php | 3 +- .../FormExtensionBootstrap3LayoutTest.php | 3 +- .../Extension/FormExtensionDivLayoutTest.php | 3 +- .../FormExtensionTableLayoutTest.php | 3 +- .../Extension/HttpKernelExtensionTest.php | 8 +- .../Tests/Extension/RoutingExtensionTest.php | 9 +- .../Extension/StopwatchExtensionTest.php | 9 +- .../Extension/TranslationExtensionTest.php | 18 +-- .../Bridge/Twig/Tests/Node/DumpNodeTest.php | 34 ++--- .../Bridge/Twig/Tests/Node/FormThemeTest.php | 30 +++-- .../Node/SearchAndRenderBlockNodeTest.php | 125 +++++++++--------- .../Bridge/Twig/Tests/Node/TransNodeTest.php | 14 +- ...ranslationDefaultDomainNodeVisitorTest.php | 15 ++- .../TranslationNodeVisitorTest.php | 22 +-- .../Tests/NodeVisitor/TwigNodeProvider.php | 51 ++++--- .../TokenParser/FormThemeTokenParserTest.php | 56 ++++---- .../Tests/Translation/TwigExtractorTest.php | 17 ++- .../Bridge/Twig/Tests/TwigEngineTest.php | 8 +- .../Twig/TokenParser/DumpTokenParser.php | 10 +- .../Twig/TokenParser/FormThemeTokenParser.php | 20 +-- .../Twig/TokenParser/StopwatchTokenParser.php | 15 ++- .../TokenParser/TransChoiceTokenParser.php | 24 ++-- .../TransDefaultDomainTokenParser.php | 13 +- .../Twig/TokenParser/TransTokenParser.php | 33 +++-- .../Bridge/Twig/Translation/TwigExtractor.php | 13 +- src/Symfony/Bridge/Twig/TwigEngine.php | 45 +++---- src/Symfony/Bridge/Twig/composer.json | 2 +- ...ainerAwareHIncludeFragmentRendererTest.php | 2 +- .../Bundle/FrameworkBundle/composer.json | 2 +- .../Twig/Extension/LogoutUrlExtension.php | 8 +- .../Bundle/SecurityBundle/composer.json | 2 +- .../CacheWarmer/TemplateCacheCacheWarmer.php | 3 +- .../Controller/ExceptionController.php | 9 +- .../TwigBundle/Debug/TimedTwigEngine.php | 11 +- .../DependencyInjection/Configuration.php | 2 +- .../Configurator/EnvironmentConfigurator.php | 13 +- .../TwigBundle/Extension/ActionsExtension.php | 6 +- .../TwigBundle/Extension/AssetsExtension.php | 12 +- .../TwigBundle/Loader/FilesystemLoader.php | 10 +- .../Bundle/TwigBundle/Node/RenderNode.php | 15 +-- .../TwigBundle/Resources/config/twig.xml | 10 +- .../Controller/ExceptionControllerTest.php | 10 +- .../Compiler/ExtensionPassTest.php | 2 +- .../DependencyInjection/TwigExtensionTest.php | 4 +- .../Tests/Loader/FilesystemLoaderTest.php | 6 +- .../LegacyRenderTokenParserTest.php | 23 ++-- .../TokenParser/RenderTokenParser.php | 18 ++- src/Symfony/Bundle/TwigBundle/TwigEngine.php | 26 ++-- src/Symfony/Bundle/TwigBundle/composer.json | 2 +- .../Controller/ExceptionController.php | 9 +- .../Controller/ProfilerController.php | 5 +- .../Controller/RouterController.php | 3 +- .../EventListener/WebDebugToolbarListener.php | 3 +- .../Profiler/TemplateManager.php | 22 ++- .../Controller/ProfilerControllerTest.php | 6 +- .../WebProfilerExtensionTest.php | 6 +- .../WebDebugToolbarListenerTest.php | 2 +- .../Tests/Profiler/TemplateManagerTest.php | 13 +- .../Twig/WebProfilerExtension.php | 6 +- .../Bundle/WebProfilerBundle/composer.json | 2 +- .../DataCollector/DumpDataCollector.php | 3 +- .../Fragment/HIncludeFragmentRenderer.php | 21 +-- .../Component/HttpKernel/composer.json | 3 +- 98 files changed, 773 insertions(+), 576 deletions(-) diff --git a/composer.json b/composer.json index ecad4326d517c..1770bc4f305af 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "paragonie/random_compat": "~1.0", "symfony/polyfill-apcu": "~1.1", "symfony/polyfill-mbstring": "~1.1", - "twig/twig": "~1.28|~2.0", + "twig/twig": "~1.34|~2.4", "psr/log": "~1.0" }, "replace": { diff --git a/src/Symfony/Bridge/Twig/Command/DebugCommand.php b/src/Symfony/Bridge/Twig/Command/DebugCommand.php index 7473221277c81..d62aef0f2c32a 100644 --- a/src/Symfony/Bridge/Twig/Command/DebugCommand.php +++ b/src/Symfony/Bridge/Twig/Command/DebugCommand.php @@ -16,6 +16,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Twig\Environment; /** * Lists twig functions, filters, globals and tests present in the current project. @@ -34,18 +35,13 @@ public function __construct($name = 'debug:twig') parent::__construct($name); } - /** - * Sets the twig environment. - * - * @param \Twig_Environment $twig - */ - public function setTwigEnvironment(\Twig_Environment $twig) + public function setTwigEnvironment(Environment $twig) { $this->twig = $twig; } /** - * @return \Twig_Environment $twig + * @return Environment $twig */ protected function getTwigEnvironment() { diff --git a/src/Symfony/Bridge/Twig/Command/LintCommand.php b/src/Symfony/Bridge/Twig/Command/LintCommand.php index 83f4e1948c4c5..a731242ce5403 100644 --- a/src/Symfony/Bridge/Twig/Command/LintCommand.php +++ b/src/Symfony/Bridge/Twig/Command/LintCommand.php @@ -17,6 +17,10 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Finder\Finder; +use Twig\Environment; +use Twig\Error\Error; +use Twig\Loader\ArrayLoader; +use Twig\Source; /** * Command that will validate your template syntax and output encountered errors. @@ -36,18 +40,13 @@ public function __construct($name = 'lint:twig') parent::__construct($name); } - /** - * Sets the twig environment. - * - * @param \Twig_Environment $twig - */ - public function setTwigEnvironment(\Twig_Environment $twig) + public function setTwigEnvironment(Environment $twig) { $this->twig = $twig; } /** - * @return \Twig_Environment $twig + * @return Environment $twig */ protected function getTwigEnvironment() { @@ -117,7 +116,7 @@ protected function execute(InputInterface $input, OutputInterface $output) return $this->display($input, $output, $filesInfo); } - private function getFilesInfo(\Twig_Environment $twig, array $filenames) + private function getFilesInfo(Environment $twig, array $filenames) { $filesInfo = array(); foreach ($filenames as $filename) { @@ -140,16 +139,16 @@ protected function findFiles($filename) throw new \RuntimeException(sprintf('File or directory "%s" is not readable', $filename)); } - private function validate(\Twig_Environment $twig, $template, $file) + private function validate(Environment $twig, $template, $file) { $realLoader = $twig->getLoader(); try { - $temporaryLoader = new \Twig_Loader_Array(array((string) $file => $template)); + $temporaryLoader = new ArrayLoader(array((string) $file => $template)); $twig->setLoader($temporaryLoader); - $nodeTree = $twig->parse($twig->tokenize(new \Twig_Source($template, (string) $file))); + $nodeTree = $twig->parse($twig->tokenize(new Source($template, (string) $file))); $twig->compile($nodeTree); $twig->setLoader($realLoader); - } catch (\Twig_Error $e) { + } catch (Error $e) { $twig->setLoader($realLoader); return array('template' => $template, 'file' => $file, 'valid' => false, 'exception' => $e); @@ -207,7 +206,7 @@ private function displayJson(OutputInterface $output, $filesInfo) return min($errors, 1); } - private function renderException(OutputInterface $output, $template, \Twig_Error $exception, $file = null) + private function renderException(OutputInterface $output, $template, Error $exception, $file = null) { $line = $exception->getTemplateLine(); diff --git a/src/Symfony/Bridge/Twig/DataCollector/TwigDataCollector.php b/src/Symfony/Bridge/Twig/DataCollector/TwigDataCollector.php index 763a5ec4b31ee..fc2583bc7b234 100644 --- a/src/Symfony/Bridge/Twig/DataCollector/TwigDataCollector.php +++ b/src/Symfony/Bridge/Twig/DataCollector/TwigDataCollector.php @@ -15,6 +15,9 @@ use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Twig\Markup; +use Twig\Profiler\Dumper\HtmlDumper; +use Twig\Profiler\Profile; /** * TwigDataCollector. @@ -26,7 +29,7 @@ class TwigDataCollector extends DataCollector implements LateDataCollectorInterf private $profile; private $computed; - public function __construct(\Twig_Profiler_Profile $profile) + public function __construct(Profile $profile) { $this->profile = $profile; } @@ -73,9 +76,9 @@ public function getMacroCount() public function getHtmlCallGraph() { - $dumper = new \Twig_Profiler_Dumper_Html(); + $dumper = new HtmlDumper(); - return new \Twig_Markup($dumper->dump($this->getProfile()), 'UTF-8'); + return new Markup($dumper->dump($this->getProfile()), 'UTF-8'); } public function getProfile() @@ -96,7 +99,7 @@ private function getComputedData($index) return $this->computed[$index]; } - private function computeData(\Twig_Profiler_Profile $profile) + private function computeData(Profile $profile) { $data = array( 'template_count' => 0, diff --git a/src/Symfony/Bridge/Twig/Extension/AssetExtension.php b/src/Symfony/Bridge/Twig/Extension/AssetExtension.php index a72f4503dd869..40974686adda4 100644 --- a/src/Symfony/Bridge/Twig/Extension/AssetExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/AssetExtension.php @@ -13,13 +13,15 @@ use Symfony\Component\Asset\Packages; use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy; +use Twig\Extension\AbstractExtension; +use Twig\TwigFunction; /** * Twig extension for the Symfony Asset component. * * @author Fabien Potencier */ -class AssetExtension extends \Twig_Extension +class AssetExtension extends AbstractExtension { private $packages; private $foundationExtension; @@ -40,9 +42,9 @@ public function __construct(Packages $packages, HttpFoundationExtension $foundat public function getFunctions() { return array( - new \Twig_SimpleFunction('asset', array($this, 'getAssetUrl')), - new \Twig_SimpleFunction('asset_version', array($this, 'getAssetVersion')), - new \Twig_SimpleFunction('assets_version', array($this, 'getAssetsVersion'), array('deprecated' => true, 'alternative' => 'asset_version')), + new TwigFunction('asset', array($this, 'getAssetUrl')), + new TwigFunction('asset_version', array($this, 'getAssetVersion')), + new TwigFunction('assets_version', array($this, 'getAssetsVersion'), array('deprecated' => true, 'alternative' => 'asset_version')), ); } diff --git a/src/Symfony/Bridge/Twig/Extension/CodeExtension.php b/src/Symfony/Bridge/Twig/Extension/CodeExtension.php index 4b25d62198341..eca1e52d77a70 100644 --- a/src/Symfony/Bridge/Twig/Extension/CodeExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/CodeExtension.php @@ -11,12 +11,15 @@ namespace Symfony\Bridge\Twig\Extension; +use Twig\Extension\AbstractExtension; +use Twig\TwigFilter; + /** * Twig extension relate to PHP code and used by the profiler and the default exception templates. * * @author Fabien Potencier */ -class CodeExtension extends \Twig_Extension +class CodeExtension extends AbstractExtension { private $fileLinkFormat; private $rootDir; @@ -42,14 +45,14 @@ public function __construct($fileLinkFormat, $rootDir, $charset) public function getFilters() { return array( - new \Twig_SimpleFilter('abbr_class', array($this, 'abbrClass'), array('is_safe' => array('html'))), - new \Twig_SimpleFilter('abbr_method', array($this, 'abbrMethod'), array('is_safe' => array('html'))), - new \Twig_SimpleFilter('format_args', array($this, 'formatArgs'), array('is_safe' => array('html'))), - new \Twig_SimpleFilter('format_args_as_text', array($this, 'formatArgsAsText')), - new \Twig_SimpleFilter('file_excerpt', array($this, 'fileExcerpt'), array('is_safe' => array('html'))), - new \Twig_SimpleFilter('format_file', array($this, 'formatFile'), array('is_safe' => array('html'))), - new \Twig_SimpleFilter('format_file_from_text', array($this, 'formatFileFromText'), array('is_safe' => array('html'))), - new \Twig_SimpleFilter('file_link', array($this, 'getFileLink')), + new TwigFilter('abbr_class', array($this, 'abbrClass'), array('is_safe' => array('html'))), + new TwigFilter('abbr_method', array($this, 'abbrMethod'), array('is_safe' => array('html'))), + new TwigFilter('format_args', array($this, 'formatArgs'), array('is_safe' => array('html'))), + new TwigFilter('format_args_as_text', array($this, 'formatArgsAsText')), + new TwigFilter('file_excerpt', array($this, 'fileExcerpt'), array('is_safe' => array('html'))), + new TwigFilter('format_file', array($this, 'formatFile'), array('is_safe' => array('html'))), + new TwigFilter('format_file_from_text', array($this, 'formatFileFromText'), array('is_safe' => array('html'))), + new TwigFilter('file_link', array($this, 'getFileLink')), ); } diff --git a/src/Symfony/Bridge/Twig/Extension/DumpExtension.php b/src/Symfony/Bridge/Twig/Extension/DumpExtension.php index 5e43547ff1f40..eddd4d7f2afa0 100644 --- a/src/Symfony/Bridge/Twig/Extension/DumpExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/DumpExtension.php @@ -14,13 +14,17 @@ use Symfony\Bridge\Twig\TokenParser\DumpTokenParser; use Symfony\Component\VarDumper\Cloner\ClonerInterface; use Symfony\Component\VarDumper\Dumper\HtmlDumper; +use Twig\Environment; +use Twig\Extension\AbstractExtension; +use Twig\Template; +use Twig\TwigFunction; /** * Provides integration of the dump() function with Twig. * * @author Nicolas Grekas */ -class DumpExtension extends \Twig_Extension +class DumpExtension extends AbstractExtension { private $cloner; @@ -32,7 +36,7 @@ public function __construct(ClonerInterface $cloner) public function getFunctions() { return array( - new \Twig_SimpleFunction('dump', array($this, 'dump'), array('is_safe' => array('html'), 'needs_context' => true, 'needs_environment' => true)), + new TwigFunction('dump', array($this, 'dump'), array('is_safe' => array('html'), 'needs_context' => true, 'needs_environment' => true)), ); } @@ -46,7 +50,7 @@ public function getName() return 'dump'; } - public function dump(\Twig_Environment $env, $context) + public function dump(Environment $env, $context) { if (!$env->isDebug()) { return; @@ -55,7 +59,7 @@ public function dump(\Twig_Environment $env, $context) if (2 === func_num_args()) { $vars = array(); foreach ($context as $key => $value) { - if (!$value instanceof \Twig_Template) { + if (!$value instanceof Template) { $vars[$key] = $value; } } diff --git a/src/Symfony/Bridge/Twig/Extension/ExpressionExtension.php b/src/Symfony/Bridge/Twig/Extension/ExpressionExtension.php index 6b30a279419b7..fc64fa3e3775d 100644 --- a/src/Symfony/Bridge/Twig/Extension/ExpressionExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/ExpressionExtension.php @@ -12,13 +12,15 @@ namespace Symfony\Bridge\Twig\Extension; use Symfony\Component\ExpressionLanguage\Expression; +use Twig\Extension\AbstractExtension; +use Twig\TwigFunction; /** * ExpressionExtension gives a way to create Expressions from a template. * * @author Fabien Potencier */ -class ExpressionExtension extends \Twig_Extension +class ExpressionExtension extends AbstractExtension { /** * {@inheritdoc} @@ -26,7 +28,7 @@ class ExpressionExtension extends \Twig_Extension public function getFunctions() { return array( - new \Twig_SimpleFunction('expression', array($this, 'createExpression')), + new TwigFunction('expression', array($this, 'createExpression')), ); } diff --git a/src/Symfony/Bridge/Twig/Extension/FormExtension.php b/src/Symfony/Bridge/Twig/Extension/FormExtension.php index e833e3de2d228..053b1d4a6b336 100644 --- a/src/Symfony/Bridge/Twig/Extension/FormExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/FormExtension.php @@ -14,6 +14,12 @@ use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser; use Symfony\Bridge\Twig\Form\TwigRendererInterface; use Symfony\Component\Form\Extension\Core\View\ChoiceView; +use Twig\Environment; +use Twig\Extension\AbstractExtension; +use Twig\Extension\InitRuntimeInterface; +use Twig\TwigFilter; +use Twig\TwigFunction; +use Twig\TwigTest; /** * FormExtension extends Twig with form capabilities. @@ -21,7 +27,7 @@ * @author Fabien Potencier * @author Bernhard Schussek */ -class FormExtension extends \Twig_Extension implements \Twig_Extension_InitRuntimeInterface +class FormExtension extends AbstractExtension implements InitRuntimeInterface { /** * This property is public so that it can be accessed directly from compiled @@ -39,7 +45,7 @@ public function __construct(TwigRendererInterface $renderer) /** * {@inheritdoc} */ - public function initRuntime(\Twig_Environment $environment) + public function initRuntime(Environment $environment) { $this->renderer->setEnvironment($environment); } @@ -61,16 +67,16 @@ public function getTokenParsers() public function getFunctions() { return array( - new \Twig_SimpleFunction('form_enctype', null, array('node_class' => 'Symfony\Bridge\Twig\Node\FormEnctypeNode', 'is_safe' => array('html'), 'deprecated' => true, 'alternative' => 'form_start')), - new \Twig_SimpleFunction('form_widget', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))), - new \Twig_SimpleFunction('form_errors', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))), - new \Twig_SimpleFunction('form_label', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))), - new \Twig_SimpleFunction('form_row', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))), - new \Twig_SimpleFunction('form_rest', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))), - new \Twig_SimpleFunction('form', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))), - new \Twig_SimpleFunction('form_start', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))), - new \Twig_SimpleFunction('form_end', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))), - new \Twig_SimpleFunction('csrf_token', array($this, 'renderCsrfToken')), + new TwigFunction('form_enctype', null, array('node_class' => 'Symfony\Bridge\Twig\Node\FormEnctypeNode', 'is_safe' => array('html'), 'deprecated' => true, 'alternative' => 'form_start')), + new TwigFunction('form_widget', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))), + new TwigFunction('form_errors', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))), + new TwigFunction('form_label', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))), + new TwigFunction('form_row', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))), + new TwigFunction('form_rest', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))), + new TwigFunction('form', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))), + new TwigFunction('form_start', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))), + new TwigFunction('form_end', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))), + new TwigFunction('csrf_token', array($this, 'renderCsrfToken')), ); } @@ -80,7 +86,7 @@ public function getFunctions() public function getFilters() { return array( - new \Twig_SimpleFilter('humanize', array($this, 'humanize')), + new TwigFilter('humanize', array($this, 'humanize')), ); } @@ -90,7 +96,7 @@ public function getFilters() public function getTests() { return array( - new \Twig_SimpleTest('selectedchoice', array($this, 'isSelectedChoice')), + new TwigTest('selectedchoice', array($this, 'isSelectedChoice')), ); } diff --git a/src/Symfony/Bridge/Twig/Extension/HttpFoundationExtension.php b/src/Symfony/Bridge/Twig/Extension/HttpFoundationExtension.php index 69d6d326f4d08..90b515ee320ba 100644 --- a/src/Symfony/Bridge/Twig/Extension/HttpFoundationExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/HttpFoundationExtension.php @@ -14,13 +14,15 @@ use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\RequestContext; +use Twig\Extension\AbstractExtension; +use Twig\TwigFunction; /** * Twig extension for the Symfony HttpFoundation component. * * @author Fabien Potencier */ -class HttpFoundationExtension extends \Twig_Extension +class HttpFoundationExtension extends AbstractExtension { private $requestStack; private $requestContext; @@ -37,8 +39,8 @@ public function __construct(RequestStack $requestStack, RequestContext $requestC public function getFunctions() { return array( - new \Twig_SimpleFunction('absolute_url', array($this, 'generateAbsoluteUrl')), - new \Twig_SimpleFunction('relative_path', array($this, 'generateRelativePath')), + new TwigFunction('absolute_url', array($this, 'generateAbsoluteUrl')), + new TwigFunction('relative_path', array($this, 'generateRelativePath')), ); } diff --git a/src/Symfony/Bridge/Twig/Extension/HttpKernelExtension.php b/src/Symfony/Bridge/Twig/Extension/HttpKernelExtension.php index 1da12aaf5eb10..07e913059754c 100644 --- a/src/Symfony/Bridge/Twig/Extension/HttpKernelExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/HttpKernelExtension.php @@ -13,13 +13,15 @@ use Symfony\Component\HttpKernel\Fragment\FragmentHandler; use Symfony\Component\HttpKernel\Controller\ControllerReference; +use Twig\Extension\AbstractExtension; +use Twig\TwigFunction; /** * Provides integration with the HttpKernel component. * * @author Fabien Potencier */ -class HttpKernelExtension extends \Twig_Extension +class HttpKernelExtension extends AbstractExtension { private $handler; @@ -36,9 +38,9 @@ public function __construct(FragmentHandler $handler) public function getFunctions() { return array( - new \Twig_SimpleFunction('render', array($this, 'renderFragment'), array('is_safe' => array('html'))), - new \Twig_SimpleFunction('render_*', array($this, 'renderFragmentStrategy'), array('is_safe' => array('html'))), - new \Twig_SimpleFunction('controller', array($this, 'controller')), + new TwigFunction('render', array($this, 'renderFragment'), array('is_safe' => array('html'))), + new TwigFunction('render_*', array($this, 'renderFragmentStrategy'), array('is_safe' => array('html'))), + new TwigFunction('controller', array($this, 'controller')), ); } diff --git a/src/Symfony/Bridge/Twig/Extension/LogoutUrlExtension.php b/src/Symfony/Bridge/Twig/Extension/LogoutUrlExtension.php index ea105e8d955e4..17abb779899ac 100644 --- a/src/Symfony/Bridge/Twig/Extension/LogoutUrlExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/LogoutUrlExtension.php @@ -12,13 +12,15 @@ namespace Symfony\Bridge\Twig\Extension; use Symfony\Component\Security\Http\Logout\LogoutUrlGenerator; +use Twig\Extension\AbstractExtension; +use Twig\TwigFunction; /** * LogoutUrlHelper provides generator functions for the logout URL to Twig. * * @author Jeremy Mikola */ -class LogoutUrlExtension extends \Twig_Extension +class LogoutUrlExtension extends AbstractExtension { private $generator; @@ -33,8 +35,8 @@ public function __construct(LogoutUrlGenerator $generator) public function getFunctions() { return array( - new \Twig_SimpleFunction('logout_url', array($this, 'getLogoutUrl')), - new \Twig_SimpleFunction('logout_path', array($this, 'getLogoutPath')), + new TwigFunction('logout_url', array($this, 'getLogoutUrl')), + new TwigFunction('logout_path', array($this, 'getLogoutPath')), ); } diff --git a/src/Symfony/Bridge/Twig/Extension/ProfilerExtension.php b/src/Symfony/Bridge/Twig/Extension/ProfilerExtension.php index 648a6c8036d75..21214f81196ad 100644 --- a/src/Symfony/Bridge/Twig/Extension/ProfilerExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/ProfilerExtension.php @@ -12,16 +12,18 @@ namespace Symfony\Bridge\Twig\Extension; use Symfony\Component\Stopwatch\Stopwatch; +use Twig\Extension\ProfilerExtension as BaseProfilerExtension; +use Twig\Profiler\Profile; /** * @author Fabien Potencier */ -class ProfilerExtension extends \Twig_Extension_Profiler +class ProfilerExtension extends BaseProfilerExtension { private $stopwatch; private $events; - public function __construct(\Twig_Profiler_Profile $profile, Stopwatch $stopwatch = null) + public function __construct(Profile $profile, Stopwatch $stopwatch = null) { parent::__construct($profile); @@ -29,7 +31,7 @@ public function __construct(\Twig_Profiler_Profile $profile, Stopwatch $stopwatc $this->events = new \SplObjectStorage(); } - public function enter(\Twig_Profiler_Profile $profile) + public function enter(Profile $profile) { if ($this->stopwatch && $profile->isTemplate()) { $this->events[$profile] = $this->stopwatch->start($profile->getName(), 'template'); @@ -38,7 +40,7 @@ public function enter(\Twig_Profiler_Profile $profile) parent::enter($profile); } - public function leave(\Twig_Profiler_Profile $profile) + public function leave(Profile $profile) { parent::leave($profile); diff --git a/src/Symfony/Bridge/Twig/Extension/RoutingExtension.php b/src/Symfony/Bridge/Twig/Extension/RoutingExtension.php index 81cef949c7408..97b1ea31360ce 100644 --- a/src/Symfony/Bridge/Twig/Extension/RoutingExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/RoutingExtension.php @@ -12,13 +12,18 @@ namespace Symfony\Bridge\Twig\Extension; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; +use Twig\Extension\AbstractExtension; +use Twig\Node\Expression\ArrayExpression; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Node; +use Twig\TwigFunction; /** * Provides integration of the Routing component with Twig. * * @author Fabien Potencier */ -class RoutingExtension extends \Twig_Extension +class RoutingExtension extends AbstractExtension { private $generator; @@ -35,8 +40,8 @@ public function __construct(UrlGeneratorInterface $generator) public function getFunctions() { return array( - new \Twig_SimpleFunction('url', array($this, 'getUrl'), array('is_safe_callback' => array($this, 'isUrlGenerationSafe'))), - new \Twig_SimpleFunction('path', array($this, 'getPath'), array('is_safe_callback' => array($this, 'isUrlGenerationSafe'))), + new TwigFunction('url', array($this, 'getUrl'), array('is_safe_callback' => array($this, 'isUrlGenerationSafe'))), + new TwigFunction('path', array($this, 'getPath'), array('is_safe_callback' => array($this, 'isUrlGenerationSafe'))), ); } @@ -82,9 +87,11 @@ public function getUrl($name, $parameters = array(), $schemeRelative = false) * - path('route', {'param1': 'value1', 'param2': 'value2'}) * If param1 and param2 reference placeholder in the route, it would still be safe. But we don't know. * - * @param \Twig_Node $argsNode The arguments of the path/url function + * @param Node $argsNode The arguments of the path/url function * * @return array An array with the contexts the URL is safe + * + * To be made @final in 3.4, and the type-hint be changed to "\Twig\Node\Node" in 4.0. */ public function isUrlGenerationSafe(\Twig_Node $argsNode) { @@ -93,8 +100,8 @@ public function isUrlGenerationSafe(\Twig_Node $argsNode) $argsNode->hasNode(1) ? $argsNode->getNode(1) : null ); - if (null === $paramsNode || $paramsNode instanceof \Twig_Node_Expression_Array && count($paramsNode) <= 2 && - (!$paramsNode->hasNode(1) || $paramsNode->getNode(1) instanceof \Twig_Node_Expression_Constant) + if (null === $paramsNode || $paramsNode instanceof ArrayExpression && count($paramsNode) <= 2 && + (!$paramsNode->hasNode(1) || $paramsNode->getNode(1) instanceof ConstantExpression) ) { return array('html'); } diff --git a/src/Symfony/Bridge/Twig/Extension/SecurityExtension.php b/src/Symfony/Bridge/Twig/Extension/SecurityExtension.php index b13d7c0f85338..ffa8293eec2b0 100644 --- a/src/Symfony/Bridge/Twig/Extension/SecurityExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/SecurityExtension.php @@ -13,13 +13,15 @@ use Symfony\Component\Security\Acl\Voter\FieldVote; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; +use Twig\Extension\AbstractExtension; +use Twig\TwigFunction; /** * SecurityExtension exposes security context features. * * @author Fabien Potencier */ -class SecurityExtension extends \Twig_Extension +class SecurityExtension extends AbstractExtension { private $securityChecker; @@ -47,7 +49,7 @@ public function isGranted($role, $object = null, $field = null) public function getFunctions() { return array( - new \Twig_SimpleFunction('is_granted', array($this, 'isGranted')), + new TwigFunction('is_granted', array($this, 'isGranted')), ); } diff --git a/src/Symfony/Bridge/Twig/Extension/StopwatchExtension.php b/src/Symfony/Bridge/Twig/Extension/StopwatchExtension.php index 52af92324c228..635188b7389e4 100644 --- a/src/Symfony/Bridge/Twig/Extension/StopwatchExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/StopwatchExtension.php @@ -13,13 +13,14 @@ use Symfony\Component\Stopwatch\Stopwatch; use Symfony\Bridge\Twig\TokenParser\StopwatchTokenParser; +use Twig\Extension\AbstractExtension; /** * Twig extension for the stopwatch helper. * * @author Wouter J */ -class StopwatchExtension extends \Twig_Extension +class StopwatchExtension extends AbstractExtension { private $stopwatch; diff --git a/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php b/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php index f1f2fbd20b82e..5155169a8173d 100644 --- a/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php @@ -17,18 +17,22 @@ use Symfony\Component\Translation\TranslatorInterface; use Symfony\Bridge\Twig\NodeVisitor\TranslationNodeVisitor; use Symfony\Bridge\Twig\NodeVisitor\TranslationDefaultDomainNodeVisitor; +use Twig\Extension\AbstractExtension; +use Twig\NodeVisitor\NodeVisitorInterface; +use Twig\TokenParser\AbstractTokenParser; +use Twig\TwigFilter; /** * Provides integration of the Translation component with Twig. * * @author Fabien Potencier */ -class TranslationExtension extends \Twig_Extension +class TranslationExtension extends AbstractExtension { private $translator; private $translationNodeVisitor; - public function __construct(TranslatorInterface $translator, \Twig_NodeVisitorInterface $translationNodeVisitor = null) + public function __construct(TranslatorInterface $translator, NodeVisitorInterface $translationNodeVisitor = null) { if (!$translationNodeVisitor) { $translationNodeVisitor = new TranslationNodeVisitor(); @@ -49,15 +53,15 @@ public function getTranslator() public function getFilters() { return array( - new \Twig_SimpleFilter('trans', array($this, 'trans')), - new \Twig_SimpleFilter('transchoice', array($this, 'transchoice')), + new TwigFilter('trans', array($this, 'trans')), + new TwigFilter('transchoice', array($this, 'transchoice')), ); } /** * Returns the token parser instance to add to the existing list. * - * @return array An array of Twig_TokenParser instances + * @return AbstractTokenParser[] */ public function getTokenParsers() { diff --git a/src/Symfony/Bridge/Twig/Extension/YamlExtension.php b/src/Symfony/Bridge/Twig/Extension/YamlExtension.php index 2d46795b4a81e..894a2fd189014 100644 --- a/src/Symfony/Bridge/Twig/Extension/YamlExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/YamlExtension.php @@ -13,13 +13,15 @@ use Symfony\Component\Yaml\Dumper as YamlDumper; use Symfony\Component\Yaml\Yaml; +use Twig\Extension\AbstractExtension; +use Twig\TwigFilter; /** * Provides integration of the Yaml component with Twig. * * @author Fabien Potencier */ -class YamlExtension extends \Twig_Extension +class YamlExtension extends AbstractExtension { /** * {@inheritdoc} @@ -27,8 +29,8 @@ class YamlExtension extends \Twig_Extension public function getFilters() { return array( - new \Twig_SimpleFilter('yaml_encode', array($this, 'encode')), - new \Twig_SimpleFilter('yaml_dump', array($this, 'dump')), + new TwigFilter('yaml_encode', array($this, 'encode')), + new TwigFilter('yaml_dump', array($this, 'dump')), ); } diff --git a/src/Symfony/Bridge/Twig/Form/TwigRenderer.php b/src/Symfony/Bridge/Twig/Form/TwigRenderer.php index ac139e44a1331..2485c0a88c530 100644 --- a/src/Symfony/Bridge/Twig/Form/TwigRenderer.php +++ b/src/Symfony/Bridge/Twig/Form/TwigRenderer.php @@ -12,6 +12,7 @@ namespace Symfony\Bridge\Twig\Form; use Symfony\Component\Form\FormRenderer; +use Twig\Environment; /** * @author Bernhard Schussek @@ -33,7 +34,7 @@ public function __construct(TwigRendererEngineInterface $engine, $csrfTokenManag /** * {@inheritdoc} */ - public function setEnvironment(\Twig_Environment $environment) + public function setEnvironment(Environment $environment) { $this->engine->setEnvironment($environment); } diff --git a/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php b/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php index 5248d5fd370ea..d83124e721366 100644 --- a/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php +++ b/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php @@ -13,6 +13,8 @@ use Symfony\Component\Form\AbstractRendererEngine; use Symfony\Component\Form\FormView; +use Twig\Environment; +use Twig\Template; /** * @author Bernhard Schussek @@ -20,19 +22,19 @@ class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererEngineInterface { /** - * @var \Twig_Environment + * @var Environment */ private $environment; /** - * @var \Twig_Template + * @var Template */ private $template; /** * {@inheritdoc} */ - public function setEnvironment(\Twig_Environment $environment) + public function setEnvironment(Environment $environment) { $this->environment = $environment; } @@ -150,13 +152,13 @@ protected function loadResourceForBlockName($cacheKey, FormView $view, $blockNam */ protected function loadResourcesFromTheme($cacheKey, &$theme) { - if (!$theme instanceof \Twig_Template) { - /* @var \Twig_Template $theme */ + if (!$theme instanceof Template) { + /* @var Template $theme */ $theme = $this->environment->loadTemplate($theme); } if (null === $this->template) { - // Store the first \Twig_Template instance that we find so that + // Store the first Template instance that we find so that // we can call displayBlock() later on. It doesn't matter *which* // template we use for that, since we pass the used blocks manually // anyway. diff --git a/src/Symfony/Bridge/Twig/Form/TwigRendererEngineInterface.php b/src/Symfony/Bridge/Twig/Form/TwigRendererEngineInterface.php index ef764a248f339..3e8a8e1f4678d 100644 --- a/src/Symfony/Bridge/Twig/Form/TwigRendererEngineInterface.php +++ b/src/Symfony/Bridge/Twig/Form/TwigRendererEngineInterface.php @@ -12,16 +12,15 @@ namespace Symfony\Bridge\Twig\Form; use Symfony\Component\Form\FormRendererEngineInterface; +use Twig\Environment; + +// BC/FC with namespaced Twig +class_exists('Twig\Environment'); /** * @author Bernhard Schussek */ interface TwigRendererEngineInterface extends FormRendererEngineInterface { - /** - * Sets Twig's environment. - * - * @param \Twig_Environment $environment - */ - public function setEnvironment(\Twig_Environment $environment); + public function setEnvironment(Environment $environment); } diff --git a/src/Symfony/Bridge/Twig/Form/TwigRendererInterface.php b/src/Symfony/Bridge/Twig/Form/TwigRendererInterface.php index 4682f520008ac..cb45c17e1afc2 100644 --- a/src/Symfony/Bridge/Twig/Form/TwigRendererInterface.php +++ b/src/Symfony/Bridge/Twig/Form/TwigRendererInterface.php @@ -12,16 +12,15 @@ namespace Symfony\Bridge\Twig\Form; use Symfony\Component\Form\FormRendererInterface; +use Twig\Environment; + +// BC/FC with namespaced Twig +class_exists('Twig\Environment'); /** * @author Bernhard Schussek */ interface TwigRendererInterface extends FormRendererInterface { - /** - * Sets Twig's environment. - * - * @param \Twig_Environment $environment - */ - public function setEnvironment(\Twig_Environment $environment); + public function setEnvironment(Environment $environment); } diff --git a/src/Symfony/Bridge/Twig/Node/DumpNode.php b/src/Symfony/Bridge/Twig/Node/DumpNode.php index a66781e36550a..d820d75cc7db9 100644 --- a/src/Symfony/Bridge/Twig/Node/DumpNode.php +++ b/src/Symfony/Bridge/Twig/Node/DumpNode.php @@ -11,14 +11,17 @@ namespace Symfony\Bridge\Twig\Node; +use Twig\Compiler; +use Twig\Node\Node; + /** * @author Julien Galenski */ -class DumpNode extends \Twig_Node +class DumpNode extends Node { private $varPrefix; - public function __construct($varPrefix, \Twig_Node $values = null, $lineno, $tag = null) + public function __construct($varPrefix, Node $values = null, $lineno, $tag = null) { $nodes = array(); if (null !== $values) { @@ -32,7 +35,7 @@ public function __construct($varPrefix, \Twig_Node $values = null, $lineno, $tag /** * {@inheritdoc} */ - public function compile(\Twig_Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->write("if (\$this->env->isDebug()) {\n") @@ -44,7 +47,7 @@ public function compile(\Twig_Compiler $compiler) ->write(sprintf('$%svars = array();'."\n", $this->varPrefix)) ->write(sprintf('foreach ($context as $%1$skey => $%1$sval) {'."\n", $this->varPrefix)) ->indent() - ->write(sprintf('if (!$%sval instanceof \Twig_Template) {'."\n", $this->varPrefix)) + ->write(sprintf('if (!$%sval instanceof \Twig\Template) {'."\n", $this->varPrefix)) ->indent() ->write(sprintf('$%1$svars[$%1$skey] = $%1$sval;'."\n", $this->varPrefix)) ->outdent() diff --git a/src/Symfony/Bridge/Twig/Node/FormThemeNode.php b/src/Symfony/Bridge/Twig/Node/FormThemeNode.php index 91793771393d8..b2eb100d5bfdc 100644 --- a/src/Symfony/Bridge/Twig/Node/FormThemeNode.php +++ b/src/Symfony/Bridge/Twig/Node/FormThemeNode.php @@ -11,22 +11,20 @@ namespace Symfony\Bridge\Twig\Node; +use Twig\Compiler; +use Twig\Node\Node; + /** * @author Fabien Potencier */ -class FormThemeNode extends \Twig_Node +class FormThemeNode extends Node { - public function __construct(\Twig_Node $form, \Twig_Node $resources, $lineno, $tag = null) + public function __construct(Node $form, Node $resources, $lineno, $tag = null) { parent::__construct(array('form' => $form, 'resources' => $resources), array(), $lineno, $tag); } - /** - * Compiles the node to PHP. - * - * @param \Twig_Compiler $compiler A Twig_Compiler instance - */ - public function compile(\Twig_Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->addDebugInfo($this) diff --git a/src/Symfony/Bridge/Twig/Node/RenderBlockNode.php b/src/Symfony/Bridge/Twig/Node/RenderBlockNode.php index 33865e2f1cb78..4a06907b0b43a 100644 --- a/src/Symfony/Bridge/Twig/Node/RenderBlockNode.php +++ b/src/Symfony/Bridge/Twig/Node/RenderBlockNode.php @@ -11,6 +11,9 @@ namespace Symfony\Bridge\Twig\Node; +use Twig\Compiler; +use Twig\Node\Expression\FunctionExpression; + /** * Compiles a call to {@link \Symfony\Component\Form\FormRendererInterface::renderBlock()}. * @@ -19,9 +22,9 @@ * * @author Bernhard Schussek */ -class RenderBlockNode extends \Twig_Node_Expression_Function +class RenderBlockNode extends FunctionExpression { - public function compile(\Twig_Compiler $compiler) + public function compile(Compiler $compiler) { $compiler->addDebugInfo($this); $arguments = iterator_to_array($this->getNode('arguments')); diff --git a/src/Symfony/Bridge/Twig/Node/SearchAndRenderBlockNode.php b/src/Symfony/Bridge/Twig/Node/SearchAndRenderBlockNode.php index 9cb964865ea19..7c95199953b2f 100644 --- a/src/Symfony/Bridge/Twig/Node/SearchAndRenderBlockNode.php +++ b/src/Symfony/Bridge/Twig/Node/SearchAndRenderBlockNode.php @@ -11,12 +11,17 @@ namespace Symfony\Bridge\Twig\Node; +use Twig\Compiler; +use Twig\Node\Expression\ArrayExpression; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\FunctionExpression; + /** * @author Bernhard Schussek */ -class SearchAndRenderBlockNode extends \Twig_Node_Expression_Function +class SearchAndRenderBlockNode extends FunctionExpression { - public function compile(\Twig_Compiler $compiler) + public function compile(Compiler $compiler) { $compiler->addDebugInfo($this); $compiler->raw('$this->env->getExtension(\'Symfony\Bridge\Twig\Extension\FormExtension\')->renderer->searchAndRenderBlock('); @@ -39,7 +44,7 @@ public function compile(\Twig_Compiler $compiler) $variables = isset($arguments[2]) ? $arguments[2] : null; $lineno = $label->getTemplateLine(); - if ($label instanceof \Twig_Node_Expression_Constant) { + if ($label instanceof ConstantExpression) { // If the label argument is given as a constant, we can either // strip it away if it is empty, or integrate it into the array // of variables at compile time. @@ -48,8 +53,8 @@ public function compile(\Twig_Compiler $compiler) // Only insert the label into the array if it is not empty if (!twig_test_empty($label->getAttribute('value'))) { $originalVariables = $variables; - $variables = new \Twig_Node_Expression_Array(array(), $lineno); - $labelKey = new \Twig_Node_Expression_Constant('label', $lineno); + $variables = new ArrayExpression(array(), $lineno); + $labelKey = new ConstantExpression('label', $lineno); if (null !== $originalVariables) { foreach ($originalVariables->getKeyValuePairs() as $pair) { diff --git a/src/Symfony/Bridge/Twig/Node/StopwatchNode.php b/src/Symfony/Bridge/Twig/Node/StopwatchNode.php index 95d755a78cdb0..fac770c2499ba 100644 --- a/src/Symfony/Bridge/Twig/Node/StopwatchNode.php +++ b/src/Symfony/Bridge/Twig/Node/StopwatchNode.php @@ -11,19 +11,23 @@ namespace Symfony\Bridge\Twig\Node; +use Twig\Compiler; +use Twig\Node\Expression\AssignNameExpression; +use Twig\Node\Node; + /** * Represents a stopwatch node. * * @author Wouter J */ -class StopwatchNode extends \Twig_Node +class StopwatchNode extends Node { - public function __construct(\Twig_Node $name, \Twig_Node $body, \Twig_Node_Expression_AssignName $var, $lineno = 0, $tag = null) + public function __construct(Node $name, Node $body, AssignNameExpression $var, $lineno = 0, $tag = null) { parent::__construct(array('body' => $body, 'name' => $name, 'var' => $var), array(), $lineno, $tag); } - public function compile(\Twig_Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->addDebugInfo($this) diff --git a/src/Symfony/Bridge/Twig/Node/TransDefaultDomainNode.php b/src/Symfony/Bridge/Twig/Node/TransDefaultDomainNode.php index adee71ffc5dc4..c9c82b33e541c 100644 --- a/src/Symfony/Bridge/Twig/Node/TransDefaultDomainNode.php +++ b/src/Symfony/Bridge/Twig/Node/TransDefaultDomainNode.php @@ -11,22 +11,21 @@ namespace Symfony\Bridge\Twig\Node; +use Twig\Compiler; +use Twig\Node\Expression\AbstractExpression; +use Twig\Node\Node; + /** * @author Fabien Potencier */ -class TransDefaultDomainNode extends \Twig_Node +class TransDefaultDomainNode extends Node { - public function __construct(\Twig_Node_Expression $expr, $lineno = 0, $tag = null) + public function __construct(AbstractExpression $expr, $lineno = 0, $tag = null) { parent::__construct(array('expr' => $expr), array(), $lineno, $tag); } - /** - * Compiles the node to PHP. - * - * @param \Twig_Compiler $compiler A Twig_Compiler instance - */ - public function compile(\Twig_Compiler $compiler) + public function compile(Compiler $compiler) { // noop as this node is just a marker for TranslationDefaultDomainNodeVisitor } diff --git a/src/Symfony/Bridge/Twig/Node/TransNode.php b/src/Symfony/Bridge/Twig/Node/TransNode.php index 7b2f9c090405f..020810f7b7c55 100644 --- a/src/Symfony/Bridge/Twig/Node/TransNode.php +++ b/src/Symfony/Bridge/Twig/Node/TransNode.php @@ -11,12 +11,23 @@ namespace Symfony\Bridge\Twig\Node; +use Twig\Compiler; +use Twig\Node\Expression\AbstractExpression; +use Twig\Node\Expression\ArrayExpression; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\NameExpression; +use Twig\Node\Node; +use Twig\Node\TextNode; + +// BC/FC with namespaced Twig +class_exists('Twig\Node\Expression\ArrayExpression'); + /** * @author Fabien Potencier */ -class TransNode extends \Twig_Node +class TransNode extends Node { - public function __construct(\Twig_Node $body, \Twig_Node $domain = null, \Twig_Node_Expression $count = null, \Twig_Node_Expression $vars = null, \Twig_Node_Expression $locale = null, $lineno = 0, $tag = null) + public function __construct(Node $body, Node $domain = null, AbstractExpression $count = null, AbstractExpression $vars = null, AbstractExpression $locale = null, $lineno = 0, $tag = null) { $nodes = array('body' => $body); if (null !== $domain) { @@ -35,17 +46,12 @@ public function __construct(\Twig_Node $body, \Twig_Node $domain = null, \Twig_N parent::__construct($nodes, array(), $lineno, $tag); } - /** - * Compiles the node to PHP. - * - * @param \Twig_Compiler $compiler A Twig_Compiler instance - */ - public function compile(\Twig_Compiler $compiler) + public function compile(Compiler $compiler) { $compiler->addDebugInfo($this); - $defaults = new \Twig_Node_Expression_Array(array(), -1); - if ($this->hasNode('vars') && ($vars = $this->getNode('vars')) instanceof \Twig_Node_Expression_Array) { + $defaults = new ArrayExpression(array(), -1); + if ($this->hasNode('vars') && ($vars = $this->getNode('vars')) instanceof ArrayExpression) { $defaults = $this->getNode('vars'); $vars = null; } @@ -96,11 +102,11 @@ public function compile(\Twig_Compiler $compiler) $compiler->raw(");\n"); } - protected function compileString(\Twig_Node $body, \Twig_Node_Expression_Array $vars, $ignoreStrictCheck = false) + protected function compileString(Node $body, ArrayExpression $vars, $ignoreStrictCheck = false) { - if ($body instanceof \Twig_Node_Expression_Constant) { + if ($body instanceof ConstantExpression) { $msg = $body->getAttribute('value'); - } elseif ($body instanceof \Twig_Node_Text) { + } elseif ($body instanceof TextNode) { $msg = $body->getAttribute('data'); } else { return array($body, $vars); @@ -109,18 +115,18 @@ protected function compileString(\Twig_Node $body, \Twig_Node_Expression_Array $ preg_match_all('/(?getTemplateLine()); + $key = new ConstantExpression('%'.$var.'%', $body->getTemplateLine()); if (!$vars->hasElement($key)) { if ('count' === $var && $this->hasNode('count')) { $vars->addElement($this->getNode('count'), $key); } else { - $varExpr = new \Twig_Node_Expression_Name($var, $body->getTemplateLine()); + $varExpr = new NameExpression($var, $body->getTemplateLine()); $varExpr->setAttribute('ignore_strict_check', $ignoreStrictCheck); $vars->addElement($varExpr, $key); } } } - return array(new \Twig_Node_Expression_Constant(str_replace('%%', '%', trim($msg)), $body->getTemplateLine()), $vars); + return array(new ConstantExpression(str_replace('%%', '%', trim($msg)), $body->getTemplateLine()), $vars); } } diff --git a/src/Symfony/Bridge/Twig/NodeVisitor/TranslationDefaultDomainNodeVisitor.php b/src/Symfony/Bridge/Twig/NodeVisitor/TranslationDefaultDomainNodeVisitor.php index e64d6eae2347d..c69ca843e83ea 100644 --- a/src/Symfony/Bridge/Twig/NodeVisitor/TranslationDefaultDomainNodeVisitor.php +++ b/src/Symfony/Bridge/Twig/NodeVisitor/TranslationDefaultDomainNodeVisitor.php @@ -13,13 +13,22 @@ use Symfony\Bridge\Twig\Node\TransNode; use Symfony\Bridge\Twig\Node\TransDefaultDomainNode; +use Twig\Environment; +use Twig\Node\Expression\ArrayExpression; +use Twig\Node\Expression\AssignNameExpression; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\FilterExpression; +use Twig\Node\Expression\NameExpression; +use Twig\Node\ModuleNode; +use Twig\Node\Node; +use Twig\NodeVisitor\AbstractNodeVisitor; /** * TranslationDefaultDomainNodeVisitor. * * @author Fabien Potencier */ -class TranslationDefaultDomainNodeVisitor extends \Twig_BaseNodeVisitor +class TranslationDefaultDomainNodeVisitor extends AbstractNodeVisitor { /** * @var Scope @@ -37,23 +46,23 @@ public function __construct() /** * {@inheritdoc} */ - protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env) + protected function doEnterNode(Node $node, Environment $env) { - if ($node instanceof \Twig_Node_Block || $node instanceof \Twig_Node_Module) { + if ($node instanceof Node_Block || $node instanceof ModuleNode) { $this->scope = $this->scope->enter(); } if ($node instanceof TransDefaultDomainNode) { - if ($node->getNode('expr') instanceof \Twig_Node_Expression_Constant) { + if ($node->getNode('expr') instanceof ConstantExpression) { $this->scope->set('domain', $node->getNode('expr')); return $node; } else { $var = $this->getVarName(); - $name = new \Twig_Node_Expression_AssignName($var, $node->getTemplateLine()); - $this->scope->set('domain', new \Twig_Node_Expression_Name($var, $node->getTemplateLine())); + $name = new AssignNameExpression($var, $node->getTemplateLine()); + $this->scope->set('domain', new NameExpression($var, $node->getTemplateLine())); - return new \Twig_Node_Set(false, new \Twig_Node(array($name)), new \Twig_Node(array($node->getNode('expr'))), $node->getTemplateLine()); + return new Node_Set(false, new Node(array($name)), new Node(array($node->getNode('expr'))), $node->getTemplateLine()); } } @@ -61,7 +70,7 @@ protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env) return $node; } - if ($node instanceof \Twig_Node_Expression_Filter && in_array($node->getNode('filter')->getAttribute('value'), array('trans', 'transchoice'))) { + if ($node instanceof FilterExpression && in_array($node->getNode('filter')->getAttribute('value'), array('trans', 'transchoice'))) { $arguments = $node->getNode('arguments'); $ind = 'trans' === $node->getNode('filter')->getAttribute('value') ? 1 : 2; if ($this->isNamedArguments($arguments)) { @@ -71,7 +80,7 @@ protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env) } else { if (!$arguments->hasNode($ind)) { if (!$arguments->hasNode($ind - 1)) { - $arguments->setNode($ind - 1, new \Twig_Node_Expression_Array(array(), $node->getTemplateLine())); + $arguments->setNode($ind - 1, new ArrayExpression(array(), $node->getTemplateLine())); } $arguments->setNode($ind, $this->scope->get('domain')); @@ -89,13 +98,13 @@ protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env) /** * {@inheritdoc} */ - protected function doLeaveNode(\Twig_Node $node, \Twig_Environment $env) + protected function doLeaveNode(Node $node, Environment $env) { if ($node instanceof TransDefaultDomainNode) { return false; } - if ($node instanceof \Twig_Node_Block || $node instanceof \Twig_Node_Module) { + if ($node instanceof Node_Block || $node instanceof ModuleNode) { $this->scope = $this->scope->leave(); } diff --git a/src/Symfony/Bridge/Twig/NodeVisitor/TranslationNodeVisitor.php b/src/Symfony/Bridge/Twig/NodeVisitor/TranslationNodeVisitor.php index 6e3880d09ed98..01f230b9efdff 100644 --- a/src/Symfony/Bridge/Twig/NodeVisitor/TranslationNodeVisitor.php +++ b/src/Symfony/Bridge/Twig/NodeVisitor/TranslationNodeVisitor.php @@ -12,13 +12,18 @@ namespace Symfony\Bridge\Twig\NodeVisitor; use Symfony\Bridge\Twig\Node\TransNode; +use Twig\Environment; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\FilterExpression; +use Twig\Node\Node; +use Twig\NodeVisitor\AbstractNodeVisitor; /** * TranslationNodeVisitor extracts translation messages. * * @author Fabien Potencier */ -class TranslationNodeVisitor extends \Twig_BaseNodeVisitor +class TranslationNodeVisitor extends AbstractNodeVisitor { const UNDEFINED_DOMAIN = '_undefined'; @@ -45,16 +50,16 @@ public function getMessages() /** * {@inheritdoc} */ - protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env) + protected function doEnterNode(Node $node, Environment $env) { if (!$this->enabled) { return $node; } if ( - $node instanceof \Twig_Node_Expression_Filter && + $node instanceof FilterExpression && 'trans' === $node->getNode('filter')->getAttribute('value') && - $node->getNode('node') instanceof \Twig_Node_Expression_Constant + $node->getNode('node') instanceof ConstantExpression ) { // extract constant nodes with a trans filter $this->messages[] = array( @@ -62,9 +67,9 @@ protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env) $this->getReadDomainFromArguments($node->getNode('arguments'), 1), ); } elseif ( - $node instanceof \Twig_Node_Expression_Filter && + $node instanceof FilterExpression && 'transchoice' === $node->getNode('filter')->getAttribute('value') && - $node->getNode('node') instanceof \Twig_Node_Expression_Constant + $node->getNode('node') instanceof ConstantExpression ) { // extract constant nodes with a trans filter $this->messages[] = array( @@ -85,7 +90,7 @@ protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env) /** * {@inheritdoc} */ - protected function doLeaveNode(\Twig_Node $node, \Twig_Environment $env) + protected function doLeaveNode(Node $node, Environment $env) { return $node; } @@ -99,12 +104,12 @@ public function getPriority() } /** - * @param \Twig_Node $arguments - * @param int $index + * @param Node $arguments + * @param int $index * * @return string|null */ - private function getReadDomainFromArguments(\Twig_Node $arguments, $index) + private function getReadDomainFromArguments(Node $arguments, $index) { if ($arguments->hasNode('domain')) { $argument = $arguments->getNode('domain'); @@ -118,13 +123,13 @@ private function getReadDomainFromArguments(\Twig_Node $arguments, $index) } /** - * @param \Twig_Node $node + * @param Node $node * * @return string|null */ - private function getReadDomainFromNode(\Twig_Node $node) + private function getReadDomainFromNode(Node $node) { - if ($node instanceof \Twig_Node_Expression_Constant) { + if ($node instanceof ConstantExpression) { return $node->getAttribute('value'); } diff --git a/src/Symfony/Bridge/Twig/Tests/Command/LintCommandTest.php b/src/Symfony/Bridge/Twig/Tests/Command/LintCommandTest.php index 9a5c33a528a37..3349e38531cad 100644 --- a/src/Symfony/Bridge/Twig/Tests/Command/LintCommandTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Command/LintCommandTest.php @@ -16,6 +16,8 @@ use Symfony\Component\Console\Application; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Tester\CommandTester; +use Twig\Loader\FilesystemLoader; +use Twig\Environment; class LintCommandTest extends TestCase { @@ -71,7 +73,7 @@ public function testLintFileCompileTimeException() */ private function createCommandTester() { - $twig = new \Twig_Environment(new \Twig_Loader_Filesystem()); + $twig = new Environment(new FilesystemLoader()); $command = new LintCommand(); $command->setTwigEnvironment($twig); diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/DumpExtensionTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/DumpExtensionTest.php index 312fda1d7106a..36e0e6a08d99e 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/DumpExtensionTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/DumpExtensionTest.php @@ -15,6 +15,8 @@ use Symfony\Bridge\Twig\Extension\DumpExtension; use Symfony\Component\VarDumper\VarDumper; use Symfony\Component\VarDumper\Cloner\VarCloner; +use Twig\Environment; +use Twig\Loader\ArrayLoader; class DumpExtensionTest extends TestCase { @@ -24,7 +26,7 @@ class DumpExtensionTest extends TestCase public function testDumpTag($template, $debug, $expectedOutput, $expectedDumped) { $extension = new DumpExtension(new VarCloner()); - $twig = new \Twig_Environment(new \Twig_Loader_Array(array('template' => $template)), array( + $twig = new Environment(new ArrayLoader(array('template' => $template)), array( 'debug' => $debug, 'cache' => false, 'optimizations' => 0, @@ -64,7 +66,7 @@ public function getDumpTags() public function testDump($context, $args, $expectedOutput, $debug = true) { $extension = new DumpExtension(new VarCloner()); - $twig = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array( + $twig = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock(), array( 'debug' => $debug, 'cache' => false, 'optimizations' => 0, diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/ExpressionExtensionTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/ExpressionExtensionTest.php index 597dfc75f4165..ab3b44ccce0c1 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/ExpressionExtensionTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/ExpressionExtensionTest.php @@ -13,6 +13,8 @@ use PHPUnit\Framework\TestCase; use Symfony\Bridge\Twig\Extension\ExpressionExtension; +use Twig\Environment; +use Twig\Loader\ArrayLoader; class ExpressionExtensionTest extends TestCase { @@ -21,7 +23,7 @@ class ExpressionExtensionTest extends TestCase public function testExpressionCreation() { $template = "{{ expression('1 == 1') }}"; - $twig = new \Twig_Environment(new \Twig_Loader_Array(array('template' => $template)), array('debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0)); + $twig = new Environment(new ArrayLoader(array('template' => $template)), array('debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0)); $twig->addExtension(new ExpressionExtension()); $output = $twig->render('template'); diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubFilesystemLoader.php b/src/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubFilesystemLoader.php index 1c8e5dcd490f7..4cbc55b46a66c 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubFilesystemLoader.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubFilesystemLoader.php @@ -11,7 +11,9 @@ namespace Symfony\Bridge\Twig\Tests\Extension\Fixtures; -class StubFilesystemLoader extends \Twig_Loader_Filesystem +use Twig\Loader\FilesystemLoader; + +class StubFilesystemLoader extends FilesystemLoader { protected function findTemplate($name, $throw = true) { diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3HorizontalLayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3HorizontalLayoutTest.php index 8abcc8cd5677b..9d84946177af2 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3HorizontalLayoutTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3HorizontalLayoutTest.php @@ -19,6 +19,7 @@ use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader; use Symfony\Component\Form\FormView; use Symfony\Component\Form\Tests\AbstractBootstrap3HorizontalLayoutTest; +use Twig\Environment; class FormExtensionBootstrap3HorizontalLayoutTest extends AbstractBootstrap3HorizontalLayoutTest { @@ -48,7 +49,7 @@ protected function setUp() __DIR__.'/Fixtures/templates/form', )); - $environment = new \Twig_Environment($loader, array('strict_variables' => true)); + $environment = new Environment($loader, array('strict_variables' => true)); $environment->addExtension(new TranslationExtension(new StubTranslator())); $environment->addExtension($this->extension); diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3LayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3LayoutTest.php index 0236dd76e1e46..10161cbd4e1a7 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3LayoutTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3LayoutTest.php @@ -19,6 +19,7 @@ use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader; use Symfony\Component\Form\FormView; use Symfony\Component\Form\Tests\AbstractBootstrap3LayoutTest; +use Twig\Environment; class FormExtensionBootstrap3LayoutTest extends AbstractBootstrap3LayoutTest { @@ -48,7 +49,7 @@ protected function setUp() __DIR__.'/Fixtures/templates/form', )); - $environment = new \Twig_Environment($loader, array('strict_variables' => true)); + $environment = new Environment($loader, array('strict_variables' => true)); $environment->addExtension(new TranslationExtension(new StubTranslator())); $environment->addExtension($this->extension); diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php index d07e585a89234..2d7339b369d30 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php @@ -20,6 +20,7 @@ use Symfony\Component\Form\ChoiceList\View\ChoiceView; use Symfony\Component\Form\FormView; use Symfony\Component\Form\Tests\AbstractDivLayoutTest; +use Twig\Environment; class FormExtensionDivLayoutTest extends AbstractDivLayoutTest { @@ -49,7 +50,7 @@ protected function setUp() __DIR__.'/Fixtures/templates/form', )); - $environment = new \Twig_Environment($loader, array('strict_variables' => true)); + $environment = new Environment($loader, array('strict_variables' => true)); $environment->addExtension(new TranslationExtension(new StubTranslator())); $environment->addGlobal('global', ''); // the value can be any template that exists diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php index 9c95db6d5fd9d..1d526d5138fa5 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php @@ -19,6 +19,7 @@ use Symfony\Component\Form\Tests\AbstractTableLayoutTest; use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubTranslator; use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader; +use Twig\Environment; class FormExtensionTableLayoutTest extends AbstractTableLayoutTest { @@ -48,7 +49,7 @@ protected function setUp() __DIR__.'/Fixtures/templates/form', )); - $environment = new \Twig_Environment($loader, array('strict_variables' => true)); + $environment = new Environment($loader, array('strict_variables' => true)); $environment->addExtension(new TranslationExtension(new StubTranslator())); $environment->addGlobal('global', ''); $environment->addExtension($this->extension); diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php index 61e041d4d4c14..564ffc0432fe9 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php @@ -16,11 +16,13 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Fragment\FragmentHandler; +use Twig\Environment; +use Twig\Loader\ArrayLoader; class HttpKernelExtensionTest extends TestCase { /** - * @expectedException \Twig_Error_Runtime + * @expectedException \Twig\Error\RuntimeError */ public function testFragmentWithError() { @@ -74,8 +76,8 @@ protected function getFragmentHandler($return) protected function renderTemplate(FragmentHandler $renderer, $template = '{{ render("foo") }}') { - $loader = new \Twig_Loader_Array(array('index' => $template)); - $twig = new \Twig_Environment($loader, array('debug' => true, 'cache' => false)); + $loader = new ArrayLoader(array('index' => $template)); + $twig = new Environment($loader, array('debug' => true, 'cache' => false)); $twig->addExtension(new HttpKernelExtension($renderer)); return $twig->render('index'); diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/RoutingExtensionTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/RoutingExtensionTest.php index 5fa4e9cd36b1c..fdff039851228 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/RoutingExtensionTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/RoutingExtensionTest.php @@ -13,6 +13,9 @@ use PHPUnit\Framework\TestCase; use Symfony\Bridge\Twig\Extension\RoutingExtension; +use Twig\Environment; +use Twig\Node\Expression\FilterExpression; +use Twig\Source; class RoutingExtensionTest extends TestCase { @@ -21,12 +24,12 @@ class RoutingExtensionTest extends TestCase */ public function testEscaping($template, $mustBeEscaped) { - $twig = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0)); + $twig = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock(), array('debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0)); $twig->addExtension(new RoutingExtension($this->getMockBuilder('Symfony\Component\Routing\Generator\UrlGeneratorInterface')->getMock())); - $nodes = $twig->parse($twig->tokenize(new \Twig_Source($template, ''))); + $nodes = $twig->parse($twig->tokenize(new Source($template, ''))); - $this->assertSame($mustBeEscaped, $nodes->getNode('body')->getNode(0)->getNode('expr') instanceof \Twig_Node_Expression_Filter); + $this->assertSame($mustBeEscaped, $nodes->getNode('body')->getNode(0)->getNode('expr') instanceof FilterExpression); } public function getEscapingTemplates() diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/StopwatchExtensionTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/StopwatchExtensionTest.php index 86a4fcbe32269..7bc4eed6ab3e1 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/StopwatchExtensionTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/StopwatchExtensionTest.php @@ -13,11 +13,14 @@ use PHPUnit\Framework\TestCase; use Symfony\Bridge\Twig\Extension\StopwatchExtension; +use Twig\Environment; +use Twig\Error\RuntimeError; +use Twig\Loader\ArrayLoader; class StopwatchExtensionTest extends TestCase { /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError */ public function testFailIfStoppingWrongEvent() { @@ -29,12 +32,12 @@ public function testFailIfStoppingWrongEvent() */ public function testTiming($template, $events) { - $twig = new \Twig_Environment(new \Twig_Loader_Array(array('template' => $template)), array('debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0)); + $twig = new Environment(new ArrayLoader(array('template' => $template)), array('debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0)); $twig->addExtension(new StopwatchExtension($this->getStopwatch($events))); try { $nodes = $twig->render('template'); - } catch (\Twig_Error_Runtime $e) { + } catch (RuntimeError $e) { throw $e->getPrevious(); } } diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php index 446697d3dd8b2..36016d7f49bca 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php @@ -16,6 +16,8 @@ use Symfony\Component\Translation\Translator; use Symfony\Component\Translation\MessageSelector; use Symfony\Component\Translation\Loader\ArrayLoader; +use Twig\Environment; +use Twig\Loader\ArrayLoader as TwigArrayLoader; class TranslationExtensionTest extends TestCase { @@ -33,8 +35,8 @@ public function testTrans($template, $expected, array $variables = array()) { if ($expected != $this->getTemplate($template)->render($variables)) { echo $template."\n"; - $loader = new \Twig_Loader_Array(array('index' => $template)); - $twig = new \Twig_Environment($loader, array('debug' => true, 'cache' => false)); + $loader = new TwigArrayLoader(array('index' => $template)); + $twig = new Environment($loader, array('debug' => true, 'cache' => false)); $twig->addExtension(new TranslationExtension(new Translator('en', new MessageSelector()))); echo $twig->compile($twig->parse($twig->tokenize($twig->getLoader()->getSourceContext('index'))))."\n\n"; @@ -45,7 +47,7 @@ public function testTrans($template, $expected, array $variables = array()) } /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError * @expectedExceptionMessage Unexpected token. Twig was looking for the "with", "from", or "into" keyword in "index" at line 3. */ public function testTransUnknownKeyword() @@ -54,7 +56,7 @@ public function testTransUnknownKeyword() } /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError * @expectedExceptionMessage A message inside a trans tag must be a simple text in "index" at line 2. */ public function testTransComplexBody() @@ -63,7 +65,7 @@ public function testTransComplexBody() } /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError * @expectedExceptionMessage A message inside a transchoice tag must be a simple text in "index" at line 2. */ public function testTransChoiceComplexBody() @@ -189,11 +191,11 @@ protected function getTemplate($template, $translator = null) } if (is_array($template)) { - $loader = new \Twig_Loader_Array($template); + $loader = new TwigArrayLoader($template); } else { - $loader = new \Twig_Loader_Array(array('index' => $template)); + $loader = new TwigArrayLoader(array('index' => $template)); } - $twig = new \Twig_Environment($loader, array('debug' => true, 'cache' => false)); + $twig = new Environment($loader, array('debug' => true, 'cache' => false)); $twig->addExtension(new TranslationExtension($translator)); return $twig->loadTemplate('index'); diff --git a/src/Symfony/Bridge/Twig/Tests/Node/DumpNodeTest.php b/src/Symfony/Bridge/Twig/Tests/Node/DumpNodeTest.php index e38d9c728283b..087596e242281 100644 --- a/src/Symfony/Bridge/Twig/Tests/Node/DumpNodeTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Node/DumpNodeTest.php @@ -13,6 +13,10 @@ use PHPUnit\Framework\TestCase; use Symfony\Bridge\Twig\Node\DumpNode; +use Twig\Compiler; +use Twig\Environment; +use Twig\Node\Expression\NameExpression; +use Twig\Node\Node; class DumpNodeTest extends TestCase { @@ -20,14 +24,14 @@ public function testNoVar() { $node = new DumpNode('bar', null, 7); - $env = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()); - $compiler = new \Twig_Compiler($env); + $env = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock()); + $compiler = new Compiler($env); $expected = <<<'EOTXT' if ($this->env->isDebug()) { $barvars = array(); foreach ($context as $barkey => $barval) { - if (!$barval instanceof \Twig_Template) { + if (!$barval instanceof \Twig\Template) { $barvars[$barkey] = $barval; } } @@ -44,14 +48,14 @@ public function testIndented() { $node = new DumpNode('bar', null, 7); - $env = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()); - $compiler = new \Twig_Compiler($env); + $env = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock()); + $compiler = new Compiler($env); $expected = <<<'EOTXT' if ($this->env->isDebug()) { $barvars = array(); foreach ($context as $barkey => $barval) { - if (!$barval instanceof \Twig_Template) { + if (!$barval instanceof \Twig\Template) { $barvars[$barkey] = $barval; } } @@ -66,13 +70,13 @@ public function testIndented() public function testOneVar() { - $vars = new \Twig_Node(array( - new \Twig_Node_Expression_Name('foo', 7), + $vars = new Node(array( + new NameExpression('foo', 7), )); $node = new DumpNode('bar', $vars, 7); - $env = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()); - $compiler = new \Twig_Compiler($env); + $env = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock()); + $compiler = new Compiler($env); $expected = <<<'EOTXT' if ($this->env->isDebug()) { @@ -94,14 +98,14 @@ public function testOneVar() public function testMultiVars() { - $vars = new \Twig_Node(array( - new \Twig_Node_Expression_Name('foo', 7), - new \Twig_Node_Expression_Name('bar', 7), + $vars = new Node(array( + new NameExpression('foo', 7), + new NameExpression('bar', 7), )); $node = new DumpNode('bar', $vars, 7); - $env = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()); - $compiler = new \Twig_Compiler($env); + $env = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock()); + $compiler = new Compiler($env); $expected = <<<'EOTXT' if ($this->env->isDebug()) { diff --git a/src/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php b/src/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php index 923c20ff35d5f..48bbdab98cf1b 100644 --- a/src/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php @@ -13,15 +13,21 @@ use PHPUnit\Framework\TestCase; use Symfony\Bridge\Twig\Node\FormThemeNode; +use Twig\Compiler; +use Twig\Environment; +use Twig\Node\Expression\ArrayExpression; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\NameExpression; +use Twig\Node\Node; class FormThemeTest extends TestCase { public function testConstructor() { - $form = new \Twig_Node_Expression_Name('form', 0); - $resources = new \Twig_Node(array( - new \Twig_Node_Expression_Constant('tpl1', 0), - new \Twig_Node_Expression_Constant('tpl2', 0), + $form = new NameExpression('form', 0); + $resources = new Node(array( + new ConstantExpression('tpl1', 0), + new ConstantExpression('tpl2', 0), )); $node = new FormThemeNode($form, $resources, 0); @@ -32,17 +38,17 @@ public function testConstructor() public function testCompile() { - $form = new \Twig_Node_Expression_Name('form', 0); - $resources = new \Twig_Node_Expression_Array(array( - new \Twig_Node_Expression_Constant(0, 0), - new \Twig_Node_Expression_Constant('tpl1', 0), - new \Twig_Node_Expression_Constant(1, 0), - new \Twig_Node_Expression_Constant('tpl2', 0), + $form = new NameExpression('form', 0); + $resources = new ArrayExpression(array( + new ConstantExpression(0, 0), + new ConstantExpression('tpl1', 0), + new ConstantExpression(1, 0), + new ConstantExpression('tpl2', 0), ), 0); $node = new FormThemeNode($form, $resources, 0); - $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); + $compiler = new Compiler(new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock())); $this->assertEquals( sprintf( @@ -52,7 +58,7 @@ public function testCompile() trim($compiler->compile($node)->getSource()) ); - $resources = new \Twig_Node_Expression_Constant('tpl1', 0); + $resources = new ConstantExpression('tpl1', 0); $node = new FormThemeNode($form, $resources, 0); diff --git a/src/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php b/src/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php index e29f66ea3c56b..a603576f30274 100644 --- a/src/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php @@ -13,18 +13,25 @@ use PHPUnit\Framework\TestCase; use Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode; +use Twig\Compiler; +use Twig\Environment; +use Twig\Node\Expression\ArrayExpression; +use Twig\Node\Expression\ConditionalExpression; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\NameExpression; +use Twig\Node\Node; class SearchAndRenderBlockNodeTest extends TestCase { public function testCompileWidget() { - $arguments = new \Twig_Node(array( - new \Twig_Node_Expression_Name('form', 0), + $arguments = new Node(array( + new NameExpression('form', 0), )); $node = new SearchAndRenderBlockNode('form_widget', $arguments, 0); - $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); + $compiler = new Compiler(new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock())); $this->assertEquals( sprintf( @@ -37,17 +44,17 @@ public function testCompileWidget() public function testCompileWidgetWithVariables() { - $arguments = new \Twig_Node(array( - new \Twig_Node_Expression_Name('form', 0), - new \Twig_Node_Expression_Array(array( - new \Twig_Node_Expression_Constant('foo', 0), - new \Twig_Node_Expression_Constant('bar', 0), + $arguments = new Node(array( + new NameExpression('form', 0), + new ArrayExpression(array( + new ConstantExpression('foo', 0), + new ConstantExpression('bar', 0), ), 0), )); $node = new SearchAndRenderBlockNode('form_widget', $arguments, 0); - $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); + $compiler = new Compiler(new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock())); $this->assertEquals( sprintf( @@ -60,14 +67,14 @@ public function testCompileWidgetWithVariables() public function testCompileLabelWithLabel() { - $arguments = new \Twig_Node(array( - new \Twig_Node_Expression_Name('form', 0), - new \Twig_Node_Expression_Constant('my label', 0), + $arguments = new Node(array( + new NameExpression('form', 0), + new ConstantExpression('my label', 0), )); $node = new SearchAndRenderBlockNode('form_label', $arguments, 0); - $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); + $compiler = new Compiler(new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock())); $this->assertEquals( sprintf( @@ -80,14 +87,14 @@ public function testCompileLabelWithLabel() public function testCompileLabelWithNullLabel() { - $arguments = new \Twig_Node(array( - new \Twig_Node_Expression_Name('form', 0), - new \Twig_Node_Expression_Constant(null, 0), + $arguments = new Node(array( + new NameExpression('form', 0), + new ConstantExpression(null, 0), )); $node = new SearchAndRenderBlockNode('form_label', $arguments, 0); - $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); + $compiler = new Compiler(new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock())); // "label" => null must not be included in the output! // Otherwise the default label is overwritten with null. @@ -102,14 +109,14 @@ public function testCompileLabelWithNullLabel() public function testCompileLabelWithEmptyStringLabel() { - $arguments = new \Twig_Node(array( - new \Twig_Node_Expression_Name('form', 0), - new \Twig_Node_Expression_Constant('', 0), + $arguments = new Node(array( + new NameExpression('form', 0), + new ConstantExpression('', 0), )); $node = new SearchAndRenderBlockNode('form_label', $arguments, 0); - $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); + $compiler = new Compiler(new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock())); // "label" => null must not be included in the output! // Otherwise the default label is overwritten with null. @@ -124,13 +131,13 @@ public function testCompileLabelWithEmptyStringLabel() public function testCompileLabelWithDefaultLabel() { - $arguments = new \Twig_Node(array( - new \Twig_Node_Expression_Name('form', 0), + $arguments = new Node(array( + new NameExpression('form', 0), )); $node = new SearchAndRenderBlockNode('form_label', $arguments, 0); - $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); + $compiler = new Compiler(new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock())); $this->assertEquals( sprintf( @@ -143,18 +150,18 @@ public function testCompileLabelWithDefaultLabel() public function testCompileLabelWithAttributes() { - $arguments = new \Twig_Node(array( - new \Twig_Node_Expression_Name('form', 0), - new \Twig_Node_Expression_Constant(null, 0), - new \Twig_Node_Expression_Array(array( - new \Twig_Node_Expression_Constant('foo', 0), - new \Twig_Node_Expression_Constant('bar', 0), + $arguments = new Node(array( + new NameExpression('form', 0), + new ConstantExpression(null, 0), + new ArrayExpression(array( + new ConstantExpression('foo', 0), + new ConstantExpression('bar', 0), ), 0), )); $node = new SearchAndRenderBlockNode('form_label', $arguments, 0); - $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); + $compiler = new Compiler(new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock())); // "label" => null must not be included in the output! // Otherwise the default label is overwritten with null. @@ -170,20 +177,20 @@ public function testCompileLabelWithAttributes() public function testCompileLabelWithLabelAndAttributes() { - $arguments = new \Twig_Node(array( - new \Twig_Node_Expression_Name('form', 0), - new \Twig_Node_Expression_Constant('value in argument', 0), - new \Twig_Node_Expression_Array(array( - new \Twig_Node_Expression_Constant('foo', 0), - new \Twig_Node_Expression_Constant('bar', 0), - new \Twig_Node_Expression_Constant('label', 0), - new \Twig_Node_Expression_Constant('value in attributes', 0), + $arguments = new Node(array( + new NameExpression('form', 0), + new ConstantExpression('value in argument', 0), + new ArrayExpression(array( + new ConstantExpression('foo', 0), + new ConstantExpression('bar', 0), + new ConstantExpression('label', 0), + new ConstantExpression('value in attributes', 0), ), 0), )); $node = new SearchAndRenderBlockNode('form_label', $arguments, 0); - $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); + $compiler = new Compiler(new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock())); $this->assertEquals( sprintf( @@ -196,22 +203,22 @@ public function testCompileLabelWithLabelAndAttributes() public function testCompileLabelWithLabelThatEvaluatesToNull() { - $arguments = new \Twig_Node(array( - new \Twig_Node_Expression_Name('form', 0), - new \Twig_Node_Expression_Conditional( + $arguments = new Node(array( + new NameExpression('form', 0), + new ConditionalExpression( // if - new \Twig_Node_Expression_Constant(true, 0), + new ConstantExpression(true, 0), // then - new \Twig_Node_Expression_Constant(null, 0), + new ConstantExpression(null, 0), // else - new \Twig_Node_Expression_Constant(null, 0), + new ConstantExpression(null, 0), 0 ), )); $node = new SearchAndRenderBlockNode('form_label', $arguments, 0); - $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); + $compiler = new Compiler(new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock())); // "label" => null must not be included in the output! // Otherwise the default label is overwritten with null. @@ -227,28 +234,28 @@ public function testCompileLabelWithLabelThatEvaluatesToNull() public function testCompileLabelWithLabelThatEvaluatesToNullAndAttributes() { - $arguments = new \Twig_Node(array( - new \Twig_Node_Expression_Name('form', 0), - new \Twig_Node_Expression_Conditional( + $arguments = new Node(array( + new NameExpression('form', 0), + new ConditionalExpression( // if - new \Twig_Node_Expression_Constant(true, 0), + new ConstantExpression(true, 0), // then - new \Twig_Node_Expression_Constant(null, 0), + new ConstantExpression(null, 0), // else - new \Twig_Node_Expression_Constant(null, 0), + new ConstantExpression(null, 0), 0 ), - new \Twig_Node_Expression_Array(array( - new \Twig_Node_Expression_Constant('foo', 0), - new \Twig_Node_Expression_Constant('bar', 0), - new \Twig_Node_Expression_Constant('label', 0), - new \Twig_Node_Expression_Constant('value in attributes', 0), + new ArrayExpression(array( + new ConstantExpression('foo', 0), + new ConstantExpression('bar', 0), + new ConstantExpression('label', 0), + new ConstantExpression('value in attributes', 0), ), 0), )); $node = new SearchAndRenderBlockNode('form_label', $arguments, 0); - $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); + $compiler = new Compiler(new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock())); // "label" => null must not be included in the output! // Otherwise the default label is overwritten with null. diff --git a/src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php b/src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php index aabd813e5c5ac..c4d67fc962666 100644 --- a/src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php @@ -13,6 +13,10 @@ use PHPUnit\Framework\TestCase; use Symfony\Bridge\Twig\Node\TransNode; +use Twig\Compiler; +use Twig\Environment; +use Twig\Node\Expression\NameExpression; +use Twig\Node\TextNode; /** * @author Asmir Mustafic @@ -21,12 +25,12 @@ class TransNodeTest extends TestCase { public function testCompileStrict() { - $body = new \Twig_Node_Text('trans %var%', 0); - $vars = new \Twig_Node_Expression_Name('foo', 0); + $body = new TextNode('trans %var%', 0); + $vars = new NameExpression('foo', 0); $node = new TransNode($body, null, null, $vars); - $env = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('strict_variables' => true)); - $compiler = new \Twig_Compiler($env); + $env = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock(), array('strict_variables' => true)); + $compiler = new Compiler($env); $this->assertEquals( sprintf( @@ -53,7 +57,7 @@ protected function getVariableGetterWithoutStrictCheck($name) protected function getVariableGetterWithStrictCheck($name) { - if (\Twig_Environment::MAJOR_VERSION >= 2) { + if (Environment::MAJOR_VERSION >= 2) { return sprintf('(isset($context["%s"]) || array_key_exists("%s", $context) ? $context["%s"] : (function () { throw new Twig_Error_Runtime(\'Variable "%s" does not exist.\', 0, $this->getSourceContext()); })())', $name, $name, $name, $name); } diff --git a/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationDefaultDomainNodeVisitorTest.php b/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationDefaultDomainNodeVisitorTest.php index da9f43a6c4e0e..eb4c9a83e86d7 100644 --- a/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationDefaultDomainNodeVisitorTest.php +++ b/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationDefaultDomainNodeVisitorTest.php @@ -14,6 +14,9 @@ use PHPUnit\Framework\TestCase; use Symfony\Bridge\Twig\NodeVisitor\TranslationDefaultDomainNodeVisitor; use Symfony\Bridge\Twig\NodeVisitor\TranslationNodeVisitor; +use Twig\Environment; +use Twig\Node\Expression\ArrayExpression; +use Twig\Node\Node; class TranslationDefaultDomainNodeVisitorTest extends TestCase { @@ -21,9 +24,9 @@ class TranslationDefaultDomainNodeVisitorTest extends TestCase private static $domain = 'domain'; /** @dataProvider getDefaultDomainAssignmentTestData */ - public function testDefaultDomainAssignment(\Twig_Node $node) + public function testDefaultDomainAssignment(Node $node) { - $env = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0)); + $env = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0)); $visitor = new TranslationDefaultDomainNodeVisitor(); // visit trans_default_domain tag @@ -47,9 +50,9 @@ public function testDefaultDomainAssignment(\Twig_Node $node) } /** @dataProvider getDefaultDomainAssignmentTestData */ - public function testNewModuleWithoutDefaultDomainTag(\Twig_Node $node) + public function testNewModuleWithoutDefaultDomainTag(Node $node) { - $env = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0)); + $env = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0)); $visitor = new TranslationDefaultDomainNodeVisitor(); // visit trans_default_domain tag @@ -80,10 +83,10 @@ public function getDefaultDomainAssignmentTestData() array(TwigNodeProvider::getTransTag(self::$message)), // with named arguments array(TwigNodeProvider::getTransFilter(self::$message, null, array( - 'arguments' => new \Twig_Node_Expression_Array(array(), 0), + 'arguments' => new ArrayExpression(array(), 0), ))), array(TwigNodeProvider::getTransChoiceFilter(self::$message), null, array( - 'arguments' => new \Twig_Node_Expression_Array(array(), 0), + 'arguments' => new ArrayExpression(array(), 0), )), ); } diff --git a/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationNodeVisitorTest.php b/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationNodeVisitorTest.php index d12fff532aaa1..9c2d0ab9e40e5 100644 --- a/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationNodeVisitorTest.php +++ b/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationNodeVisitorTest.php @@ -13,13 +13,19 @@ use PHPUnit\Framework\TestCase; use Symfony\Bridge\Twig\NodeVisitor\TranslationNodeVisitor; +use Twig\Environment; +use Twig\Node\Expression\ArrayExpression; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\FilterExpression; +use Twig\Node\Expression\NameExpression; +use Twig\Node\Node; class TranslationNodeVisitorTest extends TestCase { /** @dataProvider getMessagesExtractionTestData */ - public function testMessagesExtraction(\Twig_Node $node, array $expectedMessages) + public function testMessagesExtraction(Node $node, array $expectedMessages) { - $env = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0)); + $env = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0)); $visitor = new TranslationNodeVisitor(); $visitor->enable(); $visitor->enterNode($node, $env); @@ -31,12 +37,12 @@ public function testMessageExtractionWithInvalidDomainNode() { $message = 'new key'; - $node = new \Twig_Node_Expression_Filter( - new \Twig_Node_Expression_Constant($message, 0), - new \Twig_Node_Expression_Constant('trans', 0), - new \Twig_Node(array( - new \Twig_Node_Expression_Array(array(), 0), - new \Twig_Node_Expression_Name('variable', 0), + $node = new FilterExpression( + new ConstantExpression($message, 0), + new ConstantExpression('trans', 0), + new Node(array( + new ArrayExpression(array(), 0), + new NameExpression('variable', 0), )), 0 ); diff --git a/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TwigNodeProvider.php b/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TwigNodeProvider.php index 502cad38dec0b..49eac23e8aeda 100644 --- a/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TwigNodeProvider.php +++ b/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TwigNodeProvider.php @@ -13,19 +13,26 @@ use Symfony\Bridge\Twig\Node\TransDefaultDomainNode; use Symfony\Bridge\Twig\Node\TransNode; +use Twig\Node\BodyNode; +use Twig\Node\Expression\ArrayExpression; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\FilterExpression; +use Twig\Node\ModuleNode; +use Twig\Node\Node; +use Twig\Source; class TwigNodeProvider { public static function getModule($content) { - return new \Twig_Node_Module( - new \Twig_Node_Expression_Constant($content, 0), + return new ModuleNode( + new ConstantExpression($content, 0), null, - new \Twig_Node_Expression_Array(array(), 0), - new \Twig_Node_Expression_Array(array(), 0), - new \Twig_Node_Expression_Array(array(), 0), + new ArrayExpression(array(), 0), + new ArrayExpression(array(), 0), + new ArrayExpression(array(), 0), null, - new \Twig_Source('', '') + new Source('', '') ); } @@ -33,15 +40,15 @@ public static function getTransFilter($message, $domain = null, $arguments = nul { if (!$arguments) { $arguments = $domain ? array( - new \Twig_Node_Expression_Array(array(), 0), - new \Twig_Node_Expression_Constant($domain, 0), + new ArrayExpression(array(), 0), + new ConstantExpression($domain, 0), ) : array(); } - return new \Twig_Node_Expression_Filter( - new \Twig_Node_Expression_Constant($message, 0), - new \Twig_Node_Expression_Constant('trans', 0), - new \Twig_Node($arguments), + return new FilterExpression( + new ConstantExpression($message, 0), + new ConstantExpression('trans', 0), + new Node($arguments), 0 ); } @@ -50,16 +57,16 @@ public static function getTransChoiceFilter($message, $domain = null, $arguments { if (!$arguments) { $arguments = $domain ? array( - new \Twig_Node_Expression_Constant(0, 0), - new \Twig_Node_Expression_Array(array(), 0), - new \Twig_Node_Expression_Constant($domain, 0), + new ConstantExpression(0, 0), + new ArrayExpression(array(), 0), + new ConstantExpression($domain, 0), ) : array(); } - return new \Twig_Node_Expression_Filter( - new \Twig_Node_Expression_Constant($message, 0), - new \Twig_Node_Expression_Constant('transchoice', 0), - new \Twig_Node($arguments), + return new FilterExpression( + new ConstantExpression($message, 0), + new ConstantExpression('transchoice', 0), + new Node($arguments), 0 ); } @@ -67,15 +74,15 @@ public static function getTransChoiceFilter($message, $domain = null, $arguments public static function getTransTag($message, $domain = null) { return new TransNode( - new \Twig_Node_Body(array(), array('data' => $message)), - $domain ? new \Twig_Node_Expression_Constant($domain, 0) : null + new BodyNode(array(), array('data' => $message)), + $domain ? new ConstantExpression($domain, 0) : null ); } public static function getTransDefaultDomainTag($domain) { return new TransDefaultDomainNode( - new \Twig_Node_Expression_Constant($domain, 0) + new ConstantExpression($domain, 0) ); } } diff --git a/src/Symfony/Bridge/Twig/Tests/TokenParser/FormThemeTokenParserTest.php b/src/Symfony/Bridge/Twig/Tests/TokenParser/FormThemeTokenParserTest.php index 8931be061f9d2..0972b15e23fdc 100644 --- a/src/Symfony/Bridge/Twig/Tests/TokenParser/FormThemeTokenParserTest.php +++ b/src/Symfony/Bridge/Twig/Tests/TokenParser/FormThemeTokenParserTest.php @@ -14,6 +14,12 @@ use PHPUnit\Framework\TestCase; use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser; use Symfony\Bridge\Twig\Node\FormThemeNode; +use Twig\Environment; +use Twig\Node\Expression\ArrayExpression; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\NameExpression; +use Twig\Parser; +use Twig\Source; class FormThemeTokenParserTest extends TestCase { @@ -22,10 +28,10 @@ class FormThemeTokenParserTest extends TestCase */ public function testCompile($source, $expected) { - $env = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0)); + $env = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0)); $env->addTokenParser(new FormThemeTokenParser()); - $stream = $env->tokenize(new \Twig_Source($source, '')); - $parser = new \Twig_Parser($env); + $stream = $env->tokenize(new Source($source, '')); + $parser = new Parser($env); $this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0)); } @@ -36,10 +42,10 @@ public function getTestsForFormTheme() array( '{% form_theme form "tpl1" %}', new FormThemeNode( - new \Twig_Node_Expression_Name('form', 1), - new \Twig_Node_Expression_Array(array( - new \Twig_Node_Expression_Constant(0, 1), - new \Twig_Node_Expression_Constant('tpl1', 1), + new NameExpression('form', 1), + new ArrayExpression(array( + new ConstantExpression(0, 1), + new ConstantExpression('tpl1', 1), ), 1), 1, 'form_theme' @@ -48,12 +54,12 @@ public function getTestsForFormTheme() array( '{% form_theme form "tpl1" "tpl2" %}', new FormThemeNode( - new \Twig_Node_Expression_Name('form', 1), - new \Twig_Node_Expression_Array(array( - new \Twig_Node_Expression_Constant(0, 1), - new \Twig_Node_Expression_Constant('tpl1', 1), - new \Twig_Node_Expression_Constant(1, 1), - new \Twig_Node_Expression_Constant('tpl2', 1), + new NameExpression('form', 1), + new ArrayExpression(array( + new ConstantExpression(0, 1), + new ConstantExpression('tpl1', 1), + new ConstantExpression(1, 1), + new ConstantExpression('tpl2', 1), ), 1), 1, 'form_theme' @@ -62,8 +68,8 @@ public function getTestsForFormTheme() array( '{% form_theme form with "tpl1" %}', new FormThemeNode( - new \Twig_Node_Expression_Name('form', 1), - new \Twig_Node_Expression_Constant('tpl1', 1), + new NameExpression('form', 1), + new ConstantExpression('tpl1', 1), 1, 'form_theme' ), @@ -71,10 +77,10 @@ public function getTestsForFormTheme() array( '{% form_theme form with ["tpl1"] %}', new FormThemeNode( - new \Twig_Node_Expression_Name('form', 1), - new \Twig_Node_Expression_Array(array( - new \Twig_Node_Expression_Constant(0, 1), - new \Twig_Node_Expression_Constant('tpl1', 1), + new NameExpression('form', 1), + new ArrayExpression(array( + new ConstantExpression(0, 1), + new ConstantExpression('tpl1', 1), ), 1), 1, 'form_theme' @@ -83,12 +89,12 @@ public function getTestsForFormTheme() array( '{% form_theme form with ["tpl1", "tpl2"] %}', new FormThemeNode( - new \Twig_Node_Expression_Name('form', 1), - new \Twig_Node_Expression_Array(array( - new \Twig_Node_Expression_Constant(0, 1), - new \Twig_Node_Expression_Constant('tpl1', 1), - new \Twig_Node_Expression_Constant(1, 1), - new \Twig_Node_Expression_Constant('tpl2', 1), + new NameExpression('form', 1), + new ArrayExpression(array( + new ConstantExpression(0, 1), + new ConstantExpression('tpl1', 1), + new ConstantExpression(1, 1), + new ConstantExpression('tpl2', 1), ), 1), 1, 'form_theme' diff --git a/src/Symfony/Bridge/Twig/Tests/Translation/TwigExtractorTest.php b/src/Symfony/Bridge/Twig/Tests/Translation/TwigExtractorTest.php index 0b1fb28b0e10c..013598a40b17f 100644 --- a/src/Symfony/Bridge/Twig/Tests/Translation/TwigExtractorTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Translation/TwigExtractorTest.php @@ -15,6 +15,9 @@ use Symfony\Bridge\Twig\Extension\TranslationExtension; use Symfony\Bridge\Twig\Translation\TwigExtractor; use Symfony\Component\Translation\MessageCatalogue; +use Twig\Environment; +use Twig\Error\Error; +use Twig\Loader\ArrayLoader; class TwigExtractorTest extends TestCase { @@ -23,8 +26,8 @@ class TwigExtractorTest extends TestCase */ public function testExtract($template, $messages) { - $loader = $this->getMockBuilder('Twig_LoaderInterface')->getMock(); - $twig = new \Twig_Environment($loader, array( + $loader = $this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock(); + $twig = new Environment($loader, array( 'strict_variables' => true, 'debug' => true, 'cache' => false, @@ -73,19 +76,19 @@ public function getExtractData() } /** - * @expectedException \Twig_Error + * @expectedException \Twig\Error\Error * @dataProvider resourcesWithSyntaxErrorsProvider */ public function testExtractSyntaxError($resources) { - $twig = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()); + $twig = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock()); $twig->addExtension(new TranslationExtension($this->getMockBuilder('Symfony\Component\Translation\TranslatorInterface')->getMock())); $extractor = new TwigExtractor($twig); try { $extractor->extract($resources, new MessageCatalogue('en')); - } catch (\Twig_Error $e) { + } catch (Error $e) { if (method_exists($e, 'getSourceContext')) { $this->assertSame(dirname(__DIR__).strtr('/Fixtures/extractor/syntax_error.twig', '/', DIRECTORY_SEPARATOR), $e->getFile()); $this->assertSame(1, $e->getLine()); @@ -114,8 +117,8 @@ public function resourcesWithSyntaxErrorsProvider() */ public function testExtractWithFiles($resource) { - $loader = new \Twig_Loader_Array(array()); - $twig = new \Twig_Environment($loader, array( + $loader = new ArrayLoader(array()); + $twig = new Environment($loader, array( 'strict_variables' => true, 'debug' => true, 'cache' => false, diff --git a/src/Symfony/Bridge/Twig/Tests/TwigEngineTest.php b/src/Symfony/Bridge/Twig/Tests/TwigEngineTest.php index e2082df3dd75b..a74c59e8d28c9 100644 --- a/src/Symfony/Bridge/Twig/Tests/TwigEngineTest.php +++ b/src/Symfony/Bridge/Twig/Tests/TwigEngineTest.php @@ -14,6 +14,8 @@ use PHPUnit\Framework\TestCase; use Symfony\Bridge\Twig\TwigEngine; use Symfony\Component\Templating\TemplateReference; +use Twig\Environment; +use Twig\Loader\ArrayLoader; class TwigEngineTest extends TestCase { @@ -21,7 +23,7 @@ public function testExistsWithTemplateInstances() { $engine = $this->getTwig(); - $this->assertTrue($engine->exists($this->getMockForAbstractClass('Twig_Template', array(), '', false))); + $this->assertTrue($engine->exists($this->getMockForAbstractClass('Twig\Template', array(), '', false))); } public function testExistsWithNonExistentTemplates() @@ -57,7 +59,7 @@ public function testRender() } /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError */ public function testRenderWithError() { @@ -68,7 +70,7 @@ public function testRenderWithError() protected function getTwig() { - $twig = new \Twig_Environment(new \Twig_Loader_Array(array( + $twig = new Environment(new ArrayLoader(array( 'index' => 'foo', 'error' => '{{ foo }', ))); diff --git a/src/Symfony/Bridge/Twig/TokenParser/DumpTokenParser.php b/src/Symfony/Bridge/Twig/TokenParser/DumpTokenParser.php index 269ead64f5d40..7cdbb77b4349b 100644 --- a/src/Symfony/Bridge/Twig/TokenParser/DumpTokenParser.php +++ b/src/Symfony/Bridge/Twig/TokenParser/DumpTokenParser.php @@ -12,6 +12,8 @@ namespace Symfony\Bridge\Twig\TokenParser; use Symfony\Bridge\Twig\Node\DumpNode; +use Twig\Token; +use Twig\TokenParser\AbstractTokenParser; /** * Token Parser for the 'dump' tag. @@ -25,18 +27,18 @@ * * @author Julien Galenski */ -class DumpTokenParser extends \Twig_TokenParser +class DumpTokenParser extends AbstractTokenParser { /** * {@inheritdoc} */ - public function parse(\Twig_Token $token) + public function parse(Token $token) { $values = null; - if (!$this->parser->getStream()->test(\Twig_Token::BLOCK_END_TYPE)) { + if (!$this->parser->getStream()->test(Token::BLOCK_END_TYPE)) { $values = $this->parser->getExpressionParser()->parseMultitargetExpression(); } - $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE); + $this->parser->getStream()->expect(Token::BLOCK_END_TYPE); return new DumpNode($this->parser->getVarName(), $values, $token->getLine(), $this->getTag()); } diff --git a/src/Symfony/Bridge/Twig/TokenParser/FormThemeTokenParser.php b/src/Symfony/Bridge/Twig/TokenParser/FormThemeTokenParser.php index daf87824e7b21..12c2541851e63 100644 --- a/src/Symfony/Bridge/Twig/TokenParser/FormThemeTokenParser.php +++ b/src/Symfony/Bridge/Twig/TokenParser/FormThemeTokenParser.php @@ -12,39 +12,43 @@ namespace Symfony\Bridge\Twig\TokenParser; use Symfony\Bridge\Twig\Node\FormThemeNode; +use Twig\Node\Expression\ArrayExpression; +use Twig\Node\Node; +use Twig\Token; +use Twig\TokenParser\AbstractTokenParser; /** * Token Parser for the 'form_theme' tag. * * @author Fabien Potencier */ -class FormThemeTokenParser extends \Twig_TokenParser +class FormThemeTokenParser extends AbstractTokenParser { /** * Parses a token and returns a node. * - * @param \Twig_Token $token A Twig_Token instance + * @param Token $token * - * @return \Twig_Node A Twig_Node instance + * @return Node */ - public function parse(\Twig_Token $token) + public function parse(Token $token) { $lineno = $token->getLine(); $stream = $this->parser->getStream(); $form = $this->parser->getExpressionParser()->parseExpression(); - if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'with')) { + if ($this->parser->getStream()->test(Token::NAME_TYPE, 'with')) { $this->parser->getStream()->next(); $resources = $this->parser->getExpressionParser()->parseExpression(); } else { - $resources = new \Twig_Node_Expression_Array(array(), $stream->getCurrent()->getLine()); + $resources = new ArrayExpression(array(), $stream->getCurrent()->getLine()); do { $resources->addElement($this->parser->getExpressionParser()->parseExpression()); - } while (!$stream->test(\Twig_Token::BLOCK_END_TYPE)); + } while (!$stream->test(Token::BLOCK_END_TYPE)); } - $stream->expect(\Twig_Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); return new FormThemeNode($form, $resources, $lineno, $this->getTag()); } diff --git a/src/Symfony/Bridge/Twig/TokenParser/StopwatchTokenParser.php b/src/Symfony/Bridge/Twig/TokenParser/StopwatchTokenParser.php index 2983e4cb6b03b..82c58d40bbf8d 100644 --- a/src/Symfony/Bridge/Twig/TokenParser/StopwatchTokenParser.php +++ b/src/Symfony/Bridge/Twig/TokenParser/StopwatchTokenParser.php @@ -12,13 +12,16 @@ namespace Symfony\Bridge\Twig\TokenParser; use Symfony\Bridge\Twig\Node\StopwatchNode; +use Twig\Node\Expression\AssignNameExpression; +use Twig\Token; +use Twig\TokenParser\AbstractTokenParser; /** * Token Parser for the stopwatch tag. * * @author Wouter J */ -class StopwatchTokenParser extends \Twig_TokenParser +class StopwatchTokenParser extends AbstractTokenParser { protected $stopwatchIsAvailable; @@ -27,7 +30,7 @@ public function __construct($stopwatchIsAvailable) $this->stopwatchIsAvailable = $stopwatchIsAvailable; } - public function parse(\Twig_Token $token) + public function parse(Token $token) { $lineno = $token->getLine(); $stream = $this->parser->getStream(); @@ -35,20 +38,20 @@ public function parse(\Twig_Token $token) // {% stopwatch 'bar' %} $name = $this->parser->getExpressionParser()->parseExpression(); - $stream->expect(\Twig_Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); // {% endstopwatch %} $body = $this->parser->subparse(array($this, 'decideStopwatchEnd'), true); - $stream->expect(\Twig_Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); if ($this->stopwatchIsAvailable) { - return new StopwatchNode($name, $body, new \Twig_Node_Expression_AssignName($this->parser->getVarName(), $token->getLine()), $lineno, $this->getTag()); + return new StopwatchNode($name, $body, new AssignNameExpression($this->parser->getVarName(), $token->getLine()), $lineno, $this->getTag()); } return $body; } - public function decideStopwatchEnd(\Twig_Token $token) + public function decideStopwatchEnd(Token $token) { return $token->test('endstopwatch'); } diff --git a/src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php b/src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php index fa61a2f1486c5..2b4a9f3fc4636 100644 --- a/src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php +++ b/src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php @@ -12,6 +12,12 @@ namespace Symfony\Bridge\Twig\TokenParser; use Symfony\Bridge\Twig\Node\TransNode; +use Twig\Error\SyntaxError; +use Twig\Node\Expression\AbstractExpression; +use Twig\Node\Expression\ArrayExpression; +use Twig\Node\Node; +use Twig\Node\TextNode; +use Twig\Token; /** * Token Parser for the 'transchoice' tag. @@ -23,18 +29,18 @@ class TransChoiceTokenParser extends TransTokenParser /** * Parses a token and returns a node. * - * @param \Twig_Token $token A Twig_Token instance + * @param Token $token * - * @return \Twig_Node A Twig_Node instance + * @return Node * - * @throws \Twig_Error_Syntax + * @throws SyntaxError */ - public function parse(\Twig_Token $token) + public function parse(Token $token) { $lineno = $token->getLine(); $stream = $this->parser->getStream(); - $vars = new \Twig_Node_Expression_Array(array(), $lineno); + $vars = new ArrayExpression(array(), $lineno); $count = $this->parser->getExpressionParser()->parseExpression(); @@ -59,15 +65,15 @@ public function parse(\Twig_Token $token) $locale = $this->parser->getExpressionParser()->parseExpression(); } - $stream->expect(\Twig_Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); $body = $this->parser->subparse(array($this, 'decideTransChoiceFork'), true); - if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) { - throw new \Twig_Error_Syntax('A message inside a transchoice tag must be a simple text.', $body->getTemplateLine(), $stream->getSourceContext()->getName()); + if (!$body instanceof TextNode && !$body instanceof AbstractExpression) { + throw new SyntaxError('A message inside a transchoice tag must be a simple text.', $body->getTemplateLine(), $stream->getSourceContext()->getName()); } - $stream->expect(\Twig_Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); return new TransNode($body, $domain, $count, $vars, $locale, $lineno, $this->getTag()); } diff --git a/src/Symfony/Bridge/Twig/TokenParser/TransDefaultDomainTokenParser.php b/src/Symfony/Bridge/Twig/TokenParser/TransDefaultDomainTokenParser.php index 09832ea972d91..4096a011a300d 100644 --- a/src/Symfony/Bridge/Twig/TokenParser/TransDefaultDomainTokenParser.php +++ b/src/Symfony/Bridge/Twig/TokenParser/TransDefaultDomainTokenParser.php @@ -12,26 +12,29 @@ namespace Symfony\Bridge\Twig\TokenParser; use Symfony\Bridge\Twig\Node\TransDefaultDomainNode; +use Twig\Node\Node; +use Twig\Token; +use Twig\TokenParser\AbstractTokenParser; /** * Token Parser for the 'trans_default_domain' tag. * * @author Fabien Potencier */ -class TransDefaultDomainTokenParser extends \Twig_TokenParser +class TransDefaultDomainTokenParser extends AbstractTokenParser { /** * Parses a token and returns a node. * - * @param \Twig_Token $token A Twig_Token instance + * @param Token $token * - * @return \Twig_Node A Twig_Node instance + * @return Node */ - public function parse(\Twig_Token $token) + public function parse(Token $token) { $expr = $this->parser->getExpressionParser()->parseExpression(); - $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE); + $this->parser->getStream()->expect(Token::BLOCK_END_TYPE); return new TransDefaultDomainNode($expr, $token->getLine(), $this->getTag()); } diff --git a/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php b/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php index 4c8e7d3eeea38..848a080710fa1 100644 --- a/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php +++ b/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php @@ -12,32 +12,39 @@ namespace Symfony\Bridge\Twig\TokenParser; use Symfony\Bridge\Twig\Node\TransNode; +use Twig\Error\SyntaxError; +use Twig\Node\Expression\AbstractExpression; +use Twig\Node\Expression\ArrayExpression; +use Twig\Node\Node; +use Twig\Node\TextNode; +use Twig\Token; +use Twig\TokenParser\AbstractTokenParser; /** * Token Parser for the 'trans' tag. * * @author Fabien Potencier */ -class TransTokenParser extends \Twig_TokenParser +class TransTokenParser extends AbstractTokenParser { /** * Parses a token and returns a node. * - * @param \Twig_Token $token A Twig_Token instance + * @param Token $token * - * @return \Twig_Node A Twig_Node instance + * @return Node * - * @throws \Twig_Error_Syntax + * @throws SyntaxError */ - public function parse(\Twig_Token $token) + public function parse(Token $token) { $lineno = $token->getLine(); $stream = $this->parser->getStream(); - $vars = new \Twig_Node_Expression_Array(array(), $lineno); + $vars = new ArrayExpression(array(), $lineno); $domain = null; $locale = null; - if (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) { + if (!$stream->test(Token::BLOCK_END_TYPE)) { if ($stream->test('with')) { // {% trans with vars %} $stream->next(); @@ -54,20 +61,20 @@ public function parse(\Twig_Token $token) // {% trans into "fr" %} $stream->next(); $locale = $this->parser->getExpressionParser()->parseExpression(); - } elseif (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) { - throw new \Twig_Error_Syntax('Unexpected token. Twig was looking for the "with", "from", or "into" keyword.', $stream->getCurrent()->getLine(), $stream->getSourceContext()->getName()); + } elseif (!$stream->test(Token::BLOCK_END_TYPE)) { + throw new SyntaxError('Unexpected token. Twig was looking for the "with", "from", or "into" keyword.', $stream->getCurrent()->getLine(), $stream->getSourceContext()->getName()); } } // {% trans %}message{% endtrans %} - $stream->expect(\Twig_Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); $body = $this->parser->subparse(array($this, 'decideTransFork'), true); - if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) { - throw new \Twig_Error_Syntax('A message inside a trans tag must be a simple text.', $body->getTemplateLine(), $stream->getSourceContext()->getName()); + if (!$body instanceof TextNode && !$body instanceof AbstractExpression) { + throw new SyntaxError('A message inside a trans tag must be a simple text.', $body->getTemplateLine(), $stream->getSourceContext()->getName()); } - $stream->expect(\Twig_Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); return new TransNode($body, $domain, null, $vars, $locale, $lineno, $this->getTag()); } diff --git a/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php b/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php index 35995dbd64518..bd35fe5a8b1eb 100644 --- a/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php +++ b/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php @@ -16,6 +16,9 @@ use Symfony\Component\Translation\Extractor\AbstractFileExtractor; use Symfony\Component\Translation\Extractor\ExtractorInterface; use Symfony\Component\Translation\MessageCatalogue; +use Twig\Environment; +use Twig\Error\Error; +use Twig\Source; /** * TwigExtractor extracts translation messages from a twig template. @@ -42,11 +45,11 @@ class TwigExtractor extends AbstractFileExtractor implements ExtractorInterface /** * The twig environment. * - * @var \Twig_Environment + * @var Environment */ private $twig; - public function __construct(\Twig_Environment $twig) + public function __construct(Environment $twig) { $this->twig = $twig; } @@ -60,12 +63,12 @@ public function extract($resource, MessageCatalogue $catalogue) foreach ($files as $file) { try { $this->extractTemplate(file_get_contents($file->getPathname()), $catalogue); - } catch (\Twig_Error $e) { + } catch (Error $e) { if ($file instanceof \SplFileInfo) { $path = $file->getRealPath() ?: $file->getPathname(); $name = $file instanceof SplFileInfo ? $file->getRelativePathname() : $path; if (method_exists($e, 'setSourceContext')) { - $e->setSourceContext(new \Twig_Source('', $name, $path)); + $e->setSourceContext(new Source('', $name, $path)); } else { $e->setTemplateName($name); } @@ -89,7 +92,7 @@ protected function extractTemplate($template, MessageCatalogue $catalogue) $visitor = $this->twig->getExtension('Symfony\Bridge\Twig\Extension\TranslationExtension')->getTranslationNodeVisitor(); $visitor->enable(); - $this->twig->parse($this->twig->tokenize(new \Twig_Source($template, ''))); + $this->twig->parse($this->twig->tokenize(new Source($template, ''))); foreach ($visitor->getMessages() as $message) { $catalogue->set(trim($message[0]), $this->prefix.trim($message[0]), $message[1] ?: $this->defaultDomain); diff --git a/src/Symfony/Bridge/Twig/TwigEngine.php b/src/Symfony/Bridge/Twig/TwigEngine.php index 760461b5be578..bc0a4fecc9af5 100644 --- a/src/Symfony/Bridge/Twig/TwigEngine.php +++ b/src/Symfony/Bridge/Twig/TwigEngine.php @@ -15,6 +15,11 @@ use Symfony\Component\Templating\StreamingEngineInterface; use Symfony\Component\Templating\TemplateNameParserInterface; use Symfony\Component\Templating\TemplateReferenceInterface; +use Twig\Environment; +use Twig\Error\Error; +use Twig\Error\LoaderError; +use Twig\Loader\ExistsLoaderInterface; +use Twig\Template; /** * This engine knows how to render Twig templates. @@ -26,13 +31,7 @@ class TwigEngine implements EngineInterface, StreamingEngineInterface protected $environment; protected $parser; - /** - * Constructor. - * - * @param \Twig_Environment $environment A \Twig_Environment instance - * @param TemplateNameParserInterface $parser A TemplateNameParserInterface instance - */ - public function __construct(\Twig_Environment $environment, TemplateNameParserInterface $parser) + public function __construct(Environment $environment, TemplateNameParserInterface $parser) { $this->environment = $environment; $this->parser = $parser; @@ -41,9 +40,9 @@ public function __construct(\Twig_Environment $environment, TemplateNameParserIn /** * {@inheritdoc} * - * It also supports \Twig_Template as name parameter. + * It also supports Template as name parameter. * - * @throws \Twig_Error if something went wrong like a thrown exception while rendering the template + * @throws Error if something went wrong like a thrown exception while rendering the template */ public function render($name, array $parameters = array()) { @@ -53,9 +52,9 @@ public function render($name, array $parameters = array()) /** * {@inheritdoc} * - * It also supports \Twig_Template as name parameter. + * It also supports Template as name parameter. * - * @throws \Twig_Error if something went wrong like a thrown exception while rendering the template + * @throws Error if something went wrong like a thrown exception while rendering the template */ public function stream($name, array $parameters = array()) { @@ -65,25 +64,25 @@ public function stream($name, array $parameters = array()) /** * {@inheritdoc} * - * It also supports \Twig_Template as name parameter. + * It also supports Template as name parameter. */ public function exists($name) { - if ($name instanceof \Twig_Template) { + if ($name instanceof Template) { return true; } $loader = $this->environment->getLoader(); - if ($loader instanceof \Twig_ExistsLoaderInterface || method_exists($loader, 'exists')) { + if ($loader instanceof ExistsLoaderInterface || method_exists($loader, 'exists')) { return $loader->exists((string) $name); } try { // cast possible TemplateReferenceInterface to string because the - // EngineInterface supports them but Twig_LoaderInterface does not + // EngineInterface supports them but LoaderInterface does not $loader->getSourceContext((string) $name)->getCode(); - } catch (\Twig_Error_Loader $e) { + } catch (LoaderError $e) { return false; } @@ -93,11 +92,11 @@ public function exists($name) /** * {@inheritdoc} * - * It also supports \Twig_Template as name parameter. + * It also supports Template as name parameter. */ public function supports($name) { - if ($name instanceof \Twig_Template) { + if ($name instanceof Template) { return true; } @@ -109,22 +108,22 @@ public function supports($name) /** * Loads the given template. * - * @param string|TemplateReferenceInterface|\Twig_Template $name A template name or an instance of - * TemplateReferenceInterface or \Twig_Template + * @param string|TemplateReferenceInterface|Template $name A template name or an instance of + * TemplateReferenceInterface or Template * - * @return \Twig_Template A \Twig_Template instance + * @return Template * * @throws \InvalidArgumentException if the template does not exist */ protected function load($name) { - if ($name instanceof \Twig_Template) { + if ($name instanceof Template) { return $name; } try { return $this->environment->loadTemplate((string) $name); - } catch (\Twig_Error_Loader $e) { + } catch (LoaderError $e) { throw new \InvalidArgumentException($e->getMessage(), $e->getCode(), $e); } } diff --git a/src/Symfony/Bridge/Twig/composer.json b/src/Symfony/Bridge/Twig/composer.json index 3bc0aa6d0cddf..3b6c4356e14ba 100644 --- a/src/Symfony/Bridge/Twig/composer.json +++ b/src/Symfony/Bridge/Twig/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": ">=5.3.9", - "twig/twig": "~1.28|~2.0" + "twig/twig": "~1.34|~2.4" }, "require-dev": { "symfony/asset": "~2.7", diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fragment/LegacyContainerAwareHIncludeFragmentRendererTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Fragment/LegacyContainerAwareHIncludeFragmentRendererTest.php index cc85cdb02acb2..5fca1cc8b4674 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fragment/LegacyContainerAwareHIncludeFragmentRendererTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fragment/LegacyContainerAwareHIncludeFragmentRendererTest.php @@ -25,7 +25,7 @@ public function testRender() $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); $container->expects($this->once()) ->method('get') - ->will($this->returnValue($this->getMockBuilder('\Twig_Environment')->disableOriginalConstructor()->getMock())) + ->will($this->returnValue($this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock())) ; $renderer = new ContainerAwareHIncludeFragmentRenderer($container); $renderer->render('/', Request::create('/')); diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index ad1560ad179ee..76648774f3baa 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -24,7 +24,7 @@ "symfony/event-dispatcher": "~2.5", "symfony/finder": "^2.0.5", "symfony/http-foundation": "~2.7", - "symfony/http-kernel": "~2.7.25|^2.8.18", + "symfony/http-kernel": "~2.7.29|^2.8.22", "symfony/filesystem": "~2.3", "symfony/routing": "~2.7.24|^2.8.17", "symfony/security-core": "~2.6.13|~2.7.9|~2.8", diff --git a/src/Symfony/Bundle/SecurityBundle/Twig/Extension/LogoutUrlExtension.php b/src/Symfony/Bundle/SecurityBundle/Twig/Extension/LogoutUrlExtension.php index d1eae0ef20487..40c931795f659 100644 --- a/src/Symfony/Bundle/SecurityBundle/Twig/Extension/LogoutUrlExtension.php +++ b/src/Symfony/Bundle/SecurityBundle/Twig/Extension/LogoutUrlExtension.php @@ -14,6 +14,8 @@ @trigger_error('The '.__NAMESPACE__.'\LogoutUrlExtension class is deprecated since version 2.7 and will be removed in 3.0. Use Symfony\Bridge\Twig\Extension\LogoutUrlExtension instead.', E_USER_DEPRECATED); use Symfony\Bundle\SecurityBundle\Templating\Helper\LogoutUrlHelper; +use Twig\Extension\AbstractExtension; +use Twig\TwigFunction; /** * LogoutUrlHelper provides generator functions for the logout URL to Twig. @@ -22,7 +24,7 @@ * * @deprecated since version 2.7, to be removed in 3.0. Use Symfony\Bridge\Twig\Extension\LogoutUrlExtension instead. */ -class LogoutUrlExtension extends \Twig_Extension +class LogoutUrlExtension extends AbstractExtension { private $helper; @@ -37,8 +39,8 @@ public function __construct(LogoutUrlHelper $helper) public function getFunctions() { return array( - new \Twig_SimpleFunction('logout_url', array($this, 'getLogoutUrl')), - new \Twig_SimpleFunction('logout_path', array($this, 'getLogoutPath')), + new TwigFunction('logout_url', array($this, 'getLogoutUrl')), + new TwigFunction('logout_path', array($this, 'getLogoutPath')), ); } diff --git a/src/Symfony/Bundle/SecurityBundle/composer.json b/src/Symfony/Bundle/SecurityBundle/composer.json index 5251f0138aa56..3da10d429d4bf 100644 --- a/src/Symfony/Bundle/SecurityBundle/composer.json +++ b/src/Symfony/Bundle/SecurityBundle/composer.json @@ -37,7 +37,7 @@ "symfony/yaml": "^2.0.5", "symfony/expression-language": "~2.6", "doctrine/doctrine-bundle": "~1.2", - "twig/twig": "~1.28|~2.0", + "twig/twig": "~1.34|~2.4", "ircmaxell/password-compat": "~1.0" }, "autoload": { diff --git a/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheCacheWarmer.php b/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheCacheWarmer.php index 8557a2f55aca1..e5be1d5234d53 100644 --- a/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheCacheWarmer.php +++ b/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheCacheWarmer.php @@ -14,6 +14,7 @@ use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplateFinderInterface; +use Twig\Error\Error; /** * Generates the Twig cache for all templates. @@ -65,7 +66,7 @@ public function warmUp($cacheDir) try { $twig->loadTemplate($template); - } catch (\Twig_Error $e) { + } catch (Error $e) { // problem during compilation, give up } } diff --git a/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php b/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php index b6972fc6354cd..0eab87de26e2b 100644 --- a/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php +++ b/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php @@ -17,6 +17,9 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Templating\TemplateReferenceInterface; +use Twig\Environment; +use Twig\Error\LoaderError; +use Twig\Loader\ExistsLoaderInterface; /** * ExceptionController renders error or exception pages for a given @@ -34,7 +37,7 @@ class ExceptionController */ protected $debug; - public function __construct(\Twig_Environment $twig, $debug) + public function __construct(Environment $twig, $debug) { $this->twig = $twig; $this->debug = $debug; @@ -131,7 +134,7 @@ protected function templateExists($template) $template = (string) $template; $loader = $this->twig->getLoader(); - if ($loader instanceof \Twig_ExistsLoaderInterface || method_exists($loader, 'exists')) { + if ($loader instanceof ExistsLoaderInterface || method_exists($loader, 'exists')) { return $loader->exists($template); } @@ -139,7 +142,7 @@ protected function templateExists($template) $loader->getSourceContext($template)->getCode(); return true; - } catch (\Twig_Error_Loader $e) { + } catch (LoaderError $e) { } return false; diff --git a/src/Symfony/Bundle/TwigBundle/Debug/TimedTwigEngine.php b/src/Symfony/Bundle/TwigBundle/Debug/TimedTwigEngine.php index e09479a2845ff..40f209999a635 100644 --- a/src/Symfony/Bundle/TwigBundle/Debug/TimedTwigEngine.php +++ b/src/Symfony/Bundle/TwigBundle/Debug/TimedTwigEngine.php @@ -17,6 +17,7 @@ use Symfony\Component\Templating\TemplateNameParserInterface; use Symfony\Component\Stopwatch\Stopwatch; use Symfony\Component\Config\FileLocatorInterface; +use Twig\Environment; /** * Times the time spent to render a template. @@ -29,15 +30,7 @@ class TimedTwigEngine extends TwigEngine { protected $stopwatch; - /** - * Constructor. - * - * @param \Twig_Environment $environment A \Twig_Environment instance - * @param TemplateNameParserInterface $parser A TemplateNameParserInterface instance - * @param FileLocatorInterface $locator A FileLocatorInterface instance - * @param Stopwatch $stopwatch A Stopwatch instance - */ - public function __construct(\Twig_Environment $environment, TemplateNameParserInterface $parser, FileLocatorInterface $locator, Stopwatch $stopwatch) + public function __construct(Environment $environment, TemplateNameParserInterface $parser, FileLocatorInterface $locator, Stopwatch $stopwatch) { parent::__construct($environment, $parser, $locator); diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php index 008f9b7e769dd..1c27fe1c04af4 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php @@ -170,7 +170,7 @@ private function addTwigOptions(ArrayNodeDefinition $rootNode) ->variableNode('autoescape')->defaultValue('name')->end() ->scalarNode('autoescape_service')->defaultNull()->end() ->scalarNode('autoescape_service_method')->defaultNull()->end() - ->scalarNode('base_template_class')->example('Twig_Template')->cannotBeEmpty()->end() + ->scalarNode('base_template_class')->example('Twig\Template')->cannotBeEmpty()->end() ->scalarNode('cache')->defaultValue('%kernel.cache_dir%/twig')->end() ->scalarNode('charset')->defaultValue('%kernel.charset%')->end() ->booleanNode('debug')->defaultValue('%kernel.debug%')->end() diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configurator/EnvironmentConfigurator.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configurator/EnvironmentConfigurator.php index bf37559b9920c..1612b6eb5fec2 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configurator/EnvironmentConfigurator.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configurator/EnvironmentConfigurator.php @@ -11,6 +11,11 @@ namespace Symfony\Bundle\TwigBundle\DependencyInjection\Configurator; +use Twig\Environment; + +// BC/FC with namespaced Twig +class_exists('Twig\Environment'); + /** * Twig environment configurator. * @@ -35,14 +40,14 @@ public function __construct($dateFormat, $intervalFormat, $timezone, $decimals, $this->thousandsSeparator = $thousandsSeparator; } - public function configure(\Twig_Environment $environment) + public function configure(Environment $environment) { - $environment->getExtension('Twig_Extension_Core')->setDateFormat($this->dateFormat, $this->intervalFormat); + $environment->getExtension('Twig\Extension\CoreExtension')->setDateFormat($this->dateFormat, $this->intervalFormat); if (null !== $this->timezone) { - $environment->getExtension('Twig_Extension_Core')->setTimezone($this->timezone); + $environment->getExtension('Twig\Extension\CoreExtension')->setTimezone($this->timezone); } - $environment->getExtension('Twig_Extension_Core')->setNumberFormat($this->decimals, $this->decimalPoint, $this->thousandsSeparator); + $environment->getExtension('Twig\Extension\CoreExtension')->setNumberFormat($this->decimals, $this->decimalPoint, $this->thousandsSeparator); } } diff --git a/src/Symfony/Bundle/TwigBundle/Extension/ActionsExtension.php b/src/Symfony/Bundle/TwigBundle/Extension/ActionsExtension.php index 8b4759ea270a8..5fee94d07c099 100644 --- a/src/Symfony/Bundle/TwigBundle/Extension/ActionsExtension.php +++ b/src/Symfony/Bundle/TwigBundle/Extension/ActionsExtension.php @@ -14,6 +14,8 @@ use Symfony\Bundle\TwigBundle\TokenParser\RenderTokenParser; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpKernel\Fragment\FragmentHandler; +use Twig\Extension\AbstractExtension; +use Twig\TokenParser\AbstractTokenParser; /** * Twig extension for Symfony actions helper. @@ -22,7 +24,7 @@ * * @deprecated since version 2.2, to be removed in 3.0. */ -class ActionsExtension extends \Twig_Extension +class ActionsExtension extends AbstractExtension { private $handler; @@ -69,7 +71,7 @@ public function renderUri($uri, array $options = array()) /** * Returns the token parser instance to add to the existing list. * - * @return array An array of \Twig_TokenParser instances + * @return AbstractTokenParser[] */ public function getTokenParsers() { diff --git a/src/Symfony/Bundle/TwigBundle/Extension/AssetsExtension.php b/src/Symfony/Bundle/TwigBundle/Extension/AssetsExtension.php index 976086920e07b..892e9cc739012 100644 --- a/src/Symfony/Bundle/TwigBundle/Extension/AssetsExtension.php +++ b/src/Symfony/Bundle/TwigBundle/Extension/AssetsExtension.php @@ -11,10 +11,12 @@ namespace Symfony\Bundle\TwigBundle\Extension; +@trigger_error('The '.__NAMESPACE__.'\AssetsExtension class is deprecated since version 2.7 and will be removed in 3.0. Use the Symfony\Bridge\Twig\Extension\AssetExtension class instead.', E_USER_DEPRECATED); + use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Routing\RequestContext; - -@trigger_error('The '.__NAMESPACE__.'\AssetsExtension class is deprecated since version 2.7 and will be removed in 3.0. Use the Symfony\Bridge\Twig\Extension\AssetExtension class instead.', E_USER_DEPRECATED); +use Twig\Extension\AbstractExtension; +use Twig\TwigFunction; /** * Twig extension for Symfony assets helper. @@ -23,7 +25,7 @@ * * @deprecated since 2.7, to be removed in 3.0. Use Symfony\Bridge\Twig\Extension\AssetExtension instead. */ -class AssetsExtension extends \Twig_Extension +class AssetsExtension extends AbstractExtension { private $container; private $context; @@ -42,8 +44,8 @@ public function __construct(ContainerInterface $container, RequestContext $reque public function getFunctions() { return array( - new \Twig_SimpleFunction('asset', array($this, 'getAssetUrl')), - new \Twig_SimpleFunction('assets_version', array($this, 'getAssetsVersion')), + new TwigFunction('asset', array($this, 'getAssetUrl')), + new TwigFunction('assets_version', array($this, 'getAssetsVersion')), ); } diff --git a/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php b/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php index 53fe300e29a62..68a7b4560c95d 100644 --- a/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php +++ b/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php @@ -14,6 +14,8 @@ use Symfony\Component\Config\FileLocatorInterface; use Symfony\Component\Templating\TemplateNameParserInterface; use Symfony\Component\Templating\TemplateReferenceInterface; +use Twig\Error\LoaderError; +use Twig\Loader\FilesystemLoader as BaseFilesystemLoader; /** * FilesystemLoader extends the default Twig filesystem loader @@ -21,7 +23,7 @@ * * @author Fabien Potencier */ -class FilesystemLoader extends \Twig_Loader_Filesystem +class FilesystemLoader extends BaseFilesystemLoader { protected $locator; protected $parser; @@ -58,11 +60,11 @@ public function exists($name) * Otherwise the template is located using the locator from the twig library. * * @param string|TemplateReferenceInterface $template The template - * @param bool $throw When true, a \Twig_Error_Loader exception will be thrown if a template could not be found + * @param bool $throw When true, a LoaderError exception will be thrown if a template could not be found * * @return string The path to the template file * - * @throws \Twig_Error_Loader if the template could not be found + * @throws LoaderError if the template could not be found */ protected function findTemplate($template, $throw = true) { @@ -76,7 +78,7 @@ protected function findTemplate($template, $throw = true) $previous = null; try { $file = parent::findTemplate($logicalName); - } catch (\Twig_Error_Loader $e) { + } catch (LoaderError $e) { $twigLoaderException = $e; // for BC diff --git a/src/Symfony/Bundle/TwigBundle/Node/RenderNode.php b/src/Symfony/Bundle/TwigBundle/Node/RenderNode.php index 4e3b12dae1978..e9a378f399139 100644 --- a/src/Symfony/Bundle/TwigBundle/Node/RenderNode.php +++ b/src/Symfony/Bundle/TwigBundle/Node/RenderNode.php @@ -11,6 +11,10 @@ namespace Symfony\Bundle\TwigBundle\Node; +use Twig\Compiler; +use Twig\Node\Expression\AbstractExpression; +use Twig\Node\Node; + /** * Represents a render node. * @@ -18,19 +22,14 @@ * * @deprecated since version 2.2, to be removed in 3.0. */ -class RenderNode extends \Twig_Node +class RenderNode extends Node { - public function __construct(\Twig_Node_Expression $expr, \Twig_Node_Expression $options, $lineno, $tag = null) + public function __construct(AbstractExpression $expr, AbstractExpression $options, $lineno, $tag = null) { parent::__construct(array('expr' => $expr, 'options' => $options), array(), $lineno, $tag); } - /** - * Compiles the node to PHP. - * - * @param \Twig_Compiler $compiler A Twig_Compiler instance - */ - public function compile(\Twig_Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->addDebugInfo($this) diff --git a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml index 457cb5c06abf1..0e5f6ec9a4a37 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml +++ b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml @@ -5,9 +5,9 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - Twig_Environment + Twig\Environment Symfony\Bundle\TwigBundle\Loader\FilesystemLoader - Twig_Loader_Chain + Twig\Loader\ChainLoader Symfony\Bundle\TwigBundle\TwigEngine Symfony\Bundle\TwigBundle\CacheWarmer\TemplateCacheCacheWarmer Symfony\Bridge\Twig\Extension\TranslationExtension @@ -51,7 +51,7 @@ - + @@ -63,7 +63,7 @@ - + @@ -117,7 +117,7 @@ - + diff --git a/src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php b/src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php index b3ccd2af0199c..17f3ac17c87f2 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php @@ -15,13 +15,15 @@ use Symfony\Bundle\TwigBundle\Controller\ExceptionController; use Symfony\Component\Debug\Exception\FlattenException; use Symfony\Component\HttpFoundation\Request; +use Twig\Environment; +use Twig\Loader\ArrayLoader; class ExceptionControllerTest extends TestCase { public function testShowActionCanBeForcedToShowErrorPage() { - $twig = new \Twig_Environment( - new \Twig_Loader_Array(array( + $twig = new Environment( + new ArrayLoader(array( 'TwigBundle:Exception:error404.html.twig' => 'ok', )) ); @@ -40,8 +42,8 @@ public function testShowActionCanBeForcedToShowErrorPage() public function testFallbackToHtmlIfNoTemplateForRequestedFormat() { - $twig = new \Twig_Environment( - new \Twig_Loader_Array(array( + $twig = new Environment( + new ArrayLoader(array( 'TwigBundle:Exception:error.html.twig' => 'html', )) ); diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/ExtensionPassTest.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/ExtensionPassTest.php index b83c5645c510b..23160c4071d1d 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/ExtensionPassTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/ExtensionPassTest.php @@ -26,7 +26,7 @@ public function testProcessDoesNotDropExistingFileLoaderMethodCalls() $container->register('twig.app_variable', '\Symfony\Bridge\Twig\AppVariable'); $container->register('templating', '\Symfony\Bundle\TwigBundle\TwigEngine'); - $nativeTwigLoader = new Definition('\Twig_Loader_Filesystem'); + $nativeTwigLoader = new Definition('\Twig\Loader\FilesystemLoader'); $nativeTwigLoader->addMethodCall('addPath', array()); $container->setDefinition('twig.loader.native_filesystem', $nativeTwigLoader); diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php index 2637460ab8919..fb82ee8266dbf 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php @@ -66,7 +66,7 @@ public function testLoadEmptyConfiguration() $container->loadFromExtension('twig', array()); $this->compileContainer($container); - $this->assertEquals('Twig_Environment', $container->getParameter('twig.class'), '->load() loads the twig.xml file'); + $this->assertEquals('Twig\Environment', $container->getParameter('twig.class'), '->load() loads the twig.xml file'); $this->assertContains('form_div_layout.html.twig', $container->getParameter('twig.form.resources'), '->load() includes default template for form resources'); @@ -87,7 +87,7 @@ public function testLoadFullConfiguration($format) $this->loadFromFile($container, 'full', $format); $this->compileContainer($container); - $this->assertEquals('Twig_Environment', $container->getParameter('twig.class'), '->load() loads the twig.xml file'); + $this->assertEquals('Twig\Environment', $container->getParameter('twig.class'), '->load() loads the twig.xml file'); // Form resources $resources = $container->getParameter('twig.form.resources'); diff --git a/src/Symfony/Bundle/TwigBundle/Tests/Loader/FilesystemLoaderTest.php b/src/Symfony/Bundle/TwigBundle/Tests/Loader/FilesystemLoaderTest.php index a7abdecb87896..b9294e35b3c46 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/Loader/FilesystemLoaderTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/Loader/FilesystemLoaderTest.php @@ -52,7 +52,7 @@ public function testExists() } /** - * @expectedException \Twig_Error_Loader + * @expectedException \Twig\Error\LoaderError */ public function testTwigErrorIfLocatorThrowsInvalid() { @@ -76,7 +76,7 @@ public function testTwigErrorIfLocatorThrowsInvalid() } /** - * @expectedException \Twig_Error_Loader + * @expectedException \Twig\Error\LoaderError */ public function testTwigErrorIfLocatorReturnsFalse() { @@ -100,7 +100,7 @@ public function testTwigErrorIfLocatorReturnsFalse() } /** - * @expectedException \Twig_Error_Loader + * @expectedException \Twig\Error\LoaderError * @expectedExceptionMessageRegExp /Unable to find template "name\.format\.engine" \(looked into: .*Tests.Loader.\.\..DependencyInjection.Fixtures.Resources.views\)/ */ public function testTwigErrorIfTemplateDoesNotExist() diff --git a/src/Symfony/Bundle/TwigBundle/Tests/TokenParser/LegacyRenderTokenParserTest.php b/src/Symfony/Bundle/TwigBundle/Tests/TokenParser/LegacyRenderTokenParserTest.php index 13881c108d603..5cba98cd45ff9 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/TokenParser/LegacyRenderTokenParserTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/TokenParser/LegacyRenderTokenParserTest.php @@ -14,6 +14,11 @@ use Symfony\Bundle\TwigBundle\Tests\TestCase; use Symfony\Bundle\TwigBundle\TokenParser\RenderTokenParser; use Symfony\Bundle\TwigBundle\Node\RenderNode; +use Twig\Environment; +use Twig\Node\Expression\ArrayExpression; +use Twig\Node\Expression\ConstantExpression; +use Twig\Parser; +use Twig\Source; /** * @group legacy @@ -25,10 +30,10 @@ class LegacyRenderTokenParserTest extends TestCase */ public function testCompile($source, $expected) { - $env = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0)); + $env = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0)); $env->addTokenParser(new RenderTokenParser()); - $stream = $env->tokenize(new \Twig_Source($source, '')); - $parser = new \Twig_Parser($env); + $stream = $env->tokenize(new Source($source, '')); + $parser = new Parser($env); $this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0)); } @@ -39,8 +44,8 @@ public function getTestsForRender() array( '{% render "foo" %}', new RenderNode( - new \Twig_Node_Expression_Constant('foo', 1), - new \Twig_Node_Expression_Array(array(), 1), + new ConstantExpression('foo', 1), + new ArrayExpression(array(), 1), 1, 'render' ), @@ -48,10 +53,10 @@ public function getTestsForRender() array( '{% render "foo", {foo: 1} %}', new RenderNode( - new \Twig_Node_Expression_Constant('foo', 1), - new \Twig_Node_Expression_Array(array( - new \Twig_Node_Expression_Constant('foo', 1), - new \Twig_Node_Expression_Constant('1', 1), + new ConstantExpression('foo', 1), + new ArrayExpression(array( + new ConstantExpression('foo', 1), + new ConstantExpression('1', 1), ), 1), 1, 'render' diff --git a/src/Symfony/Bundle/TwigBundle/TokenParser/RenderTokenParser.php b/src/Symfony/Bundle/TwigBundle/TokenParser/RenderTokenParser.php index b386c9b57fc62..cef083df3dc42 100644 --- a/src/Symfony/Bundle/TwigBundle/TokenParser/RenderTokenParser.php +++ b/src/Symfony/Bundle/TwigBundle/TokenParser/RenderTokenParser.php @@ -12,6 +12,10 @@ namespace Symfony\Bundle\TwigBundle\TokenParser; use Symfony\Bundle\TwigBundle\Node\RenderNode; +use Twig\Node\Expression\ArrayExpression; +use Twig\Node\Node; +use Twig\Token; +use Twig\TokenParser\AbstractTokenParser; /** * Token Parser for the render tag. @@ -20,29 +24,29 @@ * * @deprecated since version 2.2, to be removed in 3.0. */ -class RenderTokenParser extends \Twig_TokenParser +class RenderTokenParser extends AbstractTokenParser { /** * Parses a token and returns a node. * - * @param \Twig_Token $token A \Twig_Token instance + * @param Token $token * - * @return \Twig_Node A \Twig_Node instance + * @return Node */ - public function parse(\Twig_Token $token) + public function parse(Token $token) { $expr = $this->parser->getExpressionParser()->parseExpression(); // options - if ($this->parser->getStream()->test(\Twig_Token::PUNCTUATION_TYPE, ',')) { + if ($this->parser->getStream()->test(Token::PUNCTUATION_TYPE, ',')) { $this->parser->getStream()->next(); $options = $this->parser->getExpressionParser()->parseExpression(); } else { - $options = new \Twig_Node_Expression_Array(array(), $token->getLine()); + $options = new ArrayExpression(array(), $token->getLine()); } - $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE); + $this->parser->getStream()->expect(Token::BLOCK_END_TYPE); return new RenderNode($expr, $options, $token->getLine(), $this->getTag()); } diff --git a/src/Symfony/Bundle/TwigBundle/TwigEngine.php b/src/Symfony/Bundle/TwigBundle/TwigEngine.php index 849e22348aefc..35e67b8735f72 100644 --- a/src/Symfony/Bundle/TwigBundle/TwigEngine.php +++ b/src/Symfony/Bundle/TwigBundle/TwigEngine.php @@ -17,6 +17,9 @@ use Symfony\Component\Templating\TemplateNameParserInterface; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Config\FileLocatorInterface; +use Twig\Environment; +use Twig\Error\Error; +use Twig\FileExtensionEscapingStrategy; /** * This engine renders Twig templates. @@ -27,14 +30,7 @@ class TwigEngine extends BaseEngine implements EngineInterface { protected $locator; - /** - * Constructor. - * - * @param \Twig_Environment $environment A \Twig_Environment instance - * @param TemplateNameParserInterface $parser A TemplateNameParserInterface instance - * @param FileLocatorInterface $locator A FileLocatorInterface instance - */ - public function __construct(\Twig_Environment $environment, TemplateNameParserInterface $parser, FileLocatorInterface $locator) + public function __construct(Environment $environment, TemplateNameParserInterface $parser, FileLocatorInterface $locator) { parent::__construct($environment, $parser); @@ -43,13 +39,13 @@ public function __construct(\Twig_Environment $environment, TemplateNameParserIn /** * @deprecated since version 2.7, to be removed in 3.0. - * Inject the escaping strategy on \Twig_Environment instead. + * Inject the escaping strategy on Twig instead. */ public function setDefaultEscapingStrategy($strategy) { - @trigger_error('The '.__METHOD__.' method is deprecated since version 2.7 and will be removed in 3.0. Inject the escaping strategy in the Twig_Environment object instead.', E_USER_DEPRECATED); + @trigger_error('The '.__METHOD__.' method is deprecated since version 2.7 and will be removed in 3.0. Inject the escaping strategy in the Twig\Environment object instead.', E_USER_DEPRECATED); - $this->environment->getExtension('Twig_Extension_Escaper')->setDefaultStrategy($strategy); + $this->environment->getExtension('Twig\Extension\EscaperExtension')->setDefaultStrategy($strategy); } /** @@ -58,9 +54,9 @@ public function setDefaultEscapingStrategy($strategy) */ public function guessDefaultEscapingStrategy($name) { - @trigger_error('The '.__METHOD__.' method is deprecated since version 2.7 and will be removed in 3.0. Use the Twig_FileExtensionEscapingStrategy::guess method instead.', E_USER_DEPRECATED); + @trigger_error('The '.__METHOD__.' method is deprecated since version 2.7 and will be removed in 3.0. Use the Twig\FileExtensionEscapingStrategy::guess method instead.', E_USER_DEPRECATED); - return \Twig_FileExtensionEscapingStrategy::guess($name); + return FileExtensionEscapingStrategy::guess($name); } /** @@ -70,7 +66,7 @@ public function render($name, array $parameters = array()) { try { return parent::render($name, $parameters); - } catch (\Twig_Error $e) { + } catch (Error $e) { if ($name instanceof TemplateReference && !method_exists($e, 'setSourceContext')) { try { // try to get the real name of the template where the error occurred @@ -88,7 +84,7 @@ public function render($name, array $parameters = array()) /** * {@inheritdoc} * - * @throws \Twig_Error if something went wrong like a thrown exception while rendering the template + * @throws Error if something went wrong like a thrown exception while rendering the template */ public function renderResponse($view, array $parameters = array(), Response $response = null) { diff --git a/src/Symfony/Bundle/TwigBundle/composer.json b/src/Symfony/Bundle/TwigBundle/composer.json index 4613ffb27af82..cd2f229e4ff88 100644 --- a/src/Symfony/Bundle/TwigBundle/composer.json +++ b/src/Symfony/Bundle/TwigBundle/composer.json @@ -19,7 +19,7 @@ "php": ">=5.3.9", "symfony/asset": "~2.7", "symfony/twig-bridge": "~2.7", - "twig/twig": "~1.28|~2.0", + "twig/twig": "~1.34|~2.4", "symfony/http-foundation": "~2.5", "symfony/http-kernel": "~2.7.23|^2.8.16" }, diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php index fd0dbecd2bbec..3f9d873e1d40f 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php @@ -15,6 +15,9 @@ use Symfony\Component\Debug\ExceptionHandler; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpFoundation\Response; +use Twig\Environment; +use Twig\Error\LoaderError; +use Twig\Loader\ExistsLoaderInterface; /** * ExceptionController. @@ -27,7 +30,7 @@ class ExceptionController protected $debug; protected $profiler; - public function __construct(Profiler $profiler = null, \Twig_Environment $twig, $debug) + public function __construct(Profiler $profiler = null, Environment $twig, $debug) { $this->profiler = $profiler; $this->twig = $twig; @@ -112,7 +115,7 @@ protected function getTemplate() protected function templateExists($template) { $loader = $this->twig->getLoader(); - if ($loader instanceof \Twig_ExistsLoaderInterface) { + if ($loader instanceof ExistsLoaderInterface) { return $loader->exists($template); } @@ -120,7 +123,7 @@ protected function templateExists($template) $loader->getSource($template); return true; - } catch (\Twig_Error_Loader $e) { + } catch (LoaderError $e) { } return false; diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php index 24c83d5e1d8c6..355edde5c866b 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php @@ -19,6 +19,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Bundle\WebProfilerBundle\Profiler\TemplateManager; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; +use Twig\Environment; /** * ProfilerController. @@ -39,11 +40,11 @@ class ProfilerController * * @param UrlGeneratorInterface $generator The URL Generator * @param Profiler $profiler The profiler - * @param \Twig_Environment $twig The twig environment + * @param Environment $twig The twig environment * @param array $templates The templates * @param string $toolbarPosition The toolbar position (top, bottom, normal, or null -- use the configuration) */ - public function __construct(UrlGeneratorInterface $generator, Profiler $profiler = null, \Twig_Environment $twig, array $templates, $toolbarPosition = 'normal') + public function __construct(UrlGeneratorInterface $generator, Profiler $profiler = null, Environment $twig, array $templates, $toolbarPosition = 'normal') { $this->generator = $generator; $this->profiler = $profiler; diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/RouterController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/RouterController.php index b5d299e204184..c508346bf68a4 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Controller/RouterController.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/RouterController.php @@ -20,6 +20,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Profiler\Profiler; use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector; +use Twig\Environment; /** * RouterController. @@ -33,7 +34,7 @@ class RouterController private $matcher; private $routes; - public function __construct(Profiler $profiler = null, \Twig_Environment $twig, UrlMatcherInterface $matcher = null, RouteCollection $routes = null) + public function __construct(Profiler $profiler = null, Environment $twig, UrlMatcherInterface $matcher = null, RouteCollection $routes = null) { $this->profiler = $profiler; $this->twig = $twig; diff --git a/src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php b/src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php index 317dcc9a44dda..5d020fe914bb0 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php +++ b/src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php @@ -18,6 +18,7 @@ use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; +use Twig\Environment; /** * WebDebugToolbarListener injects the Web Debug Toolbar. @@ -41,7 +42,7 @@ class WebDebugToolbarListener implements EventSubscriberInterface protected $position; protected $excludedAjaxPaths; - public function __construct(\Twig_Environment $twig, $interceptRedirects = false, $mode = self::ENABLED, $position = 'bottom', UrlGeneratorInterface $urlGenerator = null, $excludedAjaxPaths = '^/bundles|^/_wdt') + public function __construct(Environment $twig, $interceptRedirects = false, $mode = self::ENABLED, $position = 'bottom', UrlGeneratorInterface $urlGenerator = null, $excludedAjaxPaths = '^/bundles|^/_wdt') { $this->twig = $twig; $this->urlGenerator = $urlGenerator; diff --git a/src/Symfony/Bundle/WebProfilerBundle/Profiler/TemplateManager.php b/src/Symfony/Bundle/WebProfilerBundle/Profiler/TemplateManager.php index ff5dce56f9cef..5b6b9f100461a 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Profiler/TemplateManager.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Profiler/TemplateManager.php @@ -14,6 +14,11 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Profiler\Profiler; use Symfony\Component\HttpKernel\Profiler\Profile; +use Twig\Environment; +use Twig\Error\LoaderError; +use Twig\Loader\ExistsLoaderInterface; +use Twig\Loader\SourceContextLoaderInterface; +use Twig\Template; /** * Profiler Templates Manager. @@ -27,14 +32,7 @@ class TemplateManager protected $templates; protected $profiler; - /** - * Constructor. - * - * @param Profiler $profiler - * @param \Twig_Environment $twig - * @param array $templates - */ - public function __construct(Profiler $profiler, \Twig_Environment $twig, array $templates) + public function __construct(Profiler $profiler, Environment $twig, array $templates) { $this->profiler = $profiler; $this->twig = $twig; @@ -67,7 +65,7 @@ public function getName(Profile $profile, $panel) * * @param Profile $profile * - * @return \Twig_Template[] + * @return Template[] * * @deprecated not used anymore internally */ @@ -123,19 +121,19 @@ public function getNames(Profile $profile) protected function templateExists($template) { $loader = $this->twig->getLoader(); - if ($loader instanceof \Twig_ExistsLoaderInterface) { + if ($loader instanceof ExistsLoaderInterface) { return $loader->exists($template); } try { - if ($loader instanceof \Twig_SourceContextLoaderInterface) { + if ($loader instanceof SourceContextLoaderInterface) { $loader->getSourceContext($template); } else { $loader->getSource($template); } return true; - } catch (\Twig_Error_Loader $e) { + } catch (LoaderError $e) { } return false; diff --git a/src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php b/src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php index a14869d4ec206..a2d005a8b0aec 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php @@ -24,7 +24,7 @@ class ProfilerControllerTest extends TestCase public function testEmptyToken($token) { $urlGenerator = $this->getMockBuilder('Symfony\Component\Routing\Generator\UrlGeneratorInterface')->getMock(); - $twig = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock(); + $twig = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock(); $profiler = $this ->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profiler') ->disableOriginalConstructor() @@ -48,7 +48,7 @@ public function getEmptyTokenCases() public function testReturns404onTokenNotFound() { $urlGenerator = $this->getMockBuilder('Symfony\Component\Routing\Generator\UrlGeneratorInterface')->getMock(); - $twig = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock(); + $twig = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock(); $profiler = $this ->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profiler') ->disableOriginalConstructor() @@ -76,7 +76,7 @@ public function testReturns404onTokenNotFound() public function testSearchResult() { $urlGenerator = $this->getMockBuilder('Symfony\Component\Routing\Generator\UrlGeneratorInterface')->getMock(); - $twig = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock(); + $twig = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock(); $profiler = $this ->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profiler') ->disableOriginalConstructor() diff --git a/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php b/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php index 2237e18b29e54..618385ce81b54 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php @@ -52,9 +52,9 @@ protected function setUp() $this->container->addScope(new Scope('request')); $this->container->register('request', 'Symfony\\Component\\HttpFoundation\\Request')->setScope('request'); $this->container->register('router', $this->getMockClass('Symfony\\Component\\Routing\\RouterInterface')); - $this->container->register('twig', 'Twig_Environment'); - $this->container->register('twig_loader', 'Twig_Loader_Array')->addArgument(array()); - $this->container->register('twig', 'Twig_Environment')->addArgument(new Reference('twig_loader')); + $this->container->register('twig', 'Twig\Environment'); + $this->container->register('twig_loader', 'Twig\Loader\ArrayLoader')->addArgument(array()); + $this->container->register('twig', 'Twig\Environment')->addArgument(new Reference('twig_loader')); $this->container->setParameter('kernel.bundles', array()); $this->container->setParameter('kernel.cache_dir', __DIR__); $this->container->setParameter('kernel.debug', false); diff --git a/src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php b/src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php index b730afe345aa4..6f32b2101341d 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php @@ -288,7 +288,7 @@ protected function getRequestMock($isXmlHttpRequest = false, $requestFormat = 'h protected function getTwigMock($render = 'WDT') { - $templating = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock(); + $templating = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock(); $templating->expects($this->any()) ->method('render') ->will($this->returnValue($render)); diff --git a/src/Symfony/Bundle/WebProfilerBundle/Tests/Profiler/TemplateManagerTest.php b/src/Symfony/Bundle/WebProfilerBundle/Tests/Profiler/TemplateManagerTest.php index 4ac2c7de5f0a2..7b8f9a8df51c0 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Tests/Profiler/TemplateManagerTest.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/Profiler/TemplateManagerTest.php @@ -13,6 +13,7 @@ use Symfony\Bundle\WebProfilerBundle\Tests\TestCase; use Symfony\Bundle\WebProfilerBundle\Profiler\TemplateManager; +use Twig\Environment; /** * Test for TemplateManager class. @@ -22,7 +23,7 @@ class TemplateManagerTest extends TestCase { /** - * @var \Twig_Environment + * @var Environment */ protected $twigEnvironment; @@ -46,7 +47,7 @@ protected function setUp() 'data_collector.foo' => array('foo', 'FooBundle:Collector:foo'), 'data_collector.bar' => array('bar', 'FooBundle:Collector:bar'), 'data_collector.baz' => array('baz', 'FooBundle:Collector:baz'), - ); + ); $this->templateManager = new TemplateManager($profiler, $twigEnvironment, $templates); } @@ -129,16 +130,16 @@ protected function mockProfile() protected function mockTwigEnvironment() { - $this->twigEnvironment = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock(); + $this->twigEnvironment = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock(); $this->twigEnvironment->expects($this->any()) ->method('loadTemplate') ->will($this->returnValue('loadedTemplate')); - if (interface_exists('\Twig_SourceContextLoaderInterface')) { - $loader = $this->getMockBuilder('\Twig_SourceContextLoaderInterface')->getMock(); + if (interface_exists('Twig\Loader\SourceContextLoaderInterface')) { + $loader = $this->getMockBuilder('Twig\Loader\SourceContextLoaderInterface')->getMock(); } else { - $loader = $this->getMockBuilder('\Twig_LoaderInterface')->getMock(); + $loader = $this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock(); } $this->twigEnvironment->expects($this->any())->method('getLoader')->will($this->returnValue($loader)); diff --git a/src/Symfony/Bundle/WebProfilerBundle/Twig/WebProfilerExtension.php b/src/Symfony/Bundle/WebProfilerBundle/Twig/WebProfilerExtension.php index 13df2f443e9f0..8fc6b592deb42 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Twig/WebProfilerExtension.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Twig/WebProfilerExtension.php @@ -12,13 +12,15 @@ namespace Symfony\Bundle\WebProfilerBundle\Twig; use Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter; +use Twig\Extension\AbstractExtension; +use Twig\TwigFunction; /** * Twig extension for the profiler. * * @author Fabien Potencier */ -class WebProfilerExtension extends \Twig_Extension +class WebProfilerExtension extends AbstractExtension { /** * @var ValueExporter @@ -31,7 +33,7 @@ class WebProfilerExtension extends \Twig_Extension public function getFunctions() { return array( - new \Twig_SimpleFunction('profiler_dump', array($this, 'dumpValue')), + new TwigFunction('profiler_dump', array($this, 'dumpValue')), ); } diff --git a/src/Symfony/Bundle/WebProfilerBundle/composer.json b/src/Symfony/Bundle/WebProfilerBundle/composer.json index 8867a64eca35a..000b89795462d 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/composer.json +++ b/src/Symfony/Bundle/WebProfilerBundle/composer.json @@ -20,7 +20,7 @@ "symfony/http-kernel": "~2.4", "symfony/routing": "~2.2", "symfony/twig-bridge": "~2.7", - "twig/twig": "~1.28|~2.0" + "twig/twig": "~1.34|~2.4" }, "require-dev": { "symfony/config": "~2.2", diff --git a/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php index 9448ad180b4f3..049053150fef2 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php @@ -20,6 +20,7 @@ use Symfony\Component\VarDumper\Dumper\CliDumper; use Symfony\Component\VarDumper\Dumper\HtmlDumper; use Symfony\Component\VarDumper\Dumper\DataDumperInterface; +use Twig\Template; /** * @author Nicolas Grekas @@ -96,7 +97,7 @@ public function dump(Data $data) $line = $trace[$i]['line']; break; - } elseif (isset($trace[$i]['object']) && $trace[$i]['object'] instanceof \Twig_Template) { + } elseif (isset($trace[$i]['object']) && $trace[$i]['object'] instanceof Template) { $template = $trace[$i]['object']; $name = $template->getTemplateName(); $src = method_exists($template, 'getSourceContext') ? $template->getSourceContext()->getCode() : (method_exists($template, 'getSource') ? $template->getSource() : false); diff --git a/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php b/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php index 09f84ec3b8e01..e7d4aedb16404 100644 --- a/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php +++ b/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php @@ -16,6 +16,9 @@ use Symfony\Component\Templating\EngineInterface; use Symfony\Component\HttpKernel\Controller\ControllerReference; use Symfony\Component\HttpKernel\UriSigner; +use Twig\Environment; +use Twig\Error\LoaderError; +use Twig\Loader\ExistsLoaderInterface; /** * Implements the Hinclude rendering strategy. @@ -32,10 +35,10 @@ class HIncludeFragmentRenderer extends RoutableFragmentRenderer /** * Constructor. * - * @param EngineInterface|\Twig_Environment $templating An EngineInterface or a \Twig_Environment instance - * @param UriSigner $signer A UriSigner instance - * @param string $globalDefaultTemplate The global default content (it can be a template name or the content) - * @param string $charset + * @param EngineInterface|Environment $templating An EngineInterface or a Twig instance + * @param UriSigner $signer A UriSigner instance + * @param string $globalDefaultTemplate The global default content (it can be a template name or the content) + * @param string $charset */ public function __construct($templating = null, UriSigner $signer = null, $globalDefaultTemplate = null, $charset = 'utf-8') { @@ -48,14 +51,14 @@ public function __construct($templating = null, UriSigner $signer = null, $globa /** * Sets the templating engine to use to render the default content. * - * @param EngineInterface|\Twig_Environment|null $templating An EngineInterface or a \Twig_Environment instance + * @param EngineInterface|Environment|null $templating An EngineInterface or an Environment instance * * @throws \InvalidArgumentException */ public function setTemplating($templating) { - if (null !== $templating && !$templating instanceof EngineInterface && !$templating instanceof \Twig_Environment) { - throw new \InvalidArgumentException('The hinclude rendering strategy needs an instance of \Twig_Environment or Symfony\Component\Templating\EngineInterface'); + if (null !== $templating && !$templating instanceof EngineInterface && !$templating instanceof Environment) { + throw new \InvalidArgumentException('The hinclude rendering strategy needs an instance of Twig\Environment or Symfony\Component\Templating\EngineInterface'); } $this->templating = $templating; @@ -140,7 +143,7 @@ private function templateExists($template) } $loader = $this->templating->getLoader(); - if ($loader instanceof \Twig_ExistsLoaderInterface || method_exists($loader, 'exists')) { + if ($loader instanceof ExistsLoaderInterface || method_exists($loader, 'exists')) { return $loader->exists($template); } @@ -152,7 +155,7 @@ private function templateExists($template) } return true; - } catch (\Twig_Error_Loader $e) { + } catch (LoaderError $e) { } return false; diff --git a/src/Symfony/Component/HttpKernel/composer.json b/src/Symfony/Component/HttpKernel/composer.json index 7dec6ef11dfce..6b6ec3f17b886 100644 --- a/src/Symfony/Component/HttpKernel/composer.json +++ b/src/Symfony/Component/HttpKernel/composer.json @@ -40,7 +40,8 @@ "symfony/var-dumper": "~2.6" }, "conflict": { - "symfony/config": "<2.7" + "symfony/config": "<2.7", + "twig/twig": "<1.34|<2.4,>=2" }, "suggest": { "symfony/browser-kit": "", From e7c4149e78525dec0290aeda8f9c4fcdb149efe5 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 1 Jun 2017 23:47:36 +0200 Subject: [PATCH 35/57] [EventDispatcher] Fix ContainerAwareEventDispatcher::hasListeners(null) --- .../Component/EventDispatcher/ContainerAwareEventDispatcher.php | 2 +- .../EventDispatcher/Tests/AbstractEventDispatcherTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php b/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php index b92defe691257..dc2816f16906b 100644 --- a/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php +++ b/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php @@ -105,7 +105,7 @@ public function removeListener($eventName, $listener) public function hasListeners($eventName = null) { if (null === $eventName) { - return (bool) count($this->listenerIds) || (bool) count($this->listeners); + return $this->listenerIds || $this->listeners || parent::hasListeners(); } if (isset($this->listenerIds[$eventName])) { diff --git a/src/Symfony/Component/EventDispatcher/Tests/AbstractEventDispatcherTest.php b/src/Symfony/Component/EventDispatcher/Tests/AbstractEventDispatcherTest.php index bde6caa4eeb38..e5e9c2be83b43 100644 --- a/src/Symfony/Component/EventDispatcher/Tests/AbstractEventDispatcherTest.php +++ b/src/Symfony/Component/EventDispatcher/Tests/AbstractEventDispatcherTest.php @@ -56,6 +56,7 @@ public function testAddListener() { $this->dispatcher->addListener('pre.foo', array($this->listener, 'preFoo')); $this->dispatcher->addListener('post.foo', array($this->listener, 'postFoo')); + $this->assertTrue($this->dispatcher->hasListeners()); $this->assertTrue($this->dispatcher->hasListeners(self::preFoo)); $this->assertTrue($this->dispatcher->hasListeners(self::postFoo)); $this->assertCount(1, $this->dispatcher->getListeners(self::preFoo)); From 7f4824c987afea401a5e1ddb81256d91431093d8 Mon Sep 17 00:00:00 2001 From: Vincent AUBERT Date: Fri, 2 Jun 2017 07:32:06 +0200 Subject: [PATCH 36/57] add some \ on PHP_VERSION_ID for 2.8 --- src/Symfony/Component/Console/Tests/Command/CommandTest.php | 2 +- .../Component/DependencyInjection/Tests/ContainerTest.php | 2 +- src/Symfony/Component/DomCrawler/Crawler.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Console/Tests/Command/CommandTest.php b/src/Symfony/Component/Console/Tests/Command/CommandTest.php index e77292f608c21..ac4aa22fbb772 100644 --- a/src/Symfony/Component/Console/Tests/Command/CommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/CommandTest.php @@ -386,7 +386,7 @@ public function testSetCodeWithStaticClosure() $tester = new CommandTester($command); $tester->execute(array()); - if (PHP_VERSION_ID < 70000) { + if (\PHP_VERSION_ID < 70000) { // Cannot bind static closures in PHP 5 $this->assertEquals('interact called'.PHP_EOL.'not bound'.PHP_EOL, $tester->getDisplay()); } else { diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php index 834fef32b19cb..dbe18f607e968 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php @@ -698,7 +698,7 @@ public function testThatCloningIsNotSupported() { $class = new \ReflectionClass('Symfony\Component\DependencyInjection\Container'); $clone = $class->getMethod('__clone'); - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { $this->assertFalse($class->isCloneable()); } $this->assertTrue($clone->isPrivate()); diff --git a/src/Symfony/Component/DomCrawler/Crawler.php b/src/Symfony/Component/DomCrawler/Crawler.php index bb429c2b6a122..094075bfc903a 100644 --- a/src/Symfony/Component/DomCrawler/Crawler.php +++ b/src/Symfony/Component/DomCrawler/Crawler.php @@ -1191,7 +1191,7 @@ private function createSubCrawler($nodes) private function triggerDeprecation($methodName, $useTrace = false) { if ($useTrace || defined('HHVM_VERSION')) { - if (PHP_VERSION_ID >= 50400) { + if (\PHP_VERSION_ID >= 50400) { $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3); } else { $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); From 3371db9f8cd332932495eaa592ccbbf0e9c66729 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Thu, 1 Jun 2017 14:40:39 +0200 Subject: [PATCH 37/57] Fix optional cache warmers are always instantiated whereas they should be lazy-loaded --- .../CacheWarmer/TranslationsCacheWarmer.php | 22 +++++++++++++++-- .../Resources/config/translation.xml | 2 +- .../CacheWarmer/TemplateCacheWarmer.php | 24 +++++++++++++++++-- .../TwigBundle/Resources/config/twig.xml | 2 +- 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TranslationsCacheWarmer.php b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TranslationsCacheWarmer.php index 223f0216ba9ad..33f94650449fb 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TranslationsCacheWarmer.php +++ b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TranslationsCacheWarmer.php @@ -11,6 +11,7 @@ namespace Symfony\Bundle\FrameworkBundle\CacheWarmer; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface; use Symfony\Component\Translation\TranslatorInterface; @@ -22,11 +23,24 @@ */ class TranslationsCacheWarmer implements CacheWarmerInterface { + private $container; private $translator; - public function __construct(TranslatorInterface $translator) + /** + * TranslationsCacheWarmer constructor. + * + * @param ContainerInterface|TranslatorInterface $container + */ + public function __construct($container) { - $this->translator = $translator; + // As this cache warmer is optional, dependencies should be lazy-loaded, that's why a container should be injected. + if ($container instanceof ContainerInterface) { + $this->container = $container; + } elseif ($container instanceof TranslatorInterface) { + $this->translator = $container; + } else { + throw new \InvalidArgumentException(sprintf('%s only accepts instance of Symfony\Component\DependencyInjection\ContainerInterface or Symfony\Component\Translation\TranslatorInterface as first argument.', __CLASS__)); + } } /** @@ -34,6 +48,10 @@ public function __construct(TranslatorInterface $translator) */ public function warmUp($cacheDir) { + if (null === $this->translator) { + $this->translator = $this->container->get('translator'); + } + if ($this->translator instanceof WarmableInterface) { $this->translator->warmUp($cacheDir); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml index ea85f517aa399..14226ba93083f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml @@ -159,7 +159,7 @@ - + diff --git a/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheWarmer.php b/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheWarmer.php index 8946c1a98bb08..9a60a92e85375 100644 --- a/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheWarmer.php +++ b/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheWarmer.php @@ -11,6 +11,7 @@ namespace Symfony\Bundle\TwigBundle\CacheWarmer; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; use Twig\Environment; use Twig\Error\Error; @@ -22,12 +23,27 @@ */ class TemplateCacheWarmer implements CacheWarmerInterface { + private $container; private $twig; private $iterator; - public function __construct(Environment $twig, \Traversable $iterator) + /** + * TemplateCacheWarmer constructor. + * + * @param ContainerInterface|Environment $container + * @param \Traversable $iterator + */ + public function __construct($container, \Traversable $iterator) { - $this->twig = $twig; + // As this cache warmer is optional, dependencies should be lazy-loaded, that's why a container should be injected. + if ($container instanceof ContainerInterface) { + $this->container = $container; + } elseif ($container instanceof Environment) { + $this->twig = $container; + } else { + throw new \InvalidArgumentException(sprintf('%s only accepts instance of Symfony\Component\DependencyInjection\ContainerInterface or Environment as first argument.', __CLASS__)); + } + $this->iterator = $iterator; } @@ -36,6 +52,10 @@ public function __construct(Environment $twig, \Traversable $iterator) */ public function warmUp($cacheDir) { + if (null === $this->twig) { + $this->twig = $this->container->get('twig'); + } + foreach ($this->iterator as $template) { try { $this->twig->loadTemplate($template); diff --git a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml index 86e7c45cd39a8..541ac4a559738 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml +++ b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml @@ -60,7 +60,7 @@ - + From 99e0836fd4ec6c3e3f101a867eba2eb4a2b8e543 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 2 Jun 2017 10:28:06 +0200 Subject: [PATCH 38/57] typo --- src/Symfony/Component/VarDumper/Tests/CliDumperTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/VarDumper/Tests/CliDumperTest.php b/src/Symfony/Component/VarDumper/Tests/CliDumperTest.php index 8edb39c19a8b4..5ee3a6c11ed48 100644 --- a/src/Symfony/Component/VarDumper/Tests/CliDumperTest.php +++ b/src/Symfony/Component/VarDumper/Tests/CliDumperTest.php @@ -272,7 +272,7 @@ public function testThrowingCaster() %sTemplate.php:%d: """ try {\\n \$this->doDisplay(\$context, \$blocks);\\n - } catch (Twig\Error \$e) {\\n + } catch (Twig%sError \$e) {\\n """ } } From 8d609d9bbaef38e6a84585c572bdb53100143845 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 2 Jun 2017 11:00:03 +0200 Subject: [PATCH 39/57] fix merge --- src/Symfony/Bridge/Twig/CHANGELOG.md | 2 +- src/Symfony/Bridge/Twig/Extension/FormExtension.php | 2 +- src/Symfony/Bridge/Twig/Extension/WorkflowExtension.php | 8 +++++--- src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php | 2 +- .../Bridge/Twig/Tests/Extension/DumpExtensionTest.php | 2 +- .../Twig/Tests/Extension/HttpKernelExtensionTest.php | 2 +- .../Bridge/Twig/Tests/Extension/RuntimeLoaderProvider.php | 5 +++-- .../Bundle/TwigBundle/ContainerAwareRuntimeLoader.php | 3 ++- 8 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Bridge/Twig/CHANGELOG.md b/src/Symfony/Bridge/Twig/CHANGELOG.md index dee3db5a37655..04c7dfb43d0e3 100644 --- a/src/Symfony/Bridge/Twig/CHANGELOG.md +++ b/src/Symfony/Bridge/Twig/CHANGELOG.md @@ -28,7 +28,7 @@ CHANGELOG // ... $rendererEngine = new TwigRendererEngine(array('form_div_layout.html.twig'), $twig); // require Twig 1.30+ - $twig->addRuntimeLoader(new \Twig_FactoryRuntimeLoader(array( + $twig->addRuntimeLoader(new \Twig\RuntimeLoader\FactoryRuntimeLoader(array( TwigRenderer::class => function () use ($rendererEngine, $csrfTokenManager) { return new TwigRenderer($rendererEngine, $csrfTokenManager); }, diff --git a/src/Symfony/Bridge/Twig/Extension/FormExtension.php b/src/Symfony/Bridge/Twig/Extension/FormExtension.php index 2cff5996f6286..362879e43a89e 100644 --- a/src/Symfony/Bridge/Twig/Extension/FormExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/FormExtension.php @@ -38,7 +38,7 @@ class FormExtension extends AbstractExtension implements InitRuntimeInterface public function __construct($renderer = null) { if ($renderer instanceof TwigRendererInterface) { - @trigger_error(sprintf('Passing a Twig Form Renderer to the "%s" constructor is deprecated since version 3.2 and won\'t be possible in 4.0. Pass the Twig_Environment to the TwigRendererEngine constructor instead.', static::class), E_USER_DEPRECATED); + @trigger_error(sprintf('Passing a Twig Form Renderer to the "%s" constructor is deprecated since version 3.2 and won\'t be possible in 4.0. Pass the Twig\Environment to the TwigRendererEngine constructor instead.', static::class), E_USER_DEPRECATED); } elseif (null !== $renderer && !(is_array($renderer) && isset($renderer[0], $renderer[1]) && $renderer[0] instanceof ContainerInterface)) { throw new \InvalidArgumentException(sprintf('Passing any arguments the constructor of %s is reserved for internal use.', __CLASS__)); } diff --git a/src/Symfony/Bridge/Twig/Extension/WorkflowExtension.php b/src/Symfony/Bridge/Twig/Extension/WorkflowExtension.php index 2e5459fa07e68..e93008c84af6d 100644 --- a/src/Symfony/Bridge/Twig/Extension/WorkflowExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/WorkflowExtension.php @@ -13,13 +13,15 @@ use Symfony\Component\Workflow\Registry; use Symfony\Component\Workflow\Transition; +use Twig\Extension\AbstractExtension; +use Twig\TwigFunction; /** * WorkflowExtension. * * @author Grégoire Pineau */ -class WorkflowExtension extends \Twig_Extension +class WorkflowExtension extends AbstractExtension { private $workflowRegistry; @@ -31,8 +33,8 @@ public function __construct(Registry $workflowRegistry) public function getFunctions() { return array( - new \Twig_SimpleFunction('workflow_can', array($this, 'canTransition')), - new \Twig_SimpleFunction('workflow_transitions', array($this, 'getEnabledTransitions')), + new TwigFunction('workflow_can', array($this, 'canTransition')), + new TwigFunction('workflow_transitions', array($this, 'getEnabledTransitions')), ); } diff --git a/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php b/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php index 8e4790ed8db12..3805c7416f77c 100644 --- a/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php +++ b/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php @@ -31,7 +31,7 @@ class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererE */ private $template; - public function __construct(array $defaultThemes = array(), \Twig_Environment $environment = null) + public function __construct(array $defaultThemes = array(), Environment $environment = null) { if (null === $environment) { @trigger_error(sprintf('Not passing a Twig Environment as the second argument for "%s" constructor is deprecated since version 3.2 and won\'t be possible in 4.0.', static::class), E_USER_DEPRECATED); diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/DumpExtensionTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/DumpExtensionTest.php index f71d81648b22f..ce80418c83ba7 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/DumpExtensionTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/DumpExtensionTest.php @@ -123,7 +123,7 @@ public function testCustomDumper() '' ); $extension = new DumpExtension(new VarCloner(), $dumper); - $twig = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array( + $twig = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock(), array( 'debug' => true, 'cache' => false, 'optimizations' => 0, diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php index ee48ce058f833..9f19847eb8824 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php @@ -81,7 +81,7 @@ protected function renderTemplate(FragmentHandler $renderer, $template = '{{ ren $twig = new Environment($loader, array('debug' => true, 'cache' => false)); $twig->addExtension(new HttpKernelExtension()); - $loader = $this->getMockBuilder('Twig\Loader\RuntimeLoaderInterface')->getMock(); + $loader = $this->getMockBuilder('Twig\RuntimeLoader\RuntimeLoaderInterface')->getMock(); $loader->expects($this->any())->method('load')->will($this->returnValueMap(array( array('Symfony\Bridge\Twig\Extension\HttpKernelRuntime', new HttpKernelRuntime($renderer)), ))); diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/RuntimeLoaderProvider.php b/src/Symfony/Bridge/Twig/Tests/Extension/RuntimeLoaderProvider.php index a6c397ffd4d90..90db2c5d6bd44 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/RuntimeLoaderProvider.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/RuntimeLoaderProvider.php @@ -12,12 +12,13 @@ namespace Symfony\Bridge\Twig\Tests\Extension; use Symfony\Bridge\Twig\Form\TwigRenderer; +use Twig\Environment; trait RuntimeLoaderProvider { - protected function registerTwigRuntimeLoader(\Twig_Environment $environment, TwigRenderer $renderer) + protected function registerTwigRuntimeLoader(Environment $environment, TwigRenderer $renderer) { - $loader = $this->getMockBuilder('Twig_RuntimeLoaderInterface')->getMock(); + $loader = $this->getMockBuilder('Twig\RuntimeLoader\RuntimeLoaderInterface')->getMock(); $loader->expects($this->any())->method('load')->will($this->returnValueMap(array( array('Symfony\Bridge\Twig\Form\TwigRenderer', $renderer), ))); diff --git a/src/Symfony/Bundle/TwigBundle/ContainerAwareRuntimeLoader.php b/src/Symfony/Bundle/TwigBundle/ContainerAwareRuntimeLoader.php index 780454aed986e..94815467c0db2 100644 --- a/src/Symfony/Bundle/TwigBundle/ContainerAwareRuntimeLoader.php +++ b/src/Symfony/Bundle/TwigBundle/ContainerAwareRuntimeLoader.php @@ -13,13 +13,14 @@ use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; +use Twig\RuntimeLoader\RuntimeLoaderInterface; /** * Loads Twig extension runtimes via the service container. * * @author Fabien Potencier */ -class ContainerAwareRuntimeLoader implements \Twig_RuntimeLoaderInterface +class ContainerAwareRuntimeLoader implements RuntimeLoaderInterface { private $container; private $mapping; From 1945bcf6c7ceb2880fdc7e1e4bed2e1150a02843 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 2 Jun 2017 12:45:23 +0200 Subject: [PATCH 40/57] typo --- .../Doctrine/Tests/PropertyInfo/Fixtures/DoctrineDummy.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineDummy.php b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineDummy.php index 9ceae5150c7ab..580e75803db8f 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineDummy.php +++ b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineDummy.php @@ -11,7 +11,6 @@ namespace Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures; -use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping\Column; use Doctrine\ORM\Mapping\Entity; use Doctrine\ORM\Mapping\Id; From d89670461df641dada9ea32529838a78044f3cd4 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 2 Jun 2017 14:59:20 +0200 Subject: [PATCH 41/57] Fix composer deps --- src/Symfony/Bundle/FrameworkBundle/composer.json | 8 ++++---- src/Symfony/Bundle/SecurityBundle/composer.json | 2 +- src/Symfony/Component/DependencyInjection/composer.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index 05fb5b96a6cbf..6db169024f67e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -20,9 +20,9 @@ "ext-xml": "*", "symfony/cache": "~3.3", "symfony/class-loader": "~3.2", - "symfony/dependency-injection": "~3.3-beta2", + "symfony/dependency-injection": "~3.3", "symfony/config": "~3.3", - "symfony/event-dispatcher": "~3.3", + "symfony/event-dispatcher": "^3.3.1", "symfony/http-foundation": "~3.3", "symfony/http-kernel": "~3.3", "symfony/polyfill-mbstring": "~1.0", @@ -49,7 +49,7 @@ "symfony/serializer": "~3.3", "symfony/translation": "~3.2", "symfony/templating": "~2.8|~3.0", - "symfony/validator": "~3.3-rc2", + "symfony/validator": "~3.3", "symfony/workflow": "~3.3", "symfony/yaml": "~3.2", "symfony/property-info": "~3.3", @@ -69,7 +69,7 @@ "symfony/property-info": "<3.3", "symfony/serializer": "<3.3", "symfony/translation": "<3.2", - "symfony/validator": "<3.3-rc2", + "symfony/validator": "<3.3", "symfony/workflow": "<3.3" }, "suggest": { diff --git a/src/Symfony/Bundle/SecurityBundle/composer.json b/src/Symfony/Bundle/SecurityBundle/composer.json index 5c23309a46047..d0cd5fc6c953d 100644 --- a/src/Symfony/Bundle/SecurityBundle/composer.json +++ b/src/Symfony/Bundle/SecurityBundle/composer.json @@ -18,7 +18,7 @@ "require": { "php": ">=5.5.9", "symfony/security": "~3.3", - "symfony/dependency-injection": "~3.3-beta2", + "symfony/dependency-injection": "~3.3", "symfony/http-kernel": "~3.3", "symfony/polyfill-php70": "~1.0" }, diff --git a/src/Symfony/Component/DependencyInjection/composer.json b/src/Symfony/Component/DependencyInjection/composer.json index 7b0932881b464..3a2916635ffb8 100644 --- a/src/Symfony/Component/DependencyInjection/composer.json +++ b/src/Symfony/Component/DependencyInjection/composer.json @@ -32,7 +32,7 @@ "symfony/proxy-manager-bridge": "Generate service proxies to lazy load them" }, "conflict": { - "symfony/config": "<=3.3-beta1", + "symfony/config": "<3.3", "symfony/finder": "<3.3", "symfony/yaml": "<3.3" }, From 86bf26c466fa695a64b8836decc8a1c8b6296682 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 2 Jun 2017 19:23:28 +0200 Subject: [PATCH 42/57] [Config] Always protect ClassExistenceResource against bad parents --- .../Resource/ClassExistenceResource.php | 40 +++++++++---------- .../Resource/ClassExistenceResourceTest.php | 4 +- .../Compiler/AutowirePass.php | 6 +-- .../DependencyInjection/ContainerBuilder.php | 12 ++---- .../DependencyInjection/composer.json | 2 +- 5 files changed, 28 insertions(+), 36 deletions(-) diff --git a/src/Symfony/Component/Config/Resource/ClassExistenceResource.php b/src/Symfony/Component/Config/Resource/ClassExistenceResource.php index 040cfc510eb9b..8a86a4209961b 100644 --- a/src/Symfony/Component/Config/Resource/ClassExistenceResource.php +++ b/src/Symfony/Component/Config/Resource/ClassExistenceResource.php @@ -21,25 +21,21 @@ */ class ClassExistenceResource implements SelfCheckingResourceInterface, \Serializable { - const EXISTS_OK = 1; - const EXISTS_KO = 0; - const EXISTS_KO_WITH_THROWING_AUTOLOADER = -1; - private $resource; - private $existsStatus; + private $exists; private static $autoloadLevel = 0; private static $existsCache = array(); /** - * @param string $resource The fully-qualified class name - * @param int|null $existsStatus One of the self::EXISTS_* const if the existency check has already been done + * @param string $resource The fully-qualified class name + * @param bool|null $exists Boolean when the existency check has already been done */ - public function __construct($resource, $existsStatus = null) + public function __construct($resource, $exists = null) { $this->resource = $resource; - if (null !== $existsStatus) { - $this->existsStatus = (int) $existsStatus; + if (null !== $exists) { + $this->exists = (bool) $exists; } } @@ -64,11 +60,13 @@ public function getResource() */ public function isFresh($timestamp) { + $loaded = class_exists($this->resource, false) || interface_exists($this->resource, false) || trait_exists($this->resource, false); + if (null !== $exists = &self::$existsCache[$this->resource]) { - $exists = $exists || class_exists($this->resource, false) || interface_exists($this->resource, false) || trait_exists($this->resource, false); - } elseif (self::EXISTS_KO_WITH_THROWING_AUTOLOADER === $this->existsStatus) { + $exists = $exists || $loaded; + } elseif (!$exists = $loaded) { if (!self::$autoloadLevel++) { - spl_autoload_register('Symfony\Component\Config\Resource\ClassExistenceResource::throwOnRequiredClass'); + spl_autoload_register(__CLASS__.'::throwOnRequiredClass'); } try { @@ -77,18 +75,16 @@ public function isFresh($timestamp) $exists = false; } finally { if (!--self::$autoloadLevel) { - spl_autoload_unregister('Symfony\Component\Config\Resource\ClassExistenceResource::throwOnRequiredClass'); + spl_autoload_unregister(__CLASS__.'::throwOnRequiredClass'); } } - } else { - $exists = class_exists($this->resource) || interface_exists($this->resource, false) || trait_exists($this->resource, false); } - if (null === $this->existsStatus) { - $this->existsStatus = $exists ? self::EXISTS_OK : self::EXISTS_KO; + if (null === $this->exists) { + $this->exists = $exists; } - return self::EXISTS_OK === $this->existsStatus xor !$exists; + return $this->exists xor !$exists; } /** @@ -96,11 +92,11 @@ public function isFresh($timestamp) */ public function serialize() { - if (null === $this->existsStatus) { + if (null === $this->exists) { $this->isFresh(0); } - return serialize(array($this->resource, $this->existsStatus)); + return serialize(array($this->resource, $this->exists)); } /** @@ -108,7 +104,7 @@ public function serialize() */ public function unserialize($serialized) { - list($this->resource, $this->existsStatus) = unserialize($serialized); + list($this->resource, $this->exists) = unserialize($serialized); } /** diff --git a/src/Symfony/Component/Config/Tests/Resource/ClassExistenceResourceTest.php b/src/Symfony/Component/Config/Tests/Resource/ClassExistenceResourceTest.php index f429a33626564..3daef17ee1300 100644 --- a/src/Symfony/Component/Config/Tests/Resource/ClassExistenceResourceTest.php +++ b/src/Symfony/Component/Config/Tests/Resource/ClassExistenceResourceTest.php @@ -66,7 +66,7 @@ public function testExistsKo() $loadedClass = 123; - $res = new ClassExistenceResource('MissingFooClass', ClassExistenceResource::EXISTS_KO); + $res = new ClassExistenceResource('MissingFooClass', false); $this->assertSame(123, $loadedClass); } finally { @@ -76,7 +76,7 @@ public function testExistsKo() public function testConditionalClass() { - $res = new ClassExistenceResource(ConditionalClass::class, ClassExistenceResource::EXISTS_KO_WITH_THROWING_AUTOLOADER); + $res = new ClassExistenceResource(ConditionalClass::class, false); $this->assertFalse($res->isFresh(0)); } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php index 49138f91bea34..8382d303859e1 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php @@ -388,7 +388,7 @@ private function populateAvailableType($id, Definition $definition) unset($this->ambiguousServiceTypes[$type]); } - if ($definition->isDeprecated() || !$reflectionClass = $this->container->getReflectionClass($definition->getClass(), true)) { + if ($definition->isDeprecated() || !$reflectionClass = $this->container->getReflectionClass($definition->getClass())) { return; } @@ -444,7 +444,7 @@ private function set($type, $id) */ private function createAutowiredDefinition($type) { - if (!($typeHint = $this->container->getReflectionClass($type, true)) || !$typeHint->isInstantiable()) { + if (!($typeHint = $this->container->getReflectionClass($type)) || !$typeHint->isInstantiable()) { return; } @@ -478,7 +478,7 @@ private function createAutowiredDefinition($type) private function createTypeNotFoundMessage(TypedReference $reference, $label) { - if (!$r = $this->container->getReflectionClass($type = $reference->getType(), true)) { + if (!$r = $this->container->getReflectionClass($type = $reference->getType())) { $message = sprintf('has type "%s" but this class does not exist.', $type); } else { $message = $this->container->has($type) ? 'this service is abstract' : 'no such service exists'; diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index 3887e56fc244a..14dd957e9ea13 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -337,13 +337,12 @@ public function addClassResource(\ReflectionClass $class) * Retrieves the requested reflection class and registers it for resource tracking. * * @param string $class - * @param bool $koWithThrowingAutoloader Whether autoload should be protected against bad parents or not * * @return \ReflectionClass|null * * @final */ - public function getReflectionClass($class, $koWithThrowingAutoloader = false) + public function getReflectionClass($class) { if (!$class = $this->getParameterBag()->resolveValue($class)) { return; @@ -353,12 +352,9 @@ public function getReflectionClass($class, $koWithThrowingAutoloader = false) try { if (isset($this->classReflectors[$class])) { $classReflector = $this->classReflectors[$class]; - } elseif ($koWithThrowingAutoloader) { - $resource = new ClassExistenceResource($class, ClassExistenceResource::EXISTS_KO_WITH_THROWING_AUTOLOADER); - - $classReflector = $resource->isFresh(0) ? false : new \ReflectionClass($class); } else { - $classReflector = new \ReflectionClass($class); + $resource = new ClassExistenceResource($class, false); + $classReflector = $resource->isFresh(0) ? false : new \ReflectionClass($class); } } catch (\ReflectionException $e) { $classReflector = false; @@ -366,7 +362,7 @@ public function getReflectionClass($class, $koWithThrowingAutoloader = false) if ($this->trackResources) { if (!$classReflector) { - $this->addResource($resource ?: new ClassExistenceResource($class, ClassExistenceResource::EXISTS_KO)); + $this->addResource($resource ?: new ClassExistenceResource($class, false)); } elseif (!$classReflector->isInternal()) { $path = $classReflector->getFileName(); diff --git a/src/Symfony/Component/DependencyInjection/composer.json b/src/Symfony/Component/DependencyInjection/composer.json index 3a2916635ffb8..8c88d4f02a790 100644 --- a/src/Symfony/Component/DependencyInjection/composer.json +++ b/src/Symfony/Component/DependencyInjection/composer.json @@ -32,7 +32,7 @@ "symfony/proxy-manager-bridge": "Generate service proxies to lazy load them" }, "conflict": { - "symfony/config": "<3.3", + "symfony/config": "<3.3.1", "symfony/finder": "<3.3", "symfony/yaml": "<3.3" }, From 2a293692f273fdd5d3b97c0ab55ced82b868b2b0 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 2 Jun 2017 21:23:33 +0200 Subject: [PATCH 43/57] [Console] Add missing dev-dep --- src/Symfony/Component/Console/composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Symfony/Component/Console/composer.json b/src/Symfony/Component/Console/composer.json index 362d55d1af8e9..db76bf3b2c7a7 100644 --- a/src/Symfony/Component/Console/composer.json +++ b/src/Symfony/Component/Console/composer.json @@ -21,6 +21,7 @@ "symfony/debug": "~2.8|~3.0" }, "require-dev": { + "symfony/config": "~3.3", "symfony/http-kernel": "~2.8|~3.0", "symfony/event-dispatcher": "~2.8|~3.0", "symfony/dependency-injection": "~3.3", From d3e6a2d6f6d69e4f693a94a0c6edd52cbc91f513 Mon Sep 17 00:00:00 2001 From: Vincent AUBERT Date: Fri, 2 Jun 2017 19:45:13 +0200 Subject: [PATCH 44/57] minor #23043 add \ to PHP_VERSION_ID fixes #22650 --- src/Symfony/Bridge/Twig/DataCollector/TwigDataCollector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Twig/DataCollector/TwigDataCollector.php b/src/Symfony/Bridge/Twig/DataCollector/TwigDataCollector.php index 382ce13987cc3..f28c92422ae48 100644 --- a/src/Symfony/Bridge/Twig/DataCollector/TwigDataCollector.php +++ b/src/Symfony/Bridge/Twig/DataCollector/TwigDataCollector.php @@ -96,7 +96,7 @@ public function getHtmlCallGraph() public function getProfile() { if (null === $this->profile) { - if (PHP_VERSION_ID >= 70000) { + if (\PHP_VERSION_ID >= 70000) { $this->profile = unserialize($this->data['profile'], array('allowed_classes' => array('Twig_Profiler_Profile', 'Twig\Profiler\Profile'))); } else { $this->profile = unserialize($this->data['profile']); From 67895f4dd33b39fb84fcd6aa13d8eeb31cfae7dd Mon Sep 17 00:00:00 2001 From: Richard van Laak Date: Fri, 2 Jun 2017 10:44:49 +0200 Subject: [PATCH 45/57] [Yaml] Clarify "incompatible key casting" deprecation message --- src/Symfony/Component/Yaml/Parser.php | 3 ++- src/Symfony/Component/Yaml/Tests/ParserTest.php | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index 42f61af9de0a4..4a5f2b91e06bf 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -237,7 +237,8 @@ private function doParse($value, $flags) } if (!(Yaml::PARSE_KEYS_AS_STRINGS & $flags) && !is_string($key)) { - @trigger_error('Implicit casting of incompatible mapping keys to strings is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRING flag to explicitly enable the type casts.', E_USER_DEPRECATED); + $keyType = is_numeric($key) ? 'numeric key' : 'incompatible key type'; + @trigger_error(sprintf('Implicit casting of %s to string on line %d is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRING flag to explicitly enable the type casts.', $keyType, $this->getRealCurrentLineNb()), E_USER_DEPRECATED); } // Convert float keys to strings, to avoid being converted to integers by PHP diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index a0bef9d528c81..a6c7b6ad12aff 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -1081,7 +1081,7 @@ public function testYamlDirective() /** * @group legacy - * @expectedDeprecation Implicit casting of incompatible mapping keys to strings is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRING flag to explicitly enable the type casts. + * @expectedDeprecation Implicit casting of numeric key to string on line 1 is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRING flag to explicitly enable the type casts. */ public function testFloatKeys() { @@ -1103,7 +1103,7 @@ public function testFloatKeys() /** * @group legacy - * @expectedDeprecation Implicit casting of incompatible mapping keys to strings is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRING flag to explicitly enable the type casts. + * @expectedDeprecation Implicit casting of incompatible key type to string on line 1 is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRING flag to explicitly enable the type casts. */ public function testBooleanKeys() { From 61685c7106c282b4e07f31f83b22f5dcd2410a40 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 3 Jun 2017 09:31:39 +0200 Subject: [PATCH 46/57] [Cache] fix Redis scheme detection --- src/Symfony/Component/Cache/Adapter/RedisAdapter.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Cache/Adapter/RedisAdapter.php b/src/Symfony/Component/Cache/Adapter/RedisAdapter.php index 922d3d3e5150b..34f7c59926e3d 100644 --- a/src/Symfony/Component/Cache/Adapter/RedisAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/RedisAdapter.php @@ -90,6 +90,11 @@ public static function createConnection($dsn, array $options = array()) $params['dbindex'] = $m[1]; $params['path'] = substr($params['path'], 0, -strlen($m[0])); } + if (isset($params['host'])) { + $scheme = 'tcp'; + } else { + $scheme = 'unix'; + } $params += array( 'host' => isset($params['host']) ? $params['host'] : $params['path'], 'port' => isset($params['host']) ? 6379 : null, @@ -120,7 +125,7 @@ public static function createConnection($dsn, array $options = array()) throw new InvalidArgumentException(sprintf('Redis connection failed (%s): %s', $e, $dsn)); } } elseif (is_a($class, \Predis\Client::class, true)) { - $params['scheme'] = isset($params['host']) ? 'tcp' : 'unix'; + $params['scheme'] = $scheme; $params['database'] = $params['dbindex'] ?: null; $params['password'] = $auth; $redis = new $class((new Factory())->create($params)); From 0068968dcc43b08827e6d3779cfc52f3eb206f80 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 3 Jun 2017 10:00:53 +0200 Subject: [PATCH 47/57] explain that a role can be an instance of Role Only mentioning the RoleInterface seems to be confusing as it is deprecated since Symfony 3.3. --- .../Security/Core/Authentication/Token/AbstractToken.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php b/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php index 0eee6d94a41c6..82e7fa672fdd8 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php +++ b/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php @@ -43,7 +43,7 @@ public function __construct(array $roles = array()) if (is_string($role)) { $role = new Role($role); } elseif (!$role instanceof RoleInterface) { - throw new \InvalidArgumentException(sprintf('$roles must be an array of strings, or RoleInterface instances, but got %s.', gettype($role))); + throw new \InvalidArgumentException(sprintf('$roles must be an array of strings, Role instances or RoleInterface instances, but got %s.', gettype($role))); } $this->roles[] = $role; From 479895f6671fef54eb92c941802509a9ad338b01 Mon Sep 17 00:00:00 2001 From: Maxime Steinhausser Date: Sat, 3 Jun 2017 10:06:02 +0200 Subject: [PATCH 48/57] [Form][FrameworkBundle] Remove non-existing arg for data_collector.form --- .../Bundle/FrameworkBundle/Resources/config/form_debug.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/form_debug.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/form_debug.xml index 843fc72bdb253..9c2dfad2ee639 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/form_debug.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/form_debug.xml @@ -24,7 +24,6 @@ - false From 6c87863a0e0896e360189b270a1964abe49c1c25 Mon Sep 17 00:00:00 2001 From: Maxime Steinhausser Date: Tue, 30 May 2017 19:05:33 +0200 Subject: [PATCH 49/57] [Profiler] Never wrap in code excerpts --- .../TwigBundle/Resources/views/exception.css.twig | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Bundle/TwigBundle/Resources/views/exception.css.twig b/src/Symfony/Bundle/TwigBundle/Resources/views/exception.css.twig index 1c8c76e78db4a..cb455274eecf9 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/views/exception.css.twig +++ b/src/Symfony/Bundle/TwigBundle/Resources/views/exception.css.twig @@ -95,7 +95,7 @@ header .container { display: flex; justify-content: space-between; } .trace-head .icon svg { height: 24px; width: 24px; } .trace-message { font-size: 14px; font-weight: normal; margin: .5em 0 0; } - +.trace-details { table-layout: fixed; } .trace-line { position: relative; padding-left: 36px; } .trace-line.sf-toggle:hover { background: #F5F5F5; } .trace-line a { color: #222; } @@ -108,12 +108,12 @@ header .container { display: flex; justify-content: space-between; } .trace-method { color: #B0413E; color: #222; font-weight: bold; color: #B0413E; } .trace-arguments { color: #222; color: #999; font-weight: normal; color: #795da3; color: #777; padding-left: 2px; } -.trace-code { background: #FFF; font-size: 12px; margin: 10px 0 2px; padding: 10px; } -.trace-code ol { margin: 0; } -.trace-code li { color: #969896; margin: 0; padding-left: 10px; } -.trace-code li + li { margin-top: 10px; } -.trace-code li.selected { background: #F8EEC7; padding: 3px 0 3px 10px; } -.trace-code li code { color: #222; } +.trace-code { background: #FFF; font-size: 12px; margin: 10px 0 2px; padding: 10px; overflow-x: auto; } +.trace-code ol { margin: 0; float: left; } +.trace-code li { color: #969896; margin: 0; padding-left: 10px; float: left; width: 100%; } +.trace-code li + li { margin-top: 5px; } +.trace-code li.selected { background: #F8EEC7; padding: 3px 0 3px 10px; margin-top: 2px; } +.trace-code li code { color: #222; white-space: nowrap; } .trace-as-text .stacktrace { line-height: 1.8; margin: 0 0 15px; white-space: pre-wrap; } From ff055ef7f377f524288a491255a33da00fbc15cc Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 3 Jun 2017 12:01:46 +0200 Subject: [PATCH 50/57] mitigate BC break with empty trusted_proxies --- .../DependencyInjection/Configuration.php | 6 +++- .../DependencyInjection/ConfigurationTest.php | 32 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 87d722b91e4d6..2ff614135983f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -67,7 +67,11 @@ public function getConfigTreeBuilder() ->end() ->arrayNode('trusted_proxies') // @deprecated in version 3.3, to be removed in 4.0 ->beforeNormalization() - ->always() + ->ifTrue(function ($v) { return empty($v); }) + ->then(function () { @trigger_error('The "framework.trusted_proxies" configuration key has been removed in Symfony 3.3. Use the Request::setTrustedProxies() method in your front controller instead.', E_USER_DEPRECATED); }) + ->end() + ->beforeNormalization() + ->ifTrue(function ($v) { return !empty($v); }) ->thenInvalid('The "framework.trusted_proxies" configuration key has been removed in Symfony 3.3. Use the Request::setTrustedProxies() method in your front controller instead.') ->end() ->end() diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index 353e959c68ebf..96835c7be3f86 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -43,6 +43,38 @@ public function testDoNoDuplicateDefaultFormResources() $this->assertEquals(array('FrameworkBundle:Form'), $config['templating']['form']['resources']); } + /** + * @group legacy + * @expectedDeprecation The "framework.trusted_proxies" configuration key has been removed in Symfony 3.3. Use the Request::setTrustedProxies() method in your front controller instead. + */ + public function testTrustedProxiesSetToNullIsDeprecated() + { + $processor = new Processor(); + $configuration = new Configuration(true); + $processor->processConfiguration($configuration, array(array('trusted_proxies' => null))); + } + + /** + * @group legacy + * @expectedDeprecation The "framework.trusted_proxies" configuration key has been removed in Symfony 3.3. Use the Request::setTrustedProxies() method in your front controller instead. + */ + public function testTrustedProxiesSetToEmptyArrayIsDeprecated() + { + $processor = new Processor(); + $configuration = new Configuration(true); + $processor->processConfiguration($configuration, array(array('trusted_proxies' => array()))); + } + + /** + * @expectedException \InvalidArgumentException + */ + public function testTrustedProxiesSetToNonEmptyArrayIsInvalid() + { + $processor = new Processor(); + $configuration = new Configuration(true); + $processor->processConfiguration($configuration, array(array('trusted_proxies' => array('127.0.0.1')))); + } + public function testAssetsCanBeEnabled() { $processor = new Processor(); From 9de898d69f755fe738839de087c20e3e547ca68e Mon Sep 17 00:00:00 2001 From: Maxime Steinhausser Date: Sat, 3 Jun 2017 13:10:54 +0200 Subject: [PATCH 51/57] [Form][Profiler] Fixes form collector triggering deprecations --- .../Resources/views/Collector/form.html.twig | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/form.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/form.html.twig index 2f8b83049d158..02b77319ac249 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/form.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/form.html.twig @@ -525,7 +525,7 @@ Model Format {% if data.default_data.model is defined %} - {{ profiler_dump(data.default_data.model) }} + {{ profiler_dump(data.default_data.seek('model')) }} {% else %} same as normalized format {% endif %} @@ -533,13 +533,13 @@ Normalized Format - {{ profiler_dump(data.default_data.norm) }} + {{ profiler_dump(data.default_data.seek('norm')) }} View Format {% if data.default_data.view is defined %} - {{ profiler_dump(data.default_data.view) }} + {{ profiler_dump(data.default_data.seek('view')) }} {% else %} same as normalized format {% endif %} @@ -571,7 +571,7 @@ View Format {% if data.submitted_data.view is defined %} - {{ profiler_dump(data.submitted_data.view) }} + {{ profiler_dump(data.submitted_data.seek('view')) }} {% else %} same as normalized format {% endif %} @@ -579,13 +579,13 @@ Normalized Format - {{ profiler_dump(data.submitted_data.norm) }} + {{ profiler_dump(data.submitted_data.seek('norm')) }} Model Format {% if data.submitted_data.model is defined %} - {{ profiler_dump(data.submitted_data.model) }} + {{ profiler_dump(data.submitted_data.seek('model')) }} {% else %} same as normalized format {% endif %} @@ -630,7 +630,7 @@ {% if resolved_option_value == option_value %} same as passed value {% else %} - {{ profiler_dump(data.resolved_options[option]) }} + {{ profiler_dump(data.resolved_options.seek(option)) }} {% endif %} From 5b819ebfee02bf295b3c76d4d879a96c5a26cbab Mon Sep 17 00:00:00 2001 From: Maxime Steinhausser Date: Sun, 4 Jun 2017 20:05:07 +0200 Subject: [PATCH 52/57] Remove closure-proxy leftovers --- .../FrameworkBundle/Console/Descriptor/Descriptor.php | 7 ------- .../FrameworkBundle/Console/Descriptor/JsonDescriptor.php | 2 +- .../Console/Descriptor/MarkdownDescriptor.php | 3 +-- .../FrameworkBundle/Console/Descriptor/TextDescriptor.php | 8 +------- .../FrameworkBundle/Console/Descriptor/XmlDescriptor.php | 2 +- .../EventDispatcher/ContainerAwareEventDispatcher.php | 6 +++--- 6 files changed, 7 insertions(+), 21 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php index acaec0bf5dbab..206b01e4f056e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php @@ -307,11 +307,4 @@ protected function sortServiceIds(array $serviceIds) return $serviceIds; } - - protected function formatClosure(\Closure $closure) - { - $r = new \ReflectionFunction($closure); - - return 'closure'; - } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php index d49c57adfec2e..6755369c06252 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php @@ -370,7 +370,7 @@ private function getCallableData($callable, array $options = array()) } if ($callable instanceof \Closure) { - $data['type'] = $this->formatClosure($callable); + $data['type'] = 'closure'; return $data; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php index 59e382d3a9cad..81c6c4a69a2f6 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php @@ -349,8 +349,7 @@ protected function describeCallable($callable, array $options = array()) } if ($callable instanceof \Closure) { - $formatted = $this->formatClosure($callable); - $string .= "\n- Type: `$formatted`"; + $string .= "\n- Type: `closure`"; return $this->write($string."\n"); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php index 06a404080d32d..861f3c21c4dd5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php @@ -474,13 +474,7 @@ private function formatCallable($callable) } if ($callable instanceof \Closure) { - $formatted = $this->formatClosure($callable); - - if ('closure' === $formatted) { - return '\Closure()'; - } - - return $formatted.'()'; + return '\Closure()'; } if (method_exists($callable, '__invoke')) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php index f1770d8c3c453..5baa8de11c730 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php @@ -593,7 +593,7 @@ private function getCallableDocument($callable) } if ($callable instanceof \Closure) { - $callableXML->setAttribute('type', $this->formatClosure($callable)); + $callableXML->setAttribute('type', 'closure'); return $dom; } diff --git a/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php b/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php index a57dd86eaf7cb..fc7b30f9ccc65 100644 --- a/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php +++ b/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php @@ -21,7 +21,7 @@ * @author Bernhard Schussek * @author Jordan Alliot * - * @deprecated since 3.3, to be removed in 4.0. Use EventDispatcher with closure-proxy injection instead. + * @deprecated since 3.3, to be removed in 4.0. Use EventDispatcher with closure factories instead. */ class ContainerAwareEventDispatcher extends EventDispatcher { @@ -60,7 +60,7 @@ public function __construct(ContainerInterface $container) $class = get_parent_class($class); } if (__CLASS__ !== $class) { - @trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use EventDispatcher with closure-proxy injection instead.', __CLASS__), E_USER_DEPRECATED); + @trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.', __CLASS__), E_USER_DEPRECATED); } } @@ -78,7 +78,7 @@ public function __construct(ContainerInterface $container) */ public function addListenerService($eventName, $callback, $priority = 0) { - @trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use EventDispatcher with closure-proxy injection instead.', __CLASS__), E_USER_DEPRECATED); + @trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.', __CLASS__), E_USER_DEPRECATED); if (!is_array($callback) || 2 !== count($callback)) { throw new \InvalidArgumentException('Expected an array("service", "method") argument'); From 213233305903d659b012acc2ae088a647e85ac4a Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 5 Jun 2017 14:57:44 +0200 Subject: [PATCH 53/57] [HttpFoundation][FrameworkBundle] Revert "trusted proxies" BC break --- .../Bundle/FrameworkBundle/CHANGELOG.md | 2 +- .../DependencyInjection/Configuration.php | 36 ++++++++-- .../FrameworkExtension.php | 3 + .../DependencyInjection/ConfigurationTest.php | 72 ++++++++++++++++++- .../Component/HttpFoundation/CHANGELOG.md | 2 +- .../Component/HttpFoundation/Request.php | 30 ++++---- .../HttpFoundation/Tests/RequestTest.php | 2 +- 7 files changed, 123 insertions(+), 24 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index d25f4547d3123..b760d28997611 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -7,7 +7,7 @@ CHANGELOG * Not defining the `type` option of the `framework.workflows.*` configuration entries is deprecated. The default value will be `state_machine` in Symfony 4.0. * Deprecated the `CompilerDebugDumpPass` class - * [BC BREAK] Removed the "framework.trusted_proxies" configuration option and the corresponding "kernel.trusted_proxies" parameter + * Deprecated the "framework.trusted_proxies" configuration option and the corresponding "kernel.trusted_proxies" parameter * Added a new new version strategy option called json_manifest_path that allows you to use the `JsonManifestVersionStrategy`. * Added `Symfony\Bundle\FrameworkBundle\Controller\AbstractController`. It provides diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 2ff614135983f..611bfad97db82 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -65,14 +65,38 @@ public function getConfigTreeBuilder() ->info("Set true to enable support for the '_method' request parameter to determine the intended HTTP method on POST requests. Note: When using the HttpCache, you need to call the method in your front controller instead") ->defaultTrue() ->end() - ->arrayNode('trusted_proxies') // @deprecated in version 3.3, to be removed in 4.0 + ->arrayNode('trusted_proxies') ->beforeNormalization() - ->ifTrue(function ($v) { return empty($v); }) - ->then(function () { @trigger_error('The "framework.trusted_proxies" configuration key has been removed in Symfony 3.3. Use the Request::setTrustedProxies() method in your front controller instead.', E_USER_DEPRECATED); }) + ->ifTrue(function ($v) { + @trigger_error('The "framework.trusted_proxies" configuration key has been deprecated in Symfony 3.3. Use the Request::setTrustedProxies() method in your front controller instead.', E_USER_DEPRECATED); + + return !is_array($v) && null !== $v; + }) + ->then(function ($v) { return is_bool($v) ? array() : preg_split('/\s*,\s*/', $v); }) ->end() - ->beforeNormalization() - ->ifTrue(function ($v) { return !empty($v); }) - ->thenInvalid('The "framework.trusted_proxies" configuration key has been removed in Symfony 3.3. Use the Request::setTrustedProxies() method in your front controller instead.') + ->prototype('scalar') + ->validate() + ->ifTrue(function ($v) { + if (empty($v)) { + return false; + } + + if (false !== strpos($v, '/')) { + if ('0.0.0.0/0' === $v) { + return false; + } + + list($v, $mask) = explode('/', $v, 2); + + if (strcmp($mask, (int) $mask) || $mask < 1 || $mask > (false !== strpos($v, ':') ? 128 : 32)) { + return true; + } + } + + return !filter_var($v, FILTER_VALIDATE_IP); + }) + ->thenInvalid('Invalid proxy IP "%s"') + ->end() ->end() ->end() ->scalarNode('ide')->defaultNull()->end() diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 4e664f1fe888c..b607cdd2bf563 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -146,6 +146,9 @@ public function load(array $configs, ContainerBuilder $container) $container->setParameter('kernel.http_method_override', $config['http_method_override']); $container->setParameter('kernel.trusted_hosts', $config['trusted_hosts']); + if ($config['trusted_proxies']) { + $container->setParameter('kernel.trusted_proxies', $config['trusted_proxies']); + } $container->setParameter('kernel.default_locale', $config['default_locale']); if (!$container->hasParameter('debug.file_link_format')) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index 96835c7be3f86..0d2578db040af 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -45,7 +45,7 @@ public function testDoNoDuplicateDefaultFormResources() /** * @group legacy - * @expectedDeprecation The "framework.trusted_proxies" configuration key has been removed in Symfony 3.3. Use the Request::setTrustedProxies() method in your front controller instead. + * @expectedDeprecation The "framework.trusted_proxies" configuration key has been deprecated in Symfony 3.3. Use the Request::setTrustedProxies() method in your front controller instead. */ public function testTrustedProxiesSetToNullIsDeprecated() { @@ -56,7 +56,7 @@ public function testTrustedProxiesSetToNullIsDeprecated() /** * @group legacy - * @expectedDeprecation The "framework.trusted_proxies" configuration key has been removed in Symfony 3.3. Use the Request::setTrustedProxies() method in your front controller instead. + * @expectedDeprecation The "framework.trusted_proxies" configuration key has been deprecated in Symfony 3.3. Use the Request::setTrustedProxies() method in your front controller instead. */ public function testTrustedProxiesSetToEmptyArrayIsDeprecated() { @@ -66,7 +66,8 @@ public function testTrustedProxiesSetToEmptyArrayIsDeprecated() } /** - * @expectedException \InvalidArgumentException + * @group legacy + * @expectedDeprecation The "framework.trusted_proxies" configuration key has been deprecated in Symfony 3.3. Use the Request::setTrustedProxies() method in your front controller instead. */ public function testTrustedProxiesSetToNonEmptyArrayIsInvalid() { @@ -75,6 +76,70 @@ public function testTrustedProxiesSetToNonEmptyArrayIsInvalid() $processor->processConfiguration($configuration, array(array('trusted_proxies' => array('127.0.0.1')))); } + /** + * @group legacy + * @dataProvider getTestValidTrustedProxiesData + */ + public function testValidTrustedProxies($trustedProxies, $processedProxies) + { + $processor = new Processor(); + $configuration = new Configuration(true); + $config = $processor->processConfiguration($configuration, array(array( + 'secret' => 's3cr3t', + 'trusted_proxies' => $trustedProxies, + ))); + + $this->assertEquals($processedProxies, $config['trusted_proxies']); + } + + public function getTestValidTrustedProxiesData() + { + return array( + array(array('127.0.0.1'), array('127.0.0.1')), + array(array('::1'), array('::1')), + array(array('127.0.0.1', '::1'), array('127.0.0.1', '::1')), + array(null, array()), + array(false, array()), + array(array(), array()), + array(array('10.0.0.0/8'), array('10.0.0.0/8')), + array(array('::ffff:0:0/96'), array('::ffff:0:0/96')), + array(array('0.0.0.0/0'), array('0.0.0.0/0')), + ); + } + + /** + * @group legacy + * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException + */ + public function testInvalidTypeTrustedProxies() + { + $processor = new Processor(); + $configuration = new Configuration(true); + $processor->processConfiguration($configuration, array( + array( + 'secret' => 's3cr3t', + 'trusted_proxies' => 'Not an IP address', + ), + )); + } + + /** + * @group legacy + * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException + */ + public function testInvalidValueTrustedProxies() + { + $processor = new Processor(); + $configuration = new Configuration(true); + + $processor->processConfiguration($configuration, array( + array( + 'secret' => 's3cr3t', + 'trusted_proxies' => array('Not an IP address'), + ), + )); + } + public function testAssetsCanBeEnabled() { $processor = new Processor(); @@ -156,6 +221,7 @@ protected static function getBundleDefaultConfig() { return array( 'http_method_override' => true, + 'trusted_proxies' => array(), 'ide' => null, 'default_locale' => 'en', 'csrf_protection' => array( diff --git a/src/Symfony/Component/HttpFoundation/CHANGELOG.md b/src/Symfony/Component/HttpFoundation/CHANGELOG.md index ac812fe1527a0..e1fdf77b9b8ae 100644 --- a/src/Symfony/Component/HttpFoundation/CHANGELOG.md +++ b/src/Symfony/Component/HttpFoundation/CHANGELOG.md @@ -4,7 +4,7 @@ CHANGELOG 3.3.0 ----- - * [BC BREAK] the `Request::setTrustedProxies()` method takes a new `$trustedHeaderSet` argument, + * the `Request::setTrustedProxies()` method takes a new `$trustedHeaderSet` argument, see http://symfony.com/doc/current/components/http_foundation/trusting_proxies.html for more info, * deprecated the `Request::setTrustedHeaderName()` and `Request::getTrustedHeaderName()` methods, * added `File\Stream`, to be passed to `BinaryFileResponse` when the size of the served file is unknown, diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 75d15df3120b9..13ff1e05528fe 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -581,7 +581,7 @@ public function overrideGlobals() * You should only list the reverse proxies that you manage directly. * * @param array $proxies A list of trusted proxies - * @param int $trustedHeaderSet A bit field of Request::HEADER_*, usually either Request::HEADER_FORWARDED or Request::HEADER_X_FORWARDED_ALL, to set which headers to trust from your proxies + * @param int $trustedHeaderSet A bit field of Request::HEADER_*, to set which headers to trust from your proxies * * @throws \InvalidArgumentException When $trustedHeaderSet is invalid */ @@ -590,10 +590,11 @@ public static function setTrustedProxies(array $proxies/*, int $trustedHeaderSet self::$trustedProxies = $proxies; if (2 > func_num_args()) { - // @deprecated code path in 3.3, to be replaced by mandatory argument in 4.0. - throw new \InvalidArgumentException(sprintf('The %s() method expects a bit field of Request::HEADER_* as second argument. Defining it is required since version 3.3. See http://symfony.com/doc/current/components/http_foundation/trusting_proxies.html for more info.', __METHOD__)); + @trigger_error(sprintf('The %s() method expects a bit field of Request::HEADER_* as second argument since version 3.3. Defining it will be required in 4.0. ', __METHOD__), E_USER_DEPRECATED); + + return; } - $trustedHeaderSet = func_get_arg(1); + $trustedHeaderSet = (int) func_get_arg(1); foreach (self::$trustedHeaderNames as $header => $name) { self::$trustedHeaders[$header] = $header & $trustedHeaderSet ? $name : null; @@ -665,11 +666,11 @@ public static function getTrustedHosts() * * @throws \InvalidArgumentException * - * @deprecated since version 3.3, to be removed in 4.0. Use "X-Forwarded-*" headers or the "Forwarded" header defined in RFC7239, and the $trustedHeaderSet argument of the Request::setTrustedProxies() method instead. + * @deprecated since version 3.3, to be removed in 4.0. Use the $trustedHeaderSet argument of the Request::setTrustedProxies() method instead. */ public static function setTrustedHeaderName($key, $value) { - @trigger_error(sprintf('The "%s()" method is deprecated since version 3.3 and will be removed in 4.0. Use "X-Forwarded-*" headers or the "Forwarded" header defined in RFC7239, and the $trustedHeaderSet argument of the Request::setTrustedProxies() method instead.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('The "%s()" method is deprecated since version 3.3 and will be removed in 4.0. Use the $trustedHeaderSet argument of the Request::setTrustedProxies() method instead.', __METHOD__), E_USER_DEPRECATED); if (!array_key_exists($key, self::$trustedHeaders)) { throw new \InvalidArgumentException(sprintf('Unable to set the trusted header name for key "%s".', $key)); @@ -679,6 +680,9 @@ public static function setTrustedHeaderName($key, $value) if (null !== $value) { self::$trustedHeaderNames[$key] = $value; + self::$trustedHeaderSet |= $key; + } else { + self::$trustedHeaderSet &= ~$key; } } @@ -886,8 +890,8 @@ public function getClientIps() * adding the IP address where it received the request from. * * If your reverse proxy uses a different header name than "X-Forwarded-For", - * ("Client-Ip" for instance), configure it via "setTrustedHeaderName()" with - * the "client-ip" key. + * ("Client-Ip" for instance), configure it via the $trustedHeaderSet + * argument of the Request::setTrustedProxies() method instead. * * @return string|null The client IP address * @@ -993,7 +997,8 @@ public function getScheme() * The "X-Forwarded-Port" header must contain the client port. * * If your reverse proxy uses a different header name than "X-Forwarded-Port", - * configure it via "setTrustedHeaderName()" with the "client-port" key. + * configure it via via the $trustedHeaderSet argument of the + * Request::setTrustedProxies() method instead. * * @return int|string can be a string if fetched from the server bag */ @@ -1210,8 +1215,8 @@ public function getQueryString() * The "X-Forwarded-Proto" header must contain the protocol: "https" or "http". * * If your reverse proxy uses a different header name than "X-Forwarded-Proto" - * ("SSL_HTTPS" for instance), configure it via "setTrustedHeaderName()" with - * the "client-proto" key. + * ("SSL_HTTPS" for instance), configure it via the $trustedHeaderSet + * argument of the Request::setTrustedProxies() method instead. * * @return bool */ @@ -1235,7 +1240,8 @@ public function isSecure() * The "X-Forwarded-Host" header must contain the client host name. * * If your reverse proxy uses a different header name than "X-Forwarded-Host", - * configure it via "setTrustedHeaderName()" with the "client-host" key. + * configure it via the $trustedHeaderSet argument of the + * Request::setTrustedProxies() method instead. * * @return string * diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index 9042fc49ba824..b36fbb7e96258 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -1729,7 +1729,7 @@ public function testTrustedProxiesXForwardedFor() /** * @group legacy - * @expectedDeprecation The "Symfony\Component\HttpFoundation\Request::setTrustedHeaderName()" method is deprecated since version 3.3 and will be removed in 4.0. Use "X-Forwarded-*" headers or the "Forwarded" header defined in RFC7239, and the $trustedHeaderSet argument of the Request::setTrustedProxies() method instead. + * @expectedDeprecation The "Symfony\Component\HttpFoundation\Request::setTrustedHeaderName()" method is deprecated since version 3.3 and will be removed in 4.0. Use the $trustedHeaderSet argument of the Request::setTrustedProxies() method instead. */ public function testLegacyTrustedProxies() { From 28aaa8eb05fd037ab3740f3123153dc2a6f275a4 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 5 Jun 2017 10:23:13 +0200 Subject: [PATCH 54/57] [Cache] Fallback to positional when keyed results are broken --- .../Component/Cache/Adapter/AbstractAdapter.php | 3 +++ .../Component/Cache/Adapter/MemcachedAdapter.php | 12 ++++++++++++ src/Symfony/Component/Cache/Simple/AbstractCache.php | 3 +++ .../Tests/Adapter/TraceableTagAwareAdapterTest.php | 3 +++ .../Component/Cache/Tests/Simple/CacheTestCase.php | 9 +++++++++ 5 files changed, 30 insertions(+) diff --git a/src/Symfony/Component/Cache/Adapter/AbstractAdapter.php b/src/Symfony/Component/Cache/Adapter/AbstractAdapter.php index c761b9a2010bf..e4fa4c97b7ba9 100644 --- a/src/Symfony/Component/Cache/Adapter/AbstractAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/AbstractAdapter.php @@ -266,6 +266,9 @@ private function generateItems($items, &$keys) try { foreach ($items as $id => $value) { + if (!isset($keys[$id])) { + $id = key($keys); + } $key = $keys[$id]; unset($keys[$id]); yield $key => $f($key, $value, true); diff --git a/src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php b/src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php index 5c8784e69cf44..3acf8bdb86c6a 100644 --- a/src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php @@ -19,6 +19,18 @@ class MemcachedAdapter extends AbstractAdapter protected $maxIdLength = 250; + /** + * Constructor. + * + * Using a MemcachedAdapter with a TagAwareAdapter for storing tags is discouraged. + * Using a RedisAdapter is recommended instead. If you cannot do otherwise, be aware that: + * - the Memcached::OPT_BINARY_PROTOCOL must be enabled + * (that's the default when using MemcachedAdapter::createConnection()); + * - tags eviction by Memcached's LRU algorithm will break by-tags invalidation; + * your Memcached memory should be large enough to never trigger LRU. + * + * Using a MemcachedAdapter as a pure items store is fine. + */ public function __construct(\Memcached $client, $namespace = '', $defaultLifetime = 0) { $this->init($client, $namespace, $defaultLifetime); diff --git a/src/Symfony/Component/Cache/Simple/AbstractCache.php b/src/Symfony/Component/Cache/Simple/AbstractCache.php index 4c44b9b323bb0..bbd35780fd5c4 100644 --- a/src/Symfony/Component/Cache/Simple/AbstractCache.php +++ b/src/Symfony/Component/Cache/Simple/AbstractCache.php @@ -162,6 +162,9 @@ private function generateValues($values, &$keys, $default) { try { foreach ($values as $id => $value) { + if (!isset($keys[$id])) { + $id = key($keys); + } $key = $keys[$id]; unset($keys[$id]); yield $key => $value; diff --git a/src/Symfony/Component/Cache/Tests/Adapter/TraceableTagAwareAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/TraceableTagAwareAdapterTest.php index 38f3c6c087dfc..9b50bfabe65b7 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/TraceableTagAwareAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/TraceableTagAwareAdapterTest.php @@ -15,6 +15,9 @@ use Symfony\Component\Cache\Adapter\TagAwareAdapter; use Symfony\Component\Cache\Adapter\TraceableTagAwareAdapter; +/** + * @group time-sensitive + */ class TraceableTagAwareAdapterTest extends TraceableAdapterTest { public function testInvalidateTags() diff --git a/src/Symfony/Component/Cache/Tests/Simple/CacheTestCase.php b/src/Symfony/Component/Cache/Tests/Simple/CacheTestCase.php index 81d412bd66354..b3799ebcda24c 100644 --- a/src/Symfony/Component/Cache/Tests/Simple/CacheTestCase.php +++ b/src/Symfony/Component/Cache/Tests/Simple/CacheTestCase.php @@ -15,6 +15,15 @@ abstract class CacheTestCase extends SimpleCacheTest { + public static function validKeys() + { + if (defined('HHVM_VERSION')) { + return parent::validKeys(); + } + + return array_merge(parent::validKeys(), array(array("a\0b"))); + } + public function testDefaultLifeTime() { if (isset($this->skippedTests[__FUNCTION__])) { From 1ab3e413d4e732f53841c4d8db900a8edb01d50a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Wed, 31 May 2017 08:51:10 +0200 Subject: [PATCH 55/57] [DependencyInjection] Fix named args support in ChildDefinition --- .../DependencyInjection/ChildDefinition.php | 16 +++++----------- .../Tests/ChildDefinitionTest.php | 4 ++++ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/ChildDefinition.php b/src/Symfony/Component/DependencyInjection/ChildDefinition.php index dd02f860677f8..5701caa474e57 100644 --- a/src/Symfony/Component/DependencyInjection/ChildDefinition.php +++ b/src/Symfony/Component/DependencyInjection/ChildDefinition.php @@ -62,7 +62,7 @@ public function setParent($parent) * If replaceArgument() has been used to replace an argument, this method * will return the replacement value. * - * @param int $index + * @param int|string $index * * @return mixed The argument value * @@ -74,13 +74,7 @@ public function getArgument($index) return $this->arguments['index_'.$index]; } - $lastIndex = count(array_filter(array_keys($this->arguments), 'is_int')) - 1; - - if ($index < 0 || $index > $lastIndex) { - throw new OutOfBoundsException(sprintf('The index "%d" is not in the range [0, %d].', $index, $lastIndex)); - } - - return $this->arguments[$index]; + return parent::getArgument($index); } /** @@ -91,8 +85,8 @@ public function getArgument($index) * certain conventions when you want to overwrite the arguments of the * parent definition, otherwise your arguments will only be appended. * - * @param int $index - * @param mixed $value + * @param int|string $index + * @param mixed $value * * @return self the current instance * @@ -105,7 +99,7 @@ public function replaceArgument($index, $value) } elseif (0 === strpos($index, '$')) { $this->arguments[$index] = $value; } else { - throw new InvalidArgumentException('$index must be an integer.'); + throw new InvalidArgumentException('The argument must be an existing index or the name of a constructor\'s parameter.'); } return $this; diff --git a/src/Symfony/Component/DependencyInjection/Tests/ChildDefinitionTest.php b/src/Symfony/Component/DependencyInjection/Tests/ChildDefinitionTest.php index a367a8b2c4d03..a941b960746be 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ChildDefinitionTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ChildDefinitionTest.php @@ -113,6 +113,10 @@ public function testReplaceArgument() $this->assertSame('baz', $def->getArgument(1)); $this->assertSame(array(0 => 'foo', 1 => 'bar', 'index_1' => 'baz'), $def->getArguments()); + + $this->assertSame($def, $def->replaceArgument('$bar', 'val')); + $this->assertSame('val', $def->getArgument('$bar')); + $this->assertSame(array(0 => 'foo', 1 => 'bar', 'index_1' => 'baz', '$bar' => 'val'), $def->getArguments()); } /** From f16a9dafeaacc897ea080a5a76d19c5a9b44232a Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 5 Jun 2017 10:31:48 -0700 Subject: [PATCH 56/57] updated CHANGELOG for 3.3.1 --- CHANGELOG-3.3.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/CHANGELOG-3.3.md b/CHANGELOG-3.3.md index 17b9ed1ed3073..8a6626da32d0f 100644 --- a/CHANGELOG-3.3.md +++ b/CHANGELOG-3.3.md @@ -7,6 +7,36 @@ in 3.3 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.3.0...v3.3.1 +* 3.3.1 (2017-06-05) + + * bug #23067 [HttpFoundation][FrameworkBundle] Revert "trusted proxies" BC break (nicolas-grekas) + * bug #23065 [Cache] Fallback to positional when keyed results are broken (nicolas-grekas) + * bug #22981 [DependencyInjection] Fix named args support in ChildDefinition (dunglas) + * bug #23050 [Form][Profiler] Fixes form collector triggering deprecations (ogizanagi) + * bug #22971 [Profiler] Fix code excerpt wrapping (ogizanagi) + * bug #23049 [FrameworkBundle] mitigate BC break with empty trusted_proxies (xabbuh) + * bug #23045 [Cache] fix Redis scheme detection (xabbuh) + * bug #23013 Parse the _controller format in sub-requests (weaverryan) + * bug #23015 [PhpUnitBridge] Fix detection of PHPUnit 5 (enumag) + * bug #23041 [Config] Always protected ClassExistenceResource against bad parents (nicolas-grekas) + * bug #22988 [PropertyInfo][DoctrineBridge] The bigint Doctrine's type must be converted to string (dunglas) + * bug #23014 Fix optional cache warmers are always instantiated whereas they should be lazy-loaded (romainneutron) + * feature #23022 [Di] Remove closure-proxy arguments (nicolas-grekas) + * bug #23024 [EventDispatcher] Fix ContainerAwareEventDispatcher::hasListeners(null) (nicolas-grekas) + * bug #23008 [EventDispatcher] Handle laziness internally instead of relying on ClosureProxyArgument (nicolas-grekas) + * bug #23018 [FrameworkBundle] Fix CacheCollectorPass priority (chalasr) + * bug #23009 [Routing] Allow GET requests to be redirected. Fixes #23004 (frankdejonge) + * bug #22996 [Form] Fix \IntlDateFormatter timezone parameter usage to bypass PHP bug #66323 (romainneutron) + * bug #22965 [Cache] Ignore missing annotations.php (ro0NL) + * bug #22993 [DI] Autowiring exception thrown when inlined service is removed (weaverryan) + * bug #22999 Better DI type deprecation message (weaverryan) + * bug #22985 [Config] Allow empty globs (nicolas-grekas) + * bug #22961 [HttpKernel] Support unknown format in LoggerDataCollector (iltar) + * bug #22991 [DI] Don't throw Autowire exception for removed service with private __construct (weaverryan) + * bug #22968 [Profiler] Fix text selection & click on file links on exception pages (ogizanagi) + * bug #22994 Harden the debugging of Twig filters and functions (stof) + * bug #22960 [Cache] Fix decoration of TagAware adapters in dev (chalasr) + * 3.3.0 (2017-05-29) * bug #22940 [Config] Fallback to regular import when glob fails (nicolas-grekas) From af5522ebf8c11352b0f5698992954db4b50ae510 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 5 Jun 2017 10:31:57 -0700 Subject: [PATCH 57/57] updated VERSION for 3.3.1 --- src/Symfony/Component/HttpKernel/Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index ec728417eec78..b9a95ac99dbe2 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -61,12 +61,12 @@ abstract class Kernel implements KernelInterface, TerminableInterface private $projectDir; - const VERSION = '3.3.1-DEV'; + const VERSION = '3.3.1'; const VERSION_ID = 30301; const MAJOR_VERSION = 3; const MINOR_VERSION = 3; const RELEASE_VERSION = 1; - const EXTRA_VERSION = 'DEV'; + const EXTRA_VERSION = ''; const END_OF_MAINTENANCE = '01/2018'; const END_OF_LIFE = '07/2018';