diff --git a/CHANGELOG-6.4.md b/CHANGELOG-6.4.md index 0640c9486abb1..dc52e3c7b4c0d 100644 --- a/CHANGELOG-6.4.md +++ b/CHANGELOG-6.4.md @@ -7,6 +7,23 @@ in 6.4 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/v6.4.0...v6.4.1 +* 6.4.20 (2025-03-28) + + * bug #60054 [Form] Use duplicate_preferred_choices to set value of ChoiceType (aleho) + * bug #59858 Update `JsDelivrEsmResolver::IMPORT_REGEX` to support dynamic imports (natepage) + * bug #60019 [HttpKernel] Fix `TraceableEventDispatcher` when the `Stopwatch` service has been reset (lyrixx) + * bug #59975 [HttpKernel] Only remove `E_WARNING` from error level during kernel init (fritzmg) + * bug #59988 [FrameworkBundle] Remove redundant `name` attribute from `default_context` (HypeMC) + * bug #59949 [Process] Use a pipe for stderr in pty mode to avoid mixed output between stdout and stderr (joelwurtz) + * bug #59940 [Cache] Fix missing cache data in profiler (dcmbrs) + * bug #59965 [VarExporter] Fix support for hooks and asymmetric visibility (nicolas-grekas) + * bug #59874 [Console] fix progress bar messing output in section when there is an EOL (joelwurtz) + * bug #59888 [PhpUnitBridge] don't trigger "internal" deprecations for PHPUnit Stub objects (xabbuh) + * bug #59830 [Yaml] drop comments while lexing unquoted strings (xabbuh) + * bug #59884 [VarExporter] Fix support for asymmetric visibility (nicolas-grekas) + * bug #59881 [VarExporter] Fix support for abstract properties (nicolas-grekas) + * bug #59841 [Cache] fix cache data collector on late collect (dcmbrs) + * 6.4.19 (2025-02-26) * bug #59198 [Messenger] Filter out non-consumable receivers when registering `ConsumeMessagesCommand` (wazum) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index f8902ba18f029..ffc3b6feae6fd 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -50,8 +50,8 @@ The Symfony Connect username in parenthesis allows to get more information - Benjamin Eberlei (beberlei) - Igor Wiedler - Jan Schädlich (jschaedl) - - Mathieu Lechat (mat_the_cat) - Mathias Arlaud (mtarld) + - Mathieu Lechat (mat_the_cat) - Simon André (simonandre) - Vincent Langlet (deviling) - Matthias Pigulla (mpdude) @@ -65,6 +65,7 @@ The Symfony Connect username in parenthesis allows to get more information - Dany Maillard (maidmaid) - Eriksen Costa - Diego Saint Esteben (dosten) + - Dariusz Ruminski - stealth35 ‏ (stealth35) - Alexander Mols (asm89) - Gábor Egyed (1ed) @@ -73,7 +74,6 @@ The Symfony Connect username in parenthesis allows to get more information - Titouan Galopin (tgalopin) - Pierre du Plessis (pierredup) - David Maicher (dmaicher) - - Dariusz Ruminski - Tomasz Kowalczyk (thunderer) - Bulat Shakirzyanov (avalanche123) - Iltar van der Berg @@ -97,11 +97,11 @@ The Symfony Connect username in parenthesis allows to get more information - David Buchmann (dbu) - Ruud Kamphuis (ruudk) - Andrej Hudec (pulzarraider) - - Jáchym Toušek (enumag) - Tomas Norkūnas (norkunas) + - Jáchym Toušek (enumag) + - Hubert Lenoir (hubert_lenoir) - Christian Raue - Eric Clemmons (ericclemmons) - - Hubert Lenoir (hubert_lenoir) - Denis (yethee) - Alex Pott - Michel Weimerskirch (mweimerskirch) @@ -117,10 +117,11 @@ The Symfony Connect username in parenthesis allows to get more information - Antoine Makdessi (amakdessi) - Ener-Getick - Graham Campbell (graham) + - Massimiliano Arione (garak) + - Joel Wurtz (brouznouf) - Tugdual Saunier (tucksaun) - Lee McDermott - Brandon Turner - - Massimiliano Arione (garak) - Luis Cordova (cordoval) - Phil E. Taylor (philetaylor) - Konstantin Myakshin (koc) @@ -131,11 +132,10 @@ The Symfony Connect username in parenthesis allows to get more information - Vasilij Dusko | CREATION - Jordan Alliot (jalliot) - Théo FIDRY - - Joel Wurtz (brouznouf) - John Wards (johnwards) + - Valtteri R (valtzu) - Yanick Witschi (toflar) - Antoine Hérault (herzult) - - Valtteri R (valtzu) - Konstantin.Myakshin - Jeroen Spee (jeroens) - Arnaud Le Blanc (arnaud-lb) @@ -165,6 +165,7 @@ The Symfony Connect username in parenthesis allows to get more information - Przemysław Bogusz (przemyslaw-bogusz) - Colin Frei - excelwebzone + - Florent Morselli (spomky_) - Paráda József (paradajozsef) - Maximilian Beckers (maxbeckers) - Baptiste Clavié (talus) @@ -194,7 +195,7 @@ The Symfony Connect username in parenthesis allows to get more information - Niels Keurentjes (curry684) - OGAWA Katsuhiro (fivestar) - Jhonny Lidfors (jhonne) - - Florent Morselli (spomky_) + - soyuka - Juti Noppornpitak (shiroyuki) - Gregor Harlan (gharlan) - Anthony MARTIN @@ -222,7 +223,6 @@ The Symfony Connect username in parenthesis allows to get more information - Jérôme Parmentier (lctrs) - Ahmed TAILOULOUTE (ahmedtai) - Simon Berger - - soyuka - Jérémy Derussé - Matthieu Napoli (mnapoli) - Bob van de Vijver (bobvandevijver) @@ -236,6 +236,7 @@ The Symfony Connect username in parenthesis allows to get more information - George Mponos (gmponos) - Richard Shank (iampersistent) - Roland Franssen :) + - Fritz Michael Gschwantner (fritzmg) - Romain Monteil (ker0x) - Sergey (upyx) - Marco Pivetta (ocramius) @@ -265,7 +266,6 @@ The Symfony Connect username in parenthesis allows to get more information - Artur Kotyrba - Wouter J - Tyson Andre - - Fritz Michael Gschwantner (fritzmg) - GDIBass - Samuel NELA (snela) - Baptiste Leduc (korbeil) @@ -308,11 +308,13 @@ The Symfony Connect username in parenthesis allows to get more information - Karoly Gossler (connorhu) - Timo Bakx (timobakx) - Giorgio Premi + - Alan Poulain (alanpoulain) - Ruben Gonzalez (rubenrua) - Benjamin Dulau (dbenjamin) - Markus Fasselt (digilist) - Denis Brumann (dbrumann) - mcfedr (mcfedr) + - Loick Piera (pyrech) - Remon van de Kamp - Mathieu Lemoine (lemoinem) - Christian Schmidt @@ -355,11 +357,11 @@ The Symfony Connect username in parenthesis allows to get more information - fd6130 (fdtvui) - Antonio J. García Lagar (ajgarlag) - Priyadi Iman Nurcahyo (priyadi) - - Alan Poulain (alanpoulain) - Oleg Andreyev (oleg.andreyev) - Maciej Malarz (malarzm) - Marcin Sikoń (marphi) - Michele Orselli (orso) + - Arjen van der Meijden - Sven Paulus (subsven) - Peter Kruithof (pkruithof) - Alex Hofbauer (alexhofbauer) @@ -372,7 +374,6 @@ The Symfony Connect username in parenthesis allows to get more information - Jérémie Augustin (jaugustin) - Edi Modrić (emodric) - Pascal Montoya - - Loick Piera (pyrech) - Julien Brochet - François Pluchino (francoispluchino) - Tristan Darricau (tristandsensio) @@ -406,7 +407,6 @@ The Symfony Connect username in parenthesis allows to get more information - Iker Ibarguren (ikerib) - Roman Ring (inori) - Xavier Montaña Carreras (xmontana) - - Arjen van der Meijden - Romaric Drigon (romaricdrigon) - Sylvain Fabre (sylfabre) - Xavier Perez @@ -480,6 +480,7 @@ The Symfony Connect username in parenthesis allows to get more information - Michael Hirschler (mvhirsch) - Michael Holm (hollo) - Robert Meijers + - roman joly (eltharin) - Blanchon Vincent (blanchonvincent) - Cédric Anne - Christian Schmidt @@ -565,6 +566,7 @@ The Symfony Connect username in parenthesis allows to get more information - Kai Dederichs - Pavel Kirpitsov (pavel-kirpichyov) - Artur Eshenbrener + - Issam Raouf (iraouf) - Harm van Tilborg (hvt) - Thomas Perez (scullwm) - Gwendolen Lynch @@ -589,7 +591,6 @@ The Symfony Connect username in parenthesis allows to get more information - hossein zolfi (ocean) - Alexander Menshchikov - Clément Gautier (clementgautier) - - roman joly (eltharin) - James Gilliland (neclimdul) - Sanpi (sanpi) - Eduardo Gulias (egulias) @@ -634,6 +635,7 @@ The Symfony Connect username in parenthesis allows to get more information - Ivan Sarastov (isarastov) - flack (flack) - Shein Alexey + - Pierre Ambroise (dotordu) - Joe Lencioni - Daniel Tschinder - Diego Agulló (aeoris) @@ -695,6 +697,7 @@ The Symfony Connect username in parenthesis allows to get more information - Neil Peyssard (nepey) - Niklas Fiekas - Mark Challoner (markchalloner) + - Vincent Chalamon - Andreas Hennings - Markus Bachmann (baachi) - Gunnstein Lye (glye) @@ -702,6 +705,7 @@ The Symfony Connect username in parenthesis allows to get more information - Yi-Jyun Pan - Sergey Melesh (sergex) - Greg Anderson + - Arnaud De Abreu (arnaud-deabreu) - lancergr - Benjamin Zaslavsky (tiriel) - Tri Pham (phamuyentri) @@ -758,6 +762,7 @@ The Symfony Connect username in parenthesis allows to get more information - Tristan Pouliquen - Miro Michalicka - Hans Mackowiak + - Dalibor Karlović - M. Vondano - Dominik Zogg - Maximilian Zumbansen @@ -855,10 +860,10 @@ The Symfony Connect username in parenthesis allows to get more information - Andrew Udvare (audvare) - siganushka (siganushka) - alexpods + - Quentin Schuler (sukei) - Adam Szaraniec - Dariusz Ruminski - Bahman Mehrdad (bahman) - - Pierre Ambroise (dotordu) - Romain Gautier (mykiwi) - Link1515 - Matthieu Bontemps @@ -998,12 +1003,12 @@ The Symfony Connect username in parenthesis allows to get more information - Alexandre Dupuy (satchette) - Michel Hunziker - Malte Blättermann - - Arnaud De Abreu (arnaud-deabreu) - Simeon Kolev (simeon_kolev9) - Joost van Driel (j92) - Jonas Elfering - Mihai Stancu - Nahuel Cuesta (ncuesta) + - Santiago San Martin - Chris Boden (cboden) - EStyles (insidestyles) - Christophe Villeger (seragan) @@ -1017,6 +1022,7 @@ The Symfony Connect username in parenthesis allows to get more information - Maxime Douailin - Jean Pasdeloup - Maxime COLIN (maximecolin) + - Loïc Ovigne (oviglo) - Lorenzo Millucci (lmillucci) - Javier López (loalf) - Reinier Kip @@ -1044,7 +1050,6 @@ The Symfony Connect username in parenthesis allows to get more information - Rodrigo Aguilera - Vladimir Varlamov (iamvar) - Aurimas Niekis (gcds) - - Vincent Chalamon - Matthieu Calie (matth--) - Sem Schidler (xvilo) - Benjamin Schoch (bschoch) @@ -1193,7 +1198,6 @@ The Symfony Connect username in parenthesis allows to get more information - Gert de Pagter - Julien DIDIER (juliendidier) - Ворожцов Максим (myks92) - - Dalibor Karlović - Randy Geraads - Kevin van Sonsbeek (kevin_van_sonsbeek) - Simo Heinonen (simoheinonen) @@ -1208,6 +1212,7 @@ The Symfony Connect username in parenthesis allows to get more information - Arun Philip - Pascal Helfenstein - Jesper Skytte (greew) + - NanoSector - Petar Obradović - Baldur Rensch (brensch) - Carl Casbolt (carlcasbolt) @@ -1225,7 +1230,6 @@ The Symfony Connect username in parenthesis allows to get more information - Travis Carden (traviscarden) - mfettig - Besnik Br - - Issam Raouf (iraouf) - Simon Mönch - Valmonzo - Sherin Bloemendaal @@ -1235,6 +1239,7 @@ The Symfony Connect username in parenthesis allows to get more information - aegypius - Ilia (aliance) - Christian Stoller (naitsirch) + - COMBROUSE Dimitri - Dave Marshall (davedevelopment) - Jakub Kulhan (jakubkulhan) - Paweł Niedzielski (steveb) @@ -1372,7 +1377,6 @@ The Symfony Connect username in parenthesis allows to get more information - Pierre Vanliefland (pvanliefland) - Roy Klutman (royklutman) - Sofiane HADDAG (sofhad) - - Quentin Schuler (sukei) - Antoine M - frost-nzcr4 - Shahriar56 @@ -1530,6 +1534,7 @@ The Symfony Connect username in parenthesis allows to get more information - Rootie - Sébastien Santoro (dereckson) - Daniel Alejandro Castro Arellano (lexcast) + - Jiří Bok - Vincent Chalamon - Farhad Hedayatifard - Alan ZARLI @@ -1602,6 +1607,7 @@ The Symfony Connect username in parenthesis allows to get more information - Chris Jones (leek) - neghmurken - stefan.r + - Florian Cellier - xaav - Jean-Christophe Cuvelier [Artack] - Mahmoud Mostafa (mahmoud) @@ -1717,6 +1723,7 @@ The Symfony Connect username in parenthesis allows to get more information - Abdiel Carrazana (abdielcs) - joris - Vadim Tyukov (vatson) + - alanzarli - Arman - Gabi Udrescu - Adamo Crespi (aerendir) @@ -1740,6 +1747,7 @@ The Symfony Connect username in parenthesis allows to get more information - Ondřej Frei - Bruno Rodrigues de Araujo (brunosinister) - Máximo Cuadros (mcuadros) + - Arkalo2 - Jacek Wilczyński (jacekwilczynski) - Christoph Kappestein - Camille Baronnet @@ -1906,6 +1914,7 @@ The Symfony Connect username in parenthesis allows to get more information - Kamil Musial - Lucas Bustamante - Olaf Klischat + - Andrii - orlovv - Claude Dioudonnat - Jonathan Hedstrom @@ -1944,6 +1953,7 @@ The Symfony Connect username in parenthesis allows to get more information - Bruno MATEU - Jeremy Bush - Lucas Bäuerle + - Steven RENAUX (steven_renaux) - Laurens Laman - Thomason, James - Dario Savella @@ -1977,7 +1987,6 @@ The Symfony Connect username in parenthesis allows to get more information - Oleg Sedinkin (akeylimepie) - Jérémy Jourdin (jjk801) - BRAMILLE Sébastien (oktapodia) - - Loïc Ovigne (oviglo) - Artem Kolesnikov (tyomo4ka) - Markkus Millend - Clément @@ -2000,6 +2009,7 @@ The Symfony Connect username in parenthesis allows to get more information - Barthold Bos - cthulhu - Andoni Larzabal (andonilarz) + - Wolfgang Klinger (wolfgangklingerplan2net) - Staormin - Dmitry Derepko - Rémi Leclerc @@ -2669,6 +2679,7 @@ The Symfony Connect username in parenthesis allows to get more information - Juraj Surman - Martin Eckhardt - natechicago + - DaikiOnodera - Victor - Andreas Allacher - Abdelilah Jabri @@ -2686,6 +2697,7 @@ The Symfony Connect username in parenthesis allows to get more information - Anton Sukhachev (mrsuh) - Pavlo Pelekh (pelekh) - Stefan Kleff (stefanxl) + - RichardGuilland - Marcel Siegert - ryunosuke - Bruno BOUTAREL @@ -2750,6 +2762,7 @@ The Symfony Connect username in parenthesis allows to get more information - Paul Seiffert (seiffert) - Vasily Khayrulin (sirian) - Stas Soroka (stasyan) + - Thomas Dubuffet (thomasdubuffet) - Stefan Hüsges (tronsha) - Jake Bishop (yakobeyak) - Dan Blows @@ -2850,12 +2863,13 @@ The Symfony Connect username in parenthesis allows to get more information - Bernhard Rusch - David Stone - Vincent Bouzeran + - fabi - Grayson Koonce - Ruben Jansen + - nathanpage - Wissame MEKHILEF - Mihai Stancu - shreypuranik - - NanoSector - Thibaut Salanon - Romain Dorgueil - Christopher Parotat @@ -2941,6 +2955,7 @@ The Symfony Connect username in parenthesis allows to get more information - Yasmany Cubela Medina (bitgandtter) - Michał Dąbrowski (defrag) - Aryel Tupinamba (dfkimera) + - Elías (eliasfernandez) - Hans Höchtl (hhoechtl) - Simone Fumagalli (hpatoio) - Brian Graham (incognito) @@ -3182,6 +3197,7 @@ The Symfony Connect username in parenthesis allows to get more information - Buster Neece - Albert Prat - Alessandro Loffredo + - Tim Düsterhus - Ian Phillips - Carlos Tasada - Remi Collet @@ -3273,6 +3289,7 @@ The Symfony Connect username in parenthesis allows to get more information - Rosio (ben-rosio) - Simon Paarlberg (blamh) - Masao Maeda (brtriver) + - Alexander Dmitryuk (coden1) - Valery Maslov (coderberg) - Damien Harper (damien.harper) - Darius Leskauskas (darles) @@ -3648,6 +3665,7 @@ The Symfony Connect username in parenthesis allows to get more information - jwaguet - Diego Campoy - Oncle Tom + - Roland Franssen :) - Sam Anthony - Christian Stocker - Oussama Elgoumri @@ -3674,6 +3692,7 @@ The Symfony Connect username in parenthesis allows to get more information - Sean Templeton - Willem Mouwen - db306 + - Bohdan Pliachenko - Dr. Gianluigi "Zane" Zanettini - Michaël VEROUX - Julia @@ -3860,6 +3879,7 @@ The Symfony Connect username in parenthesis allows to get more information - Dionysis Arvanitis - Sergey Fedotov - Konstantin Scheumann + - Josef Hlavatý - Michael - fh-github@fholzhauer.de - rogamoore diff --git a/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php b/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php index efb28dbdff66c..4d2fb4472655b 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php @@ -16,6 +16,7 @@ use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadataInfo; +use Doctrine\ORM\Mapping\PropertyAccessors\RawValuePropertyAccessor; use Doctrine\ORM\Tools\SchemaTool; use Doctrine\Persistence\ManagerRegistry; use Doctrine\Persistence\ObjectManager; @@ -115,11 +116,21 @@ class_exists(ClassMetadataInfo::class) ? ClassMetadataInfo::class : ClassMetadat ->willReturn(true) ; $refl = $this->createMock(\ReflectionProperty::class); + $refl + ->method('getName') + ->willReturn('name') + ; $refl ->method('getValue') ->willReturn(true) ; - $classMetadata->reflFields = ['name' => $refl]; + + if (property_exists(ClassMetadata::class, 'propertyAccessors')) { + $classMetadata->propertyAccessors['name'] = RawValuePropertyAccessor::fromReflectionProperty($refl); + } else { + $classMetadata->reflFields = ['name' => $refl]; + } + $em->expects($this->any()) ->method('getClassMetadata') ->willReturn($classMetadata) diff --git a/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php b/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php index b356f8068c15d..8089f820af124 100644 --- a/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php +++ b/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php @@ -11,6 +11,7 @@ namespace Symfony\Bridge\Doctrine\Validator\Constraints; +use Doctrine\ORM\Mapping\ClassMetadata as OrmClassMetadata; use Doctrine\Persistence\ManagerRegistry; use Doctrine\Persistence\Mapping\ClassMetadata; use Doctrine\Persistence\ObjectManager; @@ -92,7 +93,11 @@ public function validate(mixed $entity, Constraint $constraint) throw new ConstraintDefinitionException(sprintf('The field "%s" is not mapped by Doctrine, so it cannot be validated for uniqueness.', $fieldName)); } - $fieldValue = $class->reflFields[$fieldName]->getValue($entity); + if (property_exists(OrmClassMetadata::class, 'propertyAccessors')) { + $fieldValue = $class->propertyAccessors[$fieldName]->getValue($entity); + } else { + $fieldValue = $class->reflFields[$fieldName]->getValue($entity); + } if (null === $fieldValue && $this->ignoreNullForField($constraint, $fieldName)) { $hasIgnorableNullValue = true; diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig index 02628b5a14446..d43b40a0764e2 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig @@ -85,7 +85,7 @@ {{- block('choice_widget_options') -}} {%- else -%} - + {%- endif -%} {% endfor %} {%- endblock choice_widget_options -%} diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/AbstractDivLayoutTestCase.php b/src/Symfony/Bridge/Twig/Tests/Extension/AbstractDivLayoutTestCase.php index a02fca4bc54ca..bfbd458e97b3f 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/AbstractDivLayoutTestCase.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/AbstractDivLayoutTestCase.php @@ -856,6 +856,56 @@ public function testMultipleChoiceExpandedWithLabelsSetFalseByCallable() ); } + public function testSingleChoiceWithoutDuplicatePreferredIsSelected() + { + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&d', [ + 'choices' => ['Choice&A' => '&a', 'Choice&B' => '&b', 'Choice&C' => '&c', 'Choice&D' => '&d'], + 'preferred_choices' => ['&b', '&d'], + 'duplicate_preferred_choices' => false, + 'multiple' => false, + 'expanded' => false, + ]); + + $this->assertWidgetMatchesXpath($form->createView(), ['separator' => '-- sep --'], + '/select + [@name="name"] + [ + ./option[@value="&d"][@selected="selected"] + /following-sibling::option[@disabled="disabled"][.="-- sep --"] + /following-sibling::option[@value="&a"][not(@selected)] + /following-sibling::option[@value="&c"][not(@selected)] + ] + [count(./option)=5] +' + ); + } + + public function testSingleChoiceWithoutDuplicateNotPreferredIsSelected() + { + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&d', [ + 'choices' => ['Choice&A' => '&a', 'Choice&B' => '&b', 'Choice&C' => '&c', 'Choice&D' => '&d'], + 'preferred_choices' => ['&b', '&d'], + 'duplicate_preferred_choices' => true, + 'multiple' => false, + 'expanded' => false, + ]); + + $this->assertWidgetMatchesXpath($form->createView(), ['separator' => '-- sep --'], + '/select + [@name="name"] + [ + ./option[@value="&d"][not(@selected)] + /following-sibling::option[@disabled="disabled"][.="-- sep --"] + /following-sibling::option[@value="&a"][not(@selected)] + /following-sibling::option[@value="&b"][not(@selected)] + /following-sibling::option[@value="&c"][not(@selected)] + /following-sibling::option[@value="&d"][@selected="selected"] + ] + [count(./option)=7] +' + ); + } + public function testFormEndWithRest() { $view = $this->factory->createNamedBuilder('name', 'Symfony\Component\Form\Extension\Core\Type\FormType') diff --git a/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TwigNodeProvider.php b/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TwigNodeProvider.php index 69cf6beca0c44..4fc96d8af5fb5 100644 --- a/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TwigNodeProvider.php +++ b/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TwigNodeProvider.php @@ -15,6 +15,7 @@ use Symfony\Bridge\Twig\Node\TransNode; use Twig\Attribute\FirstClassTwigCallableReady; use Twig\Node\BodyNode; +use Twig\Node\EmptyNode; use Twig\Node\Expression\ArrayExpression; use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\FilterExpression; @@ -28,13 +29,15 @@ class TwigNodeProvider { public static function getModule($content) { + $emptyNodeExists = class_exists(EmptyNode::class); + return new ModuleNode( new BodyNode([new ConstantExpression($content, 0)]), null, - new ArrayExpression([], 0), - new ArrayExpression([], 0), - new ArrayExpression([], 0), - null, + $emptyNodeExists ? new EmptyNode() : new ArrayExpression([], 0), + $emptyNodeExists ? new EmptyNode() : new ArrayExpression([], 0), + $emptyNodeExists ? new EmptyNode() : new ArrayExpression([], 0), + $emptyNodeExists ? new EmptyNode() : null, new Source('', '') ); } diff --git a/src/Symfony/Bridge/Twig/composer.json b/src/Symfony/Bridge/Twig/composer.json index 2b7a6a3993357..f663de11da0b9 100644 --- a/src/Symfony/Bridge/Twig/composer.json +++ b/src/Symfony/Bridge/Twig/composer.json @@ -29,7 +29,7 @@ "symfony/asset-mapper": "^6.3|^7.0", "symfony/dependency-injection": "^5.4|^6.0|^7.0", "symfony/finder": "^5.4|^6.0|^7.0", - "symfony/form": "^6.4|^7.0", + "symfony/form": "^6.4.20|^7.2.5", "symfony/html-sanitizer": "^6.1|^7.0", "symfony/http-foundation": "^5.4|^6.0|^7.0", "symfony/http-kernel": "^6.4|^7.0", diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 1939337bb0e24..cb52a0704fd99 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -1196,7 +1196,6 @@ private function addSerializerSection(ArrayNodeDefinition $rootNode, callable $e ->end() ->arrayNode('default_context') ->normalizeKeys(false) - ->useAttributeAsKey('name') ->validate() ->ifTrue(fn () => $this->debug && class_exists(JsonParser::class)) ->then(fn (array $v) => $v + [JsonDecode::DETAILED_ERROR_MESSAGES => true]) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 1c57253353630..f585b5bbb784b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -2004,24 +2004,22 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder $container->setParameter('serializer.default_context', $defaultContext); } - if (!$container->hasDefinition('serializer.normalizer.object')) { - return; - } + if ($container->hasDefinition('serializer.normalizer.object')) { + $arguments = $container->getDefinition('serializer.normalizer.object')->getArguments(); + $context = $arguments[6] ?? $defaultContext; - $arguments = $container->getDefinition('serializer.normalizer.object')->getArguments(); - $context = $arguments[6] ?? $defaultContext; + if (isset($config['circular_reference_handler']) && $config['circular_reference_handler']) { + $context += ['circular_reference_handler' => new Reference($config['circular_reference_handler'])]; + $container->getDefinition('serializer.normalizer.object')->setArgument(5, null); + } - if (isset($config['circular_reference_handler']) && $config['circular_reference_handler']) { - $context += ['circular_reference_handler' => new Reference($config['circular_reference_handler'])]; - $container->getDefinition('serializer.normalizer.object')->setArgument(5, null); - } + if ($config['max_depth_handler'] ?? false) { + $context += ['max_depth_handler' => new Reference($config['max_depth_handler'])]; + } - if ($config['max_depth_handler'] ?? false) { - $context += ['max_depth_handler' => new Reference($config['max_depth_handler'])]; + $container->getDefinition('serializer.normalizer.object')->setArgument(6, $context); } - $container->getDefinition('serializer.normalizer.object')->setArgument(6, $context); - $container->getDefinition('serializer.normalizer.property')->setArgument(5, $defaultContext); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Test/HttpClientAssertionsTrait.php b/src/Symfony/Bundle/FrameworkBundle/Test/HttpClientAssertionsTrait.php index 20c64608e9dde..01a27ea87e5ac 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Test/HttpClientAssertionsTrait.php +++ b/src/Symfony/Bundle/FrameworkBundle/Test/HttpClientAssertionsTrait.php @@ -14,10 +14,9 @@ use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Component\HttpClient\DataCollector\HttpClientDataCollector; -/* +/** * @author Mathieu Santostefano */ - trait HttpClientAssertionsTrait { public static function assertHttpClientRequest(string $expectedUrl, string $expectedMethod = 'GET', string|array|null $expectedBody = null, array $expectedHeaders = [], string $httpClientId = 'http_client'): void diff --git a/src/Symfony/Bundle/FrameworkBundle/Test/NotificationAssertionsTrait.php b/src/Symfony/Bundle/FrameworkBundle/Test/NotificationAssertionsTrait.php index b68473561eb4d..2c4c5467d4ebd 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Test/NotificationAssertionsTrait.php +++ b/src/Symfony/Bundle/FrameworkBundle/Test/NotificationAssertionsTrait.php @@ -17,7 +17,7 @@ use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Test\Constraint as NotifierConstraint; -/* +/** * @author Smaïne Milianni */ trait NotificationAssertionsTrait diff --git a/src/Symfony/Component/AssetMapper/ImportMap/Resolver/JsDelivrEsmResolver.php b/src/Symfony/Component/AssetMapper/ImportMap/Resolver/JsDelivrEsmResolver.php index 93338a1b63201..1da5a394b799a 100644 --- a/src/Symfony/Component/AssetMapper/ImportMap/Resolver/JsDelivrEsmResolver.php +++ b/src/Symfony/Component/AssetMapper/ImportMap/Resolver/JsDelivrEsmResolver.php @@ -28,7 +28,7 @@ final class JsDelivrEsmResolver implements PackageResolverInterface public const URL_PATTERN_DIST = self::URL_PATTERN_DIST_CSS.'/+esm'; public const URL_PATTERN_ENTRYPOINT = 'https://data.jsdelivr.com/v1/packages/npm/%s@%s/entrypoints'; - public const IMPORT_REGEX = '#(?:import\s*(?:[\w$]+,)?(?:(?:\{[^}]*\}|[\w$]+|\*\s*as\s+[\w$]+)\s*\bfrom\s*)?|export\s*(?:\{[^}]*\}|\*)\s*from\s*)("/npm/((?:@[^/]+/)?[^@]+?)(?:@([^/]+))?((?:/[^/]+)*?)/\+esm")#'; + public const IMPORT_REGEX = '#(?:import\s*(?:[\w$]+,)?(?:(?:\{[^}]*\}|[\w$]+|\*\s*as\s+[\w$]+)\s*\bfrom\s*)?|export\s*(?:\{[^}]*\}|\*)\s*from\s*|await\simport\()("/npm/((?:@[^/]+/)?[^@]+?)(?:@([^/]+))?((?:/[^/]+)*?)/\+esm")(?:\)*)#'; private const ES_MODULE_SHIMS = 'es-module-shims'; diff --git a/src/Symfony/Component/AssetMapper/Tests/ImportMap/Resolver/JsDelivrEsmResolverTest.php b/src/Symfony/Component/AssetMapper/Tests/ImportMap/Resolver/JsDelivrEsmResolverTest.php index 8b7d82c8c6f06..d9650fd7c29d3 100644 --- a/src/Symfony/Component/AssetMapper/Tests/ImportMap/Resolver/JsDelivrEsmResolverTest.php +++ b/src/Symfony/Component/AssetMapper/Tests/ImportMap/Resolver/JsDelivrEsmResolverTest.php @@ -693,6 +693,13 @@ public static function provideImportRegex(): iterable ['jquery', '3.7.0'], ], ]; + + yield 'dynamic import with path' => [ + 'return(await import("/npm/@datadog/browser-rum@6.3.0/esm/boot/startRecording.js/+esm")).startRecording', + [ + ['@datadog/browser-rum/esm/boot/startRecording.js', '6.3.0'], + ], + ]; } private static function createRemoteEntry(string $importName, string $version, ImportMapType $type = ImportMapType::JS, ?string $packageSpecifier = null): ImportMapEntry diff --git a/src/Symfony/Component/Cache/DataCollector/CacheDataCollector.php b/src/Symfony/Component/Cache/DataCollector/CacheDataCollector.php index b9bcdaf132572..22a5a0391673f 100644 --- a/src/Symfony/Component/Cache/DataCollector/CacheDataCollector.php +++ b/src/Symfony/Component/Cache/DataCollector/CacheDataCollector.php @@ -38,15 +38,7 @@ public function addInstance(string $name, TraceableAdapter $instance): void public function collect(Request $request, Response $response, ?\Throwable $exception = null): void { - $empty = ['calls' => [], 'adapters' => [], 'config' => [], 'options' => [], 'statistics' => []]; - $this->data = ['instances' => $empty, 'total' => $empty]; - foreach ($this->instances as $name => $instance) { - $this->data['instances']['calls'][$name] = $instance->getCalls(); - $this->data['instances']['adapters'][$name] = get_debug_type($instance->getPool()); - } - - $this->data['instances']['statistics'] = $this->calculateStatistics(); - $this->data['total']['statistics'] = $this->calculateTotalStatistics(); + $this->lateCollect(); } public function reset(): void @@ -59,6 +51,15 @@ public function reset(): void public function lateCollect(): void { + $empty = ['calls' => [], 'adapters' => [], 'config' => [], 'options' => [], 'statistics' => []]; + $this->data = ['instances' => $empty, 'total' => $empty]; + foreach ($this->instances as $name => $instance) { + $this->data['instances']['calls'][$name] = $instance->getCalls(); + $this->data['instances']['adapters'][$name] = get_debug_type($instance->getPool()); + } + + $this->data['instances']['statistics'] = $this->calculateStatistics(); + $this->data['total']['statistics'] = $this->calculateTotalStatistics(); $this->data['instances']['calls'] = $this->cloneVar($this->data['instances']['calls']); } diff --git a/src/Symfony/Component/Cache/Tests/DataCollector/CacheDataCollectorTest.php b/src/Symfony/Component/Cache/Tests/DataCollector/CacheDataCollectorTest.php index a00954b6cb828..7a2f36abb4df3 100644 --- a/src/Symfony/Component/Cache/Tests/DataCollector/CacheDataCollectorTest.php +++ b/src/Symfony/Component/Cache/Tests/DataCollector/CacheDataCollectorTest.php @@ -17,6 +17,7 @@ use Symfony\Component\Cache\DataCollector\CacheDataCollector; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\VarDumper\Cloner\Data; class CacheDataCollectorTest extends TestCase { @@ -104,6 +105,27 @@ public function testCollectBeforeEnd() $this->assertEquals($stats[self::INSTANCE_NAME]['misses'], 1, 'misses'); } + public function testLateCollect() + { + $adapter = new TraceableAdapter(new NullAdapter()); + + $collector = new CacheDataCollector(); + $collector->addInstance(self::INSTANCE_NAME, $adapter); + + $adapter->get('foo', function () use ($collector) { + $collector->lateCollect(); + + return 123; + }); + + $stats = $collector->getStatistics(); + $this->assertGreaterThan(0, $stats[self::INSTANCE_NAME]['time']); + $this->assertEquals($stats[self::INSTANCE_NAME]['hits'], 0, 'hits'); + $this->assertEquals($stats[self::INSTANCE_NAME]['misses'], 1, 'misses'); + $this->assertEquals($stats[self::INSTANCE_NAME]['calls'], 1, 'calls'); + $this->assertInstanceOf(Data::class, $collector->getCalls()); + } + private function getCacheDataCollectorStatisticsFromEvents(array $traceableAdapterEvents) { $traceableAdapterMock = $this->createMock(TraceableAdapter::class); diff --git a/src/Symfony/Component/Console/Helper/ProgressBar.php b/src/Symfony/Component/Console/Helper/ProgressBar.php index 23157e3c7b2db..3dc06d7b483a8 100644 --- a/src/Symfony/Component/Console/Helper/ProgressBar.php +++ b/src/Symfony/Component/Console/Helper/ProgressBar.php @@ -486,12 +486,21 @@ private function overwrite(string $message): void if ($this->output instanceof ConsoleSectionOutput) { $messageLines = explode("\n", $this->previousMessage); $lineCount = \count($messageLines); + + $lastLineWithoutDecoration = Helper::removeDecoration($this->output->getFormatter(), end($messageLines) ?? ''); + + // When the last previous line is empty (without formatting) it is already cleared by the section output, so we don't need to clear it again + if ('' === $lastLineWithoutDecoration) { + --$lineCount; + } + foreach ($messageLines as $messageLine) { $messageLineLength = Helper::width(Helper::removeDecoration($this->output->getFormatter(), $messageLine)); if ($messageLineLength > $this->terminal->getWidth()) { $lineCount += floor($messageLineLength / $this->terminal->getWidth()); } } + $this->output->clear($lineCount); } else { $lineCount = substr_count($this->previousMessage, "\n"); diff --git a/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php b/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php index a1db94583db49..615237f1f5a45 100644 --- a/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php @@ -416,6 +416,81 @@ public function testOverwriteWithSectionOutput() ); } + public function testOverwriteWithSectionOutputAndEol() + { + $sections = []; + $stream = $this->getOutputStream(true); + $output = new ConsoleSectionOutput($stream->getStream(), $sections, $stream->getVerbosity(), $stream->isDecorated(), new OutputFormatter()); + + $bar = new ProgressBar($output, 50, 0); + $bar->setFormat('[%bar%] %percent:3s%%' . PHP_EOL . '%message%' . PHP_EOL); + $bar->setMessage(''); + $bar->start(); + $bar->display(); + $bar->setMessage('Doing something...'); + $bar->advance(); + $bar->setMessage('Doing something foo...'); + $bar->advance(); + + rewind($output->getStream()); + $this->assertEquals(escapeshellcmd( + '[>---------------------------] 0%'.\PHP_EOL.\PHP_EOL. + "\x1b[2A\x1b[0J".'[>---------------------------] 2%'.\PHP_EOL. 'Doing something...' . \PHP_EOL . + "\x1b[2A\x1b[0J".'[=>--------------------------] 4%'.\PHP_EOL. 'Doing something foo...' . \PHP_EOL), + escapeshellcmd(stream_get_contents($output->getStream())) + ); + } + + public function testOverwriteWithSectionOutputAndEolWithEmptyMessage() + { + $sections = []; + $stream = $this->getOutputStream(true); + $output = new ConsoleSectionOutput($stream->getStream(), $sections, $stream->getVerbosity(), $stream->isDecorated(), new OutputFormatter()); + + $bar = new ProgressBar($output, 50, 0); + $bar->setFormat('[%bar%] %percent:3s%%' . PHP_EOL . '%message%'); + $bar->setMessage('Start'); + $bar->start(); + $bar->display(); + $bar->setMessage(''); + $bar->advance(); + $bar->setMessage('Doing something...'); + $bar->advance(); + + rewind($output->getStream()); + $this->assertEquals(escapeshellcmd( + '[>---------------------------] 0%'.\PHP_EOL.'Start'.\PHP_EOL. + "\x1b[2A\x1b[0J".'[>---------------------------] 2%'.\PHP_EOL . + "\x1b[1A\x1b[0J".'[=>--------------------------] 4%'.\PHP_EOL. 'Doing something...' . \PHP_EOL), + escapeshellcmd(stream_get_contents($output->getStream())) + ); + } + + public function testOverwriteWithSectionOutputAndEolWithEmptyMessageComment() + { + $sections = []; + $stream = $this->getOutputStream(true); + $output = new ConsoleSectionOutput($stream->getStream(), $sections, $stream->getVerbosity(), $stream->isDecorated(), new OutputFormatter()); + + $bar = new ProgressBar($output, 50, 0); + $bar->setFormat('[%bar%] %percent:3s%%' . PHP_EOL . '%message%'); + $bar->setMessage('Start'); + $bar->start(); + $bar->display(); + $bar->setMessage(''); + $bar->advance(); + $bar->setMessage('Doing something...'); + $bar->advance(); + + rewind($output->getStream()); + $this->assertEquals(escapeshellcmd( + '[>---------------------------] 0%'.\PHP_EOL."\x1b[33mStart\x1b[39m".\PHP_EOL. + "\x1b[2A\x1b[0J".'[>---------------------------] 2%'.\PHP_EOL . + "\x1b[1A\x1b[0J".'[=>--------------------------] 4%'.\PHP_EOL. "\x1b[33mDoing something...\x1b[39m" . \PHP_EOL), + escapeshellcmd(stream_get_contents($output->getStream())) + ); + } + public function testOverwriteWithAnsiSectionOutput() { // output has 43 visible characters plus 2 invisible ANSI characters diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_wither_lazy.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_wither_lazy.php index d5c3738a62a0b..81dd1a0b9c9cb 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_wither_lazy.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_wither_lazy.php @@ -76,7 +76,7 @@ class WitherProxy580fe0f extends \Symfony\Component\DependencyInjection\Tests\Co use \Symfony\Component\VarExporter\LazyProxyTrait; private const LAZY_OBJECT_PROPERTY_SCOPES = [ - 'foo' => [parent::class, 'foo', null], + 'foo' => [parent::class, 'foo', null, 4], ]; } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_wither_lazy_non_shared.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_wither_lazy_non_shared.php index 0867347a6f845..8952ebd6d8ac9 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_wither_lazy_non_shared.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_wither_lazy_non_shared.php @@ -78,7 +78,7 @@ class WitherProxyDd381be extends \Symfony\Component\DependencyInjection\Tests\Co use \Symfony\Component\VarExporter\LazyProxyTrait; private const LAZY_OBJECT_PROPERTY_SCOPES = [ - 'foo' => [parent::class, 'foo', null], + 'foo' => [parent::class, 'foo', null, 4], ]; } diff --git a/src/Symfony/Component/DependencyInjection/composer.json b/src/Symfony/Component/DependencyInjection/composer.json index dc4a9feaf8556..86b05b91727d2 100644 --- a/src/Symfony/Component/DependencyInjection/composer.json +++ b/src/Symfony/Component/DependencyInjection/composer.json @@ -20,7 +20,7 @@ "psr/container": "^1.1|^2.0", "symfony/deprecation-contracts": "^2.5|^3", "symfony/service-contracts": "^2.5|^3.0", - "symfony/var-exporter": "^6.2.10|^7.0" + "symfony/var-exporter": "^6.4.20|^7.2.5" }, "require-dev": { "symfony/yaml": "^5.4|^6.0|^7.0", diff --git a/src/Symfony/Component/ErrorHandler/DebugClassLoader.php b/src/Symfony/Component/ErrorHandler/DebugClassLoader.php index b6ad33a632dd3..3f2a136247b4a 100644 --- a/src/Symfony/Component/ErrorHandler/DebugClassLoader.php +++ b/src/Symfony/Component/ErrorHandler/DebugClassLoader.php @@ -18,6 +18,7 @@ use Phake\IMock; use PHPUnit\Framework\MockObject\Matcher\StatelessInvocation; use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use Prophecy\Prophecy\ProphecySubjectInterface; use ProxyManager\Proxy\ProxyInterface; use Symfony\Component\DependencyInjection\Argument\LazyClosure; @@ -253,6 +254,7 @@ public static function checkClasses(): bool for (; $i < \count($symbols); ++$i) { if (!is_subclass_of($symbols[$i], MockObject::class) + && !is_subclass_of($symbols[$i], Stub::class) && !is_subclass_of($symbols[$i], ProphecySubjectInterface::class) && !is_subclass_of($symbols[$i], Proxy::class) && !is_subclass_of($symbols[$i], ProxyInterface::class) diff --git a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php index 35dcf1b1b9659..32bc67766732b 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php @@ -281,6 +281,8 @@ public function buildView(FormView $view, FormInterface $form, array $options) */ public function finishView(FormView $view, FormInterface $form, array $options) { + $view->vars['duplicate_preferred_choices'] = $options['duplicate_preferred_choices']; + if ($options['expanded']) { // Radio buttons should have the same name as the parent $childName = $view->vars['full_name']; diff --git a/src/Symfony/Component/Form/Resources/translations/validators.es.xlf b/src/Symfony/Component/Form/Resources/translations/validators.es.xlf index 301e2b33f7ed3..a9989737c33eb 100644 --- a/src/Symfony/Component/Form/Resources/translations/validators.es.xlf +++ b/src/Symfony/Component/Form/Resources/translations/validators.es.xlf @@ -52,7 +52,7 @@ Please enter a valid date. - Por favor, ingrese una fecha valida. + Por favor, ingrese una fecha válida. Please select a valid file. diff --git a/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php b/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php index d31ce75816cf2..f3101d5b14f19 100644 --- a/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php +++ b/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php @@ -66,7 +66,11 @@ protected function afterDispatch(string $eventName, object $event): void if (null === $sectionId) { break; } - $this->stopwatch->stopSection($sectionId); + try { + $this->stopwatch->stopSection($sectionId); + } catch (\LogicException) { + // The stop watch service might have been reset in the meantime + } break; case KernelEvents::TERMINATE: // In the special case described in the `preDispatch` method above, the `$token` section diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 087a393071a9d..49f3b698acc66 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -76,11 +76,11 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl */ private static array $freshCache = []; - public const VERSION = '6.4.19'; - public const VERSION_ID = 60419; + public const VERSION = '6.4.20'; + public const VERSION_ID = 60420; public const MAJOR_VERSION = 6; public const MINOR_VERSION = 4; - public const RELEASE_VERSION = 19; + public const RELEASE_VERSION = 20; public const EXTRA_VERSION = ''; public const END_OF_MAINTENANCE = '11/2026'; @@ -407,7 +407,8 @@ protected function initializeContainer() $cachePath = $cache->getPath(); // Silence E_WARNING to ignore "include" failures - don't use "@" to prevent silencing fatal errors - $errorLevel = error_reporting(\E_ALL ^ \E_WARNING); + $errorLevel = error_reporting(); + error_reporting($errorLevel & ~\E_WARNING); try { if (is_file($cachePath) && \is_object($this->container = include $cachePath) diff --git a/src/Symfony/Component/Process/Pipes/UnixPipes.php b/src/Symfony/Component/Process/Pipes/UnixPipes.php index 7bd0db0e94b45..a0e48dd3634c1 100644 --- a/src/Symfony/Component/Process/Pipes/UnixPipes.php +++ b/src/Symfony/Component/Process/Pipes/UnixPipes.php @@ -74,7 +74,7 @@ public function getDescriptors(): array return [ ['pty'], ['pty'], - ['pty'], + ['pipe', 'w'], // stderr needs to be in a pipe to correctly split error and output, since PHP will use the same stream for both ]; } diff --git a/src/Symfony/Component/Process/Tests/ProcessTest.php b/src/Symfony/Component/Process/Tests/ProcessTest.php index 0f302c2aabd3c..e9c7527c42c89 100644 --- a/src/Symfony/Component/Process/Tests/ProcessTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessTest.php @@ -540,6 +540,20 @@ public function testExitCodeTextIsNullWhenExitCodeIsNull() $this->assertNull($process->getExitCodeText()); } + public function testStderrNotMixedWithStdout() + { + if (!Process::isPtySupported()) { + $this->markTestSkipped('PTY is not supported on this operating system.'); + } + + $process = $this->getProcess('echo "foo" && echo "bar" >&2'); + $process->setPty(true); + $process->run(); + + $this->assertSame("foo\r\n", $process->getOutput()); + $this->assertSame("bar\n", $process->getErrorOutput()); + } + public function testPTYCommand() { if (!Process::isPtySupported()) { diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.ja.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.ja.xlf index c4b36fd45f7f0..f6d2e0c28a33e 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.ja.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.ja.xlf @@ -444,31 +444,31 @@ This value is too short. It should contain at least one word.|This value is too short. It should contain at least {{ min }} words. - この値は短すぎます。少なくとも 1 つの単語を含める必要があります。|この値は短すぎます。少なくとも {{ min }} 個の単語を含める必要があります。 + この値は短すぎます。{{ min }}単語以上にする必要があります。 This value is too long. It should contain one word.|This value is too long. It should contain {{ max }} words or less. - この値は長すぎます。1 つの単語のみを含める必要があります。|この値は長すぎます。{{ max }} 個以下の単語を含める必要があります。 + この値は長すぎます。{{ max }}単語以下にする必要があります。 This value does not represent a valid week in the ISO 8601 format. - この値は ISO 8601 形式の有効な週を表していません。 + この値は ISO 8601 形式の有効な週を表していません。 This value is not a valid week. - この値は有効な週ではありません。 + この値は有効な週ではありません。 This value should not be before week "{{ min }}". - この値は週 "{{ min }}" より前であってはなりません。 + この値は週 "{{ min }}" より前であってはいけません。 This value should not be after week "{{ max }}". - この値は週 "{{ max }}" 以降であってはなりません。 + この値は週 "{{ max }}" 以降であってはいけません。 This value is not a valid slug. - この値は有効なスラグではありません。 + この値は有効なスラグではありません。 diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.uk.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.uk.xlf index f83a179b1c37a..50d503e2455e7 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.uk.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.uk.xlf @@ -180,7 +180,7 @@ This value should have exactly {{ limit }} character.|This value should have exactly {{ limit }} characters. - Значення повиино бути рівним {{ limit }} символу.|Значення повиино бути рівним {{ limit }} символам.|Значення повиино бути рівним {{ limit }} символам. + Значення повинно бути рівним {{ limit }} символу.|Значення повинно бути рівним {{ limit }} символам.|Значення повинно бути рівним {{ limit }} символам. The file was only partially uploaded. diff --git a/src/Symfony/Component/VarExporter/Hydrator.php b/src/Symfony/Component/VarExporter/Hydrator.php index 5f456fb3cf7e7..b718921d9f892 100644 --- a/src/Symfony/Component/VarExporter/Hydrator.php +++ b/src/Symfony/Component/VarExporter/Hydrator.php @@ -61,8 +61,8 @@ public static function hydrate(object $instance, array $properties = [], array $ $propertyScopes = InternalHydrator::$propertyScopes[$class] ??= InternalHydrator::getPropertyScopes($class); foreach ($properties as $name => &$value) { - [$scope, $name, $readonlyScope] = $propertyScopes[$name] ?? [$class, $name, $class]; - $scopedProperties[$readonlyScope ?? $scope][$name] = &$value; + [$scope, $name, $writeScope] = $propertyScopes[$name] ?? [$class, $name, $class]; + $scopedProperties[$writeScope ?? $scope][$name] = &$value; } unset($value); } diff --git a/src/Symfony/Component/VarExporter/Internal/Exporter.php b/src/Symfony/Component/VarExporter/Internal/Exporter.php index ec711e1ed096b..21e3f5816e9de 100644 --- a/src/Symfony/Component/VarExporter/Internal/Exporter.php +++ b/src/Symfony/Component/VarExporter/Internal/Exporter.php @@ -90,7 +90,8 @@ public static function prepare($values, $objectsPool, &$refsPool, &$objectsCount $properties = $serializeProperties; } else { foreach ($serializeProperties as $n => $v) { - $c = $reflector->hasProperty($n) && ($p = $reflector->getProperty($n))->isReadOnly() ? $p->class : 'stdClass'; + $p = $reflector->hasProperty($n) ? $reflector->getProperty($n) : null; + $c = $p && (\PHP_VERSION_ID >= 80400 ? $p->isProtectedSet() || $p->isPrivateSet() : $p->isReadOnly()) ? $p->class : 'stdClass'; $properties[$c][$n] = $v; } } @@ -144,7 +145,8 @@ public static function prepare($values, $objectsPool, &$refsPool, &$objectsCount $i = 0; $n = (string) $name; if ('' === $n || "\0" !== $n[0]) { - $c = $reflector->hasProperty($n) && ($p = $reflector->getProperty($n))->isReadOnly() ? $p->class : 'stdClass'; + $p = $reflector->hasProperty($n) ? $reflector->getProperty($n) : null; + $c = $p && (\PHP_VERSION_ID >= 80400 ? $p->isProtectedSet() || $p->isPrivateSet() : $p->isReadOnly()) ? $p->class : 'stdClass'; } elseif ('*' === $n[1]) { $n = substr($n, 3); $c = $reflector->getProperty($n)->class; diff --git a/src/Symfony/Component/VarExporter/Internal/Hydrator.php b/src/Symfony/Component/VarExporter/Internal/Hydrator.php index 97ffe4c831627..d8250d44b4238 100644 --- a/src/Symfony/Component/VarExporter/Internal/Hydrator.php +++ b/src/Symfony/Component/VarExporter/Internal/Hydrator.php @@ -20,6 +20,9 @@ */ class Hydrator { + public const PROPERTY_HAS_HOOKS = 1; + public const PROPERTY_NOT_BY_REF = 2; + public static array $hydrators = []; public static array $simpleHydrators = []; public static array $propertyScopes = []; @@ -156,13 +159,16 @@ public static function getHydrator($class) public static function getSimpleHydrator($class) { $baseHydrator = self::$simpleHydrators['stdClass'] ??= (function ($properties, $object) { - $readonly = (array) $this; + $notByRef = (array) $this; foreach ($properties as $name => &$value) { - $object->$name = $value; - - if (!($readonly[$name] ?? false)) { + if (!$noRef = $notByRef[$name] ?? false) { + $object->$name = $value; $object->$name = &$value; + } elseif (true !== $noRef) { + $notByRef($object, $value); + } else { + $object->$name = $value; } } })->bindTo(new \stdClass()); @@ -217,14 +223,19 @@ public static function getSimpleHydrator($class) } if (!$classReflector->isInternal()) { - $readonly = new \stdClass(); - foreach ($classReflector->getProperties(\ReflectionProperty::IS_READONLY) as $propertyReflector) { - if ($class === $propertyReflector->class) { - $readonly->{$propertyReflector->name} = true; + $notByRef = new \stdClass(); + foreach ($classReflector->getProperties() as $propertyReflector) { + if ($propertyReflector->isStatic()) { + continue; + } + if (\PHP_VERSION_ID >= 80400 && !$propertyReflector->isAbstract() && $propertyReflector->getHooks()) { + $notByRef->{$propertyReflector->name} = $propertyReflector->setRawValue(...); + } elseif ($propertyReflector->isReadOnly()) { + $notByRef->{$propertyReflector->name} = true; } } - return $baseHydrator->bindTo($readonly, $class); + return $baseHydrator->bindTo($notByRef, $class); } if ($classReflector->name !== $class) { @@ -269,26 +280,26 @@ public static function getPropertyScopes($class) continue; } $name = $property->name; + $access = ($flags << 2) | ($flags & \ReflectionProperty::IS_READONLY ? self::PROPERTY_NOT_BY_REF : 0); + + if (\PHP_VERSION_ID >= 80400 && !$property->isAbstract() && $h = $property->getHooks()) { + $access |= self::PROPERTY_HAS_HOOKS | (isset($h['get']) && !$h['get']->returnsReference() ? self::PROPERTY_NOT_BY_REF : 0); + } if (\ReflectionProperty::IS_PRIVATE & $flags) { - $readonlyScope = null; - if ($flags & \ReflectionProperty::IS_READONLY) { - $readonlyScope = $class; - } - $propertyScopes["\0$class\0$name"] = $propertyScopes[$name] = [$class, $name, $readonlyScope, $property]; + $propertyScopes["\0$class\0$name"] = $propertyScopes[$name] = [$class, $name, null, $access, $property]; continue; } - $readonlyScope = null; - if ($flags & \ReflectionProperty::IS_READONLY) { - $readonlyScope = $property->class; + + $propertyScopes[$name] = [$class, $name, null, $access, $property]; + + if ($flags & (\PHP_VERSION_ID >= 80400 ? \ReflectionProperty::IS_PRIVATE_SET : \ReflectionProperty::IS_READONLY)) { + $propertyScopes[$name][2] = $property->class; } - $propertyScopes[$name] = [$class, $name, $readonlyScope, $property]; if (\ReflectionProperty::IS_PROTECTED & $flags) { $propertyScopes["\0*\0$name"] = $propertyScopes[$name]; - } elseif (\PHP_VERSION_ID >= 80400 && $property->getHooks()) { - $propertyScopes[$name][] = true; } } @@ -296,12 +307,20 @@ public static function getPropertyScopes($class) $class = $r->name; foreach ($r->getProperties(\ReflectionProperty::IS_PRIVATE) as $property) { - if (!$property->isStatic()) { - $name = $property->name; - $readonlyScope = $property->isReadOnly() ? $class : null; - $propertyScopes["\0$class\0$name"] = [$class, $name, $readonlyScope, $property]; - $propertyScopes[$name] ??= [$class, $name, $readonlyScope, $property]; + $flags = $property->getModifiers(); + + if (\ReflectionProperty::IS_STATIC & $flags) { + continue; + } + $name = $property->name; + $access = ($flags << 2) | ($flags & \ReflectionProperty::IS_READONLY ? self::PROPERTY_NOT_BY_REF : 0); + + if (\PHP_VERSION_ID >= 80400 && $h = $property->getHooks()) { + $access |= self::PROPERTY_HAS_HOOKS | (isset($h['get']) && !$h['get']->returnsReference() ? self::PROPERTY_NOT_BY_REF : 0); } + + $propertyScopes["\0$class\0$name"] = [$class, $name, null, $access, $property]; + $propertyScopes[$name] ??= $propertyScopes["\0$class\0$name"]; } } diff --git a/src/Symfony/Component/VarExporter/Internal/LazyObjectRegistry.php b/src/Symfony/Component/VarExporter/Internal/LazyObjectRegistry.php index a7b4987e3b0db..d096be886ad81 100644 --- a/src/Symfony/Component/VarExporter/Internal/LazyObjectRegistry.php +++ b/src/Symfony/Component/VarExporter/Internal/LazyObjectRegistry.php @@ -58,17 +58,17 @@ public static function getClassResetters($class) $propertyScopes = Hydrator::$propertyScopes[$class] ??= Hydrator::getPropertyScopes($class); } - foreach ($propertyScopes as $key => [$scope, $name, $readonlyScope]) { + foreach ($propertyScopes as $key => [$scope, $name, $writeScope, $access]) { $propertyScopes[$k = "\0$scope\0$name"] ?? $propertyScopes[$k = "\0*\0$name"] ?? $k = $name; if ($k !== $key || "\0$class\0lazyObjectState" === $k) { continue; } - if ($k === $name && ($propertyScopes[$k][4] ?? false)) { + if ($access & Hydrator::PROPERTY_HAS_HOOKS) { $hookedProperties[$k] = true; } else { - $classProperties[$readonlyScope ?? $scope][$name] = $key; + $classProperties[$writeScope ?? $scope][$name] = $key; } } @@ -101,8 +101,8 @@ public static function getClassResetters($class) public static function getClassAccessors($class) { return \Closure::bind(static fn () => [ - 'get' => static function &($instance, $name, $readonly) { - if (!$readonly) { + 'get' => static function &($instance, $name, $notByRef) { + if (!$notByRef) { return $instance->$name; } $value = $instance->$name; @@ -138,9 +138,9 @@ public static function getParentMethods($class) return $methods; } - public static function getScope($propertyScopes, $class, $property, $readonlyScope = null) + public static function getScopeForRead($propertyScopes, $class, $property) { - if (null === $readonlyScope && !isset($propertyScopes[$k = "\0$class\0$property"]) && !isset($propertyScopes[$k = "\0*\0$property"])) { + if (!isset($propertyScopes[$k = "\0$class\0$property"]) && !isset($propertyScopes[$k = "\0*\0$property"])) { return null; } $frame = debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT | \DEBUG_BACKTRACE_IGNORE_ARGS, 3)[2]; @@ -148,7 +148,27 @@ public static function getScope($propertyScopes, $class, $property, $readonlySco if (\ReflectionProperty::class === $scope = $frame['class'] ?? \Closure::class) { $scope = $frame['object']->class; } - if (null === $readonlyScope && '*' === $k[1] && ($class === $scope || (is_subclass_of($class, $scope) && !isset($propertyScopes["\0$scope\0$property"])))) { + if ('*' === $k[1] && ($class === $scope || (is_subclass_of($class, $scope) && !isset($propertyScopes["\0$scope\0$property"])))) { + return null; + } + + return $scope; + } + + public static function getScopeForWrite($propertyScopes, $class, $property, $flags) + { + if (!($flags & (\ReflectionProperty::IS_PRIVATE | \ReflectionProperty::IS_PROTECTED | \ReflectionProperty::IS_READONLY | (\PHP_VERSION_ID >= 80400 ? \ReflectionProperty::IS_PRIVATE_SET | \ReflectionProperty::IS_PROTECTED_SET : 0)))) { + return null; + } + $frame = debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT | \DEBUG_BACKTRACE_IGNORE_ARGS, 3)[2]; + + if (\ReflectionProperty::class === $scope = $frame['class'] ?? \Closure::class) { + $scope = $frame['object']->class; + } + if ($flags & (\ReflectionProperty::IS_PRIVATE | (\PHP_VERSION_ID >= 80400 ? \ReflectionProperty::IS_PRIVATE_SET : \ReflectionProperty::IS_READONLY))) { + return $scope; + } + if ($flags & (\ReflectionProperty::IS_PROTECTED | (\PHP_VERSION_ID >= 80400 ? \ReflectionProperty::IS_PROTECTED_SET : 0)) && ($class === $scope || (is_subclass_of($class, $scope) && !isset($propertyScopes["\0$scope\0$property"])))) { return null; } diff --git a/src/Symfony/Component/VarExporter/Internal/LazyObjectState.php b/src/Symfony/Component/VarExporter/Internal/LazyObjectState.php index f47dea4d8e6f5..6ec8478a4ce13 100644 --- a/src/Symfony/Component/VarExporter/Internal/LazyObjectState.php +++ b/src/Symfony/Component/VarExporter/Internal/LazyObjectState.php @@ -45,7 +45,7 @@ public function __construct(public readonly \Closure|array $initializer, $skippe $this->status = \is_array($initializer) ? self::STATUS_UNINITIALIZED_PARTIAL : self::STATUS_UNINITIALIZED_FULL; } - public function initialize($instance, $propertyName, $propertyScope) + public function initialize($instance, $propertyName, $writeScope) { if (self::STATUS_INITIALIZED_FULL === $this->status) { return self::STATUS_INITIALIZED_FULL; @@ -53,13 +53,13 @@ public function initialize($instance, $propertyName, $propertyScope) if (\is_array($this->initializer)) { $class = $instance::class; - $propertyScope ??= $class; + $writeScope ??= $class; $propertyScopes = Hydrator::$propertyScopes[$class]; - $propertyScopes[$k = "\0$propertyScope\0$propertyName"] ?? $propertyScopes[$k = "\0*\0$propertyName"] ?? $k = $propertyName; + $propertyScopes[$k = "\0$writeScope\0$propertyName"] ?? $propertyScopes[$k = "\0*\0$propertyName"] ?? $k = $propertyName; if ($initializer = $this->initializer[$k] ?? null) { - $value = $initializer(...[$instance, $propertyName, $propertyScope, LazyObjectRegistry::$defaultProperties[$class][$k] ?? null]); - $accessor = LazyObjectRegistry::$classAccessors[$propertyScope] ??= LazyObjectRegistry::getClassAccessors($propertyScope); + $value = $initializer(...[$instance, $propertyName, $writeScope, LazyObjectRegistry::$defaultProperties[$class][$k] ?? null]); + $accessor = LazyObjectRegistry::$classAccessors[$writeScope] ??= LazyObjectRegistry::getClassAccessors($writeScope); $accessor['set']($instance, $propertyName, $value); return $this->status = self::STATUS_INITIALIZED_PARTIAL; @@ -71,8 +71,8 @@ public function initialize($instance, $propertyName, $propertyScope) } $properties = (array) $instance; foreach ($values as $key => $value) { - if (!\array_key_exists($key, $properties) && [$scope, $name, $readonlyScope] = $propertyScopes[$key] ?? null) { - $scope = $readonlyScope ?? ('*' !== $scope ? $scope : $class); + if (!\array_key_exists($key, $properties) && [$scope, $name, $writeScope] = $propertyScopes[$key] ?? null) { + $scope = $writeScope ?? $scope; $accessor = LazyObjectRegistry::$classAccessors[$scope] ??= LazyObjectRegistry::getClassAccessors($scope); $accessor['set']($instance, $name, $value); @@ -116,10 +116,10 @@ public function reset($instance): void $properties = (array) $instance; $onlyProperties = \is_array($this->initializer) ? $this->initializer : null; - foreach ($propertyScopes as $key => [$scope, $name, $readonlyScope]) { + foreach ($propertyScopes as $key => [$scope, $name, , $access]) { $propertyScopes[$k = "\0$scope\0$name"] ?? $propertyScopes[$k = "\0*\0$name"] ?? $k = $name; - if ($k === $key && (null !== $readonlyScope || !\array_key_exists($k, $properties))) { + if ($k === $key && ($access & Hydrator::PROPERTY_HAS_HOOKS || ($access >> 2) & \ReflectionProperty::IS_READONLY || !\array_key_exists($k, $properties))) { $skippedProperties[$k] = true; } } diff --git a/src/Symfony/Component/VarExporter/LazyGhostTrait.php b/src/Symfony/Component/VarExporter/LazyGhostTrait.php index 5191b59e705f1..c2dbf99ce590c 100644 --- a/src/Symfony/Component/VarExporter/LazyGhostTrait.php +++ b/src/Symfony/Component/VarExporter/LazyGhostTrait.php @@ -113,10 +113,10 @@ public function initializeLazyObject(): static $properties = (array) $this; $propertyScopes = Hydrator::$propertyScopes[$class] ??= Hydrator::getPropertyScopes($class); foreach ($state->initializer as $key => $initializer) { - if (\array_key_exists($key, $properties) || ![$scope, $name, $readonlyScope] = $propertyScopes[$key] ?? null) { + if (\array_key_exists($key, $properties) || ![$scope, $name, $writeScope] = $propertyScopes[$key] ?? null) { continue; } - $scope = $readonlyScope ?? ('*' !== $scope ? $scope : $class); + $scope = $writeScope ?? $scope; if (null === $values) { if (!\is_array($values = ($state->initializer["\0"])($this, Registry::$defaultProperties[$class]))) { @@ -160,22 +160,28 @@ public function &__get($name): mixed { $propertyScopes = Hydrator::$propertyScopes[$this::class] ??= Hydrator::getPropertyScopes($this::class); $scope = null; + $notByRef = 0; - if ([$class, , $readonlyScope] = $propertyScopes[$name] ?? null) { - $scope = Registry::getScope($propertyScopes, $class, $name); + if ([$class, , $writeScope, $access] = $propertyScopes[$name] ?? null) { + $scope = Registry::getScopeForRead($propertyScopes, $class, $name); $state = $this->lazyObjectState ?? null; if ($state && (null === $scope || isset($propertyScopes["\0$scope\0$name"]))) { + $notByRef = $access & Hydrator::PROPERTY_NOT_BY_REF; + if (LazyObjectState::STATUS_INITIALIZED_FULL === $state->status) { // Work around php/php-src#12695 $property = null === $scope ? $name : "\0$scope\0$name"; - $property = $propertyScopes[$property][3] - ?? Hydrator::$propertyScopes[$this::class][$property][3] = new \ReflectionProperty($scope ?? $class, $name); + $property = $propertyScopes[$property][4] + ?? Hydrator::$propertyScopes[$this::class][$property][4] = new \ReflectionProperty($scope ?? $class, $name); } else { $property = null; } + if (\PHP_VERSION_ID >= 80400 && !$notByRef && ($access >> 2) & \ReflectionProperty::IS_PRIVATE_SET) { + $scope ??= $writeScope; + } - if ($property?->isInitialized($this) ?? LazyObjectState::STATUS_UNINITIALIZED_PARTIAL !== $state->initialize($this, $name, $readonlyScope ?? $scope)) { + if ($property?->isInitialized($this) ?? LazyObjectState::STATUS_UNINITIALIZED_PARTIAL !== $state->initialize($this, $name, $writeScope ?? $scope)) { goto get_in_scope; } } @@ -199,7 +205,7 @@ public function &__get($name): mixed try { if (null === $scope) { - if (null === $readonlyScope) { + if (!$notByRef) { return $this->$name; } $value = $this->$name; @@ -208,7 +214,7 @@ public function &__get($name): mixed } $accessor = Registry::$classAccessors[$scope] ??= Registry::getClassAccessors($scope); - return $accessor['get']($this, $name, null !== $readonlyScope); + return $accessor['get']($this, $name, $notByRef); } catch (\Error $e) { if (\Error::class !== $e::class || !str_starts_with($e->getMessage(), 'Cannot access uninitialized non-nullable property')) { throw $e; @@ -223,7 +229,7 @@ public function &__get($name): mixed $accessor['set']($this, $name, []); - return $accessor['get']($this, $name, null !== $readonlyScope); + return $accessor['get']($this, $name, $notByRef); } catch (\Error) { if (preg_match('/^Cannot access uninitialized non-nullable property ([^ ]++) by reference$/', $e->getMessage(), $matches)) { throw new \Error('Typed property '.$matches[1].' must not be accessed before initialization', $e->getCode(), $e->getPrevious()); @@ -239,15 +245,15 @@ public function __set($name, $value): void $propertyScopes = Hydrator::$propertyScopes[$this::class] ??= Hydrator::getPropertyScopes($this::class); $scope = null; - if ([$class, , $readonlyScope] = $propertyScopes[$name] ?? null) { - $scope = Registry::getScope($propertyScopes, $class, $name, $readonlyScope); + if ([$class, , $writeScope, $access] = $propertyScopes[$name] ?? null) { + $scope = Registry::getScopeForWrite($propertyScopes, $class, $name, $access >> 2); $state = $this->lazyObjectState ?? null; - if ($state && ($readonlyScope === $scope || isset($propertyScopes["\0$scope\0$name"])) + if ($state && ($writeScope === $scope || isset($propertyScopes["\0$scope\0$name"])) && LazyObjectState::STATUS_INITIALIZED_FULL !== $state->status ) { if (LazyObjectState::STATUS_UNINITIALIZED_FULL === $state->status) { - $state->initialize($this, $name, $readonlyScope ?? $scope); + $state->initialize($this, $name, $writeScope ?? $scope); } goto set_in_scope; } @@ -274,13 +280,13 @@ public function __isset($name): bool $propertyScopes = Hydrator::$propertyScopes[$this::class] ??= Hydrator::getPropertyScopes($this::class); $scope = null; - if ([$class, , $readonlyScope] = $propertyScopes[$name] ?? null) { - $scope = Registry::getScope($propertyScopes, $class, $name); + if ([$class, , $writeScope] = $propertyScopes[$name] ?? null) { + $scope = Registry::getScopeForRead($propertyScopes, $class, $name); $state = $this->lazyObjectState ?? null; if ($state && (null === $scope || isset($propertyScopes["\0$scope\0$name"])) && LazyObjectState::STATUS_INITIALIZED_FULL !== $state->status - && LazyObjectState::STATUS_UNINITIALIZED_PARTIAL !== $state->initialize($this, $name, $readonlyScope ?? $scope) + && LazyObjectState::STATUS_UNINITIALIZED_PARTIAL !== $state->initialize($this, $name, $writeScope ?? $scope) ) { goto isset_in_scope; } @@ -305,15 +311,15 @@ public function __unset($name): void $propertyScopes = Hydrator::$propertyScopes[$this::class] ??= Hydrator::getPropertyScopes($this::class); $scope = null; - if ([$class, , $readonlyScope] = $propertyScopes[$name] ?? null) { - $scope = Registry::getScope($propertyScopes, $class, $name, $readonlyScope); + if ([$class, , $writeScope, $access] = $propertyScopes[$name] ?? null) { + $scope = Registry::getScopeForWrite($propertyScopes, $class, $name, $access >> 2); $state = $this->lazyObjectState ?? null; - if ($state && ($readonlyScope === $scope || isset($propertyScopes["\0$scope\0$name"])) + if ($state && ($writeScope === $scope || isset($propertyScopes["\0$scope\0$name"])) && LazyObjectState::STATUS_INITIALIZED_FULL !== $state->status ) { if (LazyObjectState::STATUS_UNINITIALIZED_FULL === $state->status) { - $state->initialize($this, $name, $readonlyScope ?? $scope); + $state->initialize($this, $name, $writeScope ?? $scope); } goto unset_in_scope; } diff --git a/src/Symfony/Component/VarExporter/LazyProxyTrait.php b/src/Symfony/Component/VarExporter/LazyProxyTrait.php index 2033670522ab4..1074c0cba0719 100644 --- a/src/Symfony/Component/VarExporter/LazyProxyTrait.php +++ b/src/Symfony/Component/VarExporter/LazyProxyTrait.php @@ -88,14 +88,19 @@ public function &__get($name): mixed $propertyScopes = Hydrator::$propertyScopes[$this::class] ??= Hydrator::getPropertyScopes($this::class); $scope = null; $instance = $this; + $notByRef = 0; - if ([$class, , $readonlyScope] = $propertyScopes[$name] ?? null) { - $scope = Registry::getScope($propertyScopes, $class, $name); + if ([$class, , $writeScope, $access] = $propertyScopes[$name] ?? null) { + $notByRef = $access & Hydrator::PROPERTY_NOT_BY_REF; + $scope = Registry::getScopeForRead($propertyScopes, $class, $name); if (null === $scope || isset($propertyScopes["\0$scope\0$name"])) { if ($state = $this->lazyObjectState ?? null) { $instance = $state->realInstance ??= ($state->initializer)(); } + if (\PHP_VERSION_ID >= 80400 && !$notByRef && ($access >> 2) & \ReflectionProperty::IS_PRIVATE_SET) { + $scope ??= $writeScope; + } $parent = 2; goto get_in_scope; } @@ -119,10 +124,11 @@ public function &__get($name): mixed } get_in_scope: + $notByRef = $notByRef || 1 === $parent; try { if (null === $scope) { - if (null === $readonlyScope && 1 !== $parent) { + if (!$notByRef) { return $instance->$name; } $value = $instance->$name; @@ -131,7 +137,7 @@ public function &__get($name): mixed } $accessor = Registry::$classAccessors[$scope] ??= Registry::getClassAccessors($scope); - return $accessor['get']($instance, $name, null !== $readonlyScope || 1 === $parent); + return $accessor['get']($instance, $name, $notByRef); } catch (\Error $e) { if (\Error::class !== $e::class || !str_starts_with($e->getMessage(), 'Cannot access uninitialized non-nullable property')) { throw $e; @@ -146,7 +152,7 @@ public function &__get($name): mixed $accessor['set']($instance, $name, []); - return $accessor['get']($instance, $name, null !== $readonlyScope || 1 === $parent); + return $accessor['get']($instance, $name, $notByRef); } catch (\Error) { throw $e; } @@ -159,10 +165,10 @@ public function __set($name, $value): void $scope = null; $instance = $this; - if ([$class, , $readonlyScope] = $propertyScopes[$name] ?? null) { - $scope = Registry::getScope($propertyScopes, $class, $name, $readonlyScope); + if ([$class, , $writeScope, $access] = $propertyScopes[$name] ?? null) { + $scope = Registry::getScopeForWrite($propertyScopes, $class, $name, $access >> 2); - if ($readonlyScope === $scope || isset($propertyScopes["\0$scope\0$name"])) { + if ($writeScope === $scope || isset($propertyScopes["\0$scope\0$name"])) { if ($state = $this->lazyObjectState ?? null) { $instance = $state->realInstance ??= ($state->initializer)(); } @@ -195,7 +201,7 @@ public function __isset($name): bool $instance = $this; if ([$class] = $propertyScopes[$name] ?? null) { - $scope = Registry::getScope($propertyScopes, $class, $name); + $scope = Registry::getScopeForRead($propertyScopes, $class, $name); if (null === $scope || isset($propertyScopes["\0$scope\0$name"])) { if ($state = $this->lazyObjectState ?? null) { @@ -227,10 +233,10 @@ public function __unset($name): void $scope = null; $instance = $this; - if ([$class, , $readonlyScope] = $propertyScopes[$name] ?? null) { - $scope = Registry::getScope($propertyScopes, $class, $name, $readonlyScope); + if ([$class, , $writeScope, $access] = $propertyScopes[$name] ?? null) { + $scope = Registry::getScopeForWrite($propertyScopes, $class, $name, $access >> 2); - if ($readonlyScope === $scope || isset($propertyScopes["\0$scope\0$name"])) { + if ($writeScope === $scope || isset($propertyScopes["\0$scope\0$name"])) { if ($state = $this->lazyObjectState ?? null) { $instance = $state->realInstance ??= ($state->initializer)(); } diff --git a/src/Symfony/Component/VarExporter/ProxyHelper.php b/src/Symfony/Component/VarExporter/ProxyHelper.php index 246dc4d404bc7..538d23f7c5087 100644 --- a/src/Symfony/Component/VarExporter/ProxyHelper.php +++ b/src/Symfony/Component/VarExporter/ProxyHelper.php @@ -33,8 +33,8 @@ public static function generateLazyGhost(\ReflectionClass $class): string if ($class->isFinal()) { throw new LogicException(sprintf('Cannot generate lazy ghost: class "%s" is final.', $class->name)); } - if ($class->isInterface() || $class->isAbstract()) { - throw new LogicException(sprintf('Cannot generate lazy ghost: "%s" is not a concrete class.', $class->name)); + if ($class->isInterface() || $class->isAbstract() || $class->isTrait()) { + throw new LogicException(\sprintf('Cannot generate lazy ghost: "%s" is not a concrete class.', $class->name)); } if (\stdClass::class !== $class->name && $class->isInternal()) { throw new LogicException(sprintf('Cannot generate lazy ghost: class "%s" is internal.', $class->name)); @@ -61,26 +61,34 @@ public static function generateLazyGhost(\ReflectionClass $class): string $hooks = ''; $propertyScopes = Hydrator::$propertyScopes[$class->name] ??= Hydrator::getPropertyScopes($class->name); - foreach ($propertyScopes as $name => $scope) { - if (!isset($scope[4]) || ($p = $scope[3])->isVirtual()) { + foreach ($propertyScopes as $key => [$scope, $name, , $access]) { + $propertyScopes[$k = "\0$scope\0$name"] ?? $propertyScopes[$k = "\0*\0$name"] ?? $k = $name; + $flags = $access >> 2; + + if ($k !== $key || !($access & Hydrator::PROPERTY_HAS_HOOKS) || $flags & \ReflectionProperty::IS_VIRTUAL) { continue; } + if ($flags & (\ReflectionProperty::IS_FINAL | \ReflectionProperty::IS_PRIVATE)) { + throw new LogicException(sprintf('Cannot generate lazy ghost: property "%s::$%s" is final or private(set).', $class->name, $name)); + } + + $p = $propertyScopes[$k][4] ?? Hydrator::$propertyScopes[$class->name][$k][4] = new \ReflectionProperty($scope, $name); + $type = self::exportType($p); - $hooks .= "\n public {$type} \${$name} {\n"; + $hooks .= "\n " + .($p->isProtected() ? 'protected' : 'public') + .($p->isProtectedSet() ? ' protected(set)' : '') + ." {$type} \${$name} {\n"; foreach ($p->getHooks() as $hook => $method) { - if ($method->isFinal()) { - throw new LogicException(sprintf('Cannot generate lazy ghost: hook "%s::%s()" is final.', $class->name, $method->name)); - } - if ('get' === $hook) { $ref = ($method->returnsReference() ? '&' : ''); - $hooks .= " {$ref}get { \$this->initializeLazyObject(); return parent::\${$name}::get(); }\n"; + $hooks .= " {$ref}get { \$this->initializeLazyObject(); return parent::\${$name}::get(); }\n"; } elseif ('set' === $hook) { $parameters = self::exportParameters($method, true); $arg = '$'.$method->getParameters()[0]->name; - $hooks .= " set({$parameters}) { \$this->initializeLazyObject(); parent::\${$name}::set({$arg}); }\n"; + $hooks .= " set({$parameters}) { \$this->initializeLazyObject(); parent::\${$name}::set({$arg}); }\n"; } else { throw new LogicException(sprintf('Cannot generate lazy ghost: hook "%s::%s()" is not supported.', $class->name, $method->name)); } @@ -89,7 +97,7 @@ public static function generateLazyGhost(\ReflectionClass $class): string $hooks .= " }\n"; } - $propertyScopes = self::exportPropertyScopes($class->name); + $propertyScopes = self::exportPropertyScopes($class->name, $propertyScopes); return <<name} implements \Symfony\Component\VarExporter\LazyObjectInterface @@ -126,13 +134,34 @@ public static function generateLazyProxy(?\ReflectionClass $class, array $interf throw new LogicException(sprintf('Cannot generate lazy proxy with PHP < 8.3: class "%s" is readonly.', $class->name)); } + $propertyScopes = $class ? Hydrator::$propertyScopes[$class->name] ??= Hydrator::getPropertyScopes($class->name) : []; + $abstractProperties = []; $hookedProperties = []; if (\PHP_VERSION_ID >= 80400 && $class) { - $propertyScopes = Hydrator::$propertyScopes[$class->name] ??= Hydrator::getPropertyScopes($class->name); - foreach ($propertyScopes as $name => $scope) { - if (isset($scope[4]) && !($p = $scope[3])->isVirtual()) { - $hookedProperties[$name] = [$p, $p->getHooks()]; + foreach ($propertyScopes as $key => [$scope, $name, , $access]) { + $propertyScopes[$k = "\0$scope\0$name"] ?? $propertyScopes[$k = "\0*\0$name"] ?? $k = $name; + $flags = $access >> 2; + + if ($k !== $key) { + continue; } + + if ($flags & \ReflectionProperty::IS_ABSTRACT) { + $abstractProperties[$name] = $propertyScopes[$k][4] ?? Hydrator::$propertyScopes[$class->name][$k][4] = new \ReflectionProperty($scope, $name); + continue; + } + $abstractProperties[$name] = false; + + if (!($access & Hydrator::PROPERTY_HAS_HOOKS) || $flags & \ReflectionProperty::IS_VIRTUAL) { + continue; + } + + if ($flags & (\ReflectionProperty::IS_FINAL | \ReflectionProperty::IS_PRIVATE)) { + throw new LogicException(sprintf('Cannot generate lazy proxy: property "%s::$%s" is final or private(set).', $class->name, $name)); + } + + $p = $propertyScopes[$k][4] ?? Hydrator::$propertyScopes[$class->name][$k][4] = new \ReflectionProperty($scope, $name); + $hookedProperties[$name] = [$p, $p->getHooks()]; } } @@ -143,8 +172,9 @@ public static function generateLazyProxy(?\ReflectionClass $class, array $interf } $methodReflectors[] = $interface->getMethods(); - if (\PHP_VERSION_ID >= 80400 && !$class) { + if (\PHP_VERSION_ID >= 80400) { foreach ($interface->getProperties() as $p) { + $abstractProperties[$p->name] ??= $p; $hookedProperties[$p->name] ??= [$p, []]; $hookedProperties[$p->name][1] += $p->getHooks(); } @@ -152,47 +182,55 @@ public static function generateLazyProxy(?\ReflectionClass $class, array $interf } $hooks = ''; + + foreach (array_filter($abstractProperties) as $name => $p) { + $type = self::exportType($p); + $hooks .= "\n " + .($p->isProtected() ? 'protected' : 'public') + .($p->isProtectedSet() ? ' protected(set)' : '') + ." {$type} \${$name};\n"; + } + foreach ($hookedProperties as $name => [$p, $methods]) { $type = self::exportType($p); - $hooks .= "\n public {$type} \${$p->name} {\n"; + $hooks .= "\n " + .($p->isProtected() ? 'protected' : 'public') + .($p->isProtectedSet() ? ' protected(set)' : '') + ." {$type} \${$name} {\n"; foreach ($methods as $hook => $method) { - if ($method->isFinal()) { - throw new LogicException(sprintf('Cannot generate lazy proxy: hook "%s::%s()" is final.', $class->name, $method->name)); - } - if ('get' === $hook) { $ref = ($method->returnsReference() ? '&' : ''); $hooks .= <<lazyObjectState)) { - return (\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$p->name}; - } - - return parent::\${$p->name}::get(); + {$ref}get { + if (isset(\$this->lazyObjectState)) { + return (\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$p->name}; } + return parent::\${$p->name}::get(); + } + EOPHP; } elseif ('set' === $hook) { $parameters = self::exportParameters($method, true); $arg = '$'.$method->getParameters()[0]->name; $hooks .= <<lazyObjectState)) { - \$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)(); - \$this->lazyObjectState->realInstance->{$p->name} = {$arg}; - } - - parent::\${$p->name}::set({$arg}); + set({$parameters}) { + if (isset(\$this->lazyObjectState)) { + \$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)(); + \$this->lazyObjectState->realInstance->{$p->name} = {$arg}; } + parent::\${$p->name}::set({$arg}); + } + EOPHP; } else { throw new LogicException(sprintf('Cannot generate lazy proxy: hook "%s::%s()" is not supported.', $class->name, $method->name)); } } - $hooks .= " }\n"; + $hooks .= " }\n"; } $extendsInternalClass = false; @@ -287,7 +325,7 @@ public static function generateLazyProxy(?\ReflectionClass $class, array $interf $methods = ['initializeLazyObject' => implode('', $body).' }'] + $methods; } $body = $methods ? "\n".implode("\n\n", $methods)."\n" : ''; - $propertyScopes = $class ? self::exportPropertyScopes($class->name) : '[]'; + $propertyScopes = $class ? self::exportPropertyScopes($class->name, $propertyScopes) : '[]'; if ( $class?->hasMethod('__unserialize') @@ -444,12 +482,11 @@ public static function exportType(\ReflectionFunctionAbstract|\ReflectionPropert return implode($glue, $types); } - private static function exportPropertyScopes(string $parent): string + private static function exportPropertyScopes(string $parent, array $propertyScopes): string { - $propertyScopes = Hydrator::$propertyScopes[$parent] ??= Hydrator::getPropertyScopes($parent); uksort($propertyScopes, 'strnatcmp'); foreach ($propertyScopes as $k => $v) { - unset($propertyScopes[$k][3]); + unset($propertyScopes[$k][4]); } $propertyScopes = VarExporter::export($propertyScopes); $propertyScopes = str_replace(VarExporter::export($parent), 'parent::class', $propertyScopes); diff --git a/src/Symfony/Component/VarExporter/Tests/Fixtures/BackedProperty.php b/src/Symfony/Component/VarExporter/Tests/Fixtures/BackedProperty.php new file mode 100644 index 0000000000000..5c5d7688f97ca --- /dev/null +++ b/src/Symfony/Component/VarExporter/Tests/Fixtures/BackedProperty.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\VarExporter\Tests\Fixtures; + +class BackedProperty +{ + public private(set) string $name { + get => $this->name; + set => $value; + } + public function __construct(string $name) + { + $this->name = $name; + } +} diff --git a/src/Symfony/Component/VarExporter/Tests/Fixtures/LazyGhost/ChildMagicClass.php b/src/Symfony/Component/VarExporter/Tests/Fixtures/LazyGhost/ChildMagicClass.php index ca6b235eba66d..6cac9ffc03d01 100644 --- a/src/Symfony/Component/VarExporter/Tests/Fixtures/LazyGhost/ChildMagicClass.php +++ b/src/Symfony/Component/VarExporter/Tests/Fixtures/LazyGhost/ChildMagicClass.php @@ -18,14 +18,5 @@ class ChildMagicClass extends MagicClass implements LazyObjectInterface { use LazyGhostTrait; - private const LAZY_OBJECT_PROPERTY_SCOPES = [ - "\0".self::class."\0".'data' => [self::class, 'data', null], - "\0".self::class."\0".'lazyObjectState' => [self::class, 'lazyObjectState', null], - "\0".parent::class."\0".'data' => [parent::class, 'data', null], - 'cloneCounter' => [self::class, 'cloneCounter', null], - 'data' => [self::class, 'data', null], - 'lazyObjectState' => [self::class, 'lazyObjectState', null], - ]; - private int $data = 123; } diff --git a/src/Symfony/Component/VarExporter/Tests/Fixtures/LazyProxy/AbstractHooked.php b/src/Symfony/Component/VarExporter/Tests/Fixtures/LazyProxy/AbstractHooked.php new file mode 100644 index 0000000000000..3d9cde20c7b15 --- /dev/null +++ b/src/Symfony/Component/VarExporter/Tests/Fixtures/LazyProxy/AbstractHooked.php @@ -0,0 +1,22 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy; + +abstract class AbstractHooked implements HookedInterface +{ + abstract public string $bar { get; } + + public int $backed { + get { return $this->backed ??= 234; } + set { $this->backed = $value; } + } +} diff --git a/src/Symfony/Component/VarExporter/Tests/Fixtures/LazyProxy/AsymmetricVisibility.php b/src/Symfony/Component/VarExporter/Tests/Fixtures/LazyProxy/AsymmetricVisibility.php new file mode 100644 index 0000000000000..a912ca403ca26 --- /dev/null +++ b/src/Symfony/Component/VarExporter/Tests/Fixtures/LazyProxy/AsymmetricVisibility.php @@ -0,0 +1,26 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy; + +class AsymmetricVisibility +{ + public function __construct( + public private(set) int $foo, + private readonly int $bar, + ) { + } + + public function getBar(): int + { + return $this->bar; + } +} diff --git a/src/Symfony/Component/VarExporter/Tests/Fixtures/Hooked.php b/src/Symfony/Component/VarExporter/Tests/Fixtures/LazyProxy/Hooked.php similarity index 88% rename from src/Symfony/Component/VarExporter/Tests/Fixtures/Hooked.php rename to src/Symfony/Component/VarExporter/Tests/Fixtures/LazyProxy/Hooked.php index 0c46d37afe922..62174f92d5847 100644 --- a/src/Symfony/Component/VarExporter/Tests/Fixtures/Hooked.php +++ b/src/Symfony/Component/VarExporter/Tests/Fixtures/LazyProxy/Hooked.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\VarExporter\Tests\Fixtures; +namespace Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy; class Hooked { diff --git a/src/Symfony/Component/VarExporter/Tests/Fixtures/LazyProxy/HookedInterface.php b/src/Symfony/Component/VarExporter/Tests/Fixtures/LazyProxy/HookedInterface.php new file mode 100644 index 0000000000000..9cdafd9c1fdfa --- /dev/null +++ b/src/Symfony/Component/VarExporter/Tests/Fixtures/LazyProxy/HookedInterface.php @@ -0,0 +1,17 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy; + +interface HookedInterface +{ + public string $foo { get; } +} diff --git a/src/Symfony/Component/VarExporter/Tests/Fixtures/backed-property.php b/src/Symfony/Component/VarExporter/Tests/Fixtures/backed-property.php new file mode 100644 index 0000000000000..bcbc5729e9e5b --- /dev/null +++ b/src/Symfony/Component/VarExporter/Tests/Fixtures/backed-property.php @@ -0,0 +1,17 @@ + [ + 'name' => [ + 'name', + ], + ], + ], + $o[0], + [] +); diff --git a/src/Symfony/Component/VarExporter/Tests/LazyGhostTraitTest.php b/src/Symfony/Component/VarExporter/Tests/LazyGhostTraitTest.php index 00f090a43c292..5b80f6b00339b 100644 --- a/src/Symfony/Component/VarExporter/Tests/LazyGhostTraitTest.php +++ b/src/Symfony/Component/VarExporter/Tests/LazyGhostTraitTest.php @@ -17,7 +17,6 @@ use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; use Symfony\Component\VarExporter\Internal\LazyObjectState; use Symfony\Component\VarExporter\ProxyHelper; -use Symfony\Component\VarExporter\Tests\Fixtures\Hooked; use Symfony\Component\VarExporter\Tests\Fixtures\LazyGhost\ChildMagicClass; use Symfony\Component\VarExporter\Tests\Fixtures\LazyGhost\ChildStdClass; use Symfony\Component\VarExporter\Tests\Fixtures\LazyGhost\ChildTestClass; @@ -26,6 +25,8 @@ use Symfony\Component\VarExporter\Tests\Fixtures\LazyGhost\MagicClass; use Symfony\Component\VarExporter\Tests\Fixtures\LazyGhost\ReadOnlyClass; use Symfony\Component\VarExporter\Tests\Fixtures\LazyGhost\TestClass; +use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\AsymmetricVisibility; +use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\Hooked; use Symfony\Component\VarExporter\Tests\Fixtures\SimpleObject; class LazyGhostTraitTest extends TestCase @@ -504,6 +505,26 @@ public function testPropertyHooks() $this->assertSame(345, $object->backed); } + /** + * @requires PHP 8.4 + */ + public function testAsymmetricVisibility() + { + $object = $this->createLazyGhost(AsymmetricVisibility::class, function ($instance) { + $instance->__construct(123, 234); + }); + + $this->assertSame(123, $object->foo); + $this->assertSame(234, $object->getBar()); + + $object = $this->createLazyGhost(AsymmetricVisibility::class, function ($instance) { + $instance->__construct(123, 234); + }); + + $this->assertSame(234, $object->getBar()); + $this->assertSame(123, $object->foo); + } + /** * @template T * diff --git a/src/Symfony/Component/VarExporter/Tests/LazyProxyTraitTest.php b/src/Symfony/Component/VarExporter/Tests/LazyProxyTraitTest.php index 938b304461291..61be7429fb0cd 100644 --- a/src/Symfony/Component/VarExporter/Tests/LazyProxyTraitTest.php +++ b/src/Symfony/Component/VarExporter/Tests/LazyProxyTraitTest.php @@ -18,7 +18,9 @@ use Symfony\Component\VarExporter\Exception\LogicException; use Symfony\Component\VarExporter\LazyProxyTrait; use Symfony\Component\VarExporter\ProxyHelper; -use Symfony\Component\VarExporter\Tests\Fixtures\Hooked; +use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\AbstractHooked; +use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\AsymmetricVisibility; +use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\Hooked; use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\FinalPublicClass; use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\ReadOnlyClass; use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\StringMagicGetClass; @@ -302,11 +304,12 @@ public function testNormalization() /** * @requires PHP 8.4 */ - public function testPropertyHooks() + public function testConcretePropertyHooks() { $initialized = false; $object = $this->createLazyProxy(Hooked::class, function () use (&$initialized) { $initialized = true; + return new Hooked(); }); @@ -318,6 +321,7 @@ public function testPropertyHooks() $initialized = false; $object = $this->createLazyProxy(Hooked::class, function () use (&$initialized) { $initialized = true; + return new Hooked(); }); @@ -326,6 +330,60 @@ public function testPropertyHooks() $this->assertSame(345, $object->backed); } + /** + * @requires PHP 8.4 + */ + public function testAbstractPropertyHooks() + { + $initialized = false; + $object = $this->createLazyProxy(AbstractHooked::class, function () use (&$initialized) { + $initialized = true; + + return new class extends AbstractHooked { + public string $foo = 'Foo'; + public string $bar = 'Bar'; + }; + }); + + $this->assertSame('Foo', $object->foo); + $this->assertSame('Bar', $object->bar); + $this->assertTrue($initialized); + + $initialized = false; + $object = $this->createLazyProxy(AbstractHooked::class, function () use (&$initialized) { + $initialized = true; + + return new class extends AbstractHooked { + public string $foo = 'Foo'; + public string $bar = 'Bar'; + }; + }); + + $this->assertSame('Bar', $object->bar); + $this->assertSame('Foo', $object->foo); + $this->assertTrue($initialized); + } + + /** + * @requires PHP 8.4 + */ + public function testAsymmetricVisibility() + { + $object = $this->createLazyProxy(AsymmetricVisibility::class, function () { + return new AsymmetricVisibility(123, 234); + }); + + $this->assertSame(123, $object->foo); + $this->assertSame(234, $object->getBar()); + + $object = $this->createLazyProxy(AsymmetricVisibility::class, function () { + return new AsymmetricVisibility(123, 234); + }); + + $this->assertSame(234, $object->getBar()); + $this->assertSame(123, $object->foo); + } + /** * @template T * diff --git a/src/Symfony/Component/VarExporter/Tests/ProxyHelperTest.php b/src/Symfony/Component/VarExporter/Tests/ProxyHelperTest.php index d0085a70498c5..874dd593b8460 100644 --- a/src/Symfony/Component/VarExporter/Tests/ProxyHelperTest.php +++ b/src/Symfony/Component/VarExporter/Tests/ProxyHelperTest.php @@ -14,7 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\VarExporter\Exception\LogicException; use Symfony\Component\VarExporter\ProxyHelper; -use Symfony\Component\VarExporter\Tests\Fixtures\Hooked; +use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\Hooked; use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\Php82NullStandaloneReturnType; use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\StringMagicGetClass; @@ -253,10 +253,9 @@ public function testNullStandaloneReturnType() */ public function testPropertyHooks() { - self::assertStringContainsString( - "[parent::class, 'backed', null, 4 => true]", - ProxyHelper::generateLazyProxy(new \ReflectionClass(Hooked::class)) - ); + $proxyCode = ProxyHelper::generateLazyProxy(new \ReflectionClass(Hooked::class)); + self::assertStringContainsString("'backed' => [parent::class, 'backed', null, 7],", $proxyCode); + self::assertStringContainsString("'notBacked' => [parent::class, 'notBacked', null, 2055],", $proxyCode); } } diff --git a/src/Symfony/Component/VarExporter/Tests/VarExporterTest.php b/src/Symfony/Component/VarExporter/Tests/VarExporterTest.php index 16c87b040d6b6..29fcf7598553b 100644 --- a/src/Symfony/Component/VarExporter/Tests/VarExporterTest.php +++ b/src/Symfony/Component/VarExporter/Tests/VarExporterTest.php @@ -16,6 +16,7 @@ use Symfony\Component\VarExporter\Exception\ClassNotFoundException; use Symfony\Component\VarExporter\Exception\NotInstantiableTypeException; use Symfony\Component\VarExporter\Internal\Registry; +use Symfony\Component\VarExporter\Tests\Fixtures\BackedProperty; use Symfony\Component\VarExporter\Tests\Fixtures\FooReadonly; use Symfony\Component\VarExporter\Tests\Fixtures\FooSerializable; use Symfony\Component\VarExporter\Tests\Fixtures\FooUnitEnum; @@ -239,6 +240,12 @@ public static function provideExport() yield ['unit-enum', [FooUnitEnum::Bar], true]; yield ['readonly', new FooReadonly('k', 'v')]; + + if (\PHP_VERSION_ID < 80400) { + return; + } + + yield ['backed-property', new BackedProperty('name')]; } public function testUnicodeDirectionality() diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index dadf7df446bcb..19b48cfe38185 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -1158,7 +1158,18 @@ private function lexInlineQuotedString(int &$cursor = 0): string private function lexUnquotedString(int &$cursor): string { $offset = $cursor; - $cursor += strcspn($this->currentLine, '[]{},:', $cursor); + + while ($cursor < strlen($this->currentLine)) { + if (in_array($this->currentLine[$cursor], ['[', ']', '{', '}', ',', ':'], true)) { + break; + } + + if (\in_array($this->currentLine[$cursor], [' ', "\t"], true) && '#' === ($this->currentLine[$cursor + 1] ?? '')) { + break; + } + + ++$cursor; + } if ($cursor === $offset) { throw new ParseException('Malformed unquoted YAML string.'); @@ -1235,7 +1246,7 @@ private function consumeWhitespaces(int &$cursor): bool $whitespacesConsumed = 0; do { - $whitespaceOnlyTokenLength = strspn($this->currentLine, ' ', $cursor); + $whitespaceOnlyTokenLength = strspn($this->currentLine, " \t", $cursor); $whitespacesConsumed += $whitespaceOnlyTokenLength; $cursor += $whitespaceOnlyTokenLength; diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index 7725ac8d4d61c..c1f643f43603d 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -1751,6 +1751,69 @@ public function testParseMultiLineUnquotedString() $this->assertSame(['foo' => 'bar baz foobar foo', 'bar' => 'baz'], $this->parser->parse($yaml)); } + /** + * @dataProvider unquotedStringWithTrailingComment + */ + public function testParseMultiLineUnquotedStringWithTrailingComment(string $yaml, array $expected) + { + $this->assertSame($expected, $this->parser->parse($yaml)); + } + + public function unquotedStringWithTrailingComment() + { + return [ + 'comment after comma' => [ + <<<'YAML' + { + foo: 3, # comment + bar: 3 + } + YAML, + ['foo' => 3, 'bar' => 3], + ], + 'comment after space' => [ + <<<'YAML' + { + foo: 3 # comment + } + YAML, + ['foo' => 3], + ], + 'comment after space, but missing space after #' => [ + <<<'YAML' + { + foo: 3 #comment + } + YAML, + ['foo' => 3], + ], + 'comment after tab' => [ + << 3], + ], + 'comment after tab, but missing space after #' => [ + << 3], + ], + '# in mapping value' => [ + <<<'YAML' + { + foo: example.com/#about + } + YAML, + ['foo' => 'example.com/#about'], + ], + ]; + } + /** * @dataProvider escapedQuotationCharactersInQuotedStrings */