diff --git a/.appveyor.yml b/.appveyor.yml index 9d863ffb3557f..67f2fcafc63f2 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -9,7 +9,7 @@ cache: init: - SET PATH=c:\php;%PATH% - SET COMPOSER_NO_INTERACTION=1 - - SET SYMFONY_DEPRECATIONS_HELPER=strict + - SET SYMFONY_DEPRECATIONS_HELPER=max[indirect]=7 - SET "SYMFONY_REQUIRE=>=4.4" - SET ANSICON=121x90 (121x90) - SET SYMFONY_PHPUNIT_DISABLE_RESULT_CACHE=1 diff --git a/.github/patch-types.php b/.github/patch-types.php index e09e5bbbf4dd8..949b858c0f1a0 100644 --- a/.github/patch-types.php +++ b/.github/patch-types.php @@ -16,6 +16,7 @@ case false !== strpos(realpath($file), '/vendor/'): case false !== strpos($file, '/src/Symfony/Bridge/PhpUnit/'): case false !== strpos($file, '/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Validation/Article.php'): + case false !== strpos($file, '/src/Symfony/Component/Config/Tests/Fixtures/BadFileName.php'): case false !== strpos($file, '/src/Symfony/Component/Config/Tests/Fixtures/BadParent.php'): case false !== strpos($file, '/src/Symfony/Component/DependencyInjection/Tests/Compiler/OptionalServiceClass.php'): case false !== strpos($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/ParentNotExists.php'): diff --git a/.travis.yml b/.travis.yml index 3f34da8c38d19..d365f8782f6d5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,10 +26,10 @@ env: matrix: include: - php: 7.2 - env: php_extra="7.4snapshot" + env: php_extra="7.4" - php: 7.3 env: deps=high - - php: 7.4snapshot + - php: 7.4 env: deps=low fast_finish: true @@ -319,7 +319,8 @@ install: echo "$COMPONENTS" | parallel --gnu "tfold {} $PHPUNIT_X {}" - tfold src/Symfony/Component/Console.tty $PHPUNIT --group tty + tfold src/Symfony/Component/Console.tty $PHPUNIT src/Symfony/Component/Console --group tty + tfold src/Symfony/Bridge/Twig.tty $PHPUNIT src/Symfony/Bridge/Twig --group tty if [[ $PHP = ${MIN_PHP%.*} ]]; then export PHP=$MIN_PHP diff --git a/CHANGELOG-4.3.md b/CHANGELOG-4.3.md index a5b9b78847b5c..3695556e82fad 100644 --- a/CHANGELOG-4.3.md +++ b/CHANGELOG-4.3.md @@ -7,6 +7,46 @@ in 4.3 minor versions. To get the diff for a specific change, go to https://github.com/symfony/symfony/commit/XXX where XXX is the change hash To get the diff between two versions, go to https://github.com/symfony/symfony/compare/v4.3.0...v4.3.1 +* 4.3.9 (2019-12-01) + + * bug #34649 more robust initialization from request (dbu) + * bug #34671 [Security] Fix clearing remember-me cookie after deauthentication (chalasr) + * bug #34711 Fix the translation commands when a template contains a syntax error (fabpot) + * bug #34560 [Config][ReflectionClassResource] Handle parameters with undefined constant as their default values (fancyweb) + * bug #34695 [Config] don't break on virtual stack frames in ClassExistenceResource (nicolas-grekas) + * bug #34716 [DependencyInjection] fix dumping number-like string parameters (xabbuh) + * bug #34558 [Console] Fix autocomplete multibyte input support (fancyweb) + * bug #34130 [Console] Fix commands description with numeric namespaces (fancyweb) + * bug #34677 [EventDispatcher] Better error reporting when arguments to dispatch() are swapped (rimas-kudelis) + * bug #33573 [TwigBridge] Add row_attr to all form themes (fancyweb) + * bug #34019 [Serializer] CsvEncoder::NO_HEADERS_KEY ignored when used in constructor (Dario Savella) + * bug #34083 [Form] Keep preferred_choices order for choice groups (vilius-g) + * bug #34091 [Debug] work around failing chdir() on Darwin (mary2501) + * bug #34305 [PhpUnitBridge] Read configuration CLI directive (ro0NL) + * bug #34490 [Serializer] Fix MetadataAwareNameConverter usage with string group (antograssiot) + * bug #34632 [Console] Fix trying to access array offset on value of type int (Tavafi) + * bug #34669 [HttpClient] turn exception into log when the request has no content-type (nicolas-grekas) + * bug #34636 [VarDumper] notice on potential undefined index (sylvainmetayer) + * bug #34668 [Cache] Make sure we get the correct number of values from redis::mget() (thePanz) + * bug #34569 [Workflow] Apply the same logic of precedence between the apply() and the buildTransitionBlockerList() method (lyrixx) + * bug #34533 [Monolog Bridge] Fixed accessing static property as non static. (Sander-Toonen) + * bug #34546 [Serializer] Add DateTimeZoneNormalizer into Dependency Injection (jewome62) + * bug #34547 [Messenger] Error when specified default bus is not among the configured (vudaltsov) + * bug #34551 [Security] SwitchUser is broken when the User Provider always returns a valid user (tucksaun) + * bug #34385 Avoid empty "If-Modified-Since" header in validation request (mpdude) + * bug #34458 [Validator] ConstraintValidatorTestCase: add missing return value to mocked validate method calls (ogizanagi) + * bug #34451 [DependencyInjection] Fix dumping multiple deprecated aliases (shyim) + * bug #34448 [Form] allow button names to start with uppercase letter (xabbuh) + * bug #34419 [Cache] Disable igbinary on PHP >= 7.4 (nicolas-grekas) + * bug #34366 [HttpFoundation] Allow redirecting to URLs that contain a semicolon (JayBizzle) + * bug #34397 [FrameworkBundle] Remove project dir from Translator cache vary scanned directories (fancyweb) + * bug #34408 [Cache] catch exceptions when using PDO directly (xabbuh) + * bug #34410 [HttpFoundation] Fix MySQL column type definition. (jbroutier) + * bug #34398 [Config] fix id-generation for GlobResource (nicolas-grekas) + * bug #34396 [Finder] Allow ssh2 stream wrapper for sftp (damienalexandre) + * bug #34383 [DI] Use reproducible entropy to generate env placeholders (nicolas-grekas) + * bug #34381 [WebProfilerBundle] Require symfony/twig-bundle (fancyweb) + * 4.3.8 (2019-11-13) * bug #34344 [Console] Constant STDOUT might be undefined (nicolas-grekas) diff --git a/CHANGELOG-4.4.md b/CHANGELOG-4.4.md index 64e77d4a4d718..7bd4ac031e861 100644 --- a/CHANGELOG-4.4.md +++ b/CHANGELOG-4.4.md @@ -7,6 +7,58 @@ in 4.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/v4.4.0...v4.4.1 +* 4.4.1 (2019-12-01) + + * bug #34732 [DependencyInjection][Xml] Fix the attribute 'tag' is not allowed in 'bind' tag (tienvx) + * bug #34729 [DI] auto-register singly implemented interfaces by default (nicolas-grekas) + * bug #34728 [DI] fix overriding existing services with aliases for singly-implemented interfaces (nicolas-grekas) + * bug #34649 more robust initialization from request (dbu) + * bug #34715 [TwigBundle] remove service when base class is missing (xabbuh) + * bug #34600 [DoctrineBridge] do not depend on the QueryBuilder from the ORM (xabbuh) + * bug #34627 [Security/Http] call auth listeners/guards eagerly when they "support" the request (nicolas-grekas) + * bug #34671 [Security] Fix clearing remember-me cookie after deauthentication (chalasr) + * bug #34711 Fix the translation commands when a template contains a syntax error (fabpot) + * bug #34032 [Mime] Fixing multidimensional array structure with FormDataPart (jvahldick) + * bug #34560 [Config][ReflectionClassResource] Handle parameters with undefined constant as their default values (fancyweb) + * bug #34695 [Config] don't break on virtual stack frames in ClassExistenceResource (nicolas-grekas) + * bug #34716 [DependencyInjection] fix dumping number-like string parameters (xabbuh) + * bug #34558 [Console] Fix autocomplete multibyte input support (fancyweb) + * bug #34130 [Console] Fix commands description with numeric namespaces (fancyweb) + * bug #34562 [DI] Skip unknown method calls for factories in check types pass (fancyweb) + * bug #34677 [EventDispatcher] Better error reporting when arguments to dispatch() are swapped (rimas-kudelis) + * bug #33573 [TwigBridge] Add row_attr to all form themes (fancyweb) + * bug #34019 [Serializer] CsvEncoder::NO_HEADERS_KEY ignored when used in constructor (Dario Savella) + * bug #34083 [Form] Keep preferred_choices order for choice groups (vilius-g) + * bug #34091 [Debug] work around failing chdir() on Darwin (mary2501) + * bug #34305 [PhpUnitBridge] Read configuration CLI directive (ro0NL) + * bug #34490 [Serializer] Fix MetadataAwareNameConverter usage with string group (antograssiot) + * bug #34632 [Console] Fix trying to access array offset on value of type int (Tavafi) + * bug #34669 [HttpClient] turn exception into log when the request has no content-type (nicolas-grekas) + * bug #34662 [HttpKernel] Support typehint to deprecated FlattenException in controller (andrew-demb) + * bug #34619 Restores preview mode support for Html and Serializer error renderers (yceruto) + * bug #34636 [VarDumper] notice on potential undefined index (sylvainmetayer) + * bug #34668 [Cache] Make sure we get the correct number of values from redis::mget() (thePanz) + * bug #34621 [Routing] Continue supporting single colon in object route loaders (fancyweb) + * bug #34554 [HttpClient] Fix early cleanup of pushed HTTP/2 responses (lyrixx) + * bug #34607 [HttpKernel] Ability to define multiple kernel.reset tags (rmikalkenas) + * bug #34599 [Mailer][Mailchimp Bridge] Throwing undefined index _id when setting message id (monteiro) + * bug #34569 [Workflow] Apply the same logic of precedence between the apply() and the buildTransitionBlockerList() method (lyrixx) + * bug #34580 [HttpKernel] Don't cache "not-fresh" state (nicolas-grekas) + * bug #34577 [FrameworkBundle][Cache] Don't deep-merge cache pools configuration (alxndrbauer) + * bug #34515 [DependencyInjection] definitions are valid objects (xabbuh) + * bug #34536 [SecurityBundle] Don't require a user provider for the anonymous listener (chalasr) + * bug #34533 [Monolog Bridge] Fixed accessing static property as non static. (Sander-Toonen) + * bug #34502 [FrameworkBundle][ContainerLint] Keep "removing" compiler passes (fancyweb) + * bug #34552 [Dotenv] don't fail when referenced env var does not exist (xabbuh) + * bug #34546 [Serializer] Add DateTimeZoneNormalizer into Dependency Injection (jewome62) + * bug #34547 [Messenger] Error when specified default bus is not among the configured (vudaltsov) + * bug #34513 [Validator] remove return type declaration from __sleep() (xabbuh) + * bug #34551 [Security] SwitchUser is broken when the User Provider always returns a valid user (tucksaun) + * bug #34385 Avoid empty "If-Modified-Since" header in validation request (mpdude) + * bug #34458 [Validator] ConstraintValidatorTestCase: add missing return value to mocked validate method calls (ogizanagi) + * bug #34516 [HttpKernel] drop return type declaration (xabbuh) + * bug #34474 [Messenger] Ignore stamps in in-memory transport (tienvx) + * 4.4.0 (2019-11-21) * bug #34464 [Form] group constraints when calling the validator (nicolas-grekas) diff --git a/CHANGELOG-5.0.md b/CHANGELOG-5.0.md index 920d9960fb944..438bdece7ac9d 100644 --- a/CHANGELOG-5.0.md +++ b/CHANGELOG-5.0.md @@ -7,6 +7,86 @@ in 5.0 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/v5.0.0...v5.0.1 +* 5.0.2 (2019-12-19) + + * bug #35051 [DependencyInjection] Fix binding tagged services to containers (nicolas-grekas) + * bug #35039 [DI] skip looking for config class when the extension class is anonymous (nicolas-grekas) + * bug #35049 [ProxyManager] fix generating proxies for root-namespaced classes (nicolas-grekas) + * bug #35022 [Dotenv] FIX missing getenv (mccullagh) + * bug #35023 [HttpKernel] ignore failures generated by opcache.restrict_api (nicolas-grekas) + * bug #35024 [HttpFoundation] fix pdo session handler for sqlsrv (azjezz) + * bug #35025 [HttpClient][Psr18Client] Remove Psr18ExceptionTrait (fancyweb) + * bug #35028 [TwigBridge] Fix invalid typehint for subject in is_granted Twig function (emodric) + * bug #35015 [Config] fix perf of glob discovery when GLOB_BRACE is not available (nicolas-grekas) + * bug #35014 [HttpClient] make pushed responses retry-able (nicolas-grekas) + * bug #35010 [VarDumper] ignore failing __debugInfo() (nicolas-grekas) + * bug #34998 [DI] fix auto-binding service providers to their service subscribers (nicolas-grekas) + * bug #34954 [Mailer] Fixed undefined index when sending via Mandrill API (wulff) + * bug #33670 [DI] Service locators can't be decorated (malarzm) + * bug #35000 [Console][SymfonyQuestionHelper] Handle multibytes question choices keys and custom prompt (fancyweb) + * bug #35005 [HttpClient] force HTTP/1.1 when NTLM auth is used (nicolas-grekas) + * bug #34707 [Validation][FrameworkBundle] Allow EnableAutoMapping to work without auto-mapping namespaces (ogizanagi) + * bug #34996 Fix displaying anonymous classes on PHP 7.4 (nicolas-grekas) + * bug #29839 [Validator] fix comparisons with null values at property paths (xabbuh) + * bug #34900 [DoctrineBridge] Fixed submitting invalid ids when using queries with limit (HeahDude) + * bug #34791 [Serializer] Skip uninitialized (PHP 7.4) properties in PropertyNormalizer and ObjectNormalizer (vudaltsov) + * bug #34956 [Messenger][AMQP] Use delivery_mode=2 by default (lyrixx) + * bug #34915 [FrameworkBundle] Fix invalid Windows path normalization in TemplateNameParser (mvorisek) + * bug #34981 stop using deprecated Doctrine persistence classes (xabbuh) + * bug #34904 [Validator][ConstraintValidator] Safe fail on invalid timezones (fancyweb) + * bug #34935 [FrameworkBundle][DependencyInjection] Skip removed ids in the lint container command and its associated pass (fancyweb) + * bug #34957 [Security] Revert "AbstractAuthenticationListener.php error instead info" (larzuk91) + * bug #34922 [FrameworkBundle][Secrets] Hook configured local dotenv file (fancyweb) + * bug #34967 [HttpFoundation] fix redis multi host dsn not recognized (Jan Christoph Beyer) + * bug #34963 [Lock] fix constructor argument type declaration (xabbuh) + * bug #34955 Require doctrine/persistence ^1.3 (nicolas-grekas) + * bug #34923 [DI] Fix support for immutable setters in CallTrait (Lctrs) + * bug #34878 [TwigBundle] fix broken FilesystemLoader::exists() with Twig 3 (dpesch) + * bug #34921 [HttpFoundation] Removed "Content-Type" from the preferred format guessing mechanism (yceruto) + * bug #34886 [HttpKernel] fix triggering deprecation in file locator (xabbuh) + * bug #34918 [Translation] fix memoryleak in PhpFileLoader (nicolas-grekas) + * bug #34920 [Routing] fix memoryleak when loading compiled routes (nicolas-grekas) + * bug #34787 [Cache] Propagate expiry when syncing items in ChainAdapter (trvrnrth) + * bug #34694 [Validator] Fix auto-mapping constraints should not be validated (ogizanagi) + * bug #34848 [Process] change the syntax of portable command lines (nicolas-grekas) + * bug #34862 [FrameworkBundle][ContainerLintCommand] Reinitialize bundles when the container is reprepared (fancyweb) + * bug #34896 [Cache] fix memory leak when using PhpFilesAdapter (nicolas-grekas) + * bug #34438 [HttpFoundation] Use `Cache-Control: must-revalidate` only if explicit lifetime has been given (mpdude) + * bug #34449 [Yaml] Implement multiline string as scalar block for tagged values (natepage) + * bug #34601 [MonologBridge] Fix debug processor datetime type (mRoca) + * bug #34842 [ExpressionLanguage] Process division by zero (tigr1991) + * bug #34902 [PropertyAccess] forward caught exception (xabbuh) + * bug #34903 Fixing bad order of operations with null coalescing operator (weaverryan) + * bug #34888 [TwigBundle] add tags before processing them (xabbuh) + * bug #34760 [Mailer] Fix SMTP Authentication when using STARTTLS (DjLeChuck) + * bug #34762 [Config] never try loading failed classes twice with ClassExistenceResource (nicolas-grekas) + * bug #34783 [DependencyInjection] Handle env var placeholders in CheckTypeDeclarationsPass (fancyweb) + * bug #34839 [Cache] fix memory leak when using PhpArrayAdapter (nicolas-grekas) + * bug #34801 [String] implement __sleep()/__wakeup() on strings (nicolas-grekas) + * bug #34782 [String] inline Latin-ASCII rules (nicolas-grekas) + * bug #34812 [Yaml] fix parsing negative octal numbers (xabbuh) + * bug #34854 [Messenger] gracefully handle missing event dispatchers (xabbuh) + * bug #34802 [Security] Check UserInterface::getPassword is not null before calling needsRehash (dbrekelmans) + * bug #34788 [SecurityBundle] Properly escape regex in AddSessionDomainConstraintPass (fancyweb) + * bug #34859 [SecurityBundle] Fix TokenStorage::reset not called in stateless firewall (jderusse) + * bug #34827 [HttpFoundation] get currently session.gc_maxlifetime if ttl doesnt exists (rafaeltovar) + * bug #34755 [FrameworkBundle] resolve service locators in `debug:*` commands (nicolas-grekas) + * bug #34832 [Validator] Allow underscore character "_" in URL username and password (romainneutron) + * bug #34765 [DoctrineBridge] Removed QueryBuilder type hint in getLoader() (HeahDude) + * bug #34811 [TwigBridge] Update bootstrap_4_layout.html.twig missing switch-custom label (sabruss) + * bug #34820 [FrameworkBundle][SodiumVault] Create secrets directory only when it is used (fancyweb) + * bug #34776 [DI] fix resolving bindings for named TypedReference (nicolas-grekas) + * bug #34794 [DependencyInjection] Resolve expressions in CheckTypeDeclarationsPass (fancyweb) + * bug #34795 [Routing][ObjectLoader] Remove forgotten deprecation after merge (fancyweb) + * bug #34797 [Translation] Fix FileDumper behavior (yceruto) + * bug #34738 [SecurityBundle] Passwords are not encoded when algorithm set to "true" (nieuwenhuisen) + * bug #34759 [SecurityBundle] Fix switch_user provider configuration handling (fancyweb) + * bug #34779 [Security] do not validate passwords when the hash is null (xabbuh) + * bug #34786 [SecurityBundle] Use config variable in AnonymousFactory (martijnboers) + * bug #34784 [FrameworkBundle] Set the parameter bag as resolved in ContainerLintCommand (fancyweb) + * bug #34763 [Security/Core] Fix checking for SHA256/SHA512 passwords (David Brooks) + * bug #34757 [DI] Fix making the container path-independent when the app is in /app (nicolas-grekas) + * 5.0.1 (2019-12-01) * bug #34732 [DependencyInjection][Xml] Fix the attribute 'tag' is not allowed in 'bind' tag (tienvx) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index ccca55ab4bb11..9a6707977b3ec 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -19,8 +19,8 @@ Symfony is the result of the work of many people who made the code better - Jakub Zalas (jakubzalas) - Javier Eguiluz (javier.eguiluz) - Roland Franssen (ro0) - - Johannes S (johannes) - Grégoire Pineau (lyrixx) + - Johannes S (johannes) - Kris Wallsmith (kriswallsmith) - Yonel Ceruto (yonelceruto) - Hugo Hamon (hhamon) @@ -36,13 +36,13 @@ Symfony is the result of the work of many people who made the code better - Martin Hasoň (hason) - Hamza Amrouche (simperfit) - Jeremy Mikola (jmikola) - - Jean-François Simon (jfsimon) - Jules Pietri (heah) + - Jean-François Simon (jfsimon) - Benjamin Eberlei (beberlei) - Igor Wiedler (igorw) - Jérémy DERUSSÉ (jderusse) - - Eriksen Costa (eriksencosta) - Thomas Calvet (fancyweb) + - Eriksen Costa (eriksencosta) - Guilhem Niot (energetick) - Sarah Khalil (saro0h) - Tobias Nyholm (tobias) @@ -57,15 +57,15 @@ Symfony is the result of the work of many people who made the code better - Francis Besset (francisbesset) - stealth35 ‏ (stealth35) - Alexander Mols (asm89) - - Konstantin Myakshin (koc) - Matthias Pigulla (mpdude) + - Konstantin Myakshin (koc) - Bulat Shakirzyanov (avalanche123) + - Valentin Udaltsov (vudaltsov) - Grégoire Paris (greg0ire) - Saša Stamenković (umpirsky) - Peter Rehm (rpet) - Kevin Bond (kbond) - Henrik Bjørnskov (henrikbjorn) - - Valentin Udaltsov (vudaltsov) - Miha Vrhovnik - Diego Saint Esteben (dii3g0) - Gábor Egyed (1ed) @@ -91,11 +91,11 @@ Symfony is the result of the work of many people who made the code better - Henrik Westphal (snc) - Dariusz Górecki (canni) - David Buchmann (dbu) + - Graham Campbell (graham) - Dariusz Ruminski - Lee McDermott - Brandon Turner - Luis Cordova (cordoval) - - Graham Campbell (graham) - Daniel Holmes (dholmes) - Toni Uebernickel (havvg) - Bart van den Burg (burgov) @@ -109,20 +109,21 @@ Symfony is the result of the work of many people who made the code better - Maxime STEINHAUSSER - Michal Piotrowski (eventhorizon) - Tim Nagel (merk) + - Baptiste Clavié (talus) - Chris Wilkinson (thewilkybarkid) - Brice BERNARD (brikou) - - Baptiste Clavié (talus) - marc.weistroff - Tomáš Votruba (tomas_votruba) + - Peter Kokot (maastermedia) - Jérôme Vasseur (jvasseur) - lenar - Alexander Schwenn (xelaris) - Włodzimierz Gajda (gajdaw) - Sebastiaan Stok (sstok) - Adrien Brault (adrienbrault) - - Peter Kokot (maastermedia) - Jacob Dreesen (jdreesen) - Florian Voutzinos (florianv) + - Teoh Han Hui (teohhanhui) - Colin Frei - Oskar Stark (oskarstark) - Javier Spagnoletti (phansys) @@ -131,13 +132,12 @@ Symfony is the result of the work of many people who made the code better - Daniel Wehner (dawehner) - excelwebzone - Gordon Franke (gimler) - - Teoh Han Hui (teohhanhui) + - Tugdual Saunier (tucksaun) - Fabien Pennequin (fabienpennequin) - Théo FIDRY (theofidry) - Eric GELOEN (gelo) - Joel Wurtz (brouznouf) - Lars Strojny (lstrojny) - - Tugdual Saunier (tucksaun) - Jannik Zschiesche (apfelbox) - Robert Schönthal (digitalkaoz) - Gregor Harlan (gharlan) @@ -209,6 +209,7 @@ Symfony is the result of the work of many people who made the code better - Mario A. Alvarez Garcia (nomack84) - Dennis Benkert (denderello) - DQNEO + - Andre Rømcke (andrerom) - mcfedr (mcfedr) - Ben Davies (bendavies) - Gary PEGEOT (gary-p) @@ -233,7 +234,6 @@ Symfony is the result of the work of many people who made the code better - Pierre Minnieur (pminnieur) - fivestar - Dominique Bongiraud - - Andre Rømcke (andrerom) - Jeremy Livingston (jeremylivingston) - Michael Lee (zerustech) - Matthieu Auger (matthieuauger) @@ -249,6 +249,7 @@ Symfony is the result of the work of many people who made the code better - Michele Orselli (orso) - Sven Paulus (subsven) - Maxime Veber (nek-) + - Anthony GRASSIOT (antograssiot) - Rui Marinho (ruimarinho) - Eugene Wissner - Pascal Montoya @@ -257,8 +258,10 @@ Symfony is the result of the work of many people who made the code better - Tristan Darricau (nicofuma) - Victor Bocharsky (bocharsky_bw) - Marcel Beerta (mazen) + - Maxime Helias (maxhelias) - Pavel Batanov (scaytrase) - Mantis Development + - David Prévot - Loïc Faugeron - Hidde Wieringa (hiddewie) - dFayet @@ -285,7 +288,6 @@ Symfony is the result of the work of many people who made the code better - Xavier Montaña Carreras (xmontana) - Rémon van de Kamp (rpkamp) - Mickaël Andrieu (mickaelandrieu) - - Anthony GRASSIOT (antograssiot) - Xavier Perez - Arjen Brouwer (arjenjb) - Katsuhiro OGAWA @@ -311,13 +313,12 @@ Symfony is the result of the work of many people who made the code better - Smaine Milianni (ismail1432) - Chekote - François Pluchino (francoispluchino) + - Christopher Hertel (chertel) - Antoine Makdessi (amakdessi) - Thomas Adam - Jhonny Lidfors (jhonne) - Diego Agulló (aeoris) - jdhoek - - Maxime Helias (maxhelias) - - David Prévot - Bob den Otter (bopp) - Thomas Schulz (king2500) - Frank de Jonge (frenkynet) @@ -342,6 +343,7 @@ Symfony is the result of the work of many people who made the code better - Arjen van der Meijden - Mathieu Lechat - Marc Weistroff (futurecat) + - Damien Alexandre (damienalexandre) - Simon Mönch (sm) - Christian Schmidt - Patrick Landolt (scube) @@ -349,6 +351,7 @@ Symfony is the result of the work of many people who made the code better - David Badura (davidbadura) - Chad Sikorra (chadsikorra) - Chris Smith (cs278) + - Thomas Bisignani (toma) - Florian Klein (docteurklein) - Manuel Kiessling (manuelkiessling) - Atsuhiro KUBO (iteman) @@ -407,18 +410,17 @@ Symfony is the result of the work of many people who made the code better - Tomasz Kowalczyk (thunderer) - Artur Eshenbrener - Timo Bakx (timobakx) - - Damien Alexandre (damienalexandre) - Thomas Perez (scullwm) - Saif Eddin Gmati (azjezz) - Felix Labrecque - Yaroslav Kiliba - Terje Bråten + - Tien Vo (tienvx) - Robbert Klarenbeek (robbertkl) - Eric Masoero (eric-masoero) - JhonnyL - hossein zolfi (ocean) - Clément Gautier (clementgautier) - - Thomas Bisignani (toma) - Dāvis Zālītis (k0d3r1s) - Sanpi - Eduardo Gulias (egulias) @@ -429,6 +431,7 @@ Symfony is the result of the work of many people who made the code better - Grzegorz (Greg) Zdanowski (kiler129) - Iker Ibarguren (ikerib) - Kirill chEbba Chebunin (chebba) + - Rokas Mikalkėnas (rokasm) - Greg Thornton (xdissent) - Martin Hujer (martinhujer) - Alex Bowers @@ -443,7 +446,6 @@ Symfony is the result of the work of many people who made the code better - Michele Locati - Pavel Volokitin (pvolok) - Valentine Boineau (valentineboineau) - - Christopher Hertel (chertel) - Arthur de Moulins (4rthem) - Matthias Althaus (althaus) - Nicolas Dewez (nicolas_dewez) @@ -476,6 +478,7 @@ Symfony is the result of the work of many people who made the code better - Oscar Cubo Medina (ocubom) - Karel Souffriau - Christophe L. (christophelau) + - Sander Toonen (xatoo) - Anthon Pang (robocoder) - Michael Käfer (michael_kaefer) - Sébastien Santoro (dereckson) @@ -502,6 +505,7 @@ Symfony is the result of the work of many people who made the code better - Olivier Dolbeau (odolbeau) - Jan Rosier (rosier) - Alessandro Lai (jean85) + - Desjardins Jérôme (jewome62) - Arturs Vonda - Josip Kruslin - Matthew Smeets @@ -529,7 +533,6 @@ Symfony is the result of the work of many people who made the code better - Gonzalo Vilaseca (gonzalovilaseca) - Tarmo Leppänen (tarlepp) - Marcin Sikoń (marphi) - - Tien Vo (tienvx) - Denis Brumann (dbrumann) - Dominik Zogg (dominik.zogg) - Marek Pietrzak @@ -540,6 +543,7 @@ Symfony is the result of the work of many people who made the code better - Gintautas Miselis - Rob Bast - Roberto Espinoza (respinoza) + - Emanuele Panzeri (thepanz) - Soufian EZ-ZANTAR (soezz) - Zander Baldwin - Gocha Ossinkine (ossinkine) @@ -603,7 +607,6 @@ Symfony is the result of the work of many people who made the code better - Adam Szaraniec (mimol) - Dariusz Ruminski - Erik Trapman (eriktrapman) - - Rokas Mikalkėnas (rokasm) - De Cock Xavier (xdecock) - Almog Baku (almogbaku) - Karoly Gossler (connorhu) @@ -648,11 +651,11 @@ Symfony is the result of the work of many people who made the code better - Jeremy Benoist - fritzmg - Lenar Lõhmus - - Sander Toonen (xatoo) - Benjamin Laugueux (yzalis) - Zach Badgett (zachbadgett) - Aurélien Fredouelle - Pavel Campr (pcampr) + - Andrii Dembitskyi - Johnny Robeson (johnny) - Marko Kaznovac (kaznovac) - Disquedur @@ -694,7 +697,6 @@ Symfony is the result of the work of many people who made the code better - Sinan Eldem - Alexandre Dupuy (satchette) - Malte Blättermann - - Desjardins Jérôme (jewome62) - Simeon Kolev (simeon_kolev9) - Joost van Driel (j92) - Jonas Elfering @@ -762,11 +764,12 @@ Symfony is the result of the work of many people who made the code better - Giso Stallenberg (gisostallenberg) - Michael Devery (mickadoo) - Antoine Corcy + - Ahmed Ashraf (ahmedash95) - Sascha Grossenbacher - - Emanuele Panzeri (thepanz) - Szijarto Tamas - Robin Lehrmann (robinlehrmann) - Catalin Dan + - Soner Sayakci - Jaroslav Kuba - Kristijan Kanalas - Stephan Vock @@ -825,11 +828,13 @@ Symfony is the result of the work of many people who made the code better - Markus Fasselt (digilist) - Julien DIDIER (juliendidier) - Dominik Ritter (dritter) + - Dimitri Gritsajuk (ottaviano) - Sebastian Grodzicki (sgrodzicki) - Jeroen van den Enden (stoefke) - Pascal Helfenstein - Baldur Rensch (brensch) - Pierre Rineau + - Vilius Grigaliūnas - Vladyslav Petrovych - Alex Xandra Albert Sim - Carson Full @@ -946,6 +951,7 @@ Symfony is the result of the work of many people who made the code better - Patrick Allaert - Gustavo Falco (gfalco) - Matt Robinson (inanimatt) + - Kristof Van Cauwenbergh (kristofvc) - Aleksey Podskrebyshev - Calin Mihai Pristavu - David Marín Carreño (davefx) @@ -984,6 +990,7 @@ Symfony is the result of the work of many people who made the code better - Thomas Landauer - 243083df - Thibault Duplessis + - Rimas Kudelis - Marc Abramowitz - Martijn Evers - Tony Tran @@ -996,12 +1003,12 @@ Symfony is the result of the work of many people who made the code better - Johnson Page (jwpage) - Ruben Gonzalez (rubenruateltek) - Michael Roterman (wtfzdotnet) - - Andrii Dembitskyi - Arno Geurts - Adán Lobato (adanlobato) - Ian Jenkins (jenkoian) - Marcos Gómez Vilches (markitosgv) - Matthew Davis (mdavis1982) + - Markus S. (staabm) - Maks - Antoine LA - den @@ -1187,7 +1194,6 @@ Symfony is the result of the work of many people who made the code better - Sergii Smertin (nfx) - Mikkel Paulson - Michał Strzelecki - - Soner Sayakci - hugofonseca (fonsecas72) - Marc Duboc (icemad) - Matthias Krauser (mkrauser) @@ -1241,6 +1247,7 @@ Symfony is the result of the work of many people who made the code better - Jeremy Bush - wizhippo - Thomason, James + - Dario Savella - Gordienko Vladislav - marie - Viacheslav Sychov @@ -1291,6 +1298,7 @@ Symfony is the result of the work of many people who made the code better - Oxan van Leeuwen - pkowalczyk - Soner Sayakci + - Koen Reiniers (koenre) - Max Voloshin (maxvoloshin) - Nicolas Fabre (nfabre) - Raul Rodriguez (raul782) @@ -1306,6 +1314,8 @@ Symfony is the result of the work of many people who made the code better - Felicitus - Krzysztof Przybyszewski - alexpozzi + - Vladimir + - Jorge Vahldick (jvahldick) - Frederic Godfrin - Paul Matthews - Jakub Kisielewski @@ -1752,7 +1762,6 @@ Symfony is the result of the work of many people who made the code better - downace - Aarón Nieves Fernández - Mike Meier - - Vilius Grigaliūnas - Kirill Saksin - Koalabaerchen - michalmarcinkowski @@ -1765,6 +1774,7 @@ Symfony is the result of the work of many people who made the code better - efeen - Nicolas Pion - Muhammed Akbulut + - Roy-Orbison - Aaron Somi - Michał Dąbrowski (defrag) - Konstantin Grachev (grachevko) @@ -1802,12 +1812,14 @@ Symfony is the result of the work of many people who made the code better - Alexander Li (aweelex) - Bram Van der Sype (brammm) - Guile (guile) + - Mark Beech (jaybizzle) - Julien Moulin (lizjulien) - Raito Akehanareru (raito) - Mauro Foti (skler) - Yannick Warnier (ywarnier) - Kevin Decherf - Jason Woods + - Maria Grazia Patteri - klemens - dened - Dmitry Korotovsky @@ -1823,6 +1835,7 @@ Symfony is the result of the work of many people who made the code better - Sören Bernstein - devel - taiiiraaa + - Ali Tavafi - Trevor Suarez - gedrox - Bohan Yang @@ -1959,6 +1972,7 @@ Symfony is the result of the work of many people who made the code better - Juan M Martínez - Gilles Gauthier - Pavinthan + - Sylvain METAYER - ddebree - Kuba Werłos - Gyula Szucs @@ -2015,6 +2029,7 @@ Symfony is the result of the work of many people who made the code better - Marcin Szepczynski (szepczynski) - Cyrille Jouineau (tuxosaurus) - Vladimir Chernyshev (volch) + - Wim Godden (wimg) - Yorkie Chadwick (yorkie76) - GuillaumeVerdon - Philipp Keck @@ -2026,6 +2041,7 @@ Symfony is the result of the work of many people who made the code better - Taylan Kasap - Michael Orlitzky - Nicolas A. Bérard-Nault + - Quentin Favrie - Saem Ghani - Stefan Oderbolz - Curtis @@ -2051,12 +2067,10 @@ Symfony is the result of the work of many people who made the code better - Jeffrey Moelands (jeffreymoelands) - Hugo Alliaume (kocal) - Simon CONSTANS (kosssi) - - Kristof Van Cauwenbergh (kristofvc) - Dennis Langen (nijusan) - Paulius Jarmalavičius (pjarmalavicius) - Ramon Henrique Ornelas (ramonornela) - Ricardo de Vries (ricknox) - - Markus S. (staabm) - Thomas Dutrion (theocrite) - Till Klampaeckel (till) - Tobias Weinert (tweini) @@ -2074,6 +2088,7 @@ Symfony is the result of the work of many people who made the code better - Cas - Dusan Kasan - Michael Steininger + - Nardberjean - Karolis - Myke79 - Brian Debuire @@ -2145,7 +2160,6 @@ Symfony is the result of the work of many people who made the code better - Daniel STANCU - Ryan Rud - Ondrej Slinták - - Rimas Kudelis - vlechemin - Brian Corrigan - Ladislav Tánczos @@ -2263,6 +2277,7 @@ Symfony is the result of the work of many people who made the code better - Sebastian Landwehr (dword123) - Adel ELHAIBA (eadel) - Damián Nohales (eagleoneraptor) + - Jordane VASPARD (elementaire) - Elliot Anderson (elliot) - Fabien D. (fabd) - Carsten Eilers (fnc) @@ -2277,6 +2292,7 @@ Symfony is the result of the work of many people who made the code better - Peter Orosz (ill_logical) - Imangazaliev Muhammad (imangazaliev) - j0k (j0k) + - Jeremie Broutier (jbroutier) - joris de wit (jdewit) - Jérémy CROMBEZ (jeremy) - Jose Manuel Gonzalez (jgonzalez) @@ -2293,6 +2309,7 @@ Symfony is the result of the work of many people who made the code better - samuel laulhau (lalop) - Laurent Bachelier (laurentb) - Luís Cobucci (lcobucci) + - Jérémy (libertjeremy) - Mehdi Achour (machour) - Matthieu Mota (matthieumota) - Matthieu Moquet (mattketmo) @@ -2300,12 +2317,12 @@ Symfony is the result of the work of many people who made the code better - Michal Čihař (mcihar) - Matt Drollette (mdrollette) - Adam Monsen (meonkeys) + - Hugo Monteiro (monteiro) - Ala Eddine Khefifi (nayzo) - emilienbouard (neime) - Nicholas Byfleet (nickbyfleet) - Marco Petersen (ocrampete16) - ollie harridge (ollietb) - - Dimitri Gritsajuk (ottaviano) - Paul Andrieux (paulandrieux) - Paulo Ribeiro (paulo) - Paweł Szczepanek (pauluz) @@ -2333,6 +2350,7 @@ Symfony is the result of the work of many people who made the code better - Julien Sanchez (sumbobyboys) - Guillermo Gisinger (t3chn0r) - Markus Tacker (tacker) + - Thiago Cordeiro (thiagocordeiro) - Tom Newby (tomnewbyau) - Andrew Clark (tqt_andrew_clark) - David Lumaye (tux1124) @@ -2341,6 +2359,7 @@ Symfony is the result of the work of many people who made the code better - Moritz Kraft (userfriendly) - Víctor Mateo (victormateo) - Vincent (vincent1870) + - Vincent MOULENE (vints24) - David Herrmann (vworldat) - Eugene Babushkin (warl) - Wouter Sioen (wouter_sioen) @@ -2365,6 +2384,7 @@ Symfony is the result of the work of many people who made the code better - damaya - Kevin Weber - Ben Scott + - Alexandru Năstase - Dionysis Arvanitis - Sergey Fedotov - Konstantin Scheumann @@ -2378,6 +2398,7 @@ Symfony is the result of the work of many people who made the code better - Zander Baldwin - Philipp Scheit - max + - Alexander Bauer (abauer) - Ahmad Mayahi (ahmadmayahi) - Mohamed Karnichi (amiral) - Andrew Carter (andrewcarteruk) diff --git a/UPGRADE-4.4.md b/UPGRADE-4.4.md index f3377f43da2eb..3409bea3b5b66 100644 --- a/UPGRADE-4.4.md +++ b/UPGRADE-4.4.md @@ -19,6 +19,7 @@ Debug ----- * Deprecated the component in favor of the `ErrorHandler` component + * Replace uses of `Symfony\Component\Debug\Debug` by `Symfony\Component\ErrorHandler\Debug` Config ------ @@ -164,8 +165,8 @@ Lock * Deprecated `Symfony\Component\Lock\StoreInterface` in favor of `Symfony\Component\Lock\BlockingStoreInterface` and `Symfony\Component\Lock\PersistingStoreInterface`. * `Factory` is deprecated, use `LockFactory` instead - * Deprecated services `lock.store.flock`, `lock.store.semaphore`, `lock.store.memcached.abstract` and `lock.store.redis.abstract`, - use `StoreFactory::createStore` instead. + * Deprecated services `lock.store.flock`, `lock.store.semaphore`, `lock.store.memcached.abstract` and `lock.store.redis.abstract`, + use `StoreFactory::createStore` instead. Mailer ------ @@ -360,6 +361,7 @@ TwigBundle Validator --------- + * [BC BREAK] Using null as `$classValidatorRegexp` value in `DoctrineLoader::__construct` or `PropertyInfoLoader::__construct` will not enable auto-mapping for all classes anymore, use `'{.*}'` instead. * Deprecated passing an `ExpressionLanguage` instance as the second argument of `ExpressionValidator::__construct()`. * Deprecated using anything else than a `string` as the code of a `ConstraintViolation`, a `string` type-hint will be added to the constructor of the `ConstraintViolation` class and to the `ConstraintViolationBuilder::setCode()` diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index 3e67bb5e4d808..7e75c9593fbbc 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -60,6 +60,7 @@ Debug ----- * Removed the component in favor of the `ErrorHandler` component + * Replace uses of `Symfony\Component\Debug\Debug` by `Symfony\Component\ErrorHandler\Debug` DependencyInjection ------------------- diff --git a/composer.json b/composer.json index 7fdb66fac74de..f7e384c6196f4 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "php": "^7.2.5", "ext-xml": "*", "doctrine/event-manager": "~1.0", - "doctrine/persistence": "~1.0", + "doctrine/persistence": "^1.3", "twig/twig": "^2.10|^3.0", "psr/cache": "~1.0", "psr/container": "^1.0", diff --git a/link b/link index 08687bbba5cc7..cea19663e8873 100755 --- a/link +++ b/link @@ -23,11 +23,14 @@ use Symfony\Component\Filesystem\Filesystem; * @author Kévin Dunglas */ +$copy = false !== $k = array_search('--copy', $argv, true); +$copy && array_splice($argv, $k, 1); $pathToProject = $argv[1] ?? getcwd(); if (!is_dir("$pathToProject/vendor/symfony")) { - echo 'Link dependencies to components to a local clone of the main symfony/symfony GitHub repository.'.PHP_EOL.PHP_EOL; - echo "Usage: $argv[0] /path/to/the/project".PHP_EOL.PHP_EOL; + echo 'Link (or copy) dependencies to components to a local clone of the main symfony/symfony GitHub repository.'.PHP_EOL.PHP_EOL; + echo "Usage: $argv[0] /path/to/the/project".PHP_EOL; + echo ' Use `--copy` to copy dependencies instead of symlink'.PHP_EOL.PHP_EOL; echo "The directory \"$pathToProject\" does not exist or the dependencies are not installed, did you forget to run \"composer install\" in your project?".PHP_EOL; exit(1); } @@ -50,7 +53,7 @@ foreach ($directories as $dir) { foreach (glob("$pathToProject/vendor/symfony/*", GLOB_ONLYDIR | GLOB_NOSORT) as $dir) { $package = 'symfony/'.basename($dir); - if (is_link($dir)) { + if (!$copy && is_link($dir)) { echo "\"$package\" is already a symlink, skipping.".PHP_EOL; continue; } @@ -59,11 +62,17 @@ foreach (glob("$pathToProject/vendor/symfony/*", GLOB_ONLYDIR | GLOB_NOSORT) as continue; } - $sfDir = '\\' === DIRECTORY_SEPARATOR ? $sfPackages[$package] : $filesystem->makePathRelative($sfPackages[$package], dirname(realpath($dir))); + $sfDir = ('\\' === DIRECTORY_SEPARATOR || $copy) ? $sfPackages[$package] : $filesystem->makePathRelative($sfPackages[$package], dirname(realpath($dir))); $filesystem->remove($dir); - $filesystem->symlink($sfDir, $dir); - echo "\"$package\" has been linked to \"$sfPackages[$package]\".".PHP_EOL; + + if ($copy) { + $filesystem->mirror($sfDir, $dir); + echo "\"$package\" has been copied from \"$sfPackages[$package]\".".PHP_EOL; + } else { + $filesystem->symlink($sfDir, $dir); + echo "\"$package\" has been linked to \"$sfPackages[$package]\".".PHP_EOL; + } } foreach (glob("$pathToProject/var/cache/*", GLOB_NOSORT) as $cacheDir) { diff --git a/phpunit b/phpunit index b07ca07d06a20..200a9c28b4c34 100755 --- a/phpunit +++ b/phpunit @@ -21,4 +21,14 @@ if (!getenv('SYMFONY_PATCH_TYPE_DECLARATIONS')) { putenv('SYMFONY_PATCH_TYPE_DECLARATIONS=deprecations=1'); } putenv('SYMFONY_PHPUNIT_DIR='.__DIR__.'/.phpunit'); + +if (!getenv('SYMFONY_DEPRECATIONS_HELPER')) { + foreach ($_SERVER['argv'] as $v) { + if (false !== strpos($v, 'Bridge/Doctrine')) { + putenv('SYMFONY_DEPRECATIONS_HELPER=max[indirect]=7'); + break; + } + } +} + require __DIR__.'/vendor/symfony/phpunit-bridge/bin/simple-phpunit'; diff --git a/src/Symfony/Bridge/Doctrine/CHANGELOG.md b/src/Symfony/Bridge/Doctrine/CHANGELOG.md index 69428ea8bf3d3..78ebd8b4b9e77 100644 --- a/src/Symfony/Bridge/Doctrine/CHANGELOG.md +++ b/src/Symfony/Bridge/Doctrine/CHANGELOG.md @@ -12,8 +12,9 @@ CHANGELOG 4.4.0 ----- + * [BC BREAK] using null as `$classValidatorRegexp` value in `DoctrineLoader::__construct` will not enable auto-mapping for all classes anymore, use `'{.*}'` instead. * added `DoctrineClearEntityManagerWorkerSubscriber` - * deprecated `RegistryInterface`, use `Doctrine\Common\Persistence\ManagerRegistry` + * deprecated `RegistryInterface`, use `Doctrine\Persistence\ManagerRegistry` * added support for invokable event listeners * added `getMetadataDriverClass` method to deprecate class parameters in service configuration files diff --git a/src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php b/src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php index d36b3f9a70bdb..0a90bc1a3f86c 100644 --- a/src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php +++ b/src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php @@ -11,7 +11,7 @@ namespace Symfony\Bridge\Doctrine\CacheWarmer; -use Doctrine\Common\Persistence\ManagerRegistry; +use Doctrine\Persistence\ManagerRegistry; use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; /** diff --git a/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php b/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php index c686af5512944..67bf68da01596 100644 --- a/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php +++ b/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php @@ -11,10 +11,10 @@ namespace Symfony\Bridge\Doctrine\DataCollector; -use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\DBAL\Logging\DebugStack; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; +use Doctrine\Persistence\ManagerRegistry; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\DataCollector\DataCollector; diff --git a/src/Symfony/Bridge/Doctrine/DependencyInjection/AbstractDoctrineExtension.php b/src/Symfony/Bridge/Doctrine/DependencyInjection/AbstractDoctrineExtension.php index 14f8b6b8b9846..23230f7e22fa0 100644 --- a/src/Symfony/Bridge/Doctrine/DependencyInjection/AbstractDoctrineExtension.php +++ b/src/Symfony/Bridge/Doctrine/DependencyInjection/AbstractDoctrineExtension.php @@ -228,11 +228,7 @@ protected function assertValidMappingConfiguration(array $mappingConfig, string } if (!\in_array($mappingConfig['type'], ['xml', 'yml', 'annotation', 'php', 'staticphp'])) { - throw new \InvalidArgumentException(sprintf('Can only configure "xml", "yml", "annotation", "php" or '. - '"staticphp" through the DoctrineBundle. Use your own bundle to configure other metadata drivers. '. - 'You can register them by adding a new driver to the '. - '"%s" service definition.', $this->getObjectManagerElementName($objectManagerName.'_metadata_driver') - )); + throw new \InvalidArgumentException(sprintf('Can only configure "xml", "yml", "annotation", "php" or "staticphp" through the DoctrineBundle. Use your own bundle to configure other metadata drivers. You can register them by adding a new driver to the "%s" service definition.', $this->getObjectManagerElementName($objectManagerName.'_metadata_driver'))); } } diff --git a/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterMappingsPass.php b/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterMappingsPass.php index f63aca5937e77..3c06fa25a9311 100644 --- a/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterMappingsPass.php +++ b/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterMappingsPass.php @@ -143,7 +143,7 @@ public function process(ContainerBuilder $container) $mappingDriverDef = $this->getDriver($container); $chainDriverDefService = $this->getChainDriverServiceName($container); - // Definition for a Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain + // Definition for a Doctrine\Persistence\Mapping\Driver\MappingDriverChain $chainDriverDef = $container->getDefinition($chainDriverDefService); foreach ($this->namespaces as $namespace) { $chainDriverDef->addMethodCall('addDriver', [$mappingDriverDef, $namespace]); diff --git a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php index 4e06569b4d6d3..cb09a3d2c1f77 100644 --- a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php +++ b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php @@ -11,7 +11,7 @@ namespace Symfony\Bridge\Doctrine\Form\ChoiceList; -use Doctrine\Common\Persistence\ObjectManager; +use Doctrine\Persistence\ObjectManager; use Symfony\Component\Form\ChoiceList\ArrayChoiceList; use Symfony\Component\Form\ChoiceList\ChoiceListInterface; use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface; diff --git a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/IdReader.php b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/IdReader.php index b255c10364651..195e7ce80f3f4 100644 --- a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/IdReader.php +++ b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/IdReader.php @@ -11,8 +11,8 @@ namespace Symfony\Bridge\Doctrine\Form\ChoiceList; -use Doctrine\Common\Persistence\Mapping\ClassMetadata; -use Doctrine\Common\Persistence\ObjectManager; +use Doctrine\Persistence\Mapping\ClassMetadata; +use Doctrine\Persistence\ObjectManager; use Symfony\Component\Form\Exception\RuntimeException; /** diff --git a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php index 488246e6a8eae..e208c6b21cd46 100644 --- a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php +++ b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php @@ -50,6 +50,21 @@ public function getEntities() */ public function getEntitiesByIds(string $identifier, array $values) { + if (null !== $this->queryBuilder->getMaxResults() || null !== $this->queryBuilder->getFirstResult()) { + // an offset or a limit would apply on results including the where clause with submitted id values + // that could make invalid choices valid + $choices = []; + $metadata = $this->queryBuilder->getEntityManager()->getClassMetadata(current($this->queryBuilder->getRootEntities())); + + foreach ($this->getEntities() as $entity) { + if (\in_array(current($metadata->getIdentifierValues($entity)), $values, true)) { + $choices[] = $entity; + } + } + + return $choices; + } + $qb = clone $this->queryBuilder; $alias = current($qb->getRootAliases()); $parameter = 'ORMQueryBuilderLoader_getEntitiesByIds_'.$identifier; diff --git a/src/Symfony/Bridge/Doctrine/Form/DoctrineOrmExtension.php b/src/Symfony/Bridge/Doctrine/Form/DoctrineOrmExtension.php index 891754a1da08f..c2897c6d9aba8 100644 --- a/src/Symfony/Bridge/Doctrine/Form/DoctrineOrmExtension.php +++ b/src/Symfony/Bridge/Doctrine/Form/DoctrineOrmExtension.php @@ -11,7 +11,7 @@ namespace Symfony\Bridge\Doctrine\Form; -use Doctrine\Common\Persistence\ManagerRegistry; +use Doctrine\Persistence\ManagerRegistry; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractExtension; diff --git a/src/Symfony/Bridge/Doctrine/Form/DoctrineOrmTypeGuesser.php b/src/Symfony/Bridge/Doctrine/Form/DoctrineOrmTypeGuesser.php index d72146eede24a..4374ec36367b2 100644 --- a/src/Symfony/Bridge/Doctrine/Form/DoctrineOrmTypeGuesser.php +++ b/src/Symfony/Bridge/Doctrine/Form/DoctrineOrmTypeGuesser.php @@ -11,12 +11,12 @@ namespace Symfony\Bridge\Doctrine\Form; -use Doctrine\Common\Persistence\ManagerRegistry; -use Doctrine\Common\Persistence\Mapping\MappingException; -use Doctrine\Common\Persistence\Proxy; use Doctrine\DBAL\Types\Type; use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\ORM\Mapping\MappingException as LegacyMappingException; +use Doctrine\Persistence\ManagerRegistry; +use Doctrine\Persistence\Mapping\MappingException; +use Doctrine\Persistence\Proxy; use Symfony\Component\Form\FormTypeGuesserInterface; use Symfony\Component\Form\Guess\Guess; use Symfony\Component\Form\Guess\TypeGuess; diff --git a/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php b/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php index eff1245d41fa2..d7de810b18068 100644 --- a/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php +++ b/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php @@ -12,9 +12,8 @@ namespace Symfony\Bridge\Doctrine\Form\Type; use Doctrine\Common\Collections\Collection; -use Doctrine\Common\Persistence\ManagerRegistry; -use Doctrine\Common\Persistence\ObjectManager; -use Doctrine\ORM\QueryBuilder; +use Doctrine\Persistence\ManagerRegistry; +use Doctrine\Persistence\ObjectManager; use Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader; use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface; use Symfony\Bridge\Doctrine\Form\ChoiceList\IdReader; @@ -185,7 +184,6 @@ public function configureOptions(OptionsResolver $resolver) }; $emNormalizer = function (Options $options, $em) { - /* @var ManagerRegistry $registry */ if (null !== $em) { if ($em instanceof ObjectManager) { return $em; @@ -257,15 +255,17 @@ public function configureOptions(OptionsResolver $resolver) $resolver->setNormalizer('query_builder', $queryBuilderNormalizer); $resolver->setNormalizer('id_reader', $idReaderNormalizer); - $resolver->setAllowedTypes('em', ['null', 'string', 'Doctrine\Common\Persistence\ObjectManager']); + $resolver->setAllowedTypes('em', ['null', 'string', ObjectManager::class]); } /** * Return the default loader object. * + * @param mixed $queryBuilder + * * @return EntityLoaderInterface */ - abstract public function getLoader(ObjectManager $manager, QueryBuilder $queryBuilder, string $class); + abstract public function getLoader(ObjectManager $manager, $queryBuilder, string $class); public function getParent() { diff --git a/src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php b/src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php index 6429ede4ca4ab..e4dafdd0858be 100644 --- a/src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php +++ b/src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php @@ -11,9 +11,9 @@ namespace Symfony\Bridge\Doctrine\Form\Type; -use Doctrine\Common\Persistence\ObjectManager; use Doctrine\ORM\Query\Parameter; use Doctrine\ORM\QueryBuilder; +use Doctrine\Persistence\ObjectManager; use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader; use Symfony\Component\Form\Exception\UnexpectedTypeException; use Symfony\Component\OptionsResolver\Options; @@ -46,9 +46,11 @@ public function configureOptions(OptionsResolver $resolver) /** * Return the default loader object. * + * @param QueryBuilder $queryBuilder + * * @return ORMQueryBuilderLoader */ - public function getLoader(ObjectManager $manager, QueryBuilder $queryBuilder, string $class) + public function getLoader(ObjectManager $manager, $queryBuilder, string $class) { if (!$queryBuilder instanceof QueryBuilder) { throw new \TypeError(sprintf('Expected an instance of %s, but got %s.', QueryBuilder::class, \is_object($queryBuilder) ? \get_class($queryBuilder) : \gettype($queryBuilder))); diff --git a/src/Symfony/Bridge/Doctrine/ManagerRegistry.php b/src/Symfony/Bridge/Doctrine/ManagerRegistry.php index a81357a121089..ab76c4c08a778 100644 --- a/src/Symfony/Bridge/Doctrine/ManagerRegistry.php +++ b/src/Symfony/Bridge/Doctrine/ManagerRegistry.php @@ -11,7 +11,7 @@ namespace Symfony\Bridge\Doctrine; -use Doctrine\Common\Persistence\AbstractManagerRegistry; +use Doctrine\Persistence\AbstractManagerRegistry; use ProxyManager\Proxy\LazyLoadingInterface; use Symfony\Component\DependencyInjection\Container; @@ -54,17 +54,13 @@ protected function resetService($name) } $manager->setProxyInitializer(\Closure::bind( function (&$wrappedInstance, LazyLoadingInterface $manager) use ($name) { - if (isset($this->normalizedIds[$normalizedId = strtolower($name)])) { // BC with DI v3.4 - $name = $this->normalizedIds[$normalizedId]; - } if (isset($this->aliases[$name])) { $name = $this->aliases[$name]; } if (isset($this->fileMap[$name])) { $wrappedInstance = $this->load($this->fileMap[$name]); } else { - $method = $this->methodMap[$name] ?? 'get'.strtr($name, $this->underscoreMap).'Service'; // BC with DI v3.4 - $wrappedInstance = $this->{$method}(false); + $wrappedInstance = $this->{$this->methodMap[$name]}(false); } $manager->setProxyInitializer(null); diff --git a/src/Symfony/Bridge/Doctrine/Messenger/AbstractDoctrineMiddleware.php b/src/Symfony/Bridge/Doctrine/Messenger/AbstractDoctrineMiddleware.php index a29c95af3da03..9fbf2deb963e3 100644 --- a/src/Symfony/Bridge/Doctrine/Messenger/AbstractDoctrineMiddleware.php +++ b/src/Symfony/Bridge/Doctrine/Messenger/AbstractDoctrineMiddleware.php @@ -11,8 +11,8 @@ namespace Symfony\Bridge\Doctrine\Messenger; -use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\Persistence\ManagerRegistry; use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException; use Symfony\Component\Messenger\Middleware\MiddlewareInterface; diff --git a/src/Symfony/Bridge/Doctrine/Messenger/DoctrineClearEntityManagerWorkerSubscriber.php b/src/Symfony/Bridge/Doctrine/Messenger/DoctrineClearEntityManagerWorkerSubscriber.php index 8fad66c77bd6d..d702186a713ce 100644 --- a/src/Symfony/Bridge/Doctrine/Messenger/DoctrineClearEntityManagerWorkerSubscriber.php +++ b/src/Symfony/Bridge/Doctrine/Messenger/DoctrineClearEntityManagerWorkerSubscriber.php @@ -11,7 +11,7 @@ namespace Symfony\Bridge\Doctrine\Messenger; -use Doctrine\Common\Persistence\ManagerRegistry; +use Doctrine\Persistence\ManagerRegistry; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Messenger\Event\WorkerMessageFailedEvent; use Symfony\Component\Messenger\Event\WorkerMessageHandledEvent; diff --git a/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php b/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php index 896be36f84540..bc8198283e051 100644 --- a/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php +++ b/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php @@ -11,12 +11,12 @@ namespace Symfony\Bridge\Doctrine\PropertyInfo; -use Doctrine\Common\Persistence\Mapping\MappingException; use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\ORM\Mapping\MappingException as OrmMappingException; +use Doctrine\Persistence\Mapping\MappingException; use Symfony\Component\PropertyInfo\PropertyAccessExtractorInterface; use Symfony\Component\PropertyInfo\PropertyListExtractorInterface; use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface; diff --git a/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php b/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php index 17c8b4a328350..01b2d647afa68 100644 --- a/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php +++ b/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php @@ -11,10 +11,10 @@ namespace Symfony\Bridge\Doctrine\Security\User; -use Doctrine\Common\Persistence\ManagerRegistry; -use Doctrine\Common\Persistence\Mapping\ClassMetadata; -use Doctrine\Common\Persistence\ObjectManager; -use Doctrine\Common\Persistence\ObjectRepository; +use Doctrine\Persistence\ManagerRegistry; +use Doctrine\Persistence\Mapping\ClassMetadata; +use Doctrine\Persistence\ObjectManager; +use Doctrine\Persistence\ObjectRepository; use Symfony\Component\Security\Core\Exception\UnsupportedUserException; use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; use Symfony\Component\Security\Core\User\PasswordUpgraderInterface; @@ -87,11 +87,7 @@ public function refreshUser(UserInterface $user) // That's the case when the user has been changed by a form with // validation errors. if (!$id = $this->getClassMetadata()->getIdentifierValues($user)) { - throw new \InvalidArgumentException('You cannot refresh a user '. - 'from the EntityUserProvider that does not contain an identifier. '. - 'The user object has to be serialized with its own identifier '. - 'mapped by Doctrine.' - ); + throw new \InvalidArgumentException('You cannot refresh a user from the EntityUserProvider that does not contain an identifier. The user object has to be serialized with its own identifier mapped by Doctrine.'); } $refreshedUser = $repository->find($id); diff --git a/src/Symfony/Bridge/Doctrine/Test/DoctrineTestHelper.php b/src/Symfony/Bridge/Doctrine/Test/DoctrineTestHelper.php index 090007c06980a..2ad16dcd4de24 100644 --- a/src/Symfony/Bridge/Doctrine/Test/DoctrineTestHelper.php +++ b/src/Symfony/Bridge/Doctrine/Test/DoctrineTestHelper.php @@ -13,12 +13,12 @@ use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\Cache\ArrayCache; -use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain; -use Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Mapping\Driver\XmlDriver; +use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; +use Doctrine\Persistence\Mapping\Driver\SymfonyFileLocator; use PHPUnit\Framework\TestCase; /** diff --git a/src/Symfony/Bridge/Doctrine/Test/TestRepositoryFactory.php b/src/Symfony/Bridge/Doctrine/Test/TestRepositoryFactory.php index 0a44dcbf85da9..6197c6ae5169c 100644 --- a/src/Symfony/Bridge/Doctrine/Test/TestRepositoryFactory.php +++ b/src/Symfony/Bridge/Doctrine/Test/TestRepositoryFactory.php @@ -11,10 +11,10 @@ namespace Symfony\Bridge\Doctrine\Test; -use Doctrine\Common\Persistence\ObjectRepository; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Repository\RepositoryFactory; +use Doctrine\Persistence\ObjectRepository; /** * @author Andreas Braun @@ -28,8 +28,10 @@ final class TestRepositoryFactory implements RepositoryFactory /** * {@inheritdoc} + * + * @return ObjectRepository */ - public function getRepository(EntityManagerInterface $entityManager, $entityName): ObjectRepository + public function getRepository(EntityManagerInterface $entityManager, $entityName) { $repositoryHash = $this->getRepositoryHash($entityManager, $entityName); diff --git a/src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php b/src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php index 13a6c70669eeb..5569316441afd 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php @@ -13,6 +13,7 @@ use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Version; +use Doctrine\Persistence\ManagerRegistry; use PHPUnit\Framework\TestCase; use Symfony\Bridge\Doctrine\DataCollector\DoctrineDataCollector; use Symfony\Component\HttpFoundation\Request; @@ -235,7 +236,7 @@ private function createCollector($queries) ->method('getDatabasePlatform') ->willReturn(new MySqlPlatform()); - $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock(); + $registry = $this->getMockBuilder(ManagerRegistry::class)->getMock(); $registry ->expects($this->any()) ->method('getConnectionNames') diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/ContainerAwareFixture.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/ContainerAwareFixture.php index 6c3f880eaacf9..6655033ab4999 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/ContainerAwareFixture.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/ContainerAwareFixture.php @@ -12,7 +12,7 @@ namespace Symfony\Bridge\Doctrine\Tests\Fixtures; use Doctrine\Common\DataFixtures\FixtureInterface; -use Doctrine\Common\Persistence\ObjectManager; +use Doctrine\Persistence\ObjectManager; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerInterface; diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/DoctrineChoiceLoaderTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/DoctrineChoiceLoaderTest.php index c2c720a390d13..182f2703e0ac3 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/DoctrineChoiceLoaderTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/DoctrineChoiceLoaderTest.php @@ -11,9 +11,9 @@ namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList; -use Doctrine\Common\Persistence\ObjectManager; -use Doctrine\Common\Persistence\ObjectRepository; use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\Persistence\ObjectManager; +use Doctrine\Persistence\ObjectRepository; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader; @@ -75,8 +75,8 @@ class DoctrineChoiceLoaderTest extends TestCase protected function setUp(): void { $this->factory = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface')->getMock(); - $this->om = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager')->getMock(); - $this->repository = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectRepository')->getMock(); + $this->om = $this->getMockBuilder(ObjectManager::class)->getMock(); + $this->repository = $this->getMockBuilder(ObjectRepository::class)->getMock(); $this->class = 'stdClass'; $this->idReader = $this->getMockBuilder('Symfony\Bridge\Doctrine\Form\ChoiceList\IdReader') ->disableOriginalConstructor() diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/DoctrineOrmTypeGuesserTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/DoctrineOrmTypeGuesserTest.php index d2e101b4cdc58..50f222d8e8c59 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/DoctrineOrmTypeGuesserTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/DoctrineOrmTypeGuesserTest.php @@ -11,7 +11,9 @@ namespace Symfony\Bridge\Doctrine\Tests\Form; -use Doctrine\Common\Persistence\Mapping\ClassMetadata; +use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\Persistence\ManagerRegistry; +use Doctrine\Persistence\ObjectManager; use PHPUnit\Framework\TestCase; use Symfony\Bridge\Doctrine\Form\DoctrineOrmTypeGuesser; use Symfony\Component\Form\Guess\Guess; @@ -83,10 +85,10 @@ public function requiredProvider() private function getGuesser(ClassMetadata $classMetadata) { - $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager')->getMock(); + $em = $this->getMockBuilder(ObjectManager::class)->getMock(); $em->expects($this->once())->method('getClassMetaData')->with('TestEntity')->willReturn($classMetadata); - $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock(); + $registry = $this->getMockBuilder(ManagerRegistry::class)->getMock(); $registry->expects($this->once())->method('getManagers')->willReturn([$em]); return new DoctrineOrmTypeGuesser($registry); diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypePerformanceTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypePerformanceTest.php index 53be11f6d1ac8..89aa779301350 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypePerformanceTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypePerformanceTest.php @@ -12,6 +12,7 @@ namespace Symfony\Bridge\Doctrine\Tests\Form\Type; use Doctrine\ORM\Tools\SchemaTool; +use Doctrine\Persistence\ManagerRegistry; use Symfony\Bridge\Doctrine\Form\DoctrineOrmExtension; use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper; use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity; @@ -34,7 +35,7 @@ class EntityTypePerformanceTest extends FormPerformanceTestCase protected function getExtensions() { - $manager = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock(); + $manager = $this->getMockBuilder(ManagerRegistry::class)->getMock(); $manager->expects($this->any()) ->method('getManager') diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php index 933b30cff3e0f..3454b6f1172b1 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php @@ -12,10 +12,10 @@ namespace Symfony\Bridge\Doctrine\Tests\Form\Type; use Doctrine\Common\Collections\ArrayCollection; -use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Tools\SchemaTool; +use Doctrine\Persistence\ManagerRegistry; use PHPUnit\Framework\MockObject\MockObject; use Symfony\Bridge\Doctrine\Form\DoctrineOrmExtension; use Symfony\Bridge\Doctrine\Form\DoctrineOrmTypeGuesser; @@ -953,6 +953,31 @@ public function testDisallowChoicesThatAreNotIncludedQueryBuilderSingleIdentifie $this->assertNull($field->getData()); } + public function testDisallowChoicesThatAreNotIncludedQueryBuilderSingleIdentifierWithLimit() + { + $entity1 = new SingleIntIdEntity(1, 'Foo'); + $entity2 = new SingleIntIdEntity(2, 'Bar'); + $entity3 = new SingleIntIdEntity(3, 'Baz'); + + $this->persist([$entity1, $entity2, $entity3]); + + $repository = $this->em->getRepository(self::SINGLE_IDENT_CLASS); + + $field = $this->factory->createNamed('name', static::TESTED_TYPE, null, [ + 'em' => 'default', + 'class' => self::SINGLE_IDENT_CLASS, + 'query_builder' => $repository->createQueryBuilder('e') + ->where('e.id IN (1, 2, 3)') + ->setMaxResults(1), + 'choice_label' => 'name', + ]); + + $field->submit('3'); + + $this->assertFalse($field->isSynchronized()); + $this->assertNull($field->getData()); + } + public function testDisallowChoicesThatAreNotIncludedQueryBuilderSingleAssocIdentifier() { $innerEntity1 = new SingleIntIdNoToStringEntity(1, 'InFoo'); @@ -1226,7 +1251,7 @@ public function testLoaderCachingWithParameters() protected function createRegistryMock($name, $em) { - $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock(); + $registry = $this->getMockBuilder(ManagerRegistry::class)->getMock(); $registry->expects($this->any()) ->method('getManager') ->with($this->equalTo($name)) diff --git a/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrineClearEntityManagerWorkerSubscriberTest.php b/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrineClearEntityManagerWorkerSubscriberTest.php index 6a76cf8ad0739..a4cc5ffb87083 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrineClearEntityManagerWorkerSubscriberTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrineClearEntityManagerWorkerSubscriberTest.php @@ -11,8 +11,8 @@ namespace Symfony\Bridge\Doctrine\Tests\Messenger; -use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\Persistence\ManagerRegistry; use Symfony\Bridge\Doctrine\Messenger\DoctrineClearEntityManagerWorkerSubscriber; use Symfony\Component\Messenger\Test\Middleware\MiddlewareTestCase; diff --git a/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrineCloseConnectionMiddlewareTest.php b/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrineCloseConnectionMiddlewareTest.php index 5a0b7a7452f7a..ef5564eca4e95 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrineCloseConnectionMiddlewareTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrineCloseConnectionMiddlewareTest.php @@ -11,9 +11,9 @@ namespace Symfony\Bridge\Doctrine\Tests\Messenger; -use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\DBAL\Connection; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\Persistence\ManagerRegistry; use Symfony\Bridge\Doctrine\Messenger\DoctrineCloseConnectionMiddleware; use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException; diff --git a/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrinePingConnectionMiddlewareTest.php b/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrinePingConnectionMiddlewareTest.php index 446d63013d79f..a0932371dfbfd 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrinePingConnectionMiddlewareTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrinePingConnectionMiddlewareTest.php @@ -11,9 +11,9 @@ namespace Symfony\Bridge\Doctrine\Tests\Messenger; -use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\DBAL\Connection; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\Persistence\ManagerRegistry; use Symfony\Bridge\Doctrine\Messenger\DoctrinePingConnectionMiddleware; use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException; diff --git a/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrineTransactionMiddlewareTest.php b/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrineTransactionMiddlewareTest.php index d6f15e20137a7..be850277e6841 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrineTransactionMiddlewareTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrineTransactionMiddlewareTest.php @@ -11,9 +11,9 @@ namespace Symfony\Bridge\Doctrine\Tests\Messenger; -use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\DBAL\Connection; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\Persistence\ManagerRegistry; use Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddleware; use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException; diff --git a/src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php b/src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php index 5988aafefc749..10ff2ff259718 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php @@ -11,8 +11,10 @@ namespace Symfony\Bridge\Doctrine\Tests\Security\User; -use Doctrine\Common\Persistence\ObjectRepository; use Doctrine\ORM\Tools\SchemaTool; +use Doctrine\Persistence\ManagerRegistry; +use Doctrine\Persistence\ObjectManager; +use Doctrine\Persistence\ObjectRepository; use PHPUnit\Framework\TestCase; use Symfony\Bridge\Doctrine\Security\User\EntityUserProvider; use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface; @@ -180,7 +182,7 @@ public function testPasswordUpgrades() { $user = new User(1, 1, 'user1'); - $repository = $this->createMock([ObjectRepository::class, PasswordUpgraderInterface::class]); + $repository = $this->createMock([interface_exists(ObjectRepository::class) ? ObjectRepository::class : LegacyObjectRepository::class, PasswordUpgraderInterface::class]); $repository->expects($this->once()) ->method('upgradePassword') ->with($user, 'foobar'); @@ -195,7 +197,7 @@ public function testPasswordUpgrades() private function getManager($em, $name = null) { - $manager = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock(); + $manager = $this->getMockBuilder(ManagerRegistry::class)->getMock(); $manager->expects($this->any()) ->method('getManager') ->with($this->equalTo($name)) @@ -206,7 +208,7 @@ private function getManager($em, $name = null) private function getObjectManager($repository) { - $em = $this->getMockBuilder('\Doctrine\Common\Persistence\ObjectManager') + $em = $this->getMockBuilder(ObjectManager::class) ->setMethods(['getClassMetadata', 'getRepository']) ->getMockForAbstractClass(); $em->expects($this->any()) diff --git a/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php b/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php index fdf0b550ce2f8..e9e905c89c3a4 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php @@ -12,11 +12,12 @@ namespace Symfony\Bridge\Doctrine\Tests\Validator\Constraints; use Doctrine\Common\Collections\ArrayCollection; -use Doctrine\Common\Persistence\ManagerRegistry; -use Doctrine\Common\Persistence\ObjectManager; -use Doctrine\Common\Persistence\ObjectRepository; use Doctrine\DBAL\Types\Type; use Doctrine\ORM\Tools\SchemaTool; +use Doctrine\Persistence\ManagerRegistry; +use Doctrine\Persistence\Mapping\ClassMetadata; +use Doctrine\Persistence\ObjectManager; +use Doctrine\Persistence\ObjectRepository; use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper; use Symfony\Bridge\Doctrine\Test\TestRepositoryFactory; use Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity; @@ -76,9 +77,9 @@ protected function setUp(): void parent::setUp(); } - protected function createRegistryMock(ObjectManager $em = null) + protected function createRegistryMock($em = null) { - $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock(); + $registry = $this->getMockBuilder(ManagerRegistry::class)->getMock(); $registry->expects($this->any()) ->method('getManager') ->with($this->equalTo(self::EM_NAME)) @@ -89,7 +90,7 @@ protected function createRegistryMock(ObjectManager $em = null) protected function createRepositoryMock() { - $repository = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectRepository') + $repository = $this->getMockBuilder(ObjectRepository::class) ->setMethods(['findByCustom', 'find', 'findAll', 'findOneBy', 'findBy', 'getClassName']) ->getMock() ; @@ -99,7 +100,7 @@ protected function createRepositoryMock() protected function createEntityManagerMock($repositoryMock) { - $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') + $em = $this->getMockBuilder(ObjectManager::class) ->getMock() ; $em->expects($this->any()) @@ -107,7 +108,7 @@ protected function createEntityManagerMock($repositoryMock) ->willReturn($repositoryMock) ; - $classMetadata = $this->getMockBuilder('Doctrine\Common\Persistence\Mapping\ClassMetadata')->getMock(); + $classMetadata = $this->getMockBuilder(ClassMetadata::class)->getMock(); $classMetadata ->expects($this->any()) ->method('hasField') @@ -141,7 +142,7 @@ protected function createValidator() return new UniqueEntityValidator($this->registry); } - private function createSchema(ObjectManager $em) + private function createSchema($em) { $schemaTool = new SchemaTool($em); $schemaTool->createSchema([ diff --git a/src/Symfony/Bridge/Doctrine/Tests/Validator/DoctrineLoaderTest.php b/src/Symfony/Bridge/Doctrine/Tests/Validator/DoctrineLoaderTest.php index 59163de651815..35a90044f7bab 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Validator/DoctrineLoaderTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Validator/DoctrineLoaderTest.php @@ -21,15 +21,15 @@ use Symfony\Bridge\Doctrine\Tests\Fixtures\DoctrineLoaderParentEntity; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Bridge\Doctrine\Validator\DoctrineLoader; -use Symfony\Component\Validator\Constraints\DisableAutoMapping; use Symfony\Component\Validator\Constraints\Length; +use Symfony\Component\Validator\Mapping\AutoMappingStrategy; use Symfony\Component\Validator\Mapping\CascadingStrategy; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AutoMappingTrait; +use Symfony\Component\Validator\Mapping\PropertyMetadata; use Symfony\Component\Validator\Mapping\TraversalStrategy; use Symfony\Component\Validator\Tests\Fixtures\Entity; use Symfony\Component\Validator\Validation; -use Symfony\Component\Validator\ValidatorBuilder; /** * @author Kévin Dunglas @@ -140,19 +140,16 @@ public function testLoadClassMetadata() $this->assertInstanceOf(Length::class, $textFieldConstraints[0]); $this->assertSame(1000, $textFieldConstraints[0]->max); + /** @var PropertyMetadata[] $noAutoMappingMetadata */ $noAutoMappingMetadata = $classMetadata->getPropertyMetadata('noAutoMapping'); $this->assertCount(1, $noAutoMappingMetadata); $noAutoMappingConstraints = $noAutoMappingMetadata[0]->getConstraints(); - $this->assertCount(1, $noAutoMappingConstraints); - $this->assertInstanceOf(DisableAutoMapping::class, $noAutoMappingConstraints[0]); + $this->assertCount(0, $noAutoMappingConstraints); + $this->assertSame(AutoMappingStrategy::DISABLED, $noAutoMappingMetadata[0]->getAutoMappingStrategy()); } public function testFieldMappingsConfiguration() { - if (!method_exists(ValidatorBuilder::class, 'addLoader')) { - $this->markTestSkipped('Auto-mapping requires symfony/validation 4.2+'); - } - $validator = Validation::createValidatorBuilder() ->enableAnnotationMapping() ->addXmlMappings([__DIR__.'/../Resources/validator/BaseUser.xml']) @@ -176,7 +173,7 @@ public function testFieldMappingsConfiguration() */ public function testClassValidator(bool $expected, string $classValidatorRegexp = null) { - $doctrineLoader = new DoctrineLoader(DoctrineTestHelper::createTestEntityManager(), $classValidatorRegexp); + $doctrineLoader = new DoctrineLoader(DoctrineTestHelper::createTestEntityManager(), $classValidatorRegexp, false); $classMetadata = new ClassMetadata(DoctrineLoaderEntity::class); $this->assertSame($expected, $doctrineLoader->loadClassMetadata($classMetadata)); @@ -185,7 +182,8 @@ public function testClassValidator(bool $expected, string $classValidatorRegexp public function regexpProvider() { return [ - [true, null], + [false, null], + [true, '{.*}'], [true, '{^'.preg_quote(DoctrineLoaderEntity::class).'$|^'.preg_quote(Entity::class).'$}'], [false, '{^'.preg_quote(Entity::class).'$}'], ]; @@ -193,25 +191,23 @@ public function regexpProvider() public function testClassNoAutoMapping() { - if (!method_exists(ValidatorBuilder::class, 'addLoader')) { - $this->markTestSkipped('Auto-mapping requires symfony/validation 4.2+'); - } - $validator = Validation::createValidatorBuilder() ->enableAnnotationMapping() - ->addLoader(new DoctrineLoader(DoctrineTestHelper::createTestEntityManager())) + ->addLoader(new DoctrineLoader(DoctrineTestHelper::createTestEntityManager(), '{.*}')) ->getValidator(); $classMetadata = $validator->getMetadataFor(new DoctrineLoaderNoAutoMappingEntity()); $classConstraints = $classMetadata->getConstraints(); - $this->assertCount(1, $classConstraints); - $this->assertInstanceOf(DisableAutoMapping::class, $classConstraints[0]); + $this->assertCount(0, $classConstraints); + $this->assertSame(AutoMappingStrategy::DISABLED, $classMetadata->getAutoMappingStrategy()); $maxLengthMetadata = $classMetadata->getPropertyMetadata('maxLength'); $this->assertEmpty($maxLengthMetadata); + /** @var PropertyMetadata[] $autoMappingExplicitlyEnabledMetadata */ $autoMappingExplicitlyEnabledMetadata = $classMetadata->getPropertyMetadata('autoMappingExplicitlyEnabled'); - $this->assertCount(2, $autoMappingExplicitlyEnabledMetadata[0]->constraints); + $this->assertCount(1, $autoMappingExplicitlyEnabledMetadata[0]->constraints); + $this->assertSame(AutoMappingStrategy::ENABLED, $autoMappingExplicitlyEnabledMetadata[0]->getAutoMappingStrategy()); } } diff --git a/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php b/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php index 312b84a71abc8..35f723aa88d9f 100644 --- a/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php +++ b/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php @@ -11,9 +11,7 @@ namespace Symfony\Bridge\Doctrine\Validator\Constraints; -use Doctrine\Common\Persistence\ManagerRegistry; -use Doctrine\Common\Persistence\Mapping\ClassMetadata; -use Doctrine\Common\Persistence\ObjectManager; +use Doctrine\Persistence\ManagerRegistry; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; use Symfony\Component\Validator\Exception\ConstraintDefinitionException; @@ -42,7 +40,7 @@ public function __construct(ManagerRegistry $registry) public function validate($entity, Constraint $constraint) { if (!$constraint instanceof UniqueEntity) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\UniqueEntity'); + throw new UnexpectedTypeException($constraint, UniqueEntity::class); } if (!\is_array($constraint->fields) && !\is_string($constraint->fields)) { @@ -78,7 +76,6 @@ public function validate($entity, Constraint $constraint) } $class = $em->getClassMetadata(\get_class($entity)); - /* @var $class \Doctrine\Common\Persistence\Mapping\ClassMetadata */ $criteria = []; $hasNullValue = false; @@ -179,7 +176,7 @@ public function validate($entity, Constraint $constraint) ->addViolation(); } - private function formatWithIdentifiers(ObjectManager $em, ClassMetadata $class, $value) + private function formatWithIdentifiers($em, $class, $value) { if (!\is_object($value) || $value instanceof \DateTimeInterface) { return $this->formatValue($value, self::PRETTY_DATE); diff --git a/src/Symfony/Bridge/Doctrine/Validator/DoctrineInitializer.php b/src/Symfony/Bridge/Doctrine/Validator/DoctrineInitializer.php index 3b482565a8dfe..28d5fccc7459c 100644 --- a/src/Symfony/Bridge/Doctrine/Validator/DoctrineInitializer.php +++ b/src/Symfony/Bridge/Doctrine/Validator/DoctrineInitializer.php @@ -11,7 +11,7 @@ namespace Symfony\Bridge\Doctrine\Validator; -use Doctrine\Common\Persistence\ManagerRegistry; +use Doctrine\Persistence\ManagerRegistry; use Symfony\Component\Validator\ObjectInitializerInterface; /** diff --git a/src/Symfony/Bridge/Doctrine/Validator/DoctrineLoader.php b/src/Symfony/Bridge/Doctrine/Validator/DoctrineLoader.php index 7cfde6515ccc8..ca9eb4fab168c 100644 --- a/src/Symfony/Bridge/Doctrine/Validator/DoctrineLoader.php +++ b/src/Symfony/Bridge/Doctrine/Validator/DoctrineLoader.php @@ -11,15 +11,14 @@ namespace Symfony\Bridge\Doctrine\Validator; -use Doctrine\Common\Persistence\Mapping\MappingException; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\ORM\Mapping\MappingException as OrmMappingException; +use Doctrine\Persistence\Mapping\MappingException; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; -use Symfony\Component\Validator\Constraints\DisableAutoMapping; -use Symfony\Component\Validator\Constraints\EnableAutoMapping; use Symfony\Component\Validator\Constraints\Length; use Symfony\Component\Validator\Constraints\Valid; +use Symfony\Component\Validator\Mapping\AutoMappingStrategy; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AutoMappingTrait; use Symfony\Component\Validator\Mapping\Loader\LoaderInterface; @@ -76,13 +75,16 @@ public function loadClassMetadata(ClassMetadata $metadata): bool $enabledForProperty = $enabledForClass; $lengthConstraint = null; foreach ($metadata->getPropertyMetadata($mapping['fieldName']) as $propertyMetadata) { + // Enabling or disabling auto-mapping explicitly always takes precedence + if (AutoMappingStrategy::DISABLED === $propertyMetadata->getAutoMappingStrategy()) { + continue 2; + } + if (AutoMappingStrategy::ENABLED === $propertyMetadata->getAutoMappingStrategy()) { + $enabledForProperty = true; + } + foreach ($propertyMetadata->getConstraints() as $constraint) { - // Enabling or disabling auto-mapping explicitly always takes precedence - if ($constraint instanceof DisableAutoMapping) { - continue 3; - } elseif ($constraint instanceof EnableAutoMapping) { - $enabledForProperty = true; - } elseif ($constraint instanceof Length) { + if ($constraint instanceof Length) { $lengthConstraint = $constraint; } } diff --git a/src/Symfony/Bridge/Doctrine/composer.json b/src/Symfony/Bridge/Doctrine/composer.json index 4ae71532dfd69..bf8b981f583c3 100644 --- a/src/Symfony/Bridge/Doctrine/composer.json +++ b/src/Symfony/Bridge/Doctrine/composer.json @@ -18,7 +18,7 @@ "require": { "php": "^7.2.5", "doctrine/event-manager": "~1.0", - "doctrine/persistence": "~1.0", + "doctrine/persistence": "^1.3", "symfony/polyfill-ctype": "~1.8", "symfony/polyfill-mbstring": "~1.0", "symfony/service-contracts": "^1.1|^2" @@ -35,7 +35,7 @@ "symfony/proxy-manager-bridge": "^4.4|^5.0", "symfony/security-core": "^5.0", "symfony/expression-language": "^4.4|^5.0", - "symfony/validator": "^5.0", + "symfony/validator": "^5.0.2", "symfony/translation": "^4.4|^5.0", "symfony/var-dumper": "^4.4|^5.0", "doctrine/annotations": "~1.7", @@ -55,7 +55,7 @@ "symfony/property-info": "<5", "symfony/security-bundle": "<5", "symfony/security-core": "<5", - "symfony/validator": "<5" + "symfony/validator": "<5.0.2" }, "suggest": { "symfony/form": "", diff --git a/src/Symfony/Bridge/Monolog/Processor/DebugProcessor.php b/src/Symfony/Bridge/Monolog/Processor/DebugProcessor.php index a4594ca012bc2..7ba3f4668a18c 100644 --- a/src/Symfony/Bridge/Monolog/Processor/DebugProcessor.php +++ b/src/Symfony/Bridge/Monolog/Processor/DebugProcessor.php @@ -33,7 +33,7 @@ public function __invoke(array $record) $hash = $this->requestStack && ($request = $this->requestStack->getCurrentRequest()) ? spl_object_hash($request) : ''; $this->records[$hash][] = [ - 'timestamp' => $record['datetime']->getTimestamp(), + 'timestamp' => $record['datetime'] instanceof \DateTimeInterface ? $record['datetime']->getTimestamp() : strtotime($record['datetime']), 'message' => $record['message'], 'priority' => $record['level'], 'priorityName' => $record['level_name'], diff --git a/src/Symfony/Bridge/Monolog/Tests/Handler/ServerLogHandlerTest.php b/src/Symfony/Bridge/Monolog/Tests/Handler/ServerLogHandlerTest.php new file mode 100644 index 0000000000000..0664727995a66 --- /dev/null +++ b/src/Symfony/Bridge/Monolog/Tests/Handler/ServerLogHandlerTest.php @@ -0,0 +1,110 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\Monolog\Tests\Handler; + +use Monolog\Formatter\JsonFormatter; +use Monolog\Logger; +use Monolog\Processor\ProcessIdProcessor; +use PHPUnit\Framework\TestCase; +use Symfony\Bridge\Monolog\Formatter\VarDumperFormatter; +use Symfony\Bridge\Monolog\Handler\ServerLogHandler; +use Symfony\Component\VarDumper\Cloner\Data; + +/** + * Tests the ServerLogHandler. + */ +class ServerLogHandlerTest extends TestCase +{ + public function testFormatter() + { + $handler = new ServerLogHandler('tcp://127.0.0.1:9999'); + $this->assertInstanceOf(VarDumperFormatter::class, $handler->getFormatter()); + + $formatter = new JsonFormatter(); + $handler->setFormatter($formatter); + $this->assertSame($formatter, $handler->getFormatter()); + } + + public function testIsHandling() + { + $handler = new ServerLogHandler('tcp://127.0.0.1:9999', Logger::INFO); + $this->assertFalse($handler->isHandling(['level' => Logger::DEBUG]), '->isHandling returns false when no output is set'); + } + + public function testGetFormatter() + { + $handler = new ServerLogHandler('tcp://127.0.0.1:9999'); + $this->assertInstanceOf(VarDumperFormatter::class, $handler->getFormatter(), + '-getFormatter returns VarDumperFormatter by default' + ); + } + + public function testWritingAndFormatting() + { + $host = 'tcp://127.0.0.1:9999'; + $handler = new ServerLogHandler($host, Logger::INFO, false); + $handler->pushProcessor(new ProcessIdProcessor()); + + $infoRecord = [ + 'message' => 'My info message', + 'context' => [], + 'level' => Logger::INFO, + 'level_name' => Logger::getLevelName(Logger::INFO), + 'channel' => 'app', + 'datetime' => new \DateTime('2013-05-29 16:21:54'), + 'extra' => [], + ]; + + $socket = stream_socket_server($host, $errno, $errstr); + $this->assertIsResource($socket, sprintf('Server start failed on "%s": %s %s.', $host, $errstr, $errno)); + + $this->assertTrue($handler->handle($infoRecord), 'The handler finished handling the log as bubble is false.'); + + $sockets = [(int) $socket => $socket]; + $write = []; + + for ($i = 0; $i < 10; ++$i) { + $read = $sockets; + stream_select($read, $write, $write, null); + + foreach ($read as $stream) { + if ($socket === $stream) { + $stream = stream_socket_accept($socket); + $sockets[(int) $stream] = $stream; + } elseif (feof($stream)) { + unset($sockets[(int) $stream]); + fclose($stream); + } else { + $message = fgets($stream); + fclose($stream); + + $record = unserialize(base64_decode($message)); + $this->assertIsArray($record); + + $this->assertArrayHasKey('message', $record); + $this->assertEquals('My info message', $record['message']); + + $this->assertArrayHasKey('extra', $record); + $this->assertInstanceOf(Data::class, $record['extra']); + $extra = $record['extra']->getValue(true); + $this->assertIsArray($extra); + $this->assertArrayHasKey('process_id', $extra); + $this->assertSame(getmypid(), $extra['process_id']); + + return; + } + } + usleep(100000); + } + $this->fail('Fail to read message from server'); + } +} diff --git a/src/Symfony/Bridge/Monolog/Tests/Processor/DebugProcessorTest.php b/src/Symfony/Bridge/Monolog/Tests/Processor/DebugProcessorTest.php index 7a1e6706878be..6adec38a0c7f0 100644 --- a/src/Symfony/Bridge/Monolog/Tests/Processor/DebugProcessorTest.php +++ b/src/Symfony/Bridge/Monolog/Tests/Processor/DebugProcessorTest.php @@ -19,6 +19,30 @@ class DebugProcessorTest extends TestCase { + /** + * @dataProvider providerDatetimeFormatTests + */ + public function testDatetimeFormat(array $record, $expectedTimestamp) + { + $processor = new DebugProcessor(); + $processor($record); + + $records = $processor->getLogs(); + self::assertCount(1, $records); + self::assertSame($expectedTimestamp, $records[0]['timestamp']); + } + + public function providerDatetimeFormatTests(): array + { + $record = $this->getRecord(); + + return [ + [array_merge($record, ['datetime' => new \DateTime('2019-01-01T00:01:00+00:00')]), 1546300860], + [array_merge($record, ['datetime' => '2019-01-01T00:01:00+00:00']), 1546300860], + [array_merge($record, ['datetime' => 'foo']), false], + ]; + } + public function testDebugProcessor() { $processor = new DebugProcessor(); @@ -75,7 +99,7 @@ public function testInheritedClassCallCountErrorsWithoutArgument() $this->assertEquals(0, $debugProcessorChild->countErrors()); } - private function getRecord($level = Logger::WARNING, $message = 'test') + private function getRecord($level = Logger::WARNING, $message = 'test'): array { return [ 'message' => $message, diff --git a/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php b/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php index dcf7b622cebe1..a9772a2b87342 100644 --- a/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php +++ b/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php @@ -81,6 +81,7 @@ public function getProxyFactoryCode(Definition $definition, string $id, string $ public function getProxyCode(Definition $definition): string { $code = $this->classGenerator->generate($this->generateProxyClass($definition)); + $code = preg_replace('/^(class [^ ]++ extends )([^\\\\])/', '$1\\\\$2', $code); if (version_compare(self::getProxyManagerVersion(), '2.2', '<')) { $code = preg_replace( diff --git a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Fixtures/php/lazy_service_structure.txt b/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Fixtures/php/lazy_service_structure.txt index 574041b89bbb4..906fff68f7bbe 100644 --- a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Fixtures/php/lazy_service_structure.txt +++ b/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Fixtures/php/lazy_service_structure.txt @@ -21,5 +21,5 @@ class LazyServiceProjectServiceContainer extends Container } } -class stdClass_%s extends %SstdClass implements \ProxyManager\%s +class stdClass_%s extends \stdClass implements \ProxyManager\%s {%a}%A diff --git a/src/Symfony/Bridge/Twig/Extension/SecurityExtension.php b/src/Symfony/Bridge/Twig/Extension/SecurityExtension.php index c70e0bb646d29..bd82ef20b4eff 100644 --- a/src/Symfony/Bridge/Twig/Extension/SecurityExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/SecurityExtension.php @@ -31,7 +31,10 @@ public function __construct(AuthorizationCheckerInterface $securityChecker = nul $this->securityChecker = $securityChecker; } - public function isGranted($role, object $object = null, string $field = null): bool + /** + * @param mixed $object + */ + public function isGranted($role, $object = null, string $field = null): bool { if (null === $this->securityChecker) { return false; diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig index 88f3d4aecc073..8ac32978a0925 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig @@ -242,7 +242,7 @@ {% block checkbox_radio_label -%} {#- Do not display the label if widget is not defined in order to prevent double label rendering -#} {%- if widget is defined -%} - {% set is_parent_custom = parent_label_class is defined and ('checkbox-custom' in parent_label_class or 'radio-custom' in parent_label_class) %} + {% set is_parent_custom = parent_label_class is defined and ('checkbox-custom' in parent_label_class or 'radio-custom' in parent_label_class or 'switch-custom' in parent_label_class) %} {% set is_custom = label_attr.class is defined and ('checkbox-custom' in label_attr.class or 'radio-custom' in label_attr.class or 'switch-custom' in label_attr.class) %} {%- if is_parent_custom or is_custom -%} {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' custom-control-label')|trim}) -%} diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php index 39590088fcd84..4440ed065d464 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php @@ -21,6 +21,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; +use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; @@ -228,6 +229,8 @@ protected function getContainerBuilder(): ContainerBuilder $container->compile(); } else { (new XmlFileLoader($container = new ContainerBuilder(), new FileLocator()))->load($kernel->getContainer()->getParameter('debug.container.dump')); + $locatorPass = new ServiceLocatorTagPass(); + $locatorPass->process($container); } return $this->containerBuilder = $container; diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerLintCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerLintCommand.php index cba4ac58408d6..5e6277567eff3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerLintCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerLintCommand.php @@ -14,12 +14,17 @@ use Symfony\Component\Config\ConfigCache; use Symfony\Component\Config\FileLocator; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\DependencyInjection\Compiler\CheckTypeDeclarationsPass; use Symfony\Component\DependencyInjection\Compiler\PassConfig; +use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; +use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag; +use Symfony\Component\HttpKernel\Kernel; final class ContainerLintCommand extends Command { @@ -46,13 +51,18 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output): int { - $container = $this->getContainerBuilder(); + $io = new SymfonyStyle($input, $output); + $errorIo = $io->getErrorStyle(); - $container->setParameter('container.build_hash', 'lint_container'); - $container->setParameter('container.build_time', time()); - $container->setParameter('container.build_id', 'lint_container'); + try { + $container = $this->getContainerBuilder(); + } catch (RuntimeException $e) { + $errorIo->error($e->getMessage()); - $container->addCompilerPass(new CheckTypeDeclarationsPass(true), PassConfig::TYPE_AFTER_REMOVING, -100); + return 2; + } + + $container->setParameter('container.build_time', time()); $container->compile(); @@ -66,14 +76,44 @@ private function getContainerBuilder(): ContainerBuilder } $kernel = $this->getApplication()->getKernel(); + $kernelContainer = $kernel->getContainer(); + + if (!$kernel->isDebug() || !(new ConfigCache($kernelContainer->getParameter('debug.container.dump'), true))->isFresh()) { + if (!$kernel instanceof Kernel) { + throw new RuntimeException(sprintf('This command does not support the application kernel: "%s" does not extend "%s".', \get_class($kernel), Kernel::class)); + } - if (!$kernel->isDebug() || !(new ConfigCache($kernel->getContainer()->getParameter('debug.container.dump'), true))->isFresh()) { - $buildContainer = \Closure::bind(function () { return $this->buildContainer(); }, $kernel, \get_class($kernel)); + $buildContainer = \Closure::bind(function (): ContainerBuilder { + $this->initializeBundles(); + + return $this->buildContainer(); + }, $kernel, \get_class($kernel)); $container = $buildContainer(); + + $skippedIds = []; } else { - (new XmlFileLoader($container = new ContainerBuilder(), new FileLocator()))->load($kernel->getContainer()->getParameter('debug.container.dump')); + if (!$kernelContainer instanceof Container) { + throw new RuntimeException(sprintf('This command does not support the application container: "%s" does not extend "%s".', \get_class($kernelContainer), Container::class)); + } + + (new XmlFileLoader($container = new ContainerBuilder($parameterBag = new EnvPlaceholderParameterBag()), new FileLocator()))->load($kernelContainer->getParameter('debug.container.dump')); + + $refl = new \ReflectionProperty($parameterBag, 'resolved'); + $refl->setAccessible(true); + $refl->setValue($parameterBag, true); + + $passConfig = $container->getCompilerPassConfig(); + $passConfig->setRemovingPasses([]); + $passConfig->setAfterRemovingPasses([]); + + $skippedIds = $kernelContainer->getRemovedIds(); } + $container->setParameter('container.build_hash', 'lint_container'); + $container->setParameter('container.build_id', 'lint_container'); + + $container->addCompilerPass(new CheckTypeDeclarationsPass(true, $skippedIds), PassConfig::TYPE_AFTER_REMOVING, -100); + return $this->containerBuilder = $container; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php b/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php index 2f9b31b18efa2..20f420ce9d45b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php @@ -11,7 +11,7 @@ namespace Symfony\Bundle\FrameworkBundle\Controller; -use Doctrine\Common\Persistence\ManagerRegistry; +use Doctrine\Persistence\ManagerRegistry; use Psr\Container\ContainerInterface; use Psr\Link\LinkInterface; use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; @@ -351,7 +351,7 @@ protected function getDoctrine(): ManagerRegistry /** * Get a user from the Security Token Storage. * - * @return mixed + * @return UserInterface|object|null * * @throws \LogicException If SecurityBundle is not available * diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 9d6e9e9645d81..47a508cb32632 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -130,7 +130,7 @@ private function addSecretsSection(ArrayNodeDefinition $rootNode) ->canBeDisabled() ->children() ->scalarNode('vault_directory')->defaultValue('%kernel.project_dir%/config/secrets/%kernel.environment%')->cannotBeEmpty()->end() - ->scalarNode('local_dotenv_file')->defaultValue('%kernel.project_dir%/.env.local')->end() + ->scalarNode('local_dotenv_file')->defaultValue('%kernel.project_dir%/.env.%kernel.environment%.local')->end() ->scalarNode('decryption_env_var')->defaultValue('base64:default::SYMFONY_DECRYPTION_SECRET')->end() ->end() ->end() @@ -724,6 +724,11 @@ private function addValidationSection(ArrayNodeDefinition $rootNode) ->end() ->end() ->arrayNode('auto_mapping') + ->info('A collection of namespaces for which auto-mapping will be enabled by default, or null to opt-in with the EnableAutoMapping constraint.') + ->example([ + 'App\\Entity\\' => [], + 'App\\WithSpecificLoaders\\' => ['validator.property_info_loader'], + ]) ->useAttributeAsKey('namespace') ->normalizeKeys(false) ->beforeNormalization() diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 33b8f963eeb96..8f1b86b3a2229 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -1187,7 +1187,7 @@ private function registerValidationConfiguration(array $config, ContainerBuilder } $container->setParameter('validator.auto_mapping', $config['auto_mapping']); - if (!$propertyInfoEnabled || !$config['auto_mapping'] || !class_exists(PropertyInfoLoader::class)) { + if (!$propertyInfoEnabled || !class_exists(PropertyInfoLoader::class)) { $container->removeDefinition('validator.property_info_loader'); } @@ -1353,7 +1353,9 @@ private function registerSecretsConfiguration(array $config, ContainerBuilder $c $container->getDefinition('secrets.vault')->replaceArgument(0, $config['vault_directory']); - if (!$config['local_dotenv_file']) { + if ($config['local_dotenv_file']) { + $container->getDefinition('secrets.local_vault')->replaceArgument(0, $config['local_dotenv_file']); + } else { $container->removeDefinition('secrets.local_vault'); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/secrets.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/secrets.xml index f70243dd84343..65fd1073fd46f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/secrets.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/secrets.xml @@ -7,12 +7,12 @@ - %kernel.project_dir%/config/secrets/%kernel.environment% - %env(base64:default::SYMFONY_DECRYPTION_SECRET)% + + - %kernel.project_dir%/.env.local + diff --git a/src/Symfony/Bundle/FrameworkBundle/Secrets/SodiumVault.php b/src/Symfony/Bundle/FrameworkBundle/Secrets/SodiumVault.php index e6fcab506057d..883a68613c540 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Secrets/SodiumVault.php +++ b/src/Symfony/Bundle/FrameworkBundle/Secrets/SodiumVault.php @@ -25,6 +25,7 @@ class SodiumVault extends AbstractVault implements EnvVarLoaderInterface private $encryptionKey; private $decryptionKey; private $pathPrefix; + private $secretsDir; /** * @param string|object|null $decryptionKey A string or a stringable object that defines the private key to use to decrypt the vault @@ -36,12 +37,9 @@ public function __construct(string $secretsDir, $decryptionKey = null) throw new \TypeError(sprintf('Decryption key should be a string or an object that implements the __toString() method, %s given.', \gettype($decryptionKey))); } - if (!is_dir($secretsDir) && !@mkdir($secretsDir, 0777, true) && !is_dir($secretsDir)) { - throw new \RuntimeException(sprintf('Unable to create the secrets directory (%s)', $secretsDir)); - } - $this->pathPrefix = rtrim(strtr($secretsDir, '/', \DIRECTORY_SEPARATOR), \DIRECTORY_SEPARATOR).\DIRECTORY_SEPARATOR.basename($secretsDir).'.'; $this->decryptionKey = $decryptionKey; + $this->secretsDir = $secretsDir; } public function generateKeys(bool $override = false): bool @@ -203,9 +201,20 @@ private function export(string $file, string $data): void $data = str_replace('%', '\x', rawurlencode($data)); $data = sprintf("createSecretsDir(); + if (false === file_put_contents($this->pathPrefix.$file.'.php', $data, LOCK_EX)) { $e = error_get_last(); throw new \ErrorException($e['message'] ?? 'Failed to write secrets data.', 0, $e['type'] ?? E_USER_WARNING); } } + + private function createSecretsDir(): void + { + if ($this->secretsDir && !is_dir($this->secretsDir) && !@mkdir($this->secretsDir, 0777, true) && !is_dir($this->secretsDir)) { + throw new \RuntimeException(sprintf('Unable to create the secrets directory (%s)', $this->secretsDir)); + } + + $this->secretsDir = null; + } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php index ca1d7ef011104..0b30d684d863c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php @@ -53,7 +53,7 @@ public function testSubscribedServices() 'session' => '?Symfony\\Component\\HttpFoundation\\Session\\SessionInterface', 'security.authorization_checker' => '?Symfony\\Component\\Security\\Core\\Authorization\\AuthorizationCheckerInterface', 'twig' => '?Twig\\Environment', - 'doctrine' => '?Doctrine\\Common\\Persistence\\ManagerRegistry', + 'doctrine' => '?Doctrine\\Persistence\\ManagerRegistry', 'form.factory' => '?Symfony\\Component\\Form\\FormFactoryInterface', 'parameter_bag' => '?Symfony\\Component\\DependencyInjection\\ParameterBag\\ContainerBagInterface', 'message_bus' => '?Symfony\\Component\\Messenger\\MessageBusInterface', @@ -532,7 +532,7 @@ public function testCreateFormBuilder() public function testGetDoctrine() { - $doctrine = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock(); + $doctrine = $this->getMockBuilder('Doctrine\Persistence\ManagerRegistry')->getMock(); $container = new Container(); $container->set('doctrine', $doctrine); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index 8d8e3a3a9e10f..bd1308ca86eb0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -503,7 +503,7 @@ class_exists(SemaphoreStore::class) && SemaphoreStore::isSupported() ? 'semaphor 'secrets' => [ 'enabled' => true, 'vault_directory' => '%kernel.project_dir%/config/secrets/%kernel.environment%', - 'local_dotenv_file' => '%kernel.project_dir%/.env.local', + 'local_dotenv_file' => '%kernel.project_dir%/.env.%kernel.environment%.local', 'decryption_env_var' => 'base64:default::SYMFONY_DECRYPTION_SECRET', ], ]; diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index 1f373a89265ce..8bcf9e8d4659b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -64,6 +64,7 @@ "twig/twig": "^2.10|^3.0" }, "conflict": { + "doctrine/persistence": "<1.3", "phpdocumentor/reflection-docblock": "<3.0", "phpdocumentor/type-resolver": "<0.2.1", "phpunit/phpunit": "<5.4.3", diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/AddSessionDomainConstraintPass.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/AddSessionDomainConstraintPass.php index b1e653a10975f..461a5ad66d081 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/AddSessionDomainConstraintPass.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/AddSessionDomainConstraintPass.php @@ -31,7 +31,7 @@ public function process(ContainerBuilder $container) } $sessionOptions = $container->getParameter('session.storage.options'); - $domainRegexp = empty($sessionOptions['cookie_domain']) ? '%s' : sprintf('(?:%%s|(?:.+\.)?%s)', preg_quote(trim($sessionOptions['cookie_domain'], '.'))); + $domainRegexp = empty($sessionOptions['cookie_domain']) ? '%%s' : sprintf('(?:%%%%s|(?:.+\.)?%s)', preg_quote(trim($sessionOptions['cookie_domain'], '.'))); if ('auto' === ($sessionOptions['cookie_secure'] ?? null)) { $secureDomainRegexp = sprintf('{^https://%s$}i', $domainRegexp); diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/RegisterTokenUsageTrackingPass.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/RegisterTokenUsageTrackingPass.php index 63c54bddc7106..94d5a184727e8 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/RegisterTokenUsageTrackingPass.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/RegisterTokenUsageTrackingPass.php @@ -43,6 +43,7 @@ public function process(ContainerBuilder $container) if (!$container->has('session')) { $container->setAlias('security.token_storage', 'security.untracked_token_storage')->setPublic(true); + $container->getDefinition('security.untracked_token_storage')->addTag('kernel.reset', ['method' => 'reset']); } elseif ($container->hasDefinition('security.context_listener')) { $container->getDefinition('security.context_listener') ->setArgument(6, [new Reference('security.token_storage'), 'enableUsageTracking']); diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php index ba55fe195c76b..ad269fd65e98f 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php @@ -362,7 +362,13 @@ private function addEncodersSection(ArrayNodeDefinition $rootNode) ->performNoDeepMerging() ->beforeNormalization()->ifString()->then(function ($v) { return ['algorithm' => $v]; })->end() ->children() - ->scalarNode('algorithm')->cannotBeEmpty()->end() + ->scalarNode('algorithm') + ->cannotBeEmpty() + ->validate() + ->ifTrue(function ($v) { return !\is_string($v); }) + ->thenInvalid('You must provide a string value.') + ->end() + ->end() ->arrayNode('migrate_from') ->prototype('scalar')->end() ->beforeNormalization()->castToArray()->end() diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AnonymousFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AnonymousFactory.php index a889edea00861..eb3c930afe379 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AnonymousFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AnonymousFactory.php @@ -24,19 +24,19 @@ class AnonymousFactory implements SecurityFactoryInterface public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint) { if (null === $config['secret']) { - $firewall['anonymous']['secret'] = new Parameter('container.build_hash'); + $config['secret'] = new Parameter('container.build_hash'); } $listenerId = 'security.authentication.listener.anonymous.'.$id; $container ->setDefinition($listenerId, new ChildDefinition('security.authentication.listener.anonymous')) - ->replaceArgument(1, $firewall['anonymous']['secret']) + ->replaceArgument(1, $config['secret']) ; $providerId = 'security.authentication.provider.anonymous.'.$id; $container ->setDefinition($providerId, new ChildDefinition('security.authentication.provider.anonymous')) - ->replaceArgument(0, $firewall['anonymous']['secret']) + ->replaceArgument(0, $config['secret']) ; return [$providerId, $listenerId, $defaultEntryPoint]; diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php index f4c13752a7763..baf395b4c4a94 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php @@ -676,7 +676,7 @@ private function createExceptionListener(ContainerBuilder $container, array $con return $exceptionListenerId; } - private function createSwitchUserListener(ContainerBuilder $container, string $id, array $config, string $defaultProvider, bool $stateless): string + private function createSwitchUserListener(ContainerBuilder $container, string $id, array $config, ?string $defaultProvider, bool $stateless): string { $userProvider = isset($config['provider']) ? $this->getUserProviderId($config['provider']) : $defaultProvider; diff --git a/src/Symfony/Bundle/SecurityBundle/Security/FirewallMap.php b/src/Symfony/Bundle/SecurityBundle/Security/FirewallMap.php index bff2313adf3e2..06cbc64d18c6b 100644 --- a/src/Symfony/Bundle/SecurityBundle/Security/FirewallMap.php +++ b/src/Symfony/Bundle/SecurityBundle/Security/FirewallMap.php @@ -26,13 +26,11 @@ class FirewallMap implements FirewallMapInterface { private $container; private $map; - private $contexts; public function __construct(ContainerInterface $container, iterable $map) { $this->container = $container; $this->map = $map; - $this->contexts = new \SplObjectStorage(); } public function getListeners(Request $request) diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php index 4b6c05bfb36a5..c395ed1b52386 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php @@ -389,6 +389,30 @@ public function sessionConfigurationProvider() ]; } + public function testSwitchUserWithSeveralDefinedProvidersButNoFirewallRootProviderConfigured() + { + $container = $this->getRawContainer(); + $container->loadFromExtension('security', [ + 'providers' => [ + 'first' => ['id' => 'foo'], + 'second' => ['id' => 'bar'], + ], + + 'firewalls' => [ + 'foobar' => [ + 'switch_user' => [ + 'provider' => 'second', + ], + 'anonymous' => true, + ], + ], + ]); + + $container->compile(); + + $this->assertEquals(new Reference('security.user.provider.concrete.second'), $container->getDefinition('security.authentication.switchuser_listener.foobar')->getArgument(1)); + } + protected function getRawContainer() { $container = new ContainerBuilder(); diff --git a/src/Symfony/Bundle/TwigBundle/TwigBundle.php b/src/Symfony/Bundle/TwigBundle/TwigBundle.php index 483e5ae846737..3910dd5e2e389 100644 --- a/src/Symfony/Bundle/TwigBundle/TwigBundle.php +++ b/src/Symfony/Bundle/TwigBundle/TwigBundle.php @@ -31,7 +31,8 @@ public function build(ContainerBuilder $container) { parent::build($container); - $container->addCompilerPass(new ExtensionPass()); + // ExtensionPass must be run before the FragmentRendererPass as it adds tags that are processed later + $container->addCompilerPass(new ExtensionPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 10); $container->addCompilerPass(new TwigEnvironmentPass()); $container->addCompilerPass(new TwigLoaderPass()); $container->addCompilerPass(new RuntimeLoaderPass(), PassConfig::TYPE_BEFORE_REMOVING); diff --git a/src/Symfony/Component/Cache/Adapter/ChainAdapter.php b/src/Symfony/Component/Cache/Adapter/ChainAdapter.php index 78a65e9d6dc2b..a2fc8e7a3444c 100644 --- a/src/Symfony/Component/Cache/Adapter/ChainAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/ChainAdapter.php @@ -61,14 +61,15 @@ public function __construct(array $adapters, int $defaultLifetime = 0) $this->adapterCount = \count($this->adapters); $this->syncItem = \Closure::bind( - static function ($sourceItem, $item) use ($defaultLifetime) { + static function ($sourceItem, $item, $sourceMetadata = null) use ($defaultLifetime) { + $sourceItem->isTaggable = false; + $sourceMetadata = $sourceMetadata ?? $sourceItem->metadata; + unset($sourceMetadata[CacheItem::METADATA_TAGS]); + $item->value = $sourceItem->value; - $item->expiry = $sourceItem->expiry; + $item->expiry = $sourceMetadata[CacheItem::METADATA_EXPIRY] ?? $sourceItem->expiry; $item->isHit = $sourceItem->isHit; - $item->metadata = $sourceItem->metadata; - - $sourceItem->isTaggable = false; - unset($sourceItem->metadata[CacheItem::METADATA_TAGS]); + $item->metadata = $item->newMetadata = $sourceItem->metadata = $sourceMetadata; if (0 < $sourceItem->defaultLifetime && $sourceItem->defaultLifetime < $defaultLifetime) { $defaultLifetime = $sourceItem->defaultLifetime; @@ -103,7 +104,7 @@ public function get(string $key, callable $callback, float $beta = null, array & $value = $this->doGet($adapter, $key, $callback, $beta, $metadata); } if (null !== $item) { - ($this->syncItem)($lastItem = $lastItem ?? $item, $item); + ($this->syncItem)($lastItem = $lastItem ?? $item, $item, $metadata); } return $value; diff --git a/src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php b/src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php index 45c9cde14499b..84946f6446d0a 100644 --- a/src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php @@ -39,6 +39,8 @@ class PhpArrayAdapter implements AdapterInterface, CacheInterface, PruneableInte private $values; private $createCacheItem; + private static $valuesCache = []; + /** * @param string $file The PHP file were values are cached * @param AdapterInterface $fallbackPool A pool to fallback on when an item is not hit @@ -65,22 +67,17 @@ static function ($key, $value, $isHit) { * This adapter takes advantage of how PHP stores arrays in its latest versions. * * @param string $file The PHP file were values are cached - * @param CacheItemPoolInterface $fallbackPool Fallback when opcache is disabled + * @param CacheItemPoolInterface $fallbackPool A pool to fallback on when an item is not hit * * @return CacheItemPoolInterface */ public static function create(string $file, CacheItemPoolInterface $fallbackPool) { - // Shared memory is available in PHP 7.0+ with OPCache enabled - if (filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN)) { - if (!$fallbackPool instanceof AdapterInterface) { - $fallbackPool = new ProxyAdapter($fallbackPool); - } - - return new static($file, $fallbackPool); + if (!$fallbackPool instanceof AdapterInterface) { + $fallbackPool = new ProxyAdapter($fallbackPool); } - return $fallbackPool; + return new static($file, $fallbackPool); } /** @@ -281,6 +278,7 @@ public function clear(string $prefix = '') $this->keys = $this->values = []; $cleared = @unlink($this->file) || !file_exists($this->file); + unset(self::$valuesCache[$this->file]); if ($this->pool instanceof AdapterInterface) { return $this->pool->clear($prefix) && $cleared; @@ -375,6 +373,7 @@ public function warmUp(array $values) unset($serialized, $value, $dump); @rename($tmpFile, $this->file); + unset(self::$valuesCache[$this->file]); $this->initialize(); } @@ -384,12 +383,15 @@ public function warmUp(array $values) */ private function initialize() { - if (!file_exists($this->file)) { + if (isset(self::$valuesCache[$this->file])) { + $values = self::$valuesCache[$this->file]; + } elseif (!file_exists($this->file)) { $this->keys = $this->values = []; return; + } else { + $values = self::$valuesCache[$this->file] = (include $this->file) ?: [[], []]; } - $values = (include $this->file) ?: [[], []]; if (2 !== \count($values) || !isset($values[0], $values[1])) { $this->keys = $this->values = []; diff --git a/src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php b/src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php index c8a7bed9a8eb0..f148a8909fe23 100644 --- a/src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php @@ -35,6 +35,7 @@ class PhpFilesAdapter extends AbstractAdapter implements PruneableInterface private $files = []; private static $startTime; + private static $valuesCache = []; /** * @param $appendOnly Set to `true` to gain extra performance when the items stored in this pool never expire. @@ -57,7 +58,7 @@ public static function isSupported() { self::$startTime = self::$startTime ?? $_SERVER['REQUEST_TIME'] ?? time(); - return \function_exists('opcache_invalidate') && ('cli' !== \PHP_SAPI || filter_var(ini_get('opcache.enable_cli'), FILTER_VALIDATE_BOOLEAN)) && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN); + return \function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN) && (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) || filter_var(ini_get('opcache.enable_cli'), FILTER_VALIDATE_BOOLEAN)); } /** @@ -116,6 +117,8 @@ protected function doFetch(array $ids) $values[$id] = null; } elseif (!\is_object($value)) { $values[$id] = $value; + } elseif (!$value instanceof LazyValue) { + $values[$id] = $value(); } elseif (false === $values[$id] = include $value->file) { unset($values[$id], $this->values[$id]); $missingIds[] = $id; @@ -137,14 +140,20 @@ protected function doFetch(array $ids) try { $file = $this->files[$id] ?? $this->files[$id] = $this->getFile($id); - if (\is_array($expiresAt = include $file)) { + if (isset(self::$valuesCache[$file])) { + [$expiresAt, $this->values[$id]] = self::$valuesCache[$file]; + } elseif (\is_array($expiresAt = include $file)) { + if ($this->appendOnly) { + self::$valuesCache[$file] = $expiresAt; + } + [$expiresAt, $this->values[$id]] = $expiresAt; } elseif ($now < $expiresAt) { $this->values[$id] = new LazyValue($file); } if ($now >= $expiresAt) { - unset($this->values[$id], $missingIds[$k]); + unset($this->values[$id], $missingIds[$k], self::$valuesCache[$file]); } } catch (\ErrorException $e) { unset($missingIds[$k]); @@ -173,7 +182,13 @@ protected function doHave(string $id) $file = $this->files[$id] ?? $this->files[$id] = $this->getFile($id); $getExpiry = true; - if (\is_array($expiresAt = include $file)) { + if (isset(self::$valuesCache[$file])) { + [$expiresAt, $value] = self::$valuesCache[$file]; + } elseif (\is_array($expiresAt = include $file)) { + if ($this->appendOnly) { + self::$valuesCache[$file] = $expiresAt; + } + [$expiresAt, $value] = $expiresAt; } elseif ($this->appendOnly) { $value = new LazyValue($file); @@ -227,12 +242,14 @@ protected function doSave(array $values, int $lifetime) $encodedKey = rawurlencode($key); - if (!$isStaticValue) { + if ($isStaticValue) { + $value = "return [{$expiry}, {$value}];"; + } elseif ($this->appendOnly) { + $value = "return [{$expiry}, static function () { return {$value}; }];"; + } else { // We cannot use a closure here because of https://bugs.php.net/76982 $value = str_replace('\Symfony\Component\VarExporter\Internal\\', '', $value); $value = "namespace Symfony\Component\VarExporter\Internal;\n\nreturn \$getExpiry ? {$expiry} : {$value};"; - } else { - $value = "return [{$expiry}, {$value}];"; } $file = $this->files[$key] = $this->getFile($key, true); @@ -243,6 +260,7 @@ protected function doSave(array $values, int $lifetime) @opcache_invalidate($file, true); @opcache_compile_file($file); } + unset(self::$valuesCache[$file]); } if (!$ok && !is_writable($this->directory)) { @@ -276,6 +294,8 @@ protected function doDelete(array $ids) protected function doUnlink($file) { + unset(self::$valuesCache[$file]); + if (self::isSupported()) { @opcache_invalidate($file, true); } diff --git a/src/Symfony/Component/Cache/Tests/Adapter/ChainAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/ChainAdapterTest.php index ffd598bc04b87..99b38834f8dc1 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/ChainAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/ChainAdapterTest.php @@ -28,7 +28,7 @@ class ChainAdapterTest extends AdapterTestCase public function createCachePool(int $defaultLifetime = 0, string $testMethod = null): CacheItemPoolInterface { if ('testGetMetadata' === $testMethod) { - return new ChainAdapter([new FilesystemAdapter('', $defaultLifetime)], $defaultLifetime); + return new ChainAdapter([new FilesystemAdapter('a', $defaultLifetime), new FilesystemAdapter('b', $defaultLifetime)], $defaultLifetime); } return new ChainAdapter([new ArrayAdapter($defaultLifetime), new ExternalAdapter(), new FilesystemAdapter('', $defaultLifetime)], $defaultLifetime); diff --git a/src/Symfony/Component/Cache/Tests/Adapter/PdoAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/PdoAdapterTest.php index c827c5ba4db4d..dbd93bdd71f03 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/PdoAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/PdoAdapterTest.php @@ -94,9 +94,9 @@ public function testDsn(string $dsn, string $file = null) public function provideDsn() { $dbFile = tempnam(sys_get_temp_dir(), 'sf_sqlite_cache'); - yield ['sqlite://localhost/'.$dbFile, ''.$dbFile]; - yield ['sqlite:'.$dbFile, ''.$dbFile]; - yield ['sqlite3:///'.$dbFile, ''.$dbFile]; + yield ['sqlite://localhost/'.$dbFile.'1', $dbFile.'1']; + yield ['sqlite:'.$dbFile.'2', $dbFile.'2']; + yield ['sqlite3:///'.$dbFile.'3', $dbFile.'3']; yield ['sqlite://localhost/:memory:']; yield ['sqlite::memory:']; } diff --git a/src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterTest.php index 4a5aa82d59f15..69f334656d58e 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterTest.php @@ -66,6 +66,8 @@ public static function setUpBeforeClass(): void protected function tearDown(): void { + $this->createCachePool()->clear(); + if (file_exists(sys_get_temp_dir().'/symfony-cache')) { FilesystemAdapterTest::rmdir(sys_get_temp_dir().'/symfony-cache'); } diff --git a/src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterWithFallbackTest.php b/src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterWithFallbackTest.php index 694b63d89fa0f..a3e998b4b2af2 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterWithFallbackTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterWithFallbackTest.php @@ -38,6 +38,8 @@ public static function setUpBeforeClass(): void protected function tearDown(): void { + $this->createCachePool()->clear(); + if (file_exists(sys_get_temp_dir().'/symfony-cache')) { FilesystemAdapterTest::rmdir(sys_get_temp_dir().'/symfony-cache'); } diff --git a/src/Symfony/Component/Cache/Tests/Adapter/PhpFilesAdapterAppendOnlyTest.php b/src/Symfony/Component/Cache/Tests/Adapter/PhpFilesAdapterAppendOnlyTest.php new file mode 100644 index 0000000000000..a38a6f9f5c61a --- /dev/null +++ b/src/Symfony/Component/Cache/Tests/Adapter/PhpFilesAdapterAppendOnlyTest.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Cache\Tests\Adapter; + +use Psr\Cache\CacheItemPoolInterface; +use Symfony\Component\Cache\Adapter\PhpFilesAdapter; + +/** + * @group time-sensitive + */ +class PhpFilesAdapterAppendOnlyTest extends PhpFilesAdapterTest +{ + protected $skippedTests = [ + 'testDefaultLifeTime' => 'PhpFilesAdapter does not allow configuring a default lifetime.', + 'testExpiration' => 'PhpFilesAdapter in append-only mode does not expiration.', + ]; + + public function createCachePool(): CacheItemPoolInterface + { + return new PhpFilesAdapter('sf-cache', 0, null, true); + } +} diff --git a/src/Symfony/Component/Config/Definition/Builder/NodeBuilder.php b/src/Symfony/Component/Config/Definition/Builder/NodeBuilder.php index a9b48690e53c2..bab439b9ba2db 100644 --- a/src/Symfony/Component/Config/Definition/Builder/NodeBuilder.php +++ b/src/Symfony/Component/Config/Definition/Builder/NodeBuilder.php @@ -24,13 +24,13 @@ class NodeBuilder implements NodeParentInterface public function __construct() { $this->nodeMapping = [ - 'variable' => __NAMESPACE__.'\\VariableNodeDefinition', - 'scalar' => __NAMESPACE__.'\\ScalarNodeDefinition', - 'boolean' => __NAMESPACE__.'\\BooleanNodeDefinition', - 'integer' => __NAMESPACE__.'\\IntegerNodeDefinition', - 'float' => __NAMESPACE__.'\\FloatNodeDefinition', - 'array' => __NAMESPACE__.'\\ArrayNodeDefinition', - 'enum' => __NAMESPACE__.'\\EnumNodeDefinition', + 'variable' => VariableNodeDefinition::class, + 'scalar' => ScalarNodeDefinition::class, + 'boolean' => BooleanNodeDefinition::class, + 'integer' => IntegerNodeDefinition::class, + 'float' => FloatNodeDefinition::class, + 'array' => ArrayNodeDefinition::class, + 'enum' => EnumNodeDefinition::class, ]; } diff --git a/src/Symfony/Component/Config/Resource/ClassExistenceResource.php b/src/Symfony/Component/Config/Resource/ClassExistenceResource.php index 5ad88cca6ba6c..a547fb461236f 100644 --- a/src/Symfony/Component/Config/Resource/ClassExistenceResource.php +++ b/src/Symfony/Component/Config/Resource/ClassExistenceResource.php @@ -37,7 +37,9 @@ class ClassExistenceResource implements SelfCheckingResourceInterface public function __construct(string $resource, bool $exists = null) { $this->resource = $resource; - $this->exists = $exists; + if (null !== $exists) { + $this->exists = [(bool) $exists, null]; + } } /** @@ -65,9 +67,13 @@ public function isFresh(int $timestamp): bool { $loaded = class_exists($this->resource, false) || interface_exists($this->resource, false) || trait_exists($this->resource, false); - if (null !== $exists = &self::$existsCache[(int) (0 >= $timestamp)][$this->resource]) { - $exists = $exists || $loaded; - } elseif (!$exists = $loaded) { + if (null !== $exists = &self::$existsCache[$this->resource]) { + if ($loaded) { + $exists = [true, null]; + } elseif (0 >= $timestamp && !$exists[0] && null !== $exists[1]) { + throw new \ReflectionException($exists[1]); + } + } elseif ([false, null] === $exists = [$loaded, null]) { if (!self::$autoloadLevel++) { spl_autoload_register(__CLASS__.'::throwOnRequiredClass'); } @@ -75,16 +81,19 @@ public function isFresh(int $timestamp): bool self::$autoloadedClass = ltrim($this->resource, '\\'); try { - $exists = class_exists($this->resource) || interface_exists($this->resource, false) || trait_exists($this->resource, false); + $exists[0] = class_exists($this->resource) || interface_exists($this->resource, false) || trait_exists($this->resource, false); } catch (\Exception $e) { + $exists[1] = $e->getMessage(); + try { self::throwOnRequiredClass($this->resource, $e); } catch (\ReflectionException $e) { if (0 >= $timestamp) { - unset(self::$existsCache[1][$this->resource]); throw $e; } } + } catch (\Throwable $e) { + $exists[1] = $e->getMessage(); } finally { self::$autoloadedClass = $autoloadedClass; if (!--self::$autoloadLevel) { @@ -97,7 +106,7 @@ public function isFresh(int $timestamp): bool $this->exists = $exists; } - return $this->exists xor !$exists; + return $this->exists[0] xor !$exists[0]; } /** @@ -112,6 +121,16 @@ public function __sleep(): array return ['resource', 'exists']; } + /** + * @internal + */ + public function __wakeup() + { + if (\is_bool($this->exists)) { + $this->exists = [$this->exists, null]; + } + } + /** * Throws a reflection exception when the passed class does not exist but is required. * @@ -147,7 +166,17 @@ public static function throwOnRequiredClass(string $class, \Exception $previous throw $previous; } - $e = new \ReflectionException(sprintf('Class "%s" not found while loading "%s".', $class, self::$autoloadedClass), 0, $previous); + $message = sprintf('Class "%s" not found.', $class); + + if (self::$autoloadedClass !== $class) { + $message = substr_replace($message, sprintf(' while loading "%s"', self::$autoloadedClass), -1, 0); + } + + if (null !== $previous) { + $message = $previous->getMessage(); + } + + $e = new \ReflectionException($message, 0, $previous); if (null !== $previous) { throw $e; diff --git a/src/Symfony/Component/Config/Resource/GlobResource.php b/src/Symfony/Component/Config/Resource/GlobResource.php index 7095ecbf323df..8f5a2f1799051 100644 --- a/src/Symfony/Component/Config/Resource/GlobResource.php +++ b/src/Symfony/Component/Config/Resource/GlobResource.php @@ -31,6 +31,7 @@ class GlobResource implements \IteratorAggregate, SelfCheckingResourceInterface private $hash; private $forExclusion; private $excludedPrefixes; + private $globBrace; /** * @param string $prefix A directory prefix @@ -47,6 +48,7 @@ public function __construct(string $prefix, string $pattern, bool $recursive, bo $this->recursive = $recursive; $this->forExclusion = $forExclusion; $this->excludedPrefixes = $excludedPrefixes; + $this->globBrace = \defined('GLOB_BRACE') ? GLOB_BRACE : 0; if (false === $this->prefix) { throw new \InvalidArgumentException(sprintf('The path "%s" does not exist.', $prefix)); @@ -98,9 +100,20 @@ public function getIterator(): \Traversable return; } $prefix = str_replace('\\', '/', $this->prefix); + $paths = null; + + if (0 !== strpos($this->prefix, 'phar://') && false === strpos($this->pattern, '/**/')) { + if ($this->globBrace || false === strpos($this->pattern, '{')) { + $paths = glob($this->prefix.$this->pattern, GLOB_NOSORT | $this->globBrace); + } elseif (false === strpos($this->pattern, '\\') || !preg_match('/\\\\[,{}]/', $this->pattern)) { + foreach ($this->expandGlob($this->pattern) as $p) { + $paths[] = glob($this->prefix.$p, GLOB_NOSORT); + } + $paths = array_merge(...$paths); + } + } - if (0 !== strpos($this->prefix, 'phar://') && false === strpos($this->pattern, '/**/') && (\defined('GLOB_BRACE') || false === strpos($this->pattern, '{'))) { - $paths = glob($this->prefix.$this->pattern, GLOB_NOSORT | (\defined('GLOB_BRACE') ? GLOB_BRACE : 0)); + if (null !== $paths) { sort($paths); foreach ($paths as $path) { if ($this->excludedPrefixes) { @@ -184,4 +197,34 @@ private function computeHash(): string return hash_final($hash); } + + private function expandGlob(string $pattern): array + { + $segments = preg_split('/\{([^{}]*+)\}/', $pattern, -1, PREG_SPLIT_DELIM_CAPTURE); + $paths = [$segments[0]]; + $patterns = []; + + for ($i = 1; $i < \count($segments); $i += 2) { + $patterns = []; + + foreach (explode(',', $segments[$i]) as $s) { + foreach ($paths as $p) { + $patterns[] = $p.$s.$segments[1 + $i]; + } + } + + $paths = $patterns; + } + + $j = 0; + foreach ($patterns as $i => $p) { + if (false !== strpos($p, '{')) { + $p = $this->expandGlob($p); + array_splice($paths, $i + $j, 1, $p); + $j += \count($p) - 1; + } + } + + return $paths; + } } diff --git a/src/Symfony/Component/Config/Tests/Definition/Builder/NodeBuilderTest.php b/src/Symfony/Component/Config/Tests/Definition/Builder/NodeBuilderTest.php index 5cc7cfea4f492..46518c659afbd 100644 --- a/src/Symfony/Component/Config/Tests/Definition/Builder/NodeBuilderTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/Builder/NodeBuilderTest.php @@ -35,7 +35,7 @@ public function testThrowsAnExceptionWhenTheNodeClassIsNotFound() public function testAddingANewNodeType() { - $class = __NAMESPACE__.'\\SomeNodeDefinition'; + $class = SomeNodeDefinition::class; $builder = new BaseNodeBuilder(); $node = $builder @@ -47,7 +47,7 @@ public function testAddingANewNodeType() public function testOverridingAnExistingNodeType() { - $class = __NAMESPACE__.'\\SomeNodeDefinition'; + $class = SomeNodeDefinition::class; $builder = new BaseNodeBuilder(); $node = $builder @@ -66,7 +66,7 @@ public function testNodeTypesAreNotCaseSensitive() $this->assertInstanceOf(\get_class($node1), $node2); - $builder->setNodeClass('CuStOm', __NAMESPACE__.'\\SomeNodeDefinition'); + $builder->setNodeClass('CuStOm', SomeNodeDefinition::class); $node1 = $builder->node('', 'CUSTOM'); $node2 = $builder->node('', 'custom'); diff --git a/src/Symfony/Component/Config/Tests/Fixtures/BadFileName.php b/src/Symfony/Component/Config/Tests/Fixtures/BadFileName.php new file mode 100644 index 0000000000000..0f79bdd523a7f --- /dev/null +++ b/src/Symfony/Component/Config/Tests/Fixtures/BadFileName.php @@ -0,0 +1,9 @@ +isFresh(0); } + public function testBadFileName() + { + $this->expectException('ReflectionException'); + $this->expectExceptionMessage('Mismatch between file name and class name.'); + + $res = new ClassExistenceResource(BadFileName::class, false); + $res->isFresh(0); + } + + public function testBadFileNameBis() + { + $this->expectException('ReflectionException'); + $this->expectExceptionMessage('Mismatch between file name and class name.'); + + $res = new ClassExistenceResource(BadFileName::class, false); + $res->isFresh(0); + } + public function testConditionalClass() { $res = new ClassExistenceResource(ConditionalClass::class, false); diff --git a/src/Symfony/Component/Config/Tests/Resource/GlobResourceTest.php b/src/Symfony/Component/Config/Tests/Resource/GlobResourceTest.php index 629054461acaf..2b6609d740c86 100644 --- a/src/Symfony/Component/Config/Tests/Resource/GlobResourceTest.php +++ b/src/Symfony/Component/Config/Tests/Resource/GlobResourceTest.php @@ -165,4 +165,33 @@ public function testIsFreshRecursiveDetectsNewFile() touch($dir.'/Resource/TmpGlob'); $this->assertFalse($resource->isFresh(0)); } + + public function testBraceFallback() + { + $dir = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures'; + $resource = new GlobResource($dir, '/*{/*/*.txt,.x{m,n}l}', true); + + $p = new \ReflectionProperty($resource, 'globBrace'); + $p->setAccessible(true); + $p->setValue($resource, 0); + + $expected = [ + $dir.'/Exclude/ExcludeToo/AnotheExcludedFile.txt', + $dir.'/foo.xml', + ]; + + $this->assertSame($expected, array_keys(iterator_to_array($resource))); + } + + public function testUnbalancedBraceFallback() + { + $dir = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures'; + $resource = new GlobResource($dir, '/*{/*/*.txt,.x{m,nl}', true); + + $p = new \ReflectionProperty($resource, 'globBrace'); + $p->setAccessible(true); + $p->setValue($resource, 0); + + $this->assertSame([], array_keys(iterator_to_array($resource))); + } } diff --git a/src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php b/src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php index 4653c8d7c776c..d1a47a8ea3376 100644 --- a/src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php +++ b/src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php @@ -48,7 +48,7 @@ public function testLoadFile() $this->assertStringContainsString('XSD file or callable', $e->getMessage()); } - $mock = $this->getMockBuilder(__NAMESPACE__.'\Validator')->getMock(); + $mock = $this->getMockBuilder(Validator::class)->getMock(); $mock->expects($this->exactly(2))->method('validate')->will($this->onConsecutiveCalls(false, true)); try { @@ -68,7 +68,7 @@ public function testParseWithInvalidValidatorCallable() $this->expectExceptionMessage('The XML is not valid'); $fixtures = __DIR__.'/../Fixtures/Util/'; - $mock = $this->getMockBuilder(__NAMESPACE__.'\Validator')->getMock(); + $mock = $this->getMockBuilder(Validator::class)->getMock(); $mock->expects($this->once())->method('validate')->willReturn(false); XmlUtils::parse(file_get_contents($fixtures.'valid.xml'), [$mock, 'validate']); diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index 1d0d6062365cc..38956d1fe06c2 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -783,7 +783,7 @@ protected function doRenderThrowable(\Throwable $e, OutputInterface $output): vo } if (false !== strpos($message, "class@anonymous\0")) { - $message = preg_replace_callback('/class@anonymous\x00.*?\.php0x?[0-9a-fA-F]++/', function ($m) { + $message = preg_replace_callback('/class@anonymous\x00.*?\.php(?:0x?|:)[0-9a-fA-F]++/', function ($m) { return class_exists($m[0], false) ? get_parent_class($m[0]).'@anonymous' : $m[0]; }, $message); } diff --git a/src/Symfony/Component/Console/Helper/QuestionHelper.php b/src/Symfony/Component/Console/Helper/QuestionHelper.php index faf2648bd1bd1..594a291602305 100644 --- a/src/Symfony/Component/Console/Helper/QuestionHelper.php +++ b/src/Symfony/Component/Console/Helper/QuestionHelper.php @@ -166,15 +166,9 @@ protected function writePrompt(OutputInterface $output, Question $question) $message = $question->getQuestion(); if ($question instanceof ChoiceQuestion) { - $maxWidth = max(array_map([$this, 'strlen'], array_keys($question->getChoices()))); - - $messages = (array) $question->getQuestion(); - foreach ($question->getChoices() as $key => $value) { - $width = $maxWidth - $this->strlen($key); - $messages[] = ' ['.$key.str_repeat(' ', $width).'] '.$value; - } - - $output->writeln($messages); + $output->writeln(array_merge([ + $question->getQuestion(), + ], $this->formatChoiceQuestionChoices($question, 'info'))); $message = $question->getPrompt(); } @@ -182,6 +176,24 @@ protected function writePrompt(OutputInterface $output, Question $question) $output->write($message); } + /** + * @return string[] + */ + protected function formatChoiceQuestionChoices(ChoiceQuestion $question, string $tag) + { + $messages = []; + + $maxWidth = max(array_map('self::strlen', array_keys($choices = $question->getChoices()))); + + foreach ($choices as $key => $value) { + $padding = str_repeat(' ', $maxWidth - self::strlen($key)); + + $messages[] = sprintf(" [<$tag>%s$padding] %s", $key, $value); + } + + return $messages; + } + /** * Outputs an error message. */ diff --git a/src/Symfony/Component/Console/Helper/SymfonyQuestionHelper.php b/src/Symfony/Component/Console/Helper/SymfonyQuestionHelper.php index 260c03e20bf85..e4e87b2f99188 100644 --- a/src/Symfony/Component/Console/Helper/SymfonyQuestionHelper.php +++ b/src/Symfony/Component/Console/Helper/SymfonyQuestionHelper.php @@ -68,15 +68,15 @@ protected function writePrompt(OutputInterface $output, Question $question) $output->writeln($text); + $prompt = ' > '; + if ($question instanceof ChoiceQuestion) { - $width = max(array_map('strlen', array_keys($question->getChoices()))); + $output->writeln($this->formatChoiceQuestionChoices($question, 'comment')); - foreach ($question->getChoices() as $key => $value) { - $output->writeln(sprintf(" [%-${width}s] %s", $key, $value)); - } + $prompt = $question->getPrompt(); } - $output->write(' > '); + $output->write($prompt); } /** diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index a43a53f844afd..4bfbc71c5bab4 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -616,7 +616,7 @@ public function testFindAlternativeCommands() $this->assertRegExp(sprintf('/Command "%s" is not defined./', $commandName), $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternatives'); $this->assertRegExp('/afoobar1/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternative : "afoobar1"'); $this->assertRegExp('/foo:bar1/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternative : "foo:bar1"'); - $this->assertNotRegExp('/foo:bar(?>!1)/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, without "foo:bar" alternative'); + $this->assertNotRegExp('/foo:bar(?!1)/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, without "foo:bar" alternative'); } } diff --git a/src/Symfony/Component/Console/Tests/Helper/SymfonyQuestionHelperTest.php b/src/Symfony/Component/Console/Tests/Helper/SymfonyQuestionHelperTest.php index cbf3b957b3913..b7a26f95087f9 100644 --- a/src/Symfony/Component/Console/Tests/Helper/SymfonyQuestionHelperTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/SymfonyQuestionHelperTest.php @@ -130,6 +130,49 @@ public function testAskThrowsExceptionOnMissingInput() $dialog->ask($this->createStreamableInputInterfaceMock($this->getInputStream('')), $this->createOutputInterface(), new Question('What\'s your name?')); } + public function testChoiceQuestionPadding() + { + $choiceQuestion = new ChoiceQuestion('qqq', [ + 'foo' => 'foo', + 'żółw' => 'bar', + 'łabądź' => 'baz', + ]); + + (new SymfonyQuestionHelper())->ask( + $this->createStreamableInputInterfaceMock($this->getInputStream("foo\n")), + $output = $this->createOutputInterface(), + $choiceQuestion + ); + + $this->assertOutputContains(<< +EOT + , $output); + } + + public function testChoiceQuestionCustomPrompt() + { + $choiceQuestion = new ChoiceQuestion('qqq', ['foo']); + $choiceQuestion->setPrompt(' >ccc> '); + + (new SymfonyQuestionHelper())->ask( + $this->createStreamableInputInterfaceMock($this->getInputStream("foo\n")), + $output = $this->createOutputInterface(), + $choiceQuestion + ); + + $this->assertOutputContains(<<ccc> +EOT + , $output); + } + protected function getInputStream($input) { $stream = fopen('php://memory', 'r+', false); diff --git a/src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php b/src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php index eaebac8e0c71a..bb87f47cddd47 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php @@ -50,21 +50,10 @@ public function process(ContainerBuilder $container) } if (class_exists($id) || interface_exists($id, false)) { if (0 === strpos($id, '\\') && 1 < substr_count($id, '\\')) { - throw new RuntimeException(sprintf( - 'The definition for "%s" has no class attribute, and appears to reference a class or interface. ' - .'Please specify the class attribute explicitly or remove the leading backslash by renaming ' - .'the service to "%s" to get rid of this error.', - $id, substr($id, 1) - )); + throw new RuntimeException(sprintf('The definition for "%s" has no class attribute, and appears to reference a class or interface. Please specify the class attribute explicitly or remove the leading backslash by renaming the service to "%s" to get rid of this error.', $id, substr($id, 1))); } - throw new RuntimeException(sprintf( - 'The definition for "%s" has no class attribute, and appears to reference a ' - .'class or interface in the global namespace. Leaving out the "class" attribute ' - .'is only allowed for namespaced classes. Please specify the class attribute ' - .'explicitly to get rid of this error.', - $id - )); + throw new RuntimeException(sprintf('The definition for "%s" has no class attribute, and appears to reference a class or interface in the global namespace. Leaving out the "class" attribute is only allowed for namespaced classes. Please specify the class attribute explicitly to get rid of this error.', $id)); } throw new RuntimeException(sprintf('The definition for "%s" has no class. If you intend to inject this service dynamically at runtime, please mark it as synthetic=true. If this is an abstract definition solely used by child definitions, please add abstract=true, otherwise specify a class to get rid of this error.', $id)); diff --git a/src/Symfony/Component/DependencyInjection/Compiler/CheckTypeDeclarationsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/CheckTypeDeclarationsPass.php index 161cd5960ca91..0743cbbb5ff1a 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/CheckTypeDeclarationsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/CheckTypeDeclarationsPass.php @@ -14,12 +14,16 @@ use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\Exception\EnvNotFoundException; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; use Symfony\Component\DependencyInjection\Exception\InvalidParameterTypeException; use Symfony\Component\DependencyInjection\Exception\RuntimeException; +use Symfony\Component\DependencyInjection\ExpressionLanguage; use Symfony\Component\DependencyInjection\Parameter; +use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ServiceLocator; +use Symfony\Component\ExpressionLanguage\Expression; /** * Checks whether injected parameters are compatible with type declarations. @@ -38,14 +42,19 @@ final class CheckTypeDeclarationsPass extends AbstractRecursivePass private const SCALAR_TYPES = ['int', 'float', 'bool', 'string']; private $autoload; + private $skippedIds; + + private $expressionLanguage; /** - * @param bool $autoload Whether services who's class in not loaded should be checked or not. - * Defaults to false to save loading code during compilation. + * @param bool $autoload Whether services who's class in not loaded should be checked or not. + * Defaults to false to save loading code during compilation. + * @param array $skippedIds An array indexed by the service ids to skip */ - public function __construct(bool $autoload = false) + public function __construct(bool $autoload = false, array $skippedIds = []) { $this->autoload = $autoload; + $this->skippedIds = $skippedIds; } /** @@ -53,6 +62,10 @@ public function __construct(bool $autoload = false) */ protected function processValue($value, $isRoot = false) { + if (isset($this->skippedIds[$this->currentId])) { + return $value; + } + if (!$value instanceof Definition || $value->hasErrors()) { return parent::processValue($value, $isRoot); } @@ -100,19 +113,21 @@ private function checkTypeDeclarations(Definition $checkedDefinition, \Reflectio $reflectionParameters = $reflectionFunction->getParameters(); $checksCount = min($reflectionFunction->getNumberOfParameters(), \count($values)); + $envPlaceholderUniquePrefix = $this->container->getParameterBag() instanceof EnvPlaceholderParameterBag ? $this->container->getParameterBag()->getEnvPlaceholderUniquePrefix() : null; + for ($i = 0; $i < $checksCount; ++$i) { if (!$reflectionParameters[$i]->hasType() || $reflectionParameters[$i]->isVariadic()) { continue; } - $this->checkType($checkedDefinition, $values[$i], $reflectionParameters[$i]); + $this->checkType($checkedDefinition, $values[$i], $reflectionParameters[$i], $envPlaceholderUniquePrefix); } if ($reflectionFunction->isVariadic() && ($lastParameter = end($reflectionParameters))->hasType()) { $variadicParameters = \array_slice($values, $lastParameter->getPosition()); foreach ($variadicParameters as $variadicParameter) { - $this->checkType($checkedDefinition, $variadicParameter, $lastParameter); + $this->checkType($checkedDefinition, $variadicParameter, $lastParameter, $envPlaceholderUniquePrefix); } } } @@ -120,7 +135,7 @@ private function checkTypeDeclarations(Definition $checkedDefinition, \Reflectio /** * @throws InvalidParameterTypeException When a parameter is not compatible with the declared type */ - private function checkType(Definition $checkedDefinition, $value, \ReflectionParameter $parameter): void + private function checkType(Definition $checkedDefinition, $value, \ReflectionParameter $parameter, ?string $envPlaceholderUniquePrefix): void { $type = $parameter->getType()->getName(); @@ -172,8 +187,24 @@ private function checkType(Definition $checkedDefinition, $value, \ReflectionPar if ($value instanceof Parameter) { $value = $this->container->getParameter($value); - } elseif (\is_string($value) && '%' === ($value[0] ?? '') && preg_match('/^%([^%]+)%$/', $value, $match)) { - $value = $this->container->getParameter($match[1]); + } elseif ($value instanceof Expression) { + $value = $this->getExpressionLanguage()->evaluate($value, ['container' => $this->container]); + } elseif (\is_string($value)) { + if ('%' === ($value[0] ?? '') && preg_match('/^%([^%]+)%$/', $value, $match)) { + // Only array parameters are not inlined when dumped. + $value = []; + } elseif ($envPlaceholderUniquePrefix && false !== strpos($value, 'env_')) { + // If the value is an env placeholder that is either mixed with a string or with another env placeholder, then its resolved value will always be a string, so we don't need to resolve it. + // We don't need to change the value because it is already a string. + if ('' === preg_replace('/'.$envPlaceholderUniquePrefix.'_\w+_[a-f0-9]{32}/U', '', $value, -1, $c) && 1 === $c) { + try { + $value = $this->container->resolveEnvPlaceholders($value, true); + } catch (EnvNotFoundException | RuntimeException $e) { + // If an env placeholder cannot be resolved, we skip the validation. + return; + } + } + } } if (null === $value && $parameter->allowsNull()) { @@ -202,4 +233,13 @@ private function checkType(Definition $checkedDefinition, $value, \ReflectionPar throw new InvalidParameterTypeException($this->currentId, \is_object($value) ? \get_class($value) : \gettype($value), $parameter); } } + + private function getExpressionLanguage(): ExpressionLanguage + { + if (null === $this->expressionLanguage) { + $this->expressionLanguage = new ExpressionLanguage(null, $this->container->getExpressionLanguageProviders()); + } + + return $this->expressionLanguage; + } } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php b/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php index 8b5cfb683d882..8df9f0e25a9fa 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php @@ -52,13 +52,13 @@ public function __construct() new ValidateEnvPlaceholdersPass(), new ResolveChildDefinitionsPass(), new RegisterServiceSubscribersPass(), - new DecoratorServicePass(), new ResolveParameterPlaceHoldersPass(false), new ResolveFactoryClassPass(), new ResolveNamedArgumentsPass(), new AutowireRequiredMethodsPass(), new ResolveBindingsPass(), new ServiceLocatorTagPass(), + new DecoratorServicePass(), new CheckDefinitionValidityPass(), new AutowirePass(false), new ResolveTaggedIteratorArgumentPass(), diff --git a/src/Symfony/Component/DependencyInjection/Compiler/RegisterServiceSubscribersPass.php b/src/Symfony/Component/DependencyInjection/Compiler/RegisterServiceSubscribersPass.php index ca49092d84009..7d9c366da8895 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/RegisterServiceSubscribersPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/RegisterServiceSubscribersPass.php @@ -11,11 +11,14 @@ namespace Symfony\Component\DependencyInjection\Compiler; +use Psr\Container\ContainerInterface as PsrContainerInterface; +use Symfony\Component\DependencyInjection\Argument\BoundArgument; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\TypedReference; +use Symfony\Contracts\Service\ServiceProviderInterface; use Symfony\Contracts\Service\ServiceSubscriberInterface; /** @@ -105,7 +108,14 @@ protected function processValue($value, bool $isRoot = false) throw new InvalidArgumentException(sprintf('Service %s not exist in the map returned by "%s::getSubscribedServices()" for service "%s".', $message, $class, $this->currentId)); } - $value->addTag('container.service_subscriber.locator', ['id' => (string) ServiceLocatorTagPass::register($this->container, $subscriberMap, $this->currentId)]); + $locatorRef = ServiceLocatorTagPass::register($this->container, $subscriberMap, $this->currentId); + + $value->addTag('container.service_subscriber.locator', ['id' => (string) $locatorRef]); + + $value->setBindings([ + PsrContainerInterface::class => new BoundArgument($locatorRef, false), + ServiceProviderInterface::class => new BoundArgument($locatorRef, false), + ] + $value->getBindings()); return parent::processValue($value); } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveBindingsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveBindingsPass.php index 4140bade84969..77eff72565b7e 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveBindingsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveBindingsPass.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Compiler; use Symfony\Component\DependencyInjection\Argument\BoundArgument; +use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument; use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; @@ -96,6 +97,11 @@ protected function processValue($value, bool $isRoot = false) if ($value instanceof TypedReference && $value->getType() === (string) $value) { // Already checked $bindings = $this->container->getDefinition($this->currentId)->getBindings(); + $name = $value->getName(); + + if (isset($name, $bindings[$name = $value.' $'.$name])) { + return $this->getBindingValue($bindings[$name]); + } if (isset($bindings[$value->getType()])) { return $this->getBindingValue($bindings[$value->getType()]); @@ -121,8 +127,8 @@ protected function processValue($value, bool $isRoot = false) continue; } - if (null !== $bindingValue && !$bindingValue instanceof Reference && !$bindingValue instanceof Definition && !$bindingValue instanceof TaggedIteratorArgument) { - throw new InvalidArgumentException(sprintf('Invalid value for binding key "%s" for service "%s": expected null, an instance of %s or an instance of %s or an instance of %s, %s given.', $key, $this->currentId, Reference::class, Definition::class, TaggedIteratorArgument::class, \gettype($bindingValue))); + if (null !== $bindingValue && !$bindingValue instanceof Reference && !$bindingValue instanceof Definition && !$bindingValue instanceof TaggedIteratorArgument && !$bindingValue instanceof ServiceLocatorArgument) { + throw new InvalidArgumentException(sprintf('Invalid value for binding key "%s" for service "%s": expected null, %s, %s, %s or ServiceLocatorArgument, %s given.', $key, $this->currentId, Reference::class, Definition::class, TaggedIteratorArgument::class, \gettype($bindingValue))); } } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveInstanceofConditionalsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveInstanceofConditionalsPass.php index be8f8e7fd4d86..96afb039c6642 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveInstanceofConditionalsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveInstanceofConditionalsPass.php @@ -63,9 +63,10 @@ private function processDefinition(ContainerBuilder $container, string $id, Defi $instanceofTags = []; $instanceofCalls = []; $instanceofBindings = []; + $reflectionClass = null; foreach ($conditionals as $interface => $instanceofDefs) { - if ($interface !== $class && (!$container->getReflectionClass($class, false))) { + if ($interface !== $class && !(null === $reflectionClass ? $reflectionClass = ($container->getReflectionClass($class, false) ?: false) : $reflectionClass)) { continue; } diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index 57761c5fe2881..b0dd26912b62a 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -203,14 +203,14 @@ public function dump(array $options = []) if (!empty($options['file']) && is_dir($dir = \dirname($options['file']))) { // Build a regexp where the first root dirs are mandatory, // but every other sub-dir is optional up to the full path in $dir - // Mandate at least 2 root dirs and not more that 5 optional dirs. + // Mandate at least 1 root dir and not more than 5 optional dirs. $dir = explode(\DIRECTORY_SEPARATOR, realpath($dir)); $i = \count($dir); - if (3 <= $i) { + if (2 + (int) ('\\' === \DIRECTORY_SEPARATOR) <= $i) { $regex = ''; - $lastOptionalDir = $i > 8 ? $i - 5 : 3; + $lastOptionalDir = $i > 8 ? $i - 5 : (2 + (int) ('\\' === \DIRECTORY_SEPARATOR)); $this->targetDirMaxMatches = $i - $lastOptionalDir; while (--$i >= $lastOptionalDir) { diff --git a/src/Symfony/Component/DependencyInjection/Extension/Extension.php b/src/Symfony/Component/DependencyInjection/Extension/Extension.php index 5cf6d96080c3d..ffa47074d6944 100644 --- a/src/Symfony/Component/DependencyInjection/Extension/Extension.php +++ b/src/Symfony/Component/DependencyInjection/Extension/Extension.php @@ -81,6 +81,11 @@ public function getAlias() public function getConfiguration(array $config, ContainerBuilder $container) { $class = \get_class($this); + + if (false !== strpos($class, "\0")) { + return null; // ignore anonymous classes + } + $class = substr_replace($class, '\Configuration', strrpos($class, '\\')); $class = $container->getReflectionClass($class); diff --git a/src/Symfony/Component/DependencyInjection/Loader/Configurator/ContainerConfigurator.php b/src/Symfony/Component/DependencyInjection/Loader/Configurator/ContainerConfigurator.php index e6ac74d023131..28c9d7958591d 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/Configurator/ContainerConfigurator.php +++ b/src/Symfony/Component/DependencyInjection/Loader/Configurator/ContainerConfigurator.php @@ -48,13 +48,7 @@ final public function extension(string $namespace, array $config) { if (!$this->container->hasExtension($namespace)) { $extensions = array_filter(array_map(function (ExtensionInterface $ext) { return $ext->getAlias(); }, $this->container->getExtensions())); - throw new InvalidArgumentException(sprintf( - 'There is no extension able to load the configuration for "%s" (in %s). Looked for namespace "%s", found %s', - $namespace, - $this->file, - $namespace, - $extensions ? sprintf('"%s"', implode('", "', $extensions)) : 'none' - )); + throw new InvalidArgumentException(sprintf('There is no extension able to load the configuration for "%s" (in %s). Looked for namespace "%s", found %s', $namespace, $this->file, $namespace, $extensions ? sprintf('"%s"', implode('", "', $extensions)) : 'none')); } $this->container->loadFromExtension($namespace, static::processValue($config)); diff --git a/src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/CallTrait.php b/src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/CallTrait.php index 39c5ecc7d8b91..28f92d274fe11 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/CallTrait.php +++ b/src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/CallTrait.php @@ -18,16 +18,17 @@ trait CallTrait /** * Adds a method to call after service initialization. * - * @param string $method The method name to call - * @param array $arguments An array of arguments to pass to the method call + * @param string $method The method name to call + * @param array $arguments An array of arguments to pass to the method call + * @param bool $returnsClone Whether the call returns the service instance or not * * @return $this * * @throws InvalidArgumentException on empty $method param */ - final public function call(string $method, array $arguments = []): self + final public function call(string $method, array $arguments = [], bool $returnsClone = false): self { - $this->definition->addMethodCall($method, static::processValue($arguments, true)); + $this->definition->addMethodCall($method, static::processValue($arguments, true), $returnsClone); return $this; } diff --git a/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php index 1b615c758eaee..26577c9ef881a 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php @@ -73,7 +73,7 @@ public function import($resource, $type = null, $ignoreErrors = false, $sourceRe } } - if ($args !== $frame['args']) { + if (__FILE__ !== $frame['file']) { throw $e; } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php index e036059f53534..a220edd49339a 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php @@ -40,7 +40,7 @@ public function testProcess() $container = new ContainerBuilder(); $container->register(Foo::class); - $barDefinition = $container->register('bar', __NAMESPACE__.'\Bar'); + $barDefinition = $container->register('bar', Bar::class); $barDefinition->setAutowired(true); (new ResolveClassPass())->process($container); @@ -55,7 +55,7 @@ public function testProcessNotExistingActionParam() $container = new ContainerBuilder(); $container->register(Foo::class); - $barDefinition = $container->register(__NAMESPACE__.'EslaAction', __NAMESPACE__.'\ElsaAction'); + $barDefinition = $container->register(ElsaAction::class, ElsaAction::class); $barDefinition->setAutowired(true); (new ResolveClassPass())->process($container); @@ -63,7 +63,7 @@ public function testProcessNotExistingActionParam() (new AutowirePass())->process($container); $this->fail('AutowirePass should have thrown an exception'); } catch (AutowiringFailedException $e) { - $this->assertSame('Cannot autowire service "Symfony\Component\DependencyInjection\Tests\CompilerEslaAction": argument "$notExisting" of method "Symfony\Component\DependencyInjection\Tests\Compiler\ElsaAction::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotExisting" but this class was not found.', (string) $e->getMessage()); + $this->assertSame('Cannot autowire service "Symfony\Component\DependencyInjection\Tests\Compiler\ElsaAction": argument "$notExisting" of method "__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotExisting" but this class was not found.', (string) $e->getMessage()); } } @@ -86,7 +86,7 @@ public function testProcessAutowireParent() $container = new ContainerBuilder(); $container->register(B::class); - $cDefinition = $container->register('c', __NAMESPACE__.'\C'); + $cDefinition = $container->register('c', C::class); $cDefinition->setAutowired(true); (new ResolveClassPass())->process($container); @@ -103,7 +103,7 @@ public function testProcessAutowireInterface() $container = new ContainerBuilder(); $container->register(F::class); - $gDefinition = $container->register('g', __NAMESPACE__.'\G'); + $gDefinition = $container->register('g', G::class); $gDefinition->setAutowired(true); (new ResolveClassPass())->process($container); @@ -119,9 +119,9 @@ public function testCompleteExistingDefinition() { $container = new ContainerBuilder(); - $container->register('b', __NAMESPACE__.'\B'); + $container->register('b', B::class); $container->register(DInterface::class, F::class); - $hDefinition = $container->register('h', __NAMESPACE__.'\H')->addArgument(new Reference('b')); + $hDefinition = $container->register('h', H::class)->addArgument(new Reference('b')); $hDefinition->setAutowired(true); (new ResolveClassPass())->process($container); @@ -138,7 +138,7 @@ public function testCompleteExistingDefinitionWithNotDefinedArguments() $container->register(B::class); $container->register(DInterface::class, F::class); - $hDefinition = $container->register('h', __NAMESPACE__.'\H')->addArgument('')->addArgument(''); + $hDefinition = $container->register('h', H::class)->addArgument('')->addArgument(''); $hDefinition->setAutowired(true); (new ResolveClassPass())->process($container); @@ -153,7 +153,7 @@ public function testPrivateConstructorThrowsAutowireException() { $container = new ContainerBuilder(); - $container->autowire('private_service', __NAMESPACE__.'\PrivateConstructor'); + $container->autowire('private_service', PrivateConstructor::class); $pass = new AutowirePass(true); try { @@ -168,10 +168,10 @@ public function testTypeCollision() { $container = new ContainerBuilder(); - $container->register('c1', __NAMESPACE__.'\CollisionA'); - $container->register('c2', __NAMESPACE__.'\CollisionB'); - $container->register('c3', __NAMESPACE__.'\CollisionB'); - $aDefinition = $container->register('a', __NAMESPACE__.'\CannotBeAutowired'); + $container->register('c1', CollisionA::class); + $container->register('c2', CollisionB::class); + $container->register('c3', CollisionB::class); + $aDefinition = $container->register('a', CannotBeAutowired::class); $aDefinition->setAutowired(true); $pass = new AutowirePass(); @@ -187,9 +187,9 @@ public function testTypeNotGuessable() { $container = new ContainerBuilder(); - $container->register('a1', __NAMESPACE__.'\Foo'); - $container->register('a2', __NAMESPACE__.'\Foo'); - $aDefinition = $container->register('a', __NAMESPACE__.'\NotGuessableArgument'); + $container->register('a1', Foo::class); + $container->register('a2', Foo::class); + $aDefinition = $container->register('a', NotGuessableArgument::class); $aDefinition->setAutowired(true); $pass = new AutowirePass(); @@ -205,9 +205,9 @@ public function testTypeNotGuessableWithSubclass() { $container = new ContainerBuilder(); - $container->register('a1', __NAMESPACE__.'\B'); - $container->register('a2', __NAMESPACE__.'\B'); - $aDefinition = $container->register('a', __NAMESPACE__.'\NotGuessableArgumentForSubclass'); + $container->register('a1', B::class); + $container->register('a2', B::class); + $aDefinition = $container->register('a', NotGuessableArgumentForSubclass::class); $aDefinition->setAutowired(true); $pass = new AutowirePass(); @@ -223,7 +223,7 @@ public function testTypeNotGuessableNoServicesFound() { $container = new ContainerBuilder(); - $aDefinition = $container->register('a', __NAMESPACE__.'\CannotBeAutowired'); + $aDefinition = $container->register('a', CannotBeAutowired::class); $aDefinition->setAutowired(true); $pass = new AutowirePass(); @@ -239,10 +239,10 @@ public function testTypeNotGuessableWithTypeSet() { $container = new ContainerBuilder(); - $container->register('a1', __NAMESPACE__.'\Foo'); - $container->register('a2', __NAMESPACE__.'\Foo'); + $container->register('a1', Foo::class); + $container->register('a2', Foo::class); $container->register(Foo::class, Foo::class); - $aDefinition = $container->register('a', __NAMESPACE__.'\NotGuessableArgument'); + $aDefinition = $container->register('a', NotGuessableArgument::class); $aDefinition->setAutowired(true); $pass = new AutowirePass(); @@ -256,10 +256,10 @@ public function testWithTypeSet() { $container = new ContainerBuilder(); - $container->register('c1', __NAMESPACE__.'\CollisionA'); - $container->register('c2', __NAMESPACE__.'\CollisionB'); + $container->register('c1', CollisionA::class); + $container->register('c2', CollisionB::class); $container->setAlias(CollisionInterface::class, 'c2'); - $aDefinition = $container->register('a', __NAMESPACE__.'\CannotBeAutowired'); + $aDefinition = $container->register('a', CannotBeAutowired::class); $aDefinition->setAutowired(true); $pass = new AutowirePass(); @@ -273,7 +273,7 @@ public function testServicesAreNotAutoCreated() { $container = new ContainerBuilder(); - $coopTilleulsDefinition = $container->register('coop_tilleuls', __NAMESPACE__.'\LesTilleuls'); + $coopTilleulsDefinition = $container->register('coop_tilleuls', LesTilleuls::class); $coopTilleulsDefinition->setAutowired(true); $pass = new AutowirePass(); @@ -306,7 +306,7 @@ public function testOptionalParameter() $container->register(A::class); $container->register(Foo::class); - $optDefinition = $container->register('opt', __NAMESPACE__.'\OptionalParameter'); + $optDefinition = $container->register('opt', OptionalParameter::class); $optDefinition->setAutowired(true); (new ResolveClassPass())->process($container); @@ -323,7 +323,7 @@ public function testDontTriggerAutowiring() $container = new ContainerBuilder(); $container->register(Foo::class); - $container->register('bar', __NAMESPACE__.'\Bar'); + $container->register('bar', Bar::class); (new ResolveClassPass())->process($container); (new AutowirePass())->process($container); @@ -335,7 +335,7 @@ public function testClassNotFoundThrowsException() { $container = new ContainerBuilder(); - $aDefinition = $container->register('a', __NAMESPACE__.'\BadTypeHintedArgument'); + $aDefinition = $container->register('a', BadTypeHintedArgument::class); $aDefinition->setAutowired(true); $container->register(Dunglas::class, Dunglas::class); @@ -353,7 +353,7 @@ public function testParentClassNotFoundThrowsException() { $container = new ContainerBuilder(); - $aDefinition = $container->register('a', __NAMESPACE__.'\BadParentTypeHintedArgument'); + $aDefinition = $container->register('a', BadParentTypeHintedArgument::class); $aDefinition->setAutowired(true); $container->register(Dunglas::class, Dunglas::class); @@ -372,8 +372,8 @@ public function testDontUseAbstractServices() $container = new ContainerBuilder(); $container->register(Foo::class)->setAbstract(true); - $container->register('foo', __NAMESPACE__.'\Foo'); - $container->register('bar', __NAMESPACE__.'\Bar')->setAutowired(true); + $container->register('foo', Foo::class); + $container->register('bar', Bar::class)->setAutowired(true); (new ResolveClassPass())->process($container); try { @@ -391,7 +391,7 @@ public function testSomeSpecificArgumentsAreSet() $container->register('foo', Foo::class); $container->register(A::class); $container->register(Dunglas::class); - $container->register('multiple', __NAMESPACE__.'\MultipleArguments') + $container->register('multiple', MultipleArguments::class) ->setAutowired(true) // set the 2nd (index 1) argument only: autowire the first and third // args are: A, Foo, Dunglas @@ -421,7 +421,7 @@ public function testScalarArgsCannotBeAutowired() $container->register(A::class); $container->register(Dunglas::class); - $container->register('arg_no_type_hint', __NAMESPACE__.'\MultipleArguments') + $container->register('arg_no_type_hint', MultipleArguments::class) ->setArguments([1 => 'foo']) ->setAutowired(true); @@ -440,7 +440,7 @@ public function testNoTypeArgsCannotBeAutowired() $container->register(A::class); $container->register(Dunglas::class); - $container->register('arg_no_type_hint', __NAMESPACE__.'\MultipleArguments') + $container->register('arg_no_type_hint', MultipleArguments::class) ->setAutowired(true); (new ResolveClassPass())->process($container); @@ -458,7 +458,7 @@ public function testOptionalScalarNotReallyOptionalUsesDefaultValue() $container->register(A::class); $container->register(Lille::class); - $definition = $container->register('not_really_optional_scalar', __NAMESPACE__.'\MultipleArgumentsOptionalScalarNotReallyOptional') + $definition = $container->register('not_really_optional_scalar', MultipleArgumentsOptionalScalarNotReallyOptional::class) ->setAutowired(true); (new ResolveClassPass())->process($container); @@ -473,7 +473,7 @@ public function testOptionalScalarArgsDontMessUpOrder() $container->register(A::class); $container->register(Lille::class); - $container->register('with_optional_scalar', __NAMESPACE__.'\MultipleArgumentsOptionalScalar') + $container->register('with_optional_scalar', MultipleArgumentsOptionalScalar::class) ->setAutowired(true); (new ResolveClassPass())->process($container); @@ -497,7 +497,7 @@ public function testOptionalScalarArgsNotPassedIfLast() $container->register(A::class); $container->register(Lille::class); - $container->register('with_optional_scalar_last', __NAMESPACE__.'\MultipleArgumentsOptionalScalarLast') + $container->register('with_optional_scalar_last', MultipleArgumentsOptionalScalarLast::class) ->setAutowired(true); (new ResolveClassPass())->process($container); @@ -624,9 +624,9 @@ public function testIgnoreServiceWithClassNotExisting() { $container = new ContainerBuilder(); - $container->register('class_not_exist', __NAMESPACE__.'\OptionalServiceClass'); + $container->register('class_not_exist', OptionalServiceClass::class); - $barDefinition = $container->register('bar', __NAMESPACE__.'\Bar'); + $barDefinition = $container->register('bar', Bar::class); $barDefinition->setAutowired(true); $container->register(Foo::class, Foo::class); @@ -680,8 +680,8 @@ public function testProcessDoesNotTriggerDeprecations() { $container = new ContainerBuilder(); $container->register('deprecated', 'Symfony\Component\DependencyInjection\Tests\Fixtures\DeprecatedClass')->setDeprecated(true); - $container->register('foo', __NAMESPACE__.'\Foo'); - $container->register('bar', __NAMESPACE__.'\Bar')->setAutowired(true); + $container->register('foo', Foo::class); + $container->register('bar', Bar::class)->setAutowired(true); $pass = new AutowirePass(); try { @@ -702,7 +702,7 @@ public function testEmptyStringIsKept() $container->register(A::class); $container->register(Lille::class); - $container->register('foo', __NAMESPACE__.'\MultipleArgumentsOptionalScalar') + $container->register('foo', MultipleArgumentsOptionalScalar::class) ->setAutowired(true) ->setArguments(['', '']); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckTypeDeclarationsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckTypeDeclarationsPassTest.php index b012a65625610..13c34e156c67a 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckTypeDeclarationsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckTypeDeclarationsPassTest.php @@ -14,8 +14,10 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\Compiler\CheckTypeDeclarationsPass; +use Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Bar; use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarMethodCall; @@ -23,6 +25,7 @@ use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarOptionalArgumentNotNull; use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Foo; use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\FooObject; +use Symfony\Component\ExpressionLanguage\Expression; /** * @author Nicolas Grekas @@ -569,4 +572,113 @@ public function testProcessThrowsOnIterableTypeWhenScalarPassed() $this->assertInstanceOf(\stdClass::class, $container->get('bar')->foo); } + + public function testProcessResolveArrayParameters() + { + $container = new ContainerBuilder(); + $container->setParameter('ccc', ['foobar']); + + $container + ->register('foobar', BarMethodCall::class) + ->addMethodCall('setArray', ['%ccc%']); + + (new CheckTypeDeclarationsPass(true))->process($container); + + $this->addToAssertionCount(1); + } + + public function testProcessResolveExpressions() + { + $container = new ContainerBuilder(); + $container->setParameter('ccc', ['array']); + + $container + ->register('foobar', BarMethodCall::class) + ->addMethodCall('setArray', [new Expression("parameter('ccc')")]); + + (new CheckTypeDeclarationsPass(true))->process($container); + + $this->addToAssertionCount(1); + } + + public function testProcessHandleMixedEnvPlaceholder() + { + $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid definition for service "foobar": argument 1 of "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarMethodCall::setArray" accepts "array", "string" passed.'); + + $container = new ContainerBuilder(new EnvPlaceholderParameterBag([ + 'ccc' => '%env(FOO)%', + ])); + + $container + ->register('foobar', BarMethodCall::class) + ->addMethodCall('setArray', ['foo%ccc%']); + + (new CheckTypeDeclarationsPass(true))->process($container); + } + + public function testProcessHandleMultipleEnvPlaceholder() + { + $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid definition for service "foobar": argument 1 of "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarMethodCall::setArray" accepts "array", "string" passed.'); + + $container = new ContainerBuilder(new EnvPlaceholderParameterBag([ + 'ccc' => '%env(FOO)%', + 'fcy' => '%env(int:BAR)%', + ])); + + $container + ->register('foobar', BarMethodCall::class) + ->addMethodCall('setArray', ['%ccc%%fcy%']); + + (new CheckTypeDeclarationsPass(true))->process($container); + } + + public function testProcessHandleExistingEnvPlaceholder() + { + putenv('ARRAY={"foo":"bar"}'); + + $container = new ContainerBuilder(new EnvPlaceholderParameterBag([ + 'ccc' => '%env(json:ARRAY)%', + ])); + + $container + ->register('foobar', BarMethodCall::class) + ->addMethodCall('setArray', ['%ccc%']); + + (new ResolveParameterPlaceHoldersPass())->process($container); + (new CheckTypeDeclarationsPass(true))->process($container); + + $this->addToAssertionCount(1); + + putenv('ARRAY='); + } + + public function testProcessHandleNotFoundEnvPlaceholder() + { + $container = new ContainerBuilder(new EnvPlaceholderParameterBag([ + 'ccc' => '%env(json:ARRAY)%', + ])); + + $container + ->register('foobar', BarMethodCall::class) + ->addMethodCall('setArray', ['%ccc%']); + + (new ResolveParameterPlaceHoldersPass())->process($container); + (new CheckTypeDeclarationsPass(true))->process($container); + + $this->addToAssertionCount(1); + } + + public function testProcessSkipSkippedIds() + { + $container = new ContainerBuilder(); + $container + ->register('foobar', BarMethodCall::class) + ->addMethodCall('setArray', ['a string']); + + (new CheckTypeDeclarationsPass(true, ['foobar' => true]))->process($container); + + $this->addToAssertionCount(1); + } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/IntegrationTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/IntegrationTest.php index 2676f89a6c0a8..7d4f01a2657f3 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/IntegrationTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/IntegrationTest.php @@ -24,6 +24,7 @@ use Symfony\Component\DependencyInjection\Tests\Fixtures\FooBarTaggedClass; use Symfony\Component\DependencyInjection\Tests\Fixtures\FooBarTaggedForDefaultPriorityClass; use Symfony\Component\DependencyInjection\Tests\Fixtures\FooTagClass; +use Symfony\Contracts\Service\ServiceProviderInterface; use Symfony\Contracts\Service\ServiceSubscriberInterface; /** @@ -143,6 +144,29 @@ public function testCanDecorateServiceSubscriber() $this->assertInstanceOf(DecoratedServiceSubscriber::class, $container->get(ServiceSubscriberStub::class)); } + public function testCanDecorateServiceLocator() + { + $container = new ContainerBuilder(); + + $container->register('foo', 'stdClass')->setPublic(true); + + $container->register(ServiceLocator::class) + ->addTag('container.service_locator') + ->setArguments([[new Reference('foo')]]) + ; + + $container->register(DecoratedServiceLocator::class) + ->setDecoratedService(ServiceLocator::class) + ->setPublic(true) + ->setArguments([new Reference(DecoratedServiceLocator::class.'.inner')]) + ; + + $container->compile(); + + $this->assertInstanceOf(DecoratedServiceLocator::class, $container->get(DecoratedServiceLocator::class)); + $this->assertSame($container->get('foo'), $container->get(DecoratedServiceLocator::class)->get('foo')); + } + /** * @dataProvider getYamlCompileTests */ @@ -441,6 +465,34 @@ class DecoratedServiceSubscriber { } +class DecoratedServiceLocator implements ServiceProviderInterface +{ + /** + * @var ServiceLocator + */ + private $locator; + + public function __construct(ServiceLocator $locator) + { + $this->locator = $locator; + } + + public function get($id) + { + return $this->locator->get($id); + } + + public function has($id): bool + { + return $this->locator->has($id); + } + + public function getProvidedServices(): array + { + return $this->locator->getProvidedServices(); + } +} + class IntegrationTestStub extends IntegrationTestStubParent { } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterServiceSubscribersPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterServiceSubscribersPassTest.php index 699da6a31155b..6046f79639e99 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterServiceSubscribersPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterServiceSubscribersPassTest.php @@ -16,6 +16,7 @@ use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; use Symfony\Component\DependencyInjection\Compiler\AutowirePass; use Symfony\Component\DependencyInjection\Compiler\RegisterServiceSubscribersPass; +use Symfony\Component\DependencyInjection\Compiler\ResolveBindingsPass; use Symfony\Component\DependencyInjection\Compiler\ResolveServiceSubscribersPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -235,4 +236,32 @@ public static function getSubscribedServices(): array ]; $this->assertEquals($expected, $container->getDefinition((string) $locator->getFactory()[0])->getArgument(0)); } + + public function testBinding() + { + $container = new ContainerBuilder(); + + $container->register('foo', TestServiceSubscriber::class) + ->addMethodCall('setServiceProvider') + ->addTag('container.service_subscriber') + ; + + (new RegisterServiceSubscribersPass())->process($container); + (new ResolveBindingsPass())->process($container); + + $foo = $container->getDefinition('foo'); + $locator = $container->getDefinition((string) $foo->getMethodCalls()[0][1][0]); + + $this->assertFalse($locator->isPublic()); + $this->assertSame(ServiceLocator::class, $locator->getClass()); + + $expected = [ + TestServiceSubscriber::class => new ServiceClosureArgument(new TypedReference(TestServiceSubscriber::class, TestServiceSubscriber::class)), + CustomDefinition::class => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)), + 'bar' => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, 'bar')), + 'baz' => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE, 'baz')), + ]; + + $this->assertEquals($expected, $container->getDefinition((string) $locator->getFactory()[0])->getArgument(0)); + } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveBindingsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveBindingsPassTest.php index 10d684a7691fa..87a5cf2261b4a 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveBindingsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveBindingsPassTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\Argument\BoundArgument; +use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument; use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument; use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass; use Symfony\Component\DependencyInjection\Compiler\DefinitionErrorExceptionPass; @@ -35,6 +36,7 @@ public function testProcess() $bindings = [ CaseSensitiveClass::class => new BoundArgument(new Reference('foo')), + 'Psr\Container\ContainerInterface $container' => new BoundArgument(new ServiceLocatorArgument([]), true, BoundArgument::INSTANCEOF_BINDING), 'iterable $objects' => new BoundArgument(new TaggedIteratorArgument('tag.name'), true, BoundArgument::INSTANCEOF_BINDING), ]; @@ -49,7 +51,13 @@ public function testProcess() $pass = new ResolveBindingsPass(); $pass->process($container); - $this->assertEquals([0 => new Reference('foo'), 1 => '123', 4 => new TaggedIteratorArgument('tag.name')], $definition->getArguments()); + $expected = [ + 0 => new Reference('foo'), + 1 => '123', + 3 => new ServiceLocatorArgument([]), + 4 => new TaggedIteratorArgument('tag.name'), + ]; + $this->assertEquals($expected, $definition->getArguments()); $this->assertEquals([['setSensitiveClass', [new Reference('foo')]]], $definition->getMethodCalls()); } @@ -84,7 +92,10 @@ public function testTypedReferenceSupport() { $container = new ContainerBuilder(); - $bindings = [CaseSensitiveClass::class => new BoundArgument(new Reference('foo'))]; + $bindings = [ + CaseSensitiveClass::class => new BoundArgument(new Reference('foo')), + CaseSensitiveClass::class.' $c' => new BoundArgument(new Reference('bar')), + ]; // Explicit service id $definition1 = $container->register('def1', NamedArgumentsDummy::class); @@ -95,11 +106,16 @@ public function testTypedReferenceSupport() $definition2->addArgument(new TypedReference(CaseSensitiveClass::class, CaseSensitiveClass::class)); $definition2->setBindings($bindings); + $definition3 = $container->register('def3', NamedArgumentsDummy::class); + $definition3->addArgument(new TypedReference(CaseSensitiveClass::class, CaseSensitiveClass::class, ContainerBuilder::EXCEPTION_ON_INVALID_REFERENCE, 'c')); + $definition3->setBindings($bindings); + $pass = new ResolveBindingsPass(); $pass->process($container); $this->assertEquals([$typedRef], $container->getDefinition('def1')->getArguments()); $this->assertEquals([new Reference('foo')], $container->getDefinition('def2')->getArguments()); + $this->assertEquals([new Reference('bar')], $container->getDefinition('def3')->getArguments()); } public function testScalarSetter() diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php index b508576327201..e8a63a24782fb 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php @@ -1245,7 +1245,7 @@ public function testAutowiring() $container = new ContainerBuilder(); $container->register(A::class)->setPublic(true); - $bDefinition = $container->register('b', __NAMESPACE__.'\B'); + $bDefinition = $container->register('b', B::class); $bDefinition->setAutowired(true); $bDefinition->setPublic(true); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsDummy.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsDummy.php index eba4a86a2f7a8..15b11353b2ce8 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsDummy.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsDummy.php @@ -9,7 +9,7 @@ */ class NamedArgumentsDummy { - public function __construct(CaseSensitiveClass $c, $apiKey, $hostName, ContainerInterface $interface, iterable $objects) + public function __construct(CaseSensitiveClass $c, $apiKey, $hostName, ContainerInterface $container, iterable $objects) { } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/TestServiceSubscriber.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/TestServiceSubscriber.php index 968ff85f04440..6876fc5cca53d 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/TestServiceSubscriber.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/TestServiceSubscriber.php @@ -2,6 +2,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Fixtures; +use Symfony\Contracts\Service\ServiceProviderInterface; use Symfony\Contracts\Service\ServiceSubscriberInterface; class TestServiceSubscriber implements ServiceSubscriberInterface @@ -10,6 +11,10 @@ public function __construct($container) { } + public function setServiceProvider(ServiceProviderInterface $container) + { + } + public static function getSubscribedServices(): array { return [ diff --git a/src/Symfony/Component/Dotenv/Dotenv.php b/src/Symfony/Component/Dotenv/Dotenv.php index 38fb908897fee..eb17855427cc4 100644 --- a/src/Symfony/Component/Dotenv/Dotenv.php +++ b/src/Symfony/Component/Dotenv/Dotenv.php @@ -35,7 +35,7 @@ final class Dotenv private $data; private $end; private $values; - private $usePutenv = true; + private $usePutenv; /** * @var bool If `putenv()` should be used to define environment variables or not. @@ -458,7 +458,7 @@ private function resolveVariables(string $value, array $loadedVars): string } elseif (isset($this->values[$name])) { $value = $this->values[$name]; } else { - $value = ''; + $value = (string) getenv($name); } if ('' === $value && isset($matches['default_value']) && '' !== $matches['default_value']) { diff --git a/src/Symfony/Component/Dotenv/Tests/DotenvTest.php b/src/Symfony/Component/Dotenv/Tests/DotenvTest.php index 489c7fa6d1933..b1d7e7b37aa43 100644 --- a/src/Symfony/Component/Dotenv/Tests/DotenvTest.php +++ b/src/Symfony/Component/Dotenv/Tests/DotenvTest.php @@ -443,6 +443,17 @@ public function testGetVariablesValueFromEnvFirst() } } + public function testGetVariablesValueFromGetenv() + { + putenv('Foo=Bar'); + + $dotenv = new Dotenv(true); + $values = $dotenv->parse('Foo=${Foo}'); + $this->assertSame('Bar', $values['Foo']); + + putenv('Foo'); + } + public function testNoDeprecationWarning() { $dotenv = new Dotenv(true); diff --git a/src/Symfony/Component/ErrorHandler/DebugClassLoader.php b/src/Symfony/Component/ErrorHandler/DebugClassLoader.php index 7ab4c00bd3f33..a9ce96efda5e6 100644 --- a/src/Symfony/Component/ErrorHandler/DebugClassLoader.php +++ b/src/Symfony/Component/ErrorHandler/DebugClassLoader.php @@ -11,7 +11,8 @@ namespace Symfony\Component\ErrorHandler; -use Doctrine\Common\Persistence\Proxy; +use Doctrine\Common\Persistence\Proxy as LegacyProxy; +use Doctrine\Persistence\Proxy; use PHPUnit\Framework\MockObject\Matcher\StatelessInvocation; use PHPUnit\Framework\MockObject\MockObject; use Prophecy\Prophecy\ProphecySubjectInterface; @@ -298,6 +299,7 @@ public static function checkClasses(): bool && !is_subclass_of($symbols[$i], ProphecySubjectInterface::class) && !is_subclass_of($symbols[$i], Proxy::class) && !is_subclass_of($symbols[$i], ProxyInterface::class) + && !is_subclass_of($symbols[$i], LegacyProxy::class) ) { $loader->checkClass($symbols[$i]); } diff --git a/src/Symfony/Component/ErrorHandler/ErrorHandler.php b/src/Symfony/Component/ErrorHandler/ErrorHandler.php index 7e2bf11ef2085..f4dcfb10942ea 100644 --- a/src/Symfony/Component/ErrorHandler/ErrorHandler.php +++ b/src/Symfony/Component/ErrorHandler/ErrorHandler.php @@ -761,7 +761,7 @@ private function cleanTrace(array $backtrace, int $type, string $file, int $line */ private function parseAnonymousClass(string $message): string { - return preg_replace_callback('/class@anonymous\x00.*?\.php0x?[0-9a-fA-F]++/', static function ($m) { + return preg_replace_callback('/class@anonymous\x00.*?\.php(?:0x?|:)[0-9a-fA-F]++/', static function ($m) { return class_exists($m[0], false) ? get_parent_class($m[0]).'@anonymous' : $m[0]; }, $message); } diff --git a/src/Symfony/Component/ErrorHandler/Exception/FlattenException.php b/src/Symfony/Component/ErrorHandler/Exception/FlattenException.php index 762e8587dff52..0cff4cd8981ff 100644 --- a/src/Symfony/Component/ErrorHandler/Exception/FlattenException.php +++ b/src/Symfony/Component/ErrorHandler/Exception/FlattenException.php @@ -200,7 +200,7 @@ public function getMessage(): string public function setMessage($message): self { if (false !== strpos($message, "class@anonymous\0")) { - $message = preg_replace_callback('/class@anonymous\x00.*?\.php0x?[0-9a-fA-F]++/', function ($m) { + $message = preg_replace_callback('/class@anonymous\x00.*?\.php(?:0x?|:)[0-9a-fA-F]++/', function ($m) { return class_exists($m[0], false) ? get_parent_class($m[0]).'@anonymous' : $m[0]; }, $message); } diff --git a/src/Symfony/Component/ErrorHandler/Resources/views/trace.html.php b/src/Symfony/Component/ErrorHandler/Resources/views/trace.html.php index 3112af4abe8b9..153f7d6f8e656 100644 --- a/src/Symfony/Component/ErrorHandler/Resources/views/trace.html.php +++ b/src/Symfony/Component/ErrorHandler/Resources/views/trace.html.php @@ -5,7 +5,7 @@ - abbrClass($trace['class']); ?>(formatArgs($trace['args']); ?>) + abbrClass($trace['class']); ?>(formatArgs($trace['args']); ?>) diff --git a/src/Symfony/Component/ErrorHandler/Resources/views/traces_text.html.php b/src/Symfony/Component/ErrorHandler/Resources/views/traces_text.html.php index 1b06954dcdd93..e178fe0fcd413 100644 --- a/src/Symfony/Component/ErrorHandler/Resources/views/traces_text.html.php +++ b/src/Symfony/Component/ErrorHandler/Resources/views/traces_text.html.php @@ -28,7 +28,7 @@ foreach ($exception['trace'] as $trace) { echo "\n "; if ($trace['function']) { - echo 'at '.$trace['class'].$trace['type'].$trace['function'].'('.$this->formatArgsAsText($trace['args']).')'; + echo 'at '.$trace['class'].$trace['type'].$trace['function'].'('.(isset($trace['args']) ? $this->formatArgsAsText($trace['args']) : '').')'; } if ($trace['file'] && $trace['line']) { echo($trace['function'] ? "\n (" : 'at ').strtr(strip_tags($this->formatFile($trace['file'], $trace['line'])), [' at line '.$trace['line'] => '']).':'.$trace['line'].($trace['function'] ? ')' : ''); diff --git a/src/Symfony/Component/ErrorHandler/Tests/DebugClassLoaderTest.php b/src/Symfony/Component/ErrorHandler/Tests/DebugClassLoaderTest.php index 94c163a26e142..5394854738af5 100644 --- a/src/Symfony/Component/ErrorHandler/Tests/DebugClassLoaderTest.php +++ b/src/Symfony/Component/ErrorHandler/Tests/DebugClassLoaderTest.php @@ -65,21 +65,21 @@ public function testThrowingClass() $this->expectException('Exception'); $this->expectExceptionMessage('boo'); try { - class_exists(__NAMESPACE__.'\Fixtures\Throwing'); + class_exists(Fixtures\Throwing::class); $this->fail('Exception expected'); } catch (\Exception $e) { $this->assertSame('boo', $e->getMessage()); } // the second call also should throw - class_exists(__NAMESPACE__.'\Fixtures\Throwing'); + class_exists(Fixtures\Throwing::class); } public function testNameCaseMismatch() { $this->expectException('RuntimeException'); $this->expectExceptionMessage('Case mismatch between loaded and declared class names'); - class_exists(__NAMESPACE__.'\TestingCaseMismatch', true); + class_exists(TestingCaseMismatch::class, true); } public function testFileCaseMismatch() @@ -90,7 +90,7 @@ public function testFileCaseMismatch() $this->markTestSkipped('Can only be run on case insensitive filesystems'); } - class_exists(__NAMESPACE__.'\Fixtures\CaseMismatch', true); + class_exists(Fixtures\CaseMismatch::class, true); } public function testPsr4CaseMismatch() @@ -112,7 +112,7 @@ public function testNotPsr0Bis() public function testClassAlias() { - $this->assertTrue(class_exists(__NAMESPACE__.'\Fixtures\ClassAlias', true)); + $this->assertTrue(class_exists(Fixtures\ClassAlias::class, true)); } /** @@ -154,7 +154,7 @@ public function testInterfaceExtendsDeprecatedInterface() $e = error_reporting(0); trigger_error('', E_USER_NOTICE); - class_exists('Test\\'.__NAMESPACE__.'\\NonDeprecatedInterfaceClass', true); + class_exists('Test\\'.NonDeprecatedInterfaceClass::class, true); error_reporting($e); restore_error_handler(); @@ -201,7 +201,7 @@ public function testExtendedFinalClass() require __DIR__.'/Fixtures/FinalClasses.php'; $i = 1; - while (class_exists($finalClass = __NAMESPACE__.'\\Fixtures\\FinalClass'.$i++, false)) { + while (class_exists($finalClass = Fixtures\FinalClass::class.$i++, false)) { spl_autoload_call($finalClass); class_exists('Test\\'.__NAMESPACE__.'\\Extends'.substr($finalClass, strrpos($finalClass, '\\') + 1), true); } @@ -227,7 +227,7 @@ public function testExtendedFinalMethod() set_error_handler(function ($type, $msg) use (&$deprecations) { $deprecations[] = $msg; }); $e = error_reporting(E_USER_DEPRECATED); - class_exists(__NAMESPACE__.'\\Fixtures\\ExtendedFinalMethod', true); + class_exists(Fixtures\ExtendedFinalMethod::class, true); error_reporting($e); restore_error_handler(); @@ -246,7 +246,7 @@ public function testExtendedDeprecatedMethodDoesntTriggerAnyNotice() $e = error_reporting(0); trigger_error('', E_USER_NOTICE); - class_exists('Test\\'.__NAMESPACE__.'\\ExtendsAnnotatedClass', true); + class_exists('Test\\'.ExtendsAnnotatedClass::class, true); error_reporting($e); restore_error_handler(); @@ -263,7 +263,7 @@ public function testInternalsUse() set_error_handler(function ($type, $msg) use (&$deprecations) { $deprecations[] = $msg; }); $e = error_reporting(E_USER_DEPRECATED); - class_exists('Test\\'.__NAMESPACE__.'\\ExtendsInternals', true); + class_exists('Test\\'.ExtendsInternals::class, true); error_reporting($e); restore_error_handler(); @@ -282,7 +282,7 @@ public function testExtendedMethodDefinesNewParameters() set_error_handler(function ($type, $msg) use (&$deprecations) { $deprecations[] = $msg; }); $e = error_reporting(E_USER_DEPRECATED); - class_exists(__NAMESPACE__.'\\Fixtures\SubClassWithAnnotatedParameters', true); + class_exists(Fixtures\SubClassWithAnnotatedParameters::class, true); error_reporting($e); restore_error_handler(); @@ -305,7 +305,7 @@ public function testUseTraitWithInternalMethod() set_error_handler(function ($type, $msg) use (&$deprecations) { $deprecations[] = $msg; }); $e = error_reporting(E_USER_DEPRECATED); - class_exists('Test\\'.__NAMESPACE__.'\\UseTraitWithInternalMethod', true); + class_exists('Test\\'.UseTraitWithInternalMethod::class, true); error_reporting($e); restore_error_handler(); @@ -319,7 +319,7 @@ public function testVirtualUse() set_error_handler(function ($type, $msg) use (&$deprecations) { $deprecations[] = $msg; }); $e = error_reporting(E_USER_DEPRECATED); - class_exists('Test\\'.__NAMESPACE__.'\\ExtendsVirtual', true); + class_exists('Test\\'.ExtendsVirtual::class, true); error_reporting($e); restore_error_handler(); @@ -345,7 +345,7 @@ public function testVirtualUseWithMagicCall() set_error_handler(function ($type, $msg) use (&$deprecations) { $deprecations[] = $msg; }); $e = error_reporting(E_USER_DEPRECATED); - class_exists('Test\\'.__NAMESPACE__.'\\ExtendsVirtualMagicCall', true); + class_exists('Test\\'.ExtendsVirtualMagicCall::class, true); error_reporting($e); restore_error_handler(); @@ -355,7 +355,7 @@ class_exists('Test\\'.__NAMESPACE__.'\\ExtendsVirtualMagicCall', true); public function testEvaluatedCode() { - $this->assertTrue(class_exists(__NAMESPACE__.'\Fixtures\DefinitionInEvaluatedCode', true)); + $this->assertTrue(class_exists(Fixtures\DefinitionInEvaluatedCode::class, true)); } public function testReturnType() @@ -364,7 +364,7 @@ public function testReturnType() set_error_handler(function ($type, $msg) use (&$deprecations) { $deprecations[] = $msg; }); $e = error_reporting(E_USER_DEPRECATED); - class_exists('Test\\'.__NAMESPACE__.'\\ReturnType', true); + class_exists('Test\\'.ReturnType::class, true); error_reporting($e); restore_error_handler(); @@ -408,11 +408,11 @@ public function findFile($class) { $fixtureDir = __DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR; - if (__NAMESPACE__.'\TestingUnsilencing' === $class) { + if (TestingUnsilencing::class === $class) { eval('-- parse error --'); - } elseif (__NAMESPACE__.'\TestingStacking' === $class) { + } elseif (TestingStacking::class === $class) { eval('namespace '.__NAMESPACE__.'; class TestingStacking { function foo() {} }'); - } elseif (__NAMESPACE__.'\TestingCaseMismatch' === $class) { + } elseif (TestingCaseMismatch::class === $class) { eval('namespace '.__NAMESPACE__.'; class TestingCaseMisMatch {}'); } elseif (__NAMESPACE__.'\Fixtures\Psr4CaseMismatch' === $class) { return $fixtureDir.'psr4'.\DIRECTORY_SEPARATOR.'Psr4CaseMismatch.php'; @@ -422,60 +422,60 @@ public function findFile($class) return $fixtureDir.'notPsr0Bis.php'; } elseif ('Symfony\Bridge\Debug\Tests\Fixtures\ExtendsDeprecatedParent' === $class) { eval('namespace Symfony\Bridge\Debug\Tests\Fixtures; class ExtendsDeprecatedParent extends \\'.__NAMESPACE__.'\Fixtures\DeprecatedClass {}'); - } elseif ('Test\\'.__NAMESPACE__.'\DeprecatedParentClass' === $class) { + } elseif ('Test\\'.DeprecatedParentClass::class === $class) { eval('namespace Test\\'.__NAMESPACE__.'; class DeprecatedParentClass extends \\'.__NAMESPACE__.'\Fixtures\DeprecatedClass {}'); - } elseif ('Test\\'.__NAMESPACE__.'\DeprecatedInterfaceClass' === $class) { + } elseif ('Test\\'.DeprecatedInterfaceClass::class === $class) { eval('namespace Test\\'.__NAMESPACE__.'; class DeprecatedInterfaceClass implements \\'.__NAMESPACE__.'\Fixtures\DeprecatedInterface {}'); - } elseif ('Test\\'.__NAMESPACE__.'\NonDeprecatedInterfaceClass' === $class) { + } elseif ('Test\\'.NonDeprecatedInterfaceClass::class === $class) { eval('namespace Test\\'.__NAMESPACE__.'; class NonDeprecatedInterfaceClass implements \\'.__NAMESPACE__.'\Fixtures\NonDeprecatedInterface {}'); - } elseif ('Test\\'.__NAMESPACE__.'\Float' === $class) { + } elseif ('Test\\'.Float::class === $class) { eval('namespace Test\\'.__NAMESPACE__.'; class Float {}'); - } elseif (0 === strpos($class, 'Test\\'.__NAMESPACE__.'\ExtendsFinalClass')) { + } elseif (0 === strpos($class, 'Test\\'.ExtendsFinalClass::class)) { $classShortName = substr($class, strrpos($class, '\\') + 1); eval('namespace Test\\'.__NAMESPACE__.'; class '.$classShortName.' extends \\'.__NAMESPACE__.'\Fixtures\\'.substr($classShortName, 7).' {}'); - } elseif ('Test\\'.__NAMESPACE__.'\ExtendsAnnotatedClass' === $class) { + } elseif ('Test\\'.ExtendsAnnotatedClass::class === $class) { eval('namespace Test\\'.__NAMESPACE__.'; class ExtendsAnnotatedClass extends \\'.__NAMESPACE__.'\Fixtures\AnnotatedClass { public function deprecatedMethod() { } }'); - } elseif ('Test\\'.__NAMESPACE__.'\ExtendsInternals' === $class) { + } elseif ('Test\\'.ExtendsInternals::class === $class) { eval('namespace Test\\'.__NAMESPACE__.'; class ExtendsInternals extends ExtendsInternalsParent { use \\'.__NAMESPACE__.'\Fixtures\InternalTrait; public function internalMethod() { } }'); - } elseif ('Test\\'.__NAMESPACE__.'\ExtendsInternalsParent' === $class) { + } elseif ('Test\\'.ExtendsInternalsParent::class === $class) { eval('namespace Test\\'.__NAMESPACE__.'; class ExtendsInternalsParent extends \\'.__NAMESPACE__.'\Fixtures\InternalClass implements \\'.__NAMESPACE__.'\Fixtures\InternalInterface { }'); - } elseif ('Test\\'.__NAMESPACE__.'\UseTraitWithInternalMethod' === $class) { + } elseif ('Test\\'.UseTraitWithInternalMethod::class === $class) { eval('namespace Test\\'.__NAMESPACE__.'; class UseTraitWithInternalMethod { use \\'.__NAMESPACE__.'\Fixtures\TraitWithInternalMethod; }'); - } elseif ('Test\\'.__NAMESPACE__.'\ExtendsVirtual' === $class) { + } elseif ('Test\\'.ExtendsVirtual::class === $class) { eval('namespace Test\\'.__NAMESPACE__.'; class ExtendsVirtual extends ExtendsVirtualParent implements \\'.__NAMESPACE__.'\Fixtures\VirtualSubInterface { public function ownClassMethod() { } public function classMethod() { } public function sameLineInterfaceMethodNoBraces() { } }'); - } elseif ('Test\\'.__NAMESPACE__.'\ExtendsVirtualParent' === $class) { + } elseif ('Test\\'.ExtendsVirtualParent::class === $class) { eval('namespace Test\\'.__NAMESPACE__.'; class ExtendsVirtualParent extends ExtendsVirtualAbstract { public function ownParentMethod() { } public function traitMethod() { } public function sameLineInterfaceMethod() { } public function staticMethodNoBraces() { } // should be static }'); - } elseif ('Test\\'.__NAMESPACE__.'\ExtendsVirtualAbstract' === $class) { + } elseif ('Test\\'.ExtendsVirtualAbstract::class === $class) { eval('namespace Test\\'.__NAMESPACE__.'; abstract class ExtendsVirtualAbstract extends ExtendsVirtualAbstractBase { public static function staticMethod() { } public function ownAbstractMethod() { } public function interfaceMethod() { } }'); - } elseif ('Test\\'.__NAMESPACE__.'\ExtendsVirtualAbstractBase' === $class) { + } elseif ('Test\\'.ExtendsVirtualAbstractBase::class === $class) { eval('namespace Test\\'.__NAMESPACE__.'; abstract class ExtendsVirtualAbstractBase extends \\'.__NAMESPACE__.'\Fixtures\VirtualClass implements \\'.__NAMESPACE__.'\Fixtures\VirtualInterface { public function ownAbstractBaseMethod() { } }'); - } elseif ('Test\\'.__NAMESPACE__.'\ExtendsVirtualMagicCall' === $class) { + } elseif ('Test\\'.ExtendsVirtualMagicCall::class === $class) { eval('namespace Test\\'.__NAMESPACE__.'; class ExtendsVirtualMagicCall extends \\'.__NAMESPACE__.'\Fixtures\VirtualClassMagicCall implements \\'.__NAMESPACE__.'\Fixtures\VirtualInterface { }'); - } elseif ('Test\\'.__NAMESPACE__.'\ReturnType' === $class) { + } elseif ('Test\\'.ReturnType::class === $class) { return $fixtureDir.\DIRECTORY_SEPARATOR.'ReturnType.php'; - } elseif ('Test\\'.__NAMESPACE__.'\Fixtures\OutsideInterface' === $class) { + } elseif ('Test\\'.Fixtures\OutsideInterface::class === $class) { return $fixtureDir.\DIRECTORY_SEPARATOR.'OutsideInterface.php'; } } diff --git a/src/Symfony/Component/ErrorHandler/Tests/Exception/FlattenExceptionTest.php b/src/Symfony/Component/ErrorHandler/Tests/Exception/FlattenExceptionTest.php index cceb144b123e6..5783de38bcc39 100644 --- a/src/Symfony/Component/ErrorHandler/Tests/Exception/FlattenExceptionTest.php +++ b/src/Symfony/Component/ErrorHandler/Tests/Exception/FlattenExceptionTest.php @@ -226,6 +226,10 @@ public function flattenDataProvider(): array public function testArguments() { + if (\PHP_VERSION_ID >= 70400) { + $this->markTestSkipped('PHP 7.4 removes arguments from exception traces.'); + } + $dh = opendir(__DIR__); $fh = tmpfile(); @@ -288,6 +292,10 @@ function () {}, public function testRecursionInArguments() { + if (\PHP_VERSION_ID >= 70400) { + $this->markTestSkipped('PHP 7.4 removes arguments from exception traces.'); + } + $a = null; $a = ['foo', [2, &$a]]; $exception = $this->createException($a); @@ -299,6 +307,10 @@ public function testRecursionInArguments() public function testTooBigArray() { + if (\PHP_VERSION_ID >= 70400) { + $this->markTestSkipped('PHP 7.4 removes arguments from exception traces.'); + } + $a = []; for ($i = 0; $i < 20; ++$i) { for ($j = 0; $j < 50; ++$j) { diff --git a/src/Symfony/Component/ExpressionLanguage/Node/BinaryNode.php b/src/Symfony/Component/ExpressionLanguage/Node/BinaryNode.php index 21802000cd08e..c9dcdf34e4f46 100644 --- a/src/Symfony/Component/ExpressionLanguage/Node/BinaryNode.php +++ b/src/Symfony/Component/ExpressionLanguage/Node/BinaryNode.php @@ -147,8 +147,16 @@ public function evaluate(array $functions, array $values) case '*': return $left * $right; case '/': + if (0 == $right) { + throw new \DivisionByZeroError('Division by zero'); + } + return $left / $right; case '%': + if (0 == $right) { + throw new \DivisionByZeroError('Modulo by zero'); + } + return $left % $right; case 'matches': return preg_match($right, $left); diff --git a/src/Symfony/Component/Form/Extension/Core/Type/BirthdayType.php b/src/Symfony/Component/Form/Extension/Core/Type/BirthdayType.php index acb8d02b8c5a9..a4e8b8d41c0e6 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/BirthdayType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/BirthdayType.php @@ -31,7 +31,7 @@ public function configureOptions(OptionsResolver $resolver) */ public function getParent() { - return __NAMESPACE__.'\DateType'; + return DateType::class; } /** diff --git a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php index 9866ab2456c80..4be88149770f8 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php @@ -373,12 +373,12 @@ private function addSubForm(FormBuilderInterface $builder, string $name, ChoiceV ]; if ($options['multiple']) { - $choiceType = __NAMESPACE__.'\CheckboxType'; + $choiceType = CheckboxType::class; // The user can check 0 or more checkboxes. If required // is true, they are required to check all of them. $choiceOpts['required'] = false; } else { - $choiceType = __NAMESPACE__.'\RadioType'; + $choiceType = RadioType::class; } $builder->add($name, $choiceType, $choiceOpts); diff --git a/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php b/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php index fc36cca6da937..b441f08ce6fc4 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php @@ -94,7 +94,7 @@ public function configureOptions(OptionsResolver $resolver) 'prototype' => true, 'prototype_data' => null, 'prototype_name' => '__name__', - 'entry_type' => __NAMESPACE__.'\TextType', + 'entry_type' => TextType::class, 'entry_options' => [], 'delete_empty' => false, ]); diff --git a/src/Symfony/Component/Form/Extension/Core/Type/CountryType.php b/src/Symfony/Component/Form/Extension/Core/Type/CountryType.php index 1899420c6d59d..00a19c44f2be2 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/CountryType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/CountryType.php @@ -47,7 +47,7 @@ public function configureOptions(OptionsResolver $resolver) */ public function getParent() { - return __NAMESPACE__.'\ChoiceType'; + return ChoiceType::class; } /** diff --git a/src/Symfony/Component/Form/Extension/Core/Type/CurrencyType.php b/src/Symfony/Component/Form/Extension/Core/Type/CurrencyType.php index 671991452ce4e..58136ddb862d9 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/CurrencyType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/CurrencyType.php @@ -44,7 +44,7 @@ public function configureOptions(OptionsResolver $resolver) */ public function getParent() { - return __NAMESPACE__.'\ChoiceType'; + return ChoiceType::class; } /** diff --git a/src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php b/src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php index 889eb9d029a90..fd9d8cd97f418 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php @@ -168,8 +168,8 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'time' => $timeParts, ]), ])) - ->add('date', __NAMESPACE__.'\DateType', $dateOptions) - ->add('time', __NAMESPACE__.'\TimeType', $timeOptions) + ->add('date', DateType::class, $dateOptions) + ->add('time', TimeType::class, $timeOptions) ; } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/EmailType.php b/src/Symfony/Component/Form/Extension/Core/Type/EmailType.php index 2434778c760c4..1bc1019ab9f26 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/EmailType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/EmailType.php @@ -20,7 +20,7 @@ class EmailType extends AbstractType */ public function getParent() { - return __NAMESPACE__.'\TextType'; + return TextType::class; } /** diff --git a/src/Symfony/Component/Form/Extension/Core/Type/LanguageType.php b/src/Symfony/Component/Form/Extension/Core/Type/LanguageType.php index 47cd043a1b8fe..82fe37a2fc795 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/LanguageType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/LanguageType.php @@ -47,7 +47,7 @@ public function configureOptions(OptionsResolver $resolver) */ public function getParent() { - return __NAMESPACE__.'\ChoiceType'; + return ChoiceType::class; } /** diff --git a/src/Symfony/Component/Form/Extension/Core/Type/LocaleType.php b/src/Symfony/Component/Form/Extension/Core/Type/LocaleType.php index b0a60161a40d9..bc6234fd054cb 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/LocaleType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/LocaleType.php @@ -44,7 +44,7 @@ public function configureOptions(OptionsResolver $resolver) */ public function getParent() { - return __NAMESPACE__.'\ChoiceType'; + return ChoiceType::class; } /** diff --git a/src/Symfony/Component/Form/Extension/Core/Type/PasswordType.php b/src/Symfony/Component/Form/Extension/Core/Type/PasswordType.php index 5a5b2605a4222..a11708084feb7 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/PasswordType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/PasswordType.php @@ -44,7 +44,7 @@ public function configureOptions(OptionsResolver $resolver) */ public function getParent() { - return __NAMESPACE__.'\TextType'; + return TextType::class; } /** diff --git a/src/Symfony/Component/Form/Extension/Core/Type/RadioType.php b/src/Symfony/Component/Form/Extension/Core/Type/RadioType.php index 7c0e8608478bc..471075b9a6bbc 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/RadioType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/RadioType.php @@ -20,7 +20,7 @@ class RadioType extends AbstractType */ public function getParent() { - return __NAMESPACE__.'\CheckboxType'; + return CheckboxType::class; } /** diff --git a/src/Symfony/Component/Form/Extension/Core/Type/RangeType.php b/src/Symfony/Component/Form/Extension/Core/Type/RangeType.php index a69633c540407..36ecdb96da4ee 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/RangeType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/RangeType.php @@ -20,7 +20,7 @@ class RangeType extends AbstractType */ public function getParent() { - return __NAMESPACE__.'\TextType'; + return TextType::class; } /** diff --git a/src/Symfony/Component/Form/Extension/Core/Type/RepeatedType.php b/src/Symfony/Component/Form/Extension/Core/Type/RepeatedType.php index 5f9ee5329cc09..ffb7520a582b6 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/RepeatedType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/RepeatedType.php @@ -47,7 +47,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ - 'type' => __NAMESPACE__.'\TextType', + 'type' => TextType::class, 'options' => [], 'first_options' => [], 'second_options' => [], diff --git a/src/Symfony/Component/Form/Extension/Core/Type/ResetType.php b/src/Symfony/Component/Form/Extension/Core/Type/ResetType.php index 16978ec5f1433..ce8013d1b09dc 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/ResetType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/ResetType.php @@ -26,7 +26,7 @@ class ResetType extends AbstractType implements ButtonTypeInterface */ public function getParent() { - return __NAMESPACE__.'\ButtonType'; + return ButtonType::class; } /** diff --git a/src/Symfony/Component/Form/Extension/Core/Type/SearchType.php b/src/Symfony/Component/Form/Extension/Core/Type/SearchType.php index 4766ad094cd8f..c817a26d025b6 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/SearchType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/SearchType.php @@ -20,7 +20,7 @@ class SearchType extends AbstractType */ public function getParent() { - return __NAMESPACE__.'\TextType'; + return TextType::class; } /** diff --git a/src/Symfony/Component/Form/Extension/Core/Type/SubmitType.php b/src/Symfony/Component/Form/Extension/Core/Type/SubmitType.php index bf3cea2414484..945156efc62ad 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/SubmitType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/SubmitType.php @@ -47,7 +47,7 @@ public function configureOptions(OptionsResolver $resolver) */ public function getParent() { - return __NAMESPACE__.'\ButtonType'; + return ButtonType::class; } /** diff --git a/src/Symfony/Component/Form/Extension/Core/Type/TextareaType.php b/src/Symfony/Component/Form/Extension/Core/Type/TextareaType.php index e4127f932cfc6..7db19d8aedc65 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/TextareaType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/TextareaType.php @@ -30,7 +30,7 @@ public function buildView(FormView $view, FormInterface $form, array $options) */ public function getParent() { - return __NAMESPACE__.'\TextType'; + return TextType::class; } /** diff --git a/src/Symfony/Component/Form/Extension/Core/Type/TimezoneType.php b/src/Symfony/Component/Form/Extension/Core/Type/TimezoneType.php index be03a9baf2ac8..0f0157f6beaf3 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/TimezoneType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/TimezoneType.php @@ -89,7 +89,7 @@ public function configureOptions(OptionsResolver $resolver) */ public function getParent() { - return __NAMESPACE__.'\ChoiceType'; + return ChoiceType::class; } /** diff --git a/src/Symfony/Component/Form/Extension/Core/Type/UrlType.php b/src/Symfony/Component/Form/Extension/Core/Type/UrlType.php index 39b9d2d20828c..b0392a9849b03 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/UrlType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/UrlType.php @@ -56,7 +56,7 @@ public function configureOptions(OptionsResolver $resolver) */ public function getParent() { - return __NAMESPACE__.'\TextType'; + return TextType::class; } /** diff --git a/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php b/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php index 747273f88f078..e0885eae6bf33 100644 --- a/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php +++ b/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php @@ -30,7 +30,7 @@ class FormValidator extends ConstraintValidator public function validate($form, Constraint $formConstraint) { if (!$formConstraint instanceof Form) { - throw new UnexpectedTypeException($formConstraint, __NAMESPACE__.'\Form'); + throw new UnexpectedTypeException($formConstraint, Form::class); } if (!$form instanceof FormInterface) { diff --git a/src/Symfony/Component/Form/Tests/Fixtures/FooSubType.php b/src/Symfony/Component/Form/Tests/Fixtures/FooSubType.php index 9ce8b5e66e5f5..c4cfde22747e7 100644 --- a/src/Symfony/Component/Form/Tests/Fixtures/FooSubType.php +++ b/src/Symfony/Component/Form/Tests/Fixtures/FooSubType.php @@ -17,6 +17,6 @@ class FooSubType extends AbstractType { public function getParent(): ?string { - return __NAMESPACE__.'\FooType'; + return FooType::class; } } diff --git a/src/Symfony/Component/Form/Tests/Fixtures/FooTypeBarExtension.php b/src/Symfony/Component/Form/Tests/Fixtures/FooTypeBarExtension.php index fbe1601d5bf4d..70c710e922fdf 100644 --- a/src/Symfony/Component/Form/Tests/Fixtures/FooTypeBarExtension.php +++ b/src/Symfony/Component/Form/Tests/Fixtures/FooTypeBarExtension.php @@ -30,6 +30,6 @@ public function getAllowedOptionValues() public static function getExtendedTypes(): iterable { - return [__NAMESPACE__.'\FooType']; + return [FooType::class]; } } diff --git a/src/Symfony/Component/Form/Tests/Fixtures/FooTypeBazExtension.php b/src/Symfony/Component/Form/Tests/Fixtures/FooTypeBazExtension.php index 250c122f9cc25..a11f158844732 100644 --- a/src/Symfony/Component/Form/Tests/Fixtures/FooTypeBazExtension.php +++ b/src/Symfony/Component/Form/Tests/Fixtures/FooTypeBazExtension.php @@ -23,6 +23,6 @@ public function buildForm(FormBuilderInterface $builder, array $options) public static function getExtendedTypes(): iterable { - return [__NAMESPACE__.'\FooType']; + return [FooType::class]; } } diff --git a/src/Symfony/Component/Form/Tests/ResolvedFormTypeTest.php b/src/Symfony/Component/Form/Tests/ResolvedFormTypeTest.php index b24c9cf9f901b..e4c4c97485df2 100644 --- a/src/Symfony/Component/Form/Tests/ResolvedFormTypeTest.php +++ b/src/Symfony/Component/Form/Tests/ResolvedFormTypeTest.php @@ -376,12 +376,12 @@ public function testBlockPrefixDefaultsToFQCNIfNoName($typeClass, $blockPrefix) public function provideTypeClassBlockPrefixTuples() { return [ - [__NAMESPACE__.'\Fixtures\FooType', 'foo'], - [__NAMESPACE__.'\Fixtures\Foo', 'foo'], - [__NAMESPACE__.'\Fixtures\Type', 'type'], - [__NAMESPACE__.'\Fixtures\FooBarHTMLType', 'foo_bar_html'], + [Fixtures\FooType::class, 'foo'], + [Fixtures\Foo::class, 'foo'], + [Fixtures\Type::class, 'type'], + [Fixtures\FooBarHTMLType::class, 'foo_bar_html'], [__NAMESPACE__.'\Fixtures\Foo1Bar2Type', 'foo1_bar2'], - [__NAMESPACE__.'\Fixtures\FBooType', 'f_boo'], + [Fixtures\FBooType::class, 'f_boo'], ]; } diff --git a/src/Symfony/Component/HttpClient/CurlHttpClient.php b/src/Symfony/Component/HttpClient/CurlHttpClient.php index 0f872dfa97175..d26b48c19a803 100644 --- a/src/Symfony/Component/HttpClient/CurlHttpClient.php +++ b/src/Symfony/Component/HttpClient/CurlHttpClient.php @@ -119,23 +119,6 @@ public function request(string $method, string $url, array $options = []): Respo $options['normalized_headers']['user-agent'][] = $options['headers'][] = 'User-Agent: Symfony HttpClient/Curl'; } - if ($pushedResponse = $this->multi->pushedResponses[$url] ?? null) { - unset($this->multi->pushedResponses[$url]); - - if (self::acceptPushForRequest($method, $options, $pushedResponse)) { - $this->logger && $this->logger->debug(sprintf('Accepting pushed response: "%s %s"', $method, $url)); - - // Reinitialize the pushed response with request's options - $pushedResponse->response->__construct($this->multi, $url, $options, $this->logger); - - return $pushedResponse->response; - } - - $this->logger && $this->logger->debug(sprintf('Rejecting pushed response: "%s".', $url)); - } - - $this->logger && $this->logger->info(sprintf('Request: "%s %s"', $method, $url)); - $curlopts = [ CURLOPT_URL => $url, CURLOPT_TCP_NODELAY => true, @@ -158,8 +141,17 @@ public function request(string $method, string $url, array $options = []): Respo CURLOPT_CERTINFO => $options['capture_peer_cert_chain'], ]; + if (1.0 === (float) $options['http_version']) { + $curlopts[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_0; + } elseif (1.1 === (float) $options['http_version'] || 'https:' !== $scheme) { + $curlopts[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1; + } elseif (\defined('CURL_VERSION_HTTP2') && CURL_VERSION_HTTP2 & self::$curlVersion['features']) { + $curlopts[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_2_0; + } + if (isset($options['auth_ntlm'])) { $curlopts[CURLOPT_HTTPAUTH] = CURLAUTH_NTLM; + $curlopts[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1; if (\is_array($options['auth_ntlm'])) { $count = \count($options['auth_ntlm']); @@ -212,14 +204,6 @@ public function request(string $method, string $url, array $options = []): Respo $curlopts[CURLOPT_RESOLVE] = $resolve; } - if (1.0 === (float) $options['http_version']) { - $curlopts[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_0; - } elseif (1.1 === (float) $options['http_version'] || 'https:' !== $scheme) { - $curlopts[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1; - } elseif (\defined('CURL_VERSION_HTTP2') && CURL_VERSION_HTTP2 & self::$curlVersion['features']) { - $curlopts[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_2_0; - } - if ('POST' === $method) { // Use CURLOPT_POST to have browser-like POST-to-GET redirects for 301, 302 and 303 $curlopts[CURLOPT_POST] = true; @@ -293,7 +277,26 @@ public function request(string $method, string $url, array $options = []): Respo $curlopts[CURLOPT_TIMEOUT_MS] = 1000 * $options['max_duration']; } - $ch = curl_init(); + if ($pushedResponse = $this->multi->pushedResponses[$url] ?? null) { + unset($this->multi->pushedResponses[$url]); + + if (self::acceptPushForRequest($method, $options, $pushedResponse)) { + $this->logger && $this->logger->debug(sprintf('Accepting pushed response: "%s %s"', $method, $url)); + + // Reinitialize the pushed response with request's options + $ch = $pushedResponse->handle; + $pushedResponse = $pushedResponse->response; + $pushedResponse->__construct($this->multi, $url, $options, $this->logger); + } else { + $this->logger && $this->logger->debug(sprintf('Rejecting pushed response: "%s".', $url)); + $pushedResponse = null; + } + } + + if (!$pushedResponse) { + $ch = curl_init(); + $this->logger && $this->logger->info(sprintf('Request: "%s %s"', $method, $url)); + } foreach ($curlopts as $opt => $value) { if (null !== $value && !curl_setopt($ch, $opt, $value) && CURLOPT_CERTINFO !== $opt) { @@ -305,7 +308,7 @@ public function request(string $method, string $url, array $options = []): Respo } } - return new CurlResponse($this->multi, $ch, $options, $this->logger, $method, self::createRedirectResolver($options, $host)); + return $pushedResponse ?? new CurlResponse($this->multi, $ch, $options, $this->logger, $method, self::createRedirectResolver($options, $host)); } /** @@ -395,7 +398,7 @@ private static function handlePush($parent, $pushed, array $requestHeaders, Curl $url .= $headers[':path'][0]; $logger && $logger->debug(sprintf('Queueing pushed response: "%s"', $url)); - $multi->pushedResponses[$url] = new PushedResponse(new CurlResponse($multi, $pushed), $headers, $multi->openHandles[(int) $parent][1] ?? []); + $multi->pushedResponses[$url] = new PushedResponse(new CurlResponse($multi, $pushed), $headers, $multi->openHandles[(int) $parent][1] ?? [], $pushed); return CURL_PUSH_OK; } diff --git a/src/Symfony/Component/HttpClient/Internal/PushedResponse.php b/src/Symfony/Component/HttpClient/Internal/PushedResponse.php index 6f8e8fda3a6ba..08fca60dcb964 100644 --- a/src/Symfony/Component/HttpClient/Internal/PushedResponse.php +++ b/src/Symfony/Component/HttpClient/Internal/PushedResponse.php @@ -29,10 +29,13 @@ final class PushedResponse public $parentOptions = []; - public function __construct(CurlResponse $response, array $requestHeaders, array $parentOptions) + public $handle; + + public function __construct(CurlResponse $response, array $requestHeaders, array $parentOptions, $handle) { $this->response = $response; $this->requestHeaders = $requestHeaders; $this->parentOptions = $parentOptions; + $this->handle = $handle; } } diff --git a/src/Symfony/Component/HttpClient/Psr18Client.php b/src/Symfony/Component/HttpClient/Psr18Client.php index d906356bc477c..ba59dc11f7ecc 100644 --- a/src/Symfony/Component/HttpClient/Psr18Client.php +++ b/src/Symfony/Component/HttpClient/Psr18Client.php @@ -190,7 +190,7 @@ public function createUri(string $uri = ''): UriInterface /** * @internal */ -trait Psr18ExceptionTrait +class Psr18NetworkException extends \RuntimeException implements NetworkExceptionInterface { private $request; @@ -206,18 +206,21 @@ public function getRequest(): RequestInterface } } -/** - * @internal - */ -class Psr18NetworkException extends \RuntimeException implements NetworkExceptionInterface -{ - use Psr18ExceptionTrait; -} - /** * @internal */ class Psr18RequestException extends \InvalidArgumentException implements RequestExceptionInterface { - use Psr18ExceptionTrait; + private $request; + + public function __construct(TransportExceptionInterface $e, RequestInterface $request) + { + parent::__construct($e->getMessage(), 0, $e); + $this->request = $request; + } + + public function getRequest(): RequestInterface + { + return $this->request; + } } diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 1ab74d7edf22a..21cb15744e708 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -1557,20 +1557,17 @@ public function isNoCache() */ public function getPreferredFormat(?string $default = 'html'): ?string { - if (null !== $this->preferredFormat) { + if (null !== $this->preferredFormat || null !== $this->preferredFormat = $this->getRequestFormat(null)) { return $this->preferredFormat; } - $preferredFormat = null; - foreach ($this->getAcceptableContentTypes() as $contentType) { - if ($preferredFormat = $this->getFormat($contentType)) { - break; + foreach ($this->getAcceptableContentTypes() as $mimeType) { + if ($this->preferredFormat = $this->getFormat($mimeType)) { + return $this->preferredFormat; } } - $this->preferredFormat = $this->getRequestFormat($preferredFormat ?: $this->getContentType()); - - return $this->preferredFormat ?: $default; + return $default; } /** diff --git a/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php b/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php index de1e2a162daae..56b9245f93587 100644 --- a/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php +++ b/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php @@ -262,13 +262,13 @@ public function makeDisposition(string $disposition, string $filename, string $f */ protected function computeCacheControlValue() { - if (!$this->cacheControl && !$this->has('ETag') && !$this->has('Last-Modified') && !$this->has('Expires')) { - return 'no-cache, private'; - } - if (!$this->cacheControl) { + if ($this->has('Last-Modified') || $this->has('Expires')) { + return 'private, must-revalidate'; // allows for heuristic expiration (RFC 7234 Section 4.2.2) in the case of "Last-Modified" + } + // conservative by default - return 'private, must-revalidate'; + return 'no-cache, private'; } $header = $this->getCacheControlHeader(); diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php index 52f8334a2ed1b..74412e0083dd4 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php @@ -219,7 +219,7 @@ public function createTable() // - trailing space removal // - case-insensitivity // - language processing like é == e - $sql = "CREATE TABLE $this->table ($this->idCol VARBINARY(128) NOT NULL PRIMARY KEY, $this->dataCol BLOB NOT NULL, $this->lifetimeCol INTEGER UNSIGNED NOT NULL, $this->timeCol INTEGER UNSIGNED NOT NULL) COLLATE utf8_bin, ENGINE = InnoDB"; + $sql = "CREATE TABLE $this->table ($this->idCol VARBINARY(128) NOT NULL PRIMARY KEY, $this->dataCol BLOB NOT NULL, $this->lifetimeCol INTEGER UNSIGNED NOT NULL, $this->timeCol INTEGER UNSIGNED NOT NULL) COLLATE utf8mb4_bin, ENGINE = InnoDB"; break; case 'sqlite': $sql = "CREATE TABLE $this->table ($this->idCol TEXT NOT NULL PRIMARY KEY, $this->dataCol BLOB NOT NULL, $this->lifetimeCol INTEGER NOT NULL, $this->timeCol INTEGER NOT NULL)"; @@ -869,10 +869,10 @@ private function getMergeStatement(string $sessionId, string $data, int $maxlife $mergeStmt->bindParam(2, $sessionId, \PDO::PARAM_STR); $mergeStmt->bindParam(3, $data, \PDO::PARAM_LOB); $mergeStmt->bindValue(4, time() + $maxlifetime, \PDO::PARAM_INT); - $mergeStmt->bindValue(4, time(), \PDO::PARAM_INT); - $mergeStmt->bindParam(5, $data, \PDO::PARAM_LOB); - $mergeStmt->bindValue(6, time() + $maxlifetime, \PDO::PARAM_INT); - $mergeStmt->bindValue(6, time(), \PDO::PARAM_INT); + $mergeStmt->bindValue(5, time(), \PDO::PARAM_INT); + $mergeStmt->bindParam(6, $data, \PDO::PARAM_LOB); + $mergeStmt->bindValue(7, time() + $maxlifetime, \PDO::PARAM_INT); + $mergeStmt->bindValue(8, time(), \PDO::PARAM_INT); } else { $mergeStmt->bindParam(':id', $sessionId, \PDO::PARAM_STR); $mergeStmt->bindParam(':data', $data, \PDO::PARAM_LOB); diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php index 678fb02824737..b9ca28f5909f3 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php @@ -63,7 +63,7 @@ public function __construct($redis, array $options = []) $this->redis = $redis; $this->prefix = $options['prefix'] ?? 'sf_s'; - $this->ttl = $options['ttl'] ?? (int) ini_get('session.gc_maxlifetime'); + $this->ttl = $options['ttl'] ?? null; } /** @@ -79,7 +79,7 @@ protected function doRead(string $sessionId): string */ protected function doWrite(string $sessionId, string $data): bool { - $result = $this->redis->setEx($this->prefix.$sessionId, $this->ttl, $data); + $result = $this->redis->setEx($this->prefix.$sessionId, (int) ($this->ttl ?? ini_get('session.gc_maxlifetime')), $data); return $result && !$result instanceof ErrorInterface; } @@ -115,6 +115,6 @@ public function gc($maxlifetime): bool */ public function updateTimestamp($sessionId, $data) { - return (bool) $this->redis->expire($this->prefix.$sessionId, $this->ttl); + return (bool) $this->redis->expire($this->prefix.$sessionId, (int) ($this->ttl ?? ini_get('session.gc_maxlifetime'))); } } diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/SessionHandlerFactory.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/SessionHandlerFactory.php index f4feeac092304..1f017c8afdceb 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/SessionHandlerFactory.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/SessionHandlerFactory.php @@ -50,13 +50,13 @@ public static function createHandler($connection): AbstractSessionHandler case 0 === strpos($connection, 'file://'): return new StrictSessionHandler(new NativeFileSessionHandler(substr($connection, 7))); - case 0 === strpos($connection, 'redis://'): - case 0 === strpos($connection, 'rediss://'): - case 0 === strpos($connection, 'memcached://'): + case 0 === strpos($connection, 'redis:'): + case 0 === strpos($connection, 'rediss:'): + case 0 === strpos($connection, 'memcached:'): if (!class_exists(AbstractAdapter::class)) { throw new InvalidArgumentException(sprintf('Unsupported DSN "%s". Try running "composer require symfony/cache".', $connection)); } - $handlerClass = 0 === strpos($connection, 'memcached://') ? MemcachedSessionHandler::class : RedisSessionHandler::class; + $handlerClass = 0 === strpos($connection, 'memcached:') ? MemcachedSessionHandler::class : RedisSessionHandler::class; $connection = AbstractAdapter::createConnection($connection, ['lazy' => true]); return new $handlerClass($connection); diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php index d3b44c85c8ccd..eb754dbbfcfa4 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php @@ -401,13 +401,11 @@ public function setOptions(array $options) * ini_set('session.save_path', '/tmp'); * * or pass in a \SessionHandler instance which configures session.save_handler in the - * constructor, for a template see NativeFileSessionHandler or use handlers in - * composer package drak/native-session + * constructor, for a template see NativeFileSessionHandler. * * @see https://php.net/session-set-save-handler * @see https://php.net/sessionhandlerinterface * @see https://php.net/sessionhandler - * @see https://github.com/zikula/NativeSession * * @param AbstractProxy|\SessionHandlerInterface|null $saveHandler * diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index 28595c1e7a677..3c206f9f0adef 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -408,12 +408,10 @@ public function testGetPreferredFormat() $request->setRequestFormat('atom'); $request->headers->set('Accept', 'application/ld+json'); - $request->headers->set('Content-Type', 'application/merge-patch+json'); $this->assertSame('atom', $request->getPreferredFormat()); $request = new Request(); $request->headers->set('Accept', 'application/xml'); - $request->headers->set('Content-Type', 'application/json'); $this->assertSame('xml', $request->getPreferredFormat()); $request = new Request(); diff --git a/src/Symfony/Component/HttpFoundation/Tests/ResponseHeaderBagTest.php b/src/Symfony/Component/HttpFoundation/Tests/ResponseHeaderBagTest.php index 1a3817333707b..4d924412232c8 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/ResponseHeaderBagTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/ResponseHeaderBagTest.php @@ -51,9 +51,9 @@ public function testCacheControlHeader() $this->assertTrue($bag->hasCacheControlDirective('public')); $bag = new ResponseHeaderBag(['ETag' => 'abcde']); - $this->assertEquals('private, must-revalidate', $bag->get('Cache-Control')); + $this->assertEquals('no-cache, private', $bag->get('Cache-Control')); $this->assertTrue($bag->hasCacheControlDirective('private')); - $this->assertTrue($bag->hasCacheControlDirective('must-revalidate')); + $this->assertTrue($bag->hasCacheControlDirective('no-cache')); $this->assertFalse($bag->hasCacheControlDirective('max-age')); $bag = new ResponseHeaderBag(['Expires' => 'Wed, 16 Feb 2011 14:17:43 GMT']); diff --git a/src/Symfony/Component/HttpKernel/HttpCache/ResponseCacheStrategy.php b/src/Symfony/Component/HttpKernel/HttpCache/ResponseCacheStrategy.php index 39038a932d855..c30fface603eb 100644 --- a/src/Symfony/Component/HttpKernel/HttpCache/ResponseCacheStrategy.php +++ b/src/Symfony/Component/HttpKernel/HttpCache/ResponseCacheStrategy.php @@ -110,8 +110,6 @@ public function update(Response $response) $response->headers->set('Age', $this->age); if ($this->isNotCacheableResponseEmbedded) { - $response->setExpires($response->getDate()); - if ($this->flagDirectives['no-store']) { $response->headers->set('Cache-Control', 'no-cache, no-store, must-revalidate'); } else { diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index b26b487072cbe..2394fac7b0f4d 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -68,11 +68,11 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - const VERSION = '5.0.1'; - const VERSION_ID = 50001; + const VERSION = '5.0.2'; + const VERSION_ID = 50002; const MAJOR_VERSION = 5; const MINOR_VERSION = 0; - const RELEASE_VERSION = 1; + const RELEASE_VERSION = 2; const EXTRA_VERSION = ''; const END_OF_MAINTENANCE = '07/2020'; @@ -471,7 +471,7 @@ public function write(string $content, array $metadata = null) } if (\function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN)) { - opcache_invalidate($this->getPath(), true); + @opcache_invalidate($this->getPath(), true); } } diff --git a/src/Symfony/Component/HttpKernel/Tests/ControllerMetadata/ArgumentMetadataFactoryTest.php b/src/Symfony/Component/HttpKernel/Tests/ControllerMetadata/ArgumentMetadataFactoryTest.php index f77b6759afa6a..ba8ab56604a0b 100644 --- a/src/Symfony/Component/HttpKernel/Tests/ControllerMetadata/ArgumentMetadataFactoryTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/ControllerMetadata/ArgumentMetadataFactoryTest.php @@ -48,7 +48,7 @@ public function testSignature2() $this->assertEquals([ new ArgumentMetadata('foo', self::class, false, true, null, true), - new ArgumentMetadata('bar', __NAMESPACE__.'\FakeClassThatDoesNotExist', false, true, null, true), + new ArgumentMetadata('bar', FakeClassThatDoesNotExist::class, false, true, null, true), new ArgumentMetadata('baz', 'Fake\ImportedAndFake', false, true, null, true), ], $arguments); } @@ -58,7 +58,7 @@ public function testSignature3() $arguments = $this->factory->createArgumentMetadata([$this, 'signature3']); $this->assertEquals([ - new ArgumentMetadata('bar', __NAMESPACE__.'\FakeClassThatDoesNotExist', false, false, null), + new ArgumentMetadata('bar', FakeClassThatDoesNotExist::class, false, false, null), new ArgumentMetadata('baz', 'Fake\ImportedAndFake', false, false, null), ], $arguments); } diff --git a/src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php b/src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php index 4181243574352..a89aeeac1f0d5 100644 --- a/src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php @@ -99,7 +99,7 @@ public function provideControllerCallables() '"Regular" callable', [$this, 'testControllerInspection'], [ - 'class' => __NAMESPACE__.'\RequestDataCollectorTest', + 'class' => RequestDataCollectorTest::class, 'method' => 'testControllerInspection', 'file' => __FILE__, 'line' => $r1->getStartLine(), diff --git a/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php b/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php index 8f221f1960d1b..aa2c611455a3c 100644 --- a/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php @@ -1240,7 +1240,6 @@ public function testEsiCacheForceValidation() $this->request('GET', '/', [], [], true); $this->assertEquals('Hello World! My name is Bobby.', $this->response->getContent()); $this->assertNull($this->response->getTtl()); - $this->assertTrue($this->response->mustRevalidate()); $this->assertTrue($this->response->headers->hasCacheControlDirective('private')); $this->assertTrue($this->response->headers->hasCacheControlDirective('no-cache')); } @@ -1271,7 +1270,6 @@ public function testEsiCacheForceValidationForHeadRequests() // This can neither be cached nor revalidated, so it should be private/no cache $this->assertEmpty($this->response->getContent()); $this->assertNull($this->response->getTtl()); - $this->assertTrue($this->response->mustRevalidate()); $this->assertTrue($this->response->headers->hasCacheControlDirective('private')); $this->assertTrue($this->response->headers->hasCacheControlDirective('no-cache')); } diff --git a/src/Symfony/Component/Lock/Tests/Store/PdoStoreTest.php b/src/Symfony/Component/Lock/Tests/Store/PdoStoreTest.php index 81a0c9b454e13..800397d153d19 100644 --- a/src/Symfony/Component/Lock/Tests/Store/PdoStoreTest.php +++ b/src/Symfony/Component/Lock/Tests/Store/PdoStoreTest.php @@ -97,9 +97,9 @@ public function testDsn(string $dsn, string $file = null) public function provideDsn() { $dbFile = tempnam(sys_get_temp_dir(), 'sf_sqlite_cache'); - yield ['sqlite://localhost/'.$dbFile, ''.$dbFile]; - yield ['sqlite:'.$dbFile, ''.$dbFile]; - yield ['sqlite3:///'.$dbFile, ''.$dbFile]; + yield ['sqlite://localhost/'.$dbFile.'1', $dbFile.'1']; + yield ['sqlite:'.$dbFile.'2', $dbFile.'2']; + yield ['sqlite3:///'.$dbFile.'3', $dbFile.'3']; yield ['sqlite://localhost/:memory:']; yield ['sqlite::memory:']; } diff --git a/src/Symfony/Component/Mailer/Bridge/Mailchimp/Transport/MandrillApiTransport.php b/src/Symfony/Component/Mailer/Bridge/Mailchimp/Transport/MandrillApiTransport.php index fb232b05209d4..50fc33baaa65c 100644 --- a/src/Symfony/Component/Mailer/Bridge/Mailchimp/Transport/MandrillApiTransport.php +++ b/src/Symfony/Component/Mailer/Bridge/Mailchimp/Transport/MandrillApiTransport.php @@ -57,7 +57,8 @@ protected function doSendApi(SentMessage $sentMessage, Email $email, Envelope $e throw new HttpTransportException(sprintf('Unable to send an email (code %s).', $result['code']), $response); } - $sentMessage->setMessageId($result['_id']); + $firstRecipient = reset($result); + $sentMessage->setMessageId($firstRecipient['_id']); return $response; } diff --git a/src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransport.php b/src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransport.php index 85809e8f64d95..3f68227ba4190 100644 --- a/src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransport.php +++ b/src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransport.php @@ -115,6 +115,7 @@ protected function doHeloCommand(): void try { $response = $this->executeCommand(sprintf("EHLO %s\r\n", $this->getLocalDomain()), [250]); + $capabilities = $this->getCapabilities($response); } catch (TransportExceptionInterface $e) { parent::doHeloCommand(); diff --git a/src/Symfony/Component/Messenger/Command/SetupTransportsCommand.php b/src/Symfony/Component/Messenger/Command/SetupTransportsCommand.php index 6f60a2c43438e..21916f2be765e 100644 --- a/src/Symfony/Component/Messenger/Command/SetupTransportsCommand.php +++ b/src/Symfony/Component/Messenger/Command/SetupTransportsCommand.php @@ -59,7 +59,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $io = new SymfonyStyle($input, $output); $transportNames = $this->transportNames; - // do we want to setup only one transport? + // do we want to set up only one transport? if ($transport = $input->getArgument('transport')) { if (!$this->transportLocator->has($transport)) { throw new \RuntimeException(sprintf('The "%s" transport does not exist.', $transport)); @@ -71,7 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $transport = $this->transportLocator->get($transportName); if ($transport instanceof SetupableTransportInterface) { $transport->setup(); - $io->success(sprintf('The "%s" transport was setup successfully.', $transportName)); + $io->success(sprintf('The "%s" transport was set up successfully.', $transportName)); } else { $io->note(sprintf('The "%s" transport does not support setup.', $transportName)); } diff --git a/src/Symfony/Component/Messenger/Handler/MessageSubscriberInterface.php b/src/Symfony/Component/Messenger/Handler/MessageSubscriberInterface.php index 26a2f16efbf17..2eca1a9d617eb 100644 --- a/src/Symfony/Component/Messenger/Handler/MessageSubscriberInterface.php +++ b/src/Symfony/Component/Messenger/Handler/MessageSubscriberInterface.php @@ -28,7 +28,7 @@ interface MessageSubscriberInterface extends MessageHandlerInterface * It can also change the priority per classes. * * yield FirstMessage::class => ['priority' => 0]; - * yield SecondMessage::class => ['priority => -10]; + * yield SecondMessage::class => ['priority' => -10]; * * It can also specify a method, a priority, a bus and/or a transport per message: * diff --git a/src/Symfony/Component/Messenger/Middleware/SendMessageMiddleware.php b/src/Symfony/Component/Messenger/Middleware/SendMessageMiddleware.php index 6cfaeb2ef7fe7..149c0c2415f55 100644 --- a/src/Symfony/Component/Messenger/Middleware/SendMessageMiddleware.php +++ b/src/Symfony/Component/Messenger/Middleware/SendMessageMiddleware.php @@ -35,7 +35,13 @@ class SendMessageMiddleware implements MiddlewareInterface public function __construct(SendersLocatorInterface $sendersLocator, EventDispatcherInterface $eventDispatcher = null) { $this->sendersLocator = $sendersLocator; - $this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher); + + if (null !== $eventDispatcher && class_exists(LegacyEventDispatcherProxy::class)) { + $this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher); + } else { + $this->eventDispatcher = $eventDispatcher; + } + $this->logger = new NullLogger(); } diff --git a/src/Symfony/Component/Messenger/Tests/Command/SetupTransportsCommandTest.php b/src/Symfony/Component/Messenger/Tests/Command/SetupTransportsCommandTest.php index b3fdf50b7a3c4..edc28f5ea867a 100644 --- a/src/Symfony/Component/Messenger/Tests/Command/SetupTransportsCommandTest.php +++ b/src/Symfony/Component/Messenger/Tests/Command/SetupTransportsCommandTest.php @@ -42,7 +42,7 @@ public function testReceiverNames() $tester->execute([]); $display = $tester->getDisplay(); - $this->assertStringContainsString('The "amqp" transport was setup successfully.', $display); + $this->assertStringContainsString('The "amqp" transport was set up successfully.', $display); $this->assertStringContainsString('The "other_transport" transport does not support setup.', $display); } @@ -66,7 +66,7 @@ public function testReceiverNameArgument() $tester->execute(['transport' => 'amqp']); $display = $tester->getDisplay(); - $this->assertStringContainsString('The "amqp" transport was setup successfully.', $display); + $this->assertStringContainsString('The "amqp" transport was set up successfully.', $display); } public function testReceiverNameArgumentNotFound() diff --git a/src/Symfony/Component/Messenger/Tests/Transport/AmqpExt/ConnectionTest.php b/src/Symfony/Component/Messenger/Tests/Transport/AmqpExt/ConnectionTest.php index 867e5d4d94dc9..f4df694b60bb3 100644 --- a/src/Symfony/Component/Messenger/Tests/Transport/AmqpExt/ConnectionTest.php +++ b/src/Symfony/Component/Messenger/Tests/Transport/AmqpExt/ConnectionTest.php @@ -227,7 +227,7 @@ public function testItSetupsTheConnectionWithDefaults() ); $amqpExchange->expects($this->once())->method('declareExchange'); - $amqpExchange->expects($this->once())->method('publish')->with('body', null, AMQP_NOPARAM, ['headers' => []]); + $amqpExchange->expects($this->once())->method('publish')->with('body', null, AMQP_NOPARAM, ['headers' => [], 'delivery_mode' => 2]); $amqpQueue->expects($this->once())->method('declareQueue'); $amqpQueue->expects($this->once())->method('bind')->with(self::DEFAULT_EXCHANGE_NAME, null); @@ -250,7 +250,7 @@ public function testItSetupsTheConnection() $factory->method('createQueue')->will($this->onConsecutiveCalls($amqpQueue0, $amqpQueue1)); $amqpExchange->expects($this->once())->method('declareExchange'); - $amqpExchange->expects($this->once())->method('publish')->with('body', 'routing_key', AMQP_NOPARAM, ['headers' => []]); + $amqpExchange->expects($this->once())->method('publish')->with('body', 'routing_key', AMQP_NOPARAM, ['headers' => [], 'delivery_mode' => 2]); $amqpQueue0->expects($this->once())->method('declareQueue'); $amqpQueue0->expects($this->exactly(2))->method('bind')->withConsecutive( [self::DEFAULT_EXCHANGE_NAME, 'binding_key0'], @@ -287,7 +287,7 @@ public function testBindingArguments() $factory->method('createQueue')->willReturn($amqpQueue); $amqpExchange->expects($this->once())->method('declareExchange'); - $amqpExchange->expects($this->once())->method('publish')->with('body', null, AMQP_NOPARAM, ['headers' => []]); + $amqpExchange->expects($this->once())->method('publish')->with('body', null, AMQP_NOPARAM, ['headers' => [], 'delivery_mode' => 2]); $amqpQueue->expects($this->once())->method('declareQueue'); $amqpQueue->expects($this->exactly(1))->method('bind')->withConsecutive( [self::DEFAULT_EXCHANGE_NAME, null, ['x-match' => 'all']] @@ -400,7 +400,7 @@ public function testItDelaysTheMessage() $delayQueue->expects($this->once())->method('declareQueue'); $delayQueue->expects($this->once())->method('bind')->with('delays', 'delay_messages__5000'); - $delayExchange->expects($this->once())->method('publish')->with('{}', 'delay_messages__5000', AMQP_NOPARAM, ['headers' => ['x-some-headers' => 'foo']]); + $delayExchange->expects($this->once())->method('publish')->with('{}', 'delay_messages__5000', AMQP_NOPARAM, ['headers' => ['x-some-headers' => 'foo'], 'delivery_mode' => 2]); $connection = Connection::fromDsn('amqp://localhost', [], $factory); $connection->publish('{}', ['x-some-headers' => 'foo'], 5000); @@ -442,7 +442,7 @@ public function testItDelaysTheMessageWithADifferentRoutingKeyAndTTLs() $delayQueue->expects($this->once())->method('declareQueue'); $delayQueue->expects($this->once())->method('bind')->with('delays', 'delay_messages__120000'); - $delayExchange->expects($this->once())->method('publish')->with('{}', 'delay_messages__120000', AMQP_NOPARAM, ['headers' => []]); + $delayExchange->expects($this->once())->method('publish')->with('{}', 'delay_messages__120000', AMQP_NOPARAM, ['headers' => [], 'delivery_mode' => 2]); $connection->publish('{}', [], 120000); } @@ -474,12 +474,27 @@ public function testAmqpStampHeadersAreUsed() $amqpExchange = $this->createMock(\AMQPExchange::class) ); - $amqpExchange->expects($this->once())->method('publish')->with('body', null, AMQP_NOPARAM, ['headers' => ['Foo' => 'X', 'Bar' => 'Y']]); + $amqpExchange->expects($this->once())->method('publish')->with('body', null, AMQP_NOPARAM, ['headers' => ['Foo' => 'X', 'Bar' => 'Y'], 'delivery_mode' => 2]); $connection = Connection::fromDsn('amqp://localhost', [], $factory); $connection->publish('body', ['Foo' => 'X'], 0, new AmqpStamp(null, AMQP_NOPARAM, ['headers' => ['Bar' => 'Y']])); } + public function testAmqpStampDelireryModeIsUsed() + { + $factory = new TestAmqpFactory( + $this->createMock(\AMQPConnection::class), + $this->createMock(\AMQPChannel::class), + $this->createMock(\AMQPQueue::class), + $amqpExchange = $this->createMock(\AMQPExchange::class) + ); + + $amqpExchange->expects($this->once())->method('publish')->with('body', null, AMQP_NOPARAM, ['headers' => [], 'delivery_mode' => 1]); + + $connection = Connection::fromDsn('amqp://localhost', [], $factory); + $connection->publish('body', [], 0, new AmqpStamp(null, AMQP_NOPARAM, ['delivery_mode' => 1])); + } + public function testItCanPublishWithTheDefaultRoutingKey() { $factory = new TestAmqpFactory( @@ -546,7 +561,7 @@ public function testItDelaysTheMessageWithTheInitialSuppliedRoutingKeyAsArgument $delayQueue->expects($this->once())->method('declareQueue'); $delayQueue->expects($this->once())->method('bind')->with('delays', 'delay_messages_routing_key_120000'); - $delayExchange->expects($this->once())->method('publish')->with('{}', 'delay_messages_routing_key_120000', AMQP_NOPARAM, ['headers' => []]); + $delayExchange->expects($this->once())->method('publish')->with('{}', 'delay_messages_routing_key_120000', AMQP_NOPARAM, ['headers' => [], 'delivery_mode' => 2]); $connection->publish('{}', [], 120000, new AmqpStamp('routing_key')); } diff --git a/src/Symfony/Component/Messenger/Tests/Transport/Doctrine/DoctrineTransportFactoryTest.php b/src/Symfony/Component/Messenger/Tests/Transport/Doctrine/DoctrineTransportFactoryTest.php index 20559c5352156..e124bf94e8f61 100644 --- a/src/Symfony/Component/Messenger/Tests/Transport/Doctrine/DoctrineTransportFactoryTest.php +++ b/src/Symfony/Component/Messenger/Tests/Transport/Doctrine/DoctrineTransportFactoryTest.php @@ -11,9 +11,9 @@ namespace Symfony\Component\Messenger\Tests\Transport\Doctrine; -use Doctrine\Common\Persistence\ConnectionRegistry; use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\SchemaConfig; +use Doctrine\Persistence\ConnectionRegistry; use PHPUnit\Framework\TestCase; use Symfony\Component\Messenger\Transport\Doctrine\Connection; use Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransport; diff --git a/src/Symfony/Component/Messenger/Transport/AmqpExt/Connection.php b/src/Symfony/Component/Messenger/Transport/AmqpExt/Connection.php index 6d4db85b0b259..2540b9d770d0b 100644 --- a/src/Symfony/Component/Messenger/Transport/AmqpExt/Connection.php +++ b/src/Symfony/Component/Messenger/Transport/AmqpExt/Connection.php @@ -230,6 +230,7 @@ private function publishOnExchange(\AMQPExchange $exchange, string $body, string { $attributes = $amqpStamp ? $amqpStamp->getAttributes() : []; $attributes['headers'] = array_merge($attributes['headers'] ?? [], $headers); + $attributes['delivery_mode'] = $attributes['delivery_mode'] ?? 2; $exchange->publish( $body, @@ -322,7 +323,7 @@ public function get(string $queueName): ?\AMQPEnvelope } } catch (\AMQPQueueException $e) { if (404 === $e->getCode() && $this->shouldSetup()) { - // If we get a 404 for the queue, it means we need to setup the exchange & queue. + // If we get a 404 for the queue, it means we need to set up the exchange & queue. $this->setupExchangeAndQueues(); return $this->get(); diff --git a/src/Symfony/Component/Messenger/Transport/Doctrine/DoctrineTransportFactory.php b/src/Symfony/Component/Messenger/Transport/Doctrine/DoctrineTransportFactory.php index 50e95ef5e2893..b4455e04f1f8a 100644 --- a/src/Symfony/Component/Messenger/Transport/Doctrine/DoctrineTransportFactory.php +++ b/src/Symfony/Component/Messenger/Transport/Doctrine/DoctrineTransportFactory.php @@ -11,7 +11,7 @@ namespace Symfony\Component\Messenger\Transport\Doctrine; -use Doctrine\Common\Persistence\ConnectionRegistry; +use Doctrine\Persistence\ConnectionRegistry; use Symfony\Bridge\Doctrine\RegistryInterface; use Symfony\Component\Messenger\Exception\TransportException; use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface; diff --git a/src/Symfony/Component/Messenger/Worker.php b/src/Symfony/Component/Messenger/Worker.php index 73be68d47797b..9ac7ebe697ce8 100644 --- a/src/Symfony/Component/Messenger/Worker.php +++ b/src/Symfony/Component/Messenger/Worker.php @@ -47,8 +47,13 @@ public function __construct(array $receivers, MessageBusInterface $bus, EventDis { $this->receivers = $receivers; $this->bus = $bus; - $this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher); $this->logger = $logger; + + if (null !== $eventDispatcher && class_exists(LegacyEventDispatcherProxy::class)) { + $this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher); + } else { + $this->eventDispatcher = $eventDispatcher; + } } /** diff --git a/src/Symfony/Component/Messenger/composer.json b/src/Symfony/Component/Messenger/composer.json index bb15ab51d5877..33bda5acd7909 100644 --- a/src/Symfony/Component/Messenger/composer.json +++ b/src/Symfony/Component/Messenger/composer.json @@ -22,7 +22,7 @@ "require-dev": { "doctrine/dbal": "^2.6", "psr/cache": "~1.0", - "doctrine/persistence": "~1.0", + "doctrine/persistence": "^1.3", "symfony/console": "^4.4|^5.0", "symfony/dependency-injection": "^4.4|^5.0", "symfony/event-dispatcher": "^4.4|^5.0", @@ -35,6 +35,7 @@ "symfony/validator": "^4.4|^5.0" }, "conflict": { + "doctrine/persistence": "<1.3", "symfony/event-dispatcher": "<4.4", "symfony/framework-bundle": "<4.4", "symfony/http-kernel": "<4.4" diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index a44b61bfc50c2..0091ea4f5ccb6 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -1591,12 +1591,12 @@ private function escapeArgument(?string $argument): string private function replacePlaceholders(string $commandline, array $env) { - return preg_replace_callback('/"\$([_a-zA-Z]++[_a-zA-Z0-9]*+)"/', function ($matches) use ($commandline, $env) { + return preg_replace_callback('/"\$\{:([_a-zA-Z]++[_a-zA-Z0-9]*+)\}"/', function ($matches) use ($commandline, $env) { if (!isset($env[$matches[1]]) || false === $env[$matches[1]]) { - throw new InvalidArgumentException(sprintf('Command line is missing a value for key %s: %s.', $matches[0], $commandline)); + throw new InvalidArgumentException(sprintf('Command line is missing a value for parameter "%s": %s.', $matches[1], $commandline)); } - return '\\' === \DIRECTORY_SEPARATOR ? $this->escapeArgument($env[$matches[1]]) : $matches[0]; + return $this->escapeArgument($env[$matches[1]]); }, $commandline); } diff --git a/src/Symfony/Component/Process/Tests/ProcessTest.php b/src/Symfony/Component/Process/Tests/ProcessTest.php index b29e1ec1e9a69..b2138d6864ce4 100644 --- a/src/Symfony/Component/Process/Tests/ProcessTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessTest.php @@ -1463,7 +1463,7 @@ public function provideEscapeArgument() public function testPreparedCommand() { - $p = Process::fromShellCommandline('echo "$abc"DEF'); + $p = Process::fromShellCommandline('echo "${:abc}"DEF'); $p->run(null, ['abc' => 'ABC']); $this->assertSame('ABCDEF', rtrim($p->getOutput())); @@ -1471,7 +1471,7 @@ public function testPreparedCommand() public function testPreparedCommandMulti() { - $p = Process::fromShellCommandline('echo "$abc""$def"'); + $p = Process::fromShellCommandline('echo "${:abc}""${:def}"'); $p->run(null, ['abc' => 'ABC', 'def' => 'DEF']); $this->assertSame('ABCDEF', rtrim($p->getOutput())); @@ -1479,7 +1479,7 @@ public function testPreparedCommandMulti() public function testPreparedCommandWithQuoteInIt() { - $p = Process::fromShellCommandline('php -r "$code" "$def"'); + $p = Process::fromShellCommandline('php -r "${:code}" "${:def}"'); $p->run(null, ['code' => 'echo $argv[1];', 'def' => '"DEF"']); $this->assertSame('"DEF"', rtrim($p->getOutput())); @@ -1488,16 +1488,16 @@ public function testPreparedCommandWithQuoteInIt() public function testPreparedCommandWithMissingValue() { $this->expectException('Symfony\Component\Process\Exception\InvalidArgumentException'); - $this->expectExceptionMessage('Command line is missing a value for key "$abc": echo "$abc".'); - $p = Process::fromShellCommandline('echo "$abc"'); + $this->expectExceptionMessage('Command line is missing a value for parameter "abc": echo "${:abc}".'); + $p = Process::fromShellCommandline('echo "${:abc}"'); $p->run(null, ['bcd' => 'BCD']); } public function testPreparedCommandWithNoValues() { $this->expectException('Symfony\Component\Process\Exception\InvalidArgumentException'); - $this->expectExceptionMessage('Command line is missing a value for key "$abc": echo "$abc".'); - $p = Process::fromShellCommandline('echo "$abc"'); + $this->expectExceptionMessage('Command line is missing a value for parameter "abc": echo "${:abc}".'); + $p = Process::fromShellCommandline('echo "${:abc}"'); $p->run(null, []); } diff --git a/src/Symfony/Component/PropertyAccess/PropertyAccessor.php b/src/Symfony/Component/PropertyAccess/PropertyAccessor.php index 47eace5b0d817..e4626aa72fd0b 100644 --- a/src/Symfony/Component/PropertyAccess/PropertyAccessor.php +++ b/src/Symfony/Component/PropertyAccess/PropertyAccessor.php @@ -174,14 +174,14 @@ public function setValue(&$objectOrArray, $propertyPath, $value) $value = $zval[self::VALUE]; } } catch (\TypeError $e) { - self::throwInvalidArgumentException($e->getMessage(), $e->getTrace(), 0, $propertyPath); + self::throwInvalidArgumentException($e->getMessage(), $e->getTrace(), 0, $propertyPath, $e); // It wasn't thrown in this class so rethrow it throw $e; } } - private static function throwInvalidArgumentException(string $message, array $trace, int $i, string $propertyPath): void + private static function throwInvalidArgumentException(string $message, array $trace, int $i, string $propertyPath, \Throwable $previous = null): void { // the type mismatch is not caused by invalid arguments (but e.g. by an incompatible return type hint of the writer method) if (0 !== strpos($message, 'Argument ')) { @@ -195,7 +195,7 @@ private static function throwInvalidArgumentException(string $message, array $tr $type = substr($message, 2 + $j, strpos($message, ' given', $j) - $j - 2); $message = substr($message, $pos, $j - $pos); - throw new InvalidArgumentException(sprintf('Expected argument of type "%s", "%s" given at property path "%s".', $message, 'NULL' === $type ? 'null' : $type, $propertyPath)); + throw new InvalidArgumentException(sprintf('Expected argument of type "%s", "%s" given at property path "%s".', $message, 'NULL' === $type ? 'null' : $type, $propertyPath), 0, $previous); } } diff --git a/src/Symfony/Component/Routing/Loader/ObjectLoader.php b/src/Symfony/Component/Routing/Loader/ObjectLoader.php index 1a375d95ff013..aefb8295115ab 100644 --- a/src/Symfony/Component/Routing/Loader/ObjectLoader.php +++ b/src/Symfony/Component/Routing/Loader/ObjectLoader.php @@ -42,15 +42,10 @@ abstract protected function getObject(string $id); */ public function load($resource, string $type = null) { - if (!preg_match('/^[^\:]+(?:::?(?:[^\:]+))?$/', $resource)) { + if (!preg_match('/^[^\:]+(?:::(?:[^\:]+))?$/', $resource)) { throw new \InvalidArgumentException(sprintf('Invalid resource "%s" passed to the %s route loader: use the format "object_id::method" or "object_id" if your object class has an "__invoke" method.', $resource, \is_string($type) ? '"'.$type.'"' : 'object')); } - if (1 === substr_count($resource, ':')) { - $resource = str_replace(':', '::', $resource); - @trigger_error(sprintf('Referencing object route loaders with a single colon is deprecated since Symfony 4.1. Use %s instead.', $resource), E_USER_DEPRECATED); - } - $parts = explode('::', $resource); $method = $parts[1] ?? '__invoke'; diff --git a/src/Symfony/Component/Routing/Router.php b/src/Symfony/Component/Routing/Router.php index 7057f9c201606..031749b3606fc 100644 --- a/src/Symfony/Component/Routing/Router.php +++ b/src/Symfony/Component/Routing/Router.php @@ -92,6 +92,8 @@ class Router implements RouterInterface, RequestMatcherInterface */ private $expressionLanguageProviders = []; + private static $cache = []; + /** * @param mixed $resource The main resource to load */ @@ -295,7 +297,7 @@ function (ConfigCacheInterface $cache) { } ); - return $this->matcher = new $this->options['matcher_class'](require $cache->getPath(), $this->context); + return $this->matcher = new $this->options['matcher_class'](self::getCompiledRoutes($cache->getPath()), $this->context); } /** @@ -325,7 +327,7 @@ function (ConfigCacheInterface $cache) { } ); - $this->generator = new $this->options['generator_class'](require $cache->getPath(), $this->context, $this->logger, $this->defaultLocale); + $this->generator = new $this->options['generator_class'](self::getCompiledRoutes($cache->getPath()), $this->context, $this->logger, $this->defaultLocale); } if ($this->generator instanceof ConfigurableRequirementsInterface) { @@ -368,4 +370,21 @@ private function getConfigCacheFactory(): ConfigCacheFactoryInterface return $this->configCacheFactory; } + + private static function getCompiledRoutes(string $path): array + { + if ([] === self::$cache && \function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN) && (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) || filter_var(ini_get('opcache.enable_cli'), FILTER_VALIDATE_BOOLEAN))) { + self::$cache = null; + } + + if (null === self::$cache) { + return require $path; + } + + if (isset(self::$cache[$path])) { + return self::$cache[$path]; + } + + return self::$cache[$path] = require $path; + } } diff --git a/src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php b/src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php index 466c4f4536a4d..c65a9505526f7 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php +++ b/src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php @@ -55,6 +55,10 @@ protected function checkAuthentication(UserInterface $user, UsernamePasswordToke throw new BadCredentialsException('The presented password cannot be empty.'); } + if (null === $user->getPassword()) { + throw new BadCredentialsException('The presented password is invalid.'); + } + $encoder = $this->encoderFactory->getEncoder($user); if (!$encoder->isPasswordValid($user->getPassword(), $presentedPassword, $user->getSalt())) { diff --git a/src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php b/src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php index f4c567432cafa..db6f4b5068497 100644 --- a/src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php +++ b/src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php @@ -76,17 +76,13 @@ private function decideAffirmative(TokenInterface $token, array $attributes, $ob $deny = 0; foreach ($this->voters as $voter) { $result = $voter->vote($token, $object, $attributes); - switch ($result) { - case VoterInterface::ACCESS_GRANTED: - return true; - case VoterInterface::ACCESS_DENIED: - ++$deny; - - break; + if (VoterInterface::ACCESS_GRANTED === $result) { + return true; + } - default: - break; + if (VoterInterface::ACCESS_DENIED === $result) { + ++$deny; } } @@ -118,16 +114,10 @@ private function decideConsensus(TokenInterface $token, array $attributes, $obje foreach ($this->voters as $voter) { $result = $voter->vote($token, $object, $attributes); - switch ($result) { - case VoterInterface::ACCESS_GRANTED: - ++$grant; - - break; - - case VoterInterface::ACCESS_DENIED: - ++$deny; - - break; + if (VoterInterface::ACCESS_GRANTED === $result) { + ++$grant; + } elseif (VoterInterface::ACCESS_DENIED === $result) { + ++$deny; } } @@ -159,17 +149,12 @@ private function decideUnanimous(TokenInterface $token, array $attributes, $obje foreach ($attributes as $attribute) { $result = $voter->vote($token, $object, [$attribute]); - switch ($result) { - case VoterInterface::ACCESS_GRANTED: - ++$grant; - - break; - - case VoterInterface::ACCESS_DENIED: - return false; + if (VoterInterface::ACCESS_DENIED === $result) { + return false; + } - default: - break; + if (VoterInterface::ACCESS_GRANTED === $result) { + ++$grant; } } } diff --git a/src/Symfony/Component/Security/Core/Encoder/NativePasswordEncoder.php b/src/Symfony/Component/Security/Core/Encoder/NativePasswordEncoder.php index 6267a56278103..2246e9b4b0577 100644 --- a/src/Symfony/Component/Security/Core/Encoder/NativePasswordEncoder.php +++ b/src/Symfony/Component/Security/Core/Encoder/NativePasswordEncoder.php @@ -80,9 +80,9 @@ public function isPasswordValid(string $encoded, string $raw, ?string $salt): bo return false; } - if (0 === strpos($encoded, '$2')) { + if (0 !== strpos($encoded, '$argon')) { // BCrypt encodes only the first 72 chars - return 72 >= \strlen($raw) && password_verify($raw, $encoded); + return (72 >= \strlen($raw) || 0 !== strpos($encoded, '$2')) && password_verify($raw, $encoded); } if (\extension_loaded('sodium') && version_compare(\SODIUM_LIBRARY_VERSION, '1.0.14', '>=')) { diff --git a/src/Symfony/Component/Security/Core/Encoder/SodiumPasswordEncoder.php b/src/Symfony/Component/Security/Core/Encoder/SodiumPasswordEncoder.php index d023d94886328..d261d1c4b71f2 100644 --- a/src/Symfony/Component/Security/Core/Encoder/SodiumPasswordEncoder.php +++ b/src/Symfony/Component/Security/Core/Encoder/SodiumPasswordEncoder.php @@ -80,9 +80,9 @@ public function isPasswordValid(string $encoded, string $raw, ?string $salt): bo return false; } - if (72 >= \strlen($raw) && 0 === strpos($encoded, '$2')) { - // Accept validating BCrypt passwords for seamless migrations - return password_verify($raw, $encoded); + if (0 !== strpos($encoded, '$argon')) { + // Accept validating non-argon passwords for seamless migrations + return (72 >= \strlen($raw) || 0 !== strpos($encoded, '$2')) && password_verify($raw, $encoded); } if (\function_exists('sodium_crypto_pwhash_str_verify')) { diff --git a/src/Symfony/Component/Security/Core/Encoder/UserPasswordEncoder.php b/src/Symfony/Component/Security/Core/Encoder/UserPasswordEncoder.php index 98daa8154c8ff..aeb29956469d7 100644 --- a/src/Symfony/Component/Security/Core/Encoder/UserPasswordEncoder.php +++ b/src/Symfony/Component/Security/Core/Encoder/UserPasswordEncoder.php @@ -42,6 +42,10 @@ public function encodePassword(UserInterface $user, string $plainPassword) */ public function isPasswordValid(UserInterface $user, string $raw) { + if (null === $user->getPassword()) { + return false; + } + $encoder = $this->encoderFactory->getEncoder($user); return $encoder->isPasswordValid($user->getPassword(), $raw, $user->getSalt()); @@ -52,6 +56,10 @@ public function isPasswordValid(UserInterface $user, string $raw) */ public function needsRehash(UserInterface $user): bool { + if (null === $user->getPassword()) { + return false; + } + $encoder = $this->encoderFactory->getEncoder($user); return $encoder->needsRehash($user->getPassword()); diff --git a/src/Symfony/Component/Security/Core/Tests/Authentication/Provider/DaoAuthenticationProviderTest.php b/src/Symfony/Component/Security/Core/Tests/Authentication/Provider/DaoAuthenticationProviderTest.php index 8c599fcba74f8..17393f34138de 100644 --- a/src/Symfony/Component/Security/Core/Tests/Authentication/Provider/DaoAuthenticationProviderTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Authentication/Provider/DaoAuthenticationProviderTest.php @@ -147,7 +147,11 @@ public function testCheckAuthenticationWhenCredentialsAre0() ->willReturn('0') ; - $method->invoke($provider, new TestUser(), $token); + $method->invoke( + $provider, + new User('username', 'password'), + $token + ); } public function testCheckAuthenticationWhenCredentialsAreNotValid() @@ -169,7 +173,7 @@ public function testCheckAuthenticationWhenCredentialsAreNotValid() ->willReturn('foo') ; - $method->invoke($provider, new TestUser(), $token); + $method->invoke($provider, new User('username', 'password'), $token); } public function testCheckAuthenticationDoesNotReauthenticateWhenPasswordHasChanged() @@ -241,7 +245,7 @@ public function testCheckAuthentication() ->willReturn('foo') ; - $method->invoke($provider, new TestUser(), $token); + $method->invoke($provider, new User('username', 'password'), $token); } public function testPasswordUpgrades() diff --git a/src/Symfony/Component/Security/Core/Tests/Encoder/NativePasswordEncoderTest.php b/src/Symfony/Component/Security/Core/Tests/Encoder/NativePasswordEncoderTest.php index 8b15a47b82da4..965bf3751c7ee 100644 --- a/src/Symfony/Component/Security/Core/Tests/Encoder/NativePasswordEncoderTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Encoder/NativePasswordEncoderTest.php @@ -55,6 +55,15 @@ public function testValidation() $this->assertFalse($encoder->isPasswordValid($result, 'anotherPassword', null)); } + public function testNonArgonValidation() + { + $encoder = new NativePasswordEncoder(); + $this->assertTrue($encoder->isPasswordValid('$5$abcdefgh$ZLdkj8mkc2XVSrPVjskDAgZPGjtj1VGVaa1aUkrMTU/', 'password', null)); + $this->assertFalse($encoder->isPasswordValid('$5$abcdefgh$ZLdkj8mkc2XVSrPVjskDAgZPGjtj1VGVaa1aUkrMTU/', 'anotherPassword', null)); + $this->assertTrue($encoder->isPasswordValid('$6$abcdefgh$yVfUwsw5T.JApa8POvClA1pQ5peiq97DUNyXCZN5IrF.BMSkiaLQ5kvpuEm/VQ1Tvh/KV2TcaWh8qinoW5dhA1', 'password', null)); + $this->assertFalse($encoder->isPasswordValid('$6$abcdefgh$yVfUwsw5T.JApa8POvClA1pQ5peiq97DUNyXCZN5IrF.BMSkiaLQ5kvpuEm/VQ1Tvh/KV2TcaWh8qinoW5dhA1', 'anotherPassword', null)); + } + public function testConfiguredAlgorithm() { $encoder = new NativePasswordEncoder(null, null, null, PASSWORD_BCRYPT); diff --git a/src/Symfony/Component/Security/Core/Tests/Encoder/SodiumPasswordEncoderTest.php b/src/Symfony/Component/Security/Core/Tests/Encoder/SodiumPasswordEncoderTest.php index 9075fc4e8ab14..8fa0813115e16 100644 --- a/src/Symfony/Component/Security/Core/Tests/Encoder/SodiumPasswordEncoderTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Encoder/SodiumPasswordEncoderTest.php @@ -37,6 +37,15 @@ public function testBCryptValidation() $this->assertTrue($encoder->isPasswordValid('$2y$04$M8GDODMoGQLQRpkYCdoJh.lbiZPee3SZI32RcYK49XYTolDGwoRMm', 'abc', null)); } + public function testNonArgonValidation() + { + $encoder = new SodiumPasswordEncoder(); + $this->assertTrue($encoder->isPasswordValid('$5$abcdefgh$ZLdkj8mkc2XVSrPVjskDAgZPGjtj1VGVaa1aUkrMTU/', 'password', null)); + $this->assertFalse($encoder->isPasswordValid('$5$abcdefgh$ZLdkj8mkc2XVSrPVjskDAgZPGjtj1VGVaa1aUkrMTU/', 'anotherPassword', null)); + $this->assertTrue($encoder->isPasswordValid('$6$abcdefgh$yVfUwsw5T.JApa8POvClA1pQ5peiq97DUNyXCZN5IrF.BMSkiaLQ5kvpuEm/VQ1Tvh/KV2TcaWh8qinoW5dhA1', 'password', null)); + $this->assertFalse($encoder->isPasswordValid('$6$abcdefgh$yVfUwsw5T.JApa8POvClA1pQ5peiq97DUNyXCZN5IrF.BMSkiaLQ5kvpuEm/VQ1Tvh/KV2TcaWh8qinoW5dhA1', 'anotherPassword', null)); + } + public function testEncodePasswordLength() { $this->expectException('Symfony\Component\Security\Core\Exception\BadCredentialsException'); diff --git a/src/Symfony/Component/Security/Core/Validator/Constraints/UserPasswordValidator.php b/src/Symfony/Component/Security/Core/Validator/Constraints/UserPasswordValidator.php index 41559a3adcd17..24b032484fa1a 100644 --- a/src/Symfony/Component/Security/Core/Validator/Constraints/UserPasswordValidator.php +++ b/src/Symfony/Component/Security/Core/Validator/Constraints/UserPasswordValidator.php @@ -36,7 +36,7 @@ public function __construct(TokenStorageInterface $tokenStorage, EncoderFactoryI public function validate($password, Constraint $constraint) { if (!$constraint instanceof UserPassword) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\UserPassword'); + throw new UnexpectedTypeException($constraint, UserPassword::class); } if (null === $password || '' === $password) { @@ -53,7 +53,7 @@ public function validate($password, Constraint $constraint) $encoder = $this->encoderFactory->getEncoder($user); - if (!$encoder->isPasswordValid($user->getPassword(), $password, $user->getSalt())) { + if (null === $user->getPassword() || !$encoder->isPasswordValid($user->getPassword(), $password, $user->getSalt())) { $this->context->addViolation($constraint->message); } } diff --git a/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php b/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php index 4fa09b30fc2df..612622bf051e8 100644 --- a/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php @@ -175,7 +175,7 @@ abstract protected function attemptAuthentication(Request $request); private function onFailure(Request $request, AuthenticationException $failed): Response { if (null !== $this->logger) { - $this->logger->error('Authentication request failed.', ['exception' => $failed]); + $this->logger->info('Authentication request failed.', ['exception' => $failed]); } $token = $this->tokenStorage->getToken(); diff --git a/src/Symfony/Component/Security/Http/Firewall/ContextListener.php b/src/Symfony/Component/Security/Http/Firewall/ContextListener.php index 02de94628a396..69066552d7ca6 100644 --- a/src/Symfony/Component/Security/Http/Firewall/ContextListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/ContextListener.php @@ -66,7 +66,13 @@ public function __construct(TokenStorageInterface $tokenStorage, iterable $userP $this->userProviders = $userProviders; $this->sessionKey = '_security_'.$contextKey; $this->logger = $logger; - $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); + + if (null !== $dispatcher && class_exists(LegacyEventDispatcherProxy::class)) { + $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); + } else { + $this->dispatcher = $dispatcher; + } + $this->trustResolver = $trustResolver ?: new AuthenticationTrustResolver(AnonymousToken::class, RememberMeToken::class); $this->sessionTrackerEnabler = $sessionTrackerEnabler; } diff --git a/src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php index f664ab064b201..e33cf4cc8a356 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php @@ -94,13 +94,7 @@ public function denormalize($data, string $type, string $format = null, array $c $dateTimeErrors = \DateTime::class === $type ? \DateTime::getLastErrors() : \DateTimeImmutable::getLastErrors(); - throw new NotNormalizableValueException(sprintf( - 'Parsing datetime string "%s" using format "%s" resulted in %d errors:'."\n".'%s', - $data, - $dateTimeFormat, - $dateTimeErrors['error_count'], - implode("\n", $this->formatDateTimeErrors($dateTimeErrors['errors'])) - )); + throw new NotNormalizableValueException(sprintf('Parsing datetime string "%s" using format "%s" resulted in %d errors:'."\n".'%s', $data, $dateTimeFormat, $dateTimeErrors['error_count'], implode("\n", $this->formatDateTimeErrors($dateTimeErrors['errors'])))); } try { diff --git a/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php index c2fa6557fe863..81fe9c1166797 100644 --- a/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php @@ -103,8 +103,14 @@ protected function extractAttributes(object $object, string $format = null, arra } } + $checkPropertyInitialization = \PHP_VERSION_ID >= 70400; + // properties foreach ($reflClass->getProperties(\ReflectionProperty::IS_PUBLIC) as $reflProperty) { + if ($checkPropertyInitialization && !$reflProperty->isInitialized($object)) { + continue; + } + if ($reflProperty->isStatic() || !$this->isAllowedAttribute($object, $reflProperty->name, $format, $context)) { continue; } diff --git a/src/Symfony/Component/Serializer/Normalizer/ProblemNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/ProblemNormalizer.php index e2ec20b881f2a..51821de2a06d8 100644 --- a/src/Symfony/Component/Serializer/Normalizer/ProblemNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/ProblemNormalizer.php @@ -41,7 +41,7 @@ public function __construct(bool $debug = false, array $defaultContext = []) public function normalize($exception, string $format = null, array $context = []) { $context += $this->defaultContext; - $debug = $this->debug && $context['debug'] ?? true; + $debug = $this->debug && ($context['debug'] ?? true); $data = [ 'type' => $context['type'], diff --git a/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php index e21498fe9feda..2d12b5ec5125b 100644 --- a/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php @@ -101,9 +101,20 @@ protected function extractAttributes(object $object, string $format = null, arra { $reflectionObject = new \ReflectionObject($object); $attributes = []; + $checkPropertyInitialization = \PHP_VERSION_ID >= 70400; do { foreach ($reflectionObject->getProperties() as $property) { + if ($checkPropertyInitialization) { + if (!$property->isPublic()) { + $property->setAccessible(true); + } + + if (!$property->isInitialized($object)) { + continue; + } + } + if (!$this->isAllowedAttribute($reflectionObject->getName(), $property->name, $format, $context)) { continue; } diff --git a/src/Symfony/Component/Serializer/Tests/Fixtures/Php74Dummy.php b/src/Symfony/Component/Serializer/Tests/Fixtures/Php74Dummy.php new file mode 100644 index 0000000000000..e8cebd9b45e95 --- /dev/null +++ b/src/Symfony/Component/Serializer/Tests/Fixtures/Php74Dummy.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\Serializer\Tests\Fixtures; + +/** + * @author Valentin Udaltsov + */ +final class Php74Dummy +{ + public string $uninitializedProperty; + + public string $initializedProperty = 'defaultValue'; +} diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php index 428ac6012b1e7..0ea075e056b57 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php @@ -40,7 +40,7 @@ class AbstractObjectNormalizerTest extends TestCase public function testDenormalize() { $normalizer = new AbstractObjectNormalizerDummy(); - $normalizedData = $normalizer->denormalize(['foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz'], __NAMESPACE__.'\Dummy'); + $normalizedData = $normalizer->denormalize(['foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz'], Dummy::class); $this->assertSame('foo', $normalizedData->foo); $this->assertNull($normalizedData->bar); @@ -50,12 +50,12 @@ public function testDenormalize() public function testInstantiateObjectDenormalizer() { $data = ['foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz']; - $class = __NAMESPACE__.'\Dummy'; + $class = Dummy::class; $context = []; $normalizer = new AbstractObjectNormalizerDummy(); - $this->assertInstanceOf(__NAMESPACE__.'\Dummy', $normalizer->instantiateObject($data, $class, $context, new \ReflectionClass($class), [])); + $this->assertInstanceOf(Dummy::class, $normalizer->instantiateObject($data, $class, $context, new \ReflectionClass($class), [])); } public function testDenormalizeWithExtraAttributes() @@ -66,7 +66,7 @@ public function testDenormalizeWithExtraAttributes() $normalizer = new AbstractObjectNormalizerDummy($factory); $normalizer->denormalize( ['fooFoo' => 'foo', 'fooBar' => 'bar'], - __NAMESPACE__.'\Dummy', + Dummy::class, 'any', ['allow_extra_attributes' => false] ); diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/ArrayDenormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/ArrayDenormalizerTest.php index a8302be91ed76..fbceb90cffd45 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/ArrayDenormalizerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/ArrayDenormalizerTest.php @@ -68,7 +68,7 @@ public function testSupportsValidArray() { $this->serializer->expects($this->once()) ->method('supportsDenormalization') - ->with($this->anything(), __NAMESPACE__.'\ArrayDummy', $this->anything()) + ->with($this->anything(), ArrayDummy::class, $this->anything()) ->willReturn(true); $this->assertTrue( @@ -104,7 +104,7 @@ public function testSupportsNoArray() $this->assertFalse( $this->denormalizer->supportsDenormalization( ['foo' => 'one', 'bar' => 'two'], - __NAMESPACE__.'\ArrayDummy' + ArrayDummy::class ) ); } diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php index 2f41cad5db049..bc5eb596e1dd2 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php @@ -66,7 +66,7 @@ protected function setUp(): void private function createNormalizer(array $defaultContext = []) { - $this->serializer = $this->getMockBuilder(__NAMESPACE__.'\SerializerNormalizer')->getMock(); + $this->serializer = $this->getMockBuilder(SerializerNormalizer::class)->getMock(); $this->normalizer = new GetSetMethodNormalizer(null, null, null, null, null, $defaultContext); $this->normalizer->setSerializer($this->serializer); } @@ -155,7 +155,7 @@ public function testConstructorDenormalize() { $obj = $this->normalizer->denormalize( ['foo' => 'foo', 'bar' => 'bar', 'baz' => true, 'fooBar' => 'foobar'], - __NAMESPACE__.'\GetConstructorDummy', 'any'); + GetConstructorDummy::class, 'any'); $this->assertEquals('foo', $obj->getFoo()); $this->assertEquals('bar', $obj->getBar()); $this->assertTrue($obj->isBaz()); @@ -165,7 +165,7 @@ public function testConstructorDenormalizeWithNullArgument() { $obj = $this->normalizer->denormalize( ['foo' => 'foo', 'bar' => null, 'baz' => true], - __NAMESPACE__.'\GetConstructorDummy', 'any'); + GetConstructorDummy::class, 'any'); $this->assertEquals('foo', $obj->getFoo()); $this->assertNull($obj->getBar()); $this->assertTrue($obj->isBaz()); @@ -175,7 +175,7 @@ public function testConstructorDenormalizeWithMissingOptionalArgument() { $obj = $this->normalizer->denormalize( ['foo' => 'test', 'baz' => [1, 2, 3]], - __NAMESPACE__.'\GetConstructorOptionalArgsDummy', 'any'); + GetConstructorOptionalArgsDummy::class, 'any'); $this->assertEquals('test', $obj->getFoo()); $this->assertEquals([], $obj->getBar()); $this->assertEquals([1, 2, 3], $obj->getBaz()); @@ -185,7 +185,7 @@ public function testConstructorDenormalizeWithOptionalDefaultArgument() { $obj = $this->normalizer->denormalize( ['bar' => 'test'], - __NAMESPACE__.'\GetConstructorArgsWithDefaultValueDummy', 'any'); + GetConstructorArgsWithDefaultValueDummy::class, 'any'); $this->assertEquals([], $obj->getFoo()); $this->assertEquals('test', $obj->getBar()); } @@ -213,14 +213,14 @@ public function testConstructorWithObjectDenormalize() $data->bar = 'bar'; $data->baz = true; $data->fooBar = 'foobar'; - $obj = $this->normalizer->denormalize($data, __NAMESPACE__.'\GetConstructorDummy', 'any'); + $obj = $this->normalizer->denormalize($data, GetConstructorDummy::class, 'any'); $this->assertEquals('foo', $obj->getFoo()); $this->assertEquals('bar', $obj->getBar()); } public function testConstructorWArgWithPrivateMutator() { - $obj = $this->normalizer->denormalize(['foo' => 'bar'], __NAMESPACE__.'\ObjectConstructorArgsWithPrivateMutatorDummy', 'any'); + $obj = $this->normalizer->denormalize(['foo' => 'bar'], ObjectConstructorArgsWithPrivateMutatorDummy::class, 'any'); $this->assertEquals('bar', $obj->getFoo()); } @@ -419,7 +419,7 @@ public function testNoStaticGetSetSupport() public function testPrivateSetter() { - $obj = $this->normalizer->denormalize(['foo' => 'foobar'], __NAMESPACE__.'\ObjectWithPrivateSetterDummy'); + $obj = $this->normalizer->denormalize(['foo' => 'foobar'], ObjectWithPrivateSetterDummy::class); $this->assertEquals('bar', $obj->getFoo()); } diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php index 5c6a396822365..aca0ded3ab4ec 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php @@ -31,6 +31,7 @@ use Symfony\Component\Serializer\Tests\Fixtures\CircularReferenceDummy; use Symfony\Component\Serializer\Tests\Fixtures\GroupDummy; use Symfony\Component\Serializer\Tests\Fixtures\OtherSerializedNameDummy; +use Symfony\Component\Serializer\Tests\Fixtures\Php74Dummy; use Symfony\Component\Serializer\Tests\Fixtures\SiblingHolder; use Symfony\Component\Serializer\Tests\Normalizer\Features\AttributesTestTrait; use Symfony\Component\Serializer\Tests\Normalizer\Features\CallbacksTestTrait; @@ -76,7 +77,7 @@ protected function setUp(): void private function createNormalizer(array $defaultContext = [], ClassMetadataFactoryInterface $classMetadataFactory = null) { - $this->serializer = $this->getMockBuilder(__NAMESPACE__.'\ObjectSerializerNormalizer')->getMock(); + $this->serializer = $this->getMockBuilder(ObjectSerializerNormalizer::class)->getMock(); $this->normalizer = new ObjectNormalizer($classMetadataFactory, null, null, null, null, null, $defaultContext); $this->normalizer->setSerializer($this->serializer); } @@ -111,6 +112,18 @@ public function testNormalize() ); } + /** + * @requires PHP 7.4 + */ + public function testNormalizeObjectWithUninitializedProperties() + { + $obj = new Php74Dummy(); + $this->assertEquals( + ['initializedProperty' => 'defaultValue'], + $this->normalizer->normalize($obj, 'any') + ); + } + public function testDenormalize() { $obj = $this->normalizer->denormalize( @@ -143,7 +156,7 @@ public function testConstructorDenormalize() { $obj = $this->normalizer->denormalize( ['foo' => 'foo', 'bar' => 'bar', 'baz' => true, 'fooBar' => 'foobar'], - __NAMESPACE__.'\ObjectConstructorDummy', 'any'); + ObjectConstructorDummy::class, 'any'); $this->assertEquals('foo', $obj->getFoo()); $this->assertEquals('bar', $obj->bar); $this->assertTrue($obj->isBaz()); @@ -153,7 +166,7 @@ public function testConstructorDenormalizeWithNullArgument() { $obj = $this->normalizer->denormalize( ['foo' => 'foo', 'bar' => null, 'baz' => true], - __NAMESPACE__.'\ObjectConstructorDummy', 'any'); + ObjectConstructorDummy::class, 'any'); $this->assertEquals('foo', $obj->getFoo()); $this->assertNull($obj->bar); $this->assertTrue($obj->isBaz()); @@ -163,7 +176,7 @@ public function testConstructorDenormalizeWithMissingOptionalArgument() { $obj = $this->normalizer->denormalize( ['foo' => 'test', 'baz' => [1, 2, 3]], - __NAMESPACE__.'\ObjectConstructorOptionalArgsDummy', 'any'); + ObjectConstructorOptionalArgsDummy::class, 'any'); $this->assertEquals('test', $obj->getFoo()); $this->assertEquals([], $obj->bar); $this->assertEquals([1, 2, 3], $obj->getBaz()); @@ -173,7 +186,7 @@ public function testConstructorDenormalizeWithOptionalDefaultArgument() { $obj = $this->normalizer->denormalize( ['bar' => 'test'], - __NAMESPACE__.'\ObjectConstructorArgsWithDefaultValueDummy', 'any'); + ObjectConstructorArgsWithDefaultValueDummy::class, 'any'); $this->assertEquals([], $obj->getFoo()); $this->assertEquals('test', $obj->getBar()); } @@ -185,7 +198,7 @@ public function testConstructorWithObjectDenormalize() $data->bar = 'bar'; $data->baz = true; $data->fooBar = 'foobar'; - $obj = $this->normalizer->denormalize($data, __NAMESPACE__.'\ObjectConstructorDummy', 'any'); + $obj = $this->normalizer->denormalize($data, ObjectConstructorDummy::class, 'any'); $this->assertEquals('foo', $obj->getFoo()); $this->assertEquals('bar', $obj->bar); } diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/PropertyNormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/PropertyNormalizerTest.php index 625b41c223e98..f93f7616763d0 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/PropertyNormalizerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/PropertyNormalizerTest.php @@ -28,6 +28,7 @@ use Symfony\Component\Serializer\Tests\Fixtures\Dummy; use Symfony\Component\Serializer\Tests\Fixtures\GroupDummy; use Symfony\Component\Serializer\Tests\Fixtures\GroupDummyChild; +use Symfony\Component\Serializer\Tests\Fixtures\Php74Dummy; use Symfony\Component\Serializer\Tests\Fixtures\PropertyCircularReferenceDummy; use Symfony\Component\Serializer\Tests\Fixtures\PropertySiblingHolder; use Symfony\Component\Serializer\Tests\Normalizer\Features\CallbacksTestTrait; @@ -84,11 +85,23 @@ public function testNormalize() ); } + /** + * @requires PHP 7.4 + */ + public function testNormalizeObjectWithUninitializedProperties() + { + $obj = new Php74Dummy(); + $this->assertEquals( + ['initializedProperty' => 'defaultValue'], + $this->normalizer->normalize($obj, 'any') + ); + } + public function testDenormalize() { $obj = $this->normalizer->denormalize( ['foo' => 'foo', 'bar' => 'bar'], - __NAMESPACE__.'\PropertyDummy', + PropertyDummy::class, 'any' ); $this->assertEquals('foo', $obj->foo); @@ -127,7 +140,7 @@ public function testConstructorDenormalize() { $obj = $this->normalizer->denormalize( ['foo' => 'foo', 'bar' => 'bar'], - __NAMESPACE__.'\PropertyConstructorDummy', + PropertyConstructorDummy::class, 'any' ); $this->assertEquals('foo', $obj->getFoo()); @@ -138,7 +151,7 @@ public function testConstructorDenormalizeWithNullArgument() { $obj = $this->normalizer->denormalize( ['foo' => null, 'bar' => 'bar'], - __NAMESPACE__.'\PropertyConstructorDummy', ' + PropertyConstructorDummy::class, ' any' ); $this->assertNull($obj->getFoo()); @@ -300,13 +313,13 @@ public function testDenormalizeNonExistingAttribute() { $this->assertEquals( new PropertyDummy(), - $this->normalizer->denormalize(['non_existing' => true], __NAMESPACE__.'\PropertyDummy') + $this->normalizer->denormalize(['non_existing' => true], PropertyDummy::class) ); } public function testDenormalizeShouldIgnoreStaticProperty() { - $obj = $this->normalizer->denormalize(['outOfScope' => true], __NAMESPACE__.'\PropertyDummy'); + $obj = $this->normalizer->denormalize(['outOfScope' => true], PropertyDummy::class); $this->assertEquals(new PropertyDummy(), $obj); $this->assertEquals('out_of_scope', PropertyDummy::$outOfScope); diff --git a/src/Symfony/Component/String/AbstractString.php b/src/Symfony/Component/String/AbstractString.php index 435363b798d25..e56697e391549 100644 --- a/src/Symfony/Component/String/AbstractString.php +++ b/src/Symfony/Component/String/AbstractString.php @@ -692,6 +692,11 @@ public function wordwrap(int $width = 75, string $break = "\n", bool $cut = fals return $str; } + public function __sleep(): array + { + return ['string']; + } + public function __clone() { $this->ignoreCase = false; diff --git a/src/Symfony/Component/String/AbstractUnicodeString.php b/src/Symfony/Component/String/AbstractUnicodeString.php index ce1c8094ab034..19ad5e8939d95 100644 --- a/src/Symfony/Component/String/AbstractUnicodeString.php +++ b/src/Symfony/Component/String/AbstractUnicodeString.php @@ -35,14 +35,20 @@ abstract class AbstractUnicodeString extends AbstractString public const NFKC = \Normalizer::NFKC; public const NFKD = \Normalizer::NFKD; + // all ASCII letters sorted by typical frequency of occurrence private const ASCII = "\x20\x65\x69\x61\x73\x6E\x74\x72\x6F\x6C\x75\x64\x5D\x5B\x63\x6D\x70\x27\x0A\x67\x7C\x68\x76\x2E\x66\x62\x2C\x3A\x3D\x2D\x71\x31\x30\x43\x32\x2A\x79\x78\x29\x28\x4C\x39\x41\x53\x2F\x50\x22\x45\x6A\x4D\x49\x6B\x33\x3E\x35\x54\x3C\x44\x34\x7D\x42\x7B\x38\x46\x77\x52\x36\x37\x55\x47\x4E\x3B\x4A\x7A\x56\x23\x48\x4F\x57\x5F\x26\x21\x4B\x3F\x58\x51\x25\x59\x5C\x09\x5A\x2B\x7E\x5E\x24\x40\x60\x7F\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; + + // the subset of folded case mappings that is not in lower case mappings private const FOLD_FROM = ['İ', 'µ', 'ſ', "\xCD\x85", 'ς', 'ϐ', 'ϑ', 'ϕ', 'ϖ', 'ϰ', 'ϱ', 'ϵ', 'ẛ', "\xE1\xBE\xBE", 'ß', 'İ', 'ʼn', 'ǰ', 'ΐ', 'ΰ', 'և', 'ẖ', 'ẗ', 'ẘ', 'ẙ', 'ẚ', 'ẞ', 'ὐ', 'ὒ', 'ὔ', 'ὖ', 'ᾀ', 'ᾁ', 'ᾂ', 'ᾃ', 'ᾄ', 'ᾅ', 'ᾆ', 'ᾇ', 'ᾈ', 'ᾉ', 'ᾊ', 'ᾋ', 'ᾌ', 'ᾍ', 'ᾎ', 'ᾏ', 'ᾐ', 'ᾑ', 'ᾒ', 'ᾓ', 'ᾔ', 'ᾕ', 'ᾖ', 'ᾗ', 'ᾘ', 'ᾙ', 'ᾚ', 'ᾛ', 'ᾜ', 'ᾝ', 'ᾞ', 'ᾟ', 'ᾠ', 'ᾡ', 'ᾢ', 'ᾣ', 'ᾤ', 'ᾥ', 'ᾦ', 'ᾧ', 'ᾨ', 'ᾩ', 'ᾪ', 'ᾫ', 'ᾬ', 'ᾭ', 'ᾮ', 'ᾯ', 'ᾲ', 'ᾳ', 'ᾴ', 'ᾶ', 'ᾷ', 'ᾼ', 'ῂ', 'ῃ', 'ῄ', 'ῆ', 'ῇ', 'ῌ', 'ῒ', 'ΐ', 'ῖ', 'ῗ', 'ῢ', 'ΰ', 'ῤ', 'ῦ', 'ῧ', 'ῲ', 'ῳ', 'ῴ', 'ῶ', 'ῷ', 'ῼ', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'ſt', 'st', 'ﬓ', 'ﬔ', 'ﬕ', 'ﬖ', 'ﬗ']; private const FOLD_TO = ['i̇', 'μ', 's', 'ι', 'σ', 'β', 'θ', 'φ', 'π', 'κ', 'ρ', 'ε', 'ṡ', 'ι', 'ss', 'i̇', 'ʼn', 'ǰ', 'ΐ', 'ΰ', 'եւ', 'ẖ', 'ẗ', 'ẘ', 'ẙ', 'aʾ', 'ss', 'ὐ', 'ὒ', 'ὔ', 'ὖ', 'ἀι', 'ἁι', 'ἂι', 'ἃι', 'ἄι', 'ἅι', 'ἆι', 'ἇι', 'ἀι', 'ἁι', 'ἂι', 'ἃι', 'ἄι', 'ἅι', 'ἆι', 'ἇι', 'ἠι', 'ἡι', 'ἢι', 'ἣι', 'ἤι', 'ἥι', 'ἦι', 'ἧι', 'ἠι', 'ἡι', 'ἢι', 'ἣι', 'ἤι', 'ἥι', 'ἦι', 'ἧι', 'ὠι', 'ὡι', 'ὢι', 'ὣι', 'ὤι', 'ὥι', 'ὦι', 'ὧι', 'ὠι', 'ὡι', 'ὢι', 'ὣι', 'ὤι', 'ὥι', 'ὦι', 'ὧι', 'ὰι', 'αι', 'άι', 'ᾶ', 'ᾶι', 'αι', 'ὴι', 'ηι', 'ήι', 'ῆ', 'ῆι', 'ηι', 'ῒ', 'ΐ', 'ῖ', 'ῗ', 'ῢ', 'ΰ', 'ῤ', 'ῦ', 'ῧ', 'ὼι', 'ωι', 'ώι', 'ῶ', 'ῶι', 'ωι', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'st', 'st', 'մն', 'մե', 'մի', 'վն', 'մխ']; - private const UPPER_FROM = ['ß', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'ſt', 'st', 'և', 'ﬓ', 'ﬔ', 'ﬕ', 'ﬖ', 'ﬗ', 'ʼn', 'ΐ', 'ΰ', 'ǰ', 'ẖ', 'ẗ', 'ẘ', 'ẙ', 'ẚ', 'ὐ', 'ὒ', 'ὔ', 'ὖ', 'ᾶ', 'ῆ', 'ῒ', 'ΐ', 'ῖ', 'ῗ', 'ῢ', 'ΰ', 'ῤ', 'ῦ', 'ῧ', 'ῶ -']; + + // the subset of upper case mappings that map one code point to many code points + private const UPPER_FROM = ['ß', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'ſt', 'st', 'և', 'ﬓ', 'ﬔ', 'ﬕ', 'ﬖ', 'ﬗ', 'ʼn', 'ΐ', 'ΰ', 'ǰ', 'ẖ', 'ẗ', 'ẘ', 'ẙ', 'ẚ', 'ὐ', 'ὒ', 'ὔ', 'ὖ', 'ᾶ', 'ῆ', 'ῒ', 'ΐ', 'ῖ', 'ῗ', 'ῢ', 'ΰ', 'ῤ', 'ῦ', 'ῧ', 'ῶ']; private const UPPER_TO = ['SS', 'FF', 'FI', 'FL', 'FFI', 'FFL', 'ST', 'ST', 'ԵՒ', 'ՄՆ', 'ՄԵ', 'ՄԻ', 'ՎՆ', 'ՄԽ', 'ʼN', 'Ϊ́', 'Ϋ́', 'J̌', 'H̱', 'T̈', 'W̊', 'Y̊', 'Aʾ', 'Υ̓', 'Υ̓̀', 'Υ̓́', 'Υ̓͂', 'Α͂', 'Η͂', 'Ϊ̀', 'Ϊ́', 'Ι͂', 'Ϊ͂', 'Ϋ̀', 'Ϋ́', 'Ρ̓', 'Υ͂', 'Ϋ͂', 'Ω͂']; - private const TRANSLIT_FROM = ['Ð', 'Ø', 'Þ', 'ð', 'ø', 'þ', 'Đ', 'đ', 'Ħ', 'ħ', 'ı', 'ĸ', 'Ŋ', 'ŋ', 'Ŧ', 'ŧ', 'ƀ', 'Ɓ', 'Ƃ', 'ƃ', 'Ƈ', 'ƈ', 'Ɖ', 'Ɗ', 'Ƌ', 'ƌ', 'Ɛ', 'Ƒ', 'ƒ', 'Ɠ', 'ƕ', 'Ɩ', 'Ɨ', 'Ƙ', 'ƙ', 'ƚ', 'Ɲ', 'ƞ', 'Ƣ', 'ƣ', 'Ƥ', 'ƥ', 'ƫ', 'Ƭ', 'ƭ', 'Ʈ', 'Ʋ', 'Ƴ', 'ƴ', 'Ƶ', 'ƶ', 'Ǥ', 'ǥ', 'ȡ', 'Ȥ', 'ȥ', 'ȴ', 'ȵ', 'ȶ', 'ȷ', 'ȸ', 'ȹ', 'Ⱥ', 'Ȼ', 'ȼ', 'Ƚ', 'Ⱦ', 'ȿ', 'ɀ', 'Ƀ', 'Ʉ', 'Ɇ', 'ɇ', 'Ɉ', 'ɉ', 'Ɍ', 'ɍ', 'Ɏ', 'ɏ', 'ɓ', 'ɕ', 'ɖ', 'ɗ', 'ɛ', 'ɟ', 'ɠ', 'ɡ', 'ɢ', 'ɦ', 'ɧ', 'ɨ', 'ɪ', 'ɫ', 'ɬ', 'ɭ', 'ɱ', 'ɲ', 'ɳ', 'ɴ', 'ɶ', 'ɼ', 'ɽ', 'ɾ', 'ʀ', 'ʂ', 'ʈ', 'ʉ', 'ʋ', 'ʏ', 'ʐ', 'ʑ', 'ʙ', 'ʛ', 'ʜ', 'ʝ', 'ʟ', 'ʠ', 'ʣ', 'ʥ', 'ʦ', 'ʪ', 'ʫ', 'ᴀ', 'ᴁ', 'ᴃ', 'ᴄ', 'ᴅ', 'ᴆ', 'ᴇ', 'ᴊ', 'ᴋ', 'ᴌ', 'ᴍ', 'ᴏ', 'ᴘ', 'ᴛ', 'ᴜ', 'ᴠ', 'ᴡ', 'ᴢ', 'ᵫ', 'ᵬ', 'ᵭ', 'ᵮ', 'ᵯ', 'ᵰ', 'ᵱ', 'ᵲ', 'ᵳ', 'ᵴ', 'ᵵ', 'ᵶ', 'ᵺ', 'ᵻ', 'ᵽ', 'ᵾ', 'ᶀ', 'ᶁ', 'ᶂ', 'ᶃ', 'ᶄ', 'ᶅ', 'ᶆ', 'ᶇ', 'ᶈ', 'ᶉ', 'ᶊ', 'ᶌ', 'ᶍ', 'ᶎ', 'ᶏ', 'ᶑ', 'ᶒ', 'ᶓ', 'ᶖ', 'ᶙ', 'ẜ', 'ẝ', 'ẞ', 'Ỻ', 'ỻ', 'Ỽ', 'ỽ', 'Ỿ', 'ỿ', '₠', '₢', '₣', '₤', '₧', '₹', '℞', '〇', '′', '〝', '〞', '‖', '⁅', '⁆', '⁎', '、', '。', '〈', '〉', '《', '》', '〔', '〕', '〘', '〙', '〚', '〛', '︑', '︒', '︹', '︺', '︽', '︾', '︿', '﹀', '÷', '∥', '⦅', '⦆']; - private const TRANSLIT_TO = ['D', 'O', 'TH', 'd', 'o', 'th', 'D', 'd', 'H', 'h', 'i', 'q', 'N', 'n', 'T', 't', 'b', 'B', 'B', 'b', 'C', 'c', 'D', 'D', 'D', 'd', 'E', 'F', 'f', 'G', 'hv', 'I', 'I', 'K', 'k', 'l', 'N', 'n', 'OI', 'oi', 'P', 'p', 't', 'T', 't', 'T', 'V', 'Y', 'y', 'Z', 'z', 'G', 'g', 'd', 'Z', 'z', 'l', 'n', 't', 'j', 'db', 'qp', 'A', 'C', 'c', 'L', 'T', 's', 'z', 'B', 'U', 'E', 'e', 'J', 'j', 'R', 'r', 'Y', 'y', 'b', 'c', 'd', 'd', 'e', 'j', 'g', 'g', 'G', 'h', 'h', 'i', 'I', 'l', 'l', 'l', 'm', 'n', 'n', 'N', 'OE', 'r', 'r', 'r', 'R', 's', 't', 'u', 'v', 'Y', 'z', 'z', 'B', 'G', 'H', 'j', 'L', 'q', 'dz', 'dz', 'ts', 'ls', 'lz', 'A', 'AE', 'B', 'C', 'D', 'D', 'E', 'J', 'K', 'L', 'M', 'O', 'P', 'T', 'U', 'V', 'W', 'Z', 'ue', 'b', 'd', 'f', 'm', 'n', 'p', 'r', 'r', 's', 't', 'z', 'th', 'I', 'p', 'U', 'b', 'd', 'f', 'g', 'k', 'l', 'm', 'n', 'p', 'r', 's', 'v', 'x', 'z', 'a', 'd', 'e', 'e', 'i', 'u', 's', 's', 'SS', 'LL', 'll', 'V', 'v', 'Y', 'y', 'CE', 'Cr', 'Fr.', 'L.', 'Pts', 'Rs', 'Rx', '0', '\'', '"', '"', '||', '[', ']', '*', ',', '.', '<', '>', '<<', '>>', '[', ']', '[', ']', '[', ']', ',', '.', '[', ']', '<<', '>>', '<', '>', '/', '||', '((', '))']; + + // the subset of https://github.com/unicode-org/cldr/blob/master/common/transforms/Latin-ASCII.xml that is not in NFKD + private const TRANSLIT_FROM = ['Æ', 'Ð', 'Ø', 'Þ', 'ß', 'æ', 'ð', 'ø', 'þ', 'Đ', 'đ', 'Ħ', 'ħ', 'ı', 'ĸ', 'Ŀ', 'ŀ', 'Ł', 'ł', 'ʼn', 'Ŋ', 'ŋ', 'Œ', 'œ', 'Ŧ', 'ŧ', 'ƀ', 'Ɓ', 'Ƃ', 'ƃ', 'Ƈ', 'ƈ', 'Ɖ', 'Ɗ', 'Ƌ', 'ƌ', 'Ɛ', 'Ƒ', 'ƒ', 'Ɠ', 'ƕ', 'Ɩ', 'Ɨ', 'Ƙ', 'ƙ', 'ƚ', 'Ɲ', 'ƞ', 'Ƣ', 'ƣ', 'Ƥ', 'ƥ', 'ƫ', 'Ƭ', 'ƭ', 'Ʈ', 'Ʋ', 'Ƴ', 'ƴ', 'Ƶ', 'ƶ', 'DŽ', 'Dž', 'dž', 'Ǥ', 'ǥ', 'ȡ', 'Ȥ', 'ȥ', 'ȴ', 'ȵ', 'ȶ', 'ȷ', 'ȸ', 'ȹ', 'Ⱥ', 'Ȼ', 'ȼ', 'Ƚ', 'Ⱦ', 'ȿ', 'ɀ', 'Ƀ', 'Ʉ', 'Ɇ', 'ɇ', 'Ɉ', 'ɉ', 'Ɍ', 'ɍ', 'Ɏ', 'ɏ', 'ɓ', 'ɕ', 'ɖ', 'ɗ', 'ɛ', 'ɟ', 'ɠ', 'ɡ', 'ɢ', 'ɦ', 'ɧ', 'ɨ', 'ɪ', 'ɫ', 'ɬ', 'ɭ', 'ɱ', 'ɲ', 'ɳ', 'ɴ', 'ɶ', 'ɼ', 'ɽ', 'ɾ', 'ʀ', 'ʂ', 'ʈ', 'ʉ', 'ʋ', 'ʏ', 'ʐ', 'ʑ', 'ʙ', 'ʛ', 'ʜ', 'ʝ', 'ʟ', 'ʠ', 'ʣ', 'ʥ', 'ʦ', 'ʪ', 'ʫ', 'ᴀ', 'ᴁ', 'ᴃ', 'ᴄ', 'ᴅ', 'ᴆ', 'ᴇ', 'ᴊ', 'ᴋ', 'ᴌ', 'ᴍ', 'ᴏ', 'ᴘ', 'ᴛ', 'ᴜ', 'ᴠ', 'ᴡ', 'ᴢ', 'ᵫ', 'ᵬ', 'ᵭ', 'ᵮ', 'ᵯ', 'ᵰ', 'ᵱ', 'ᵲ', 'ᵳ', 'ᵴ', 'ᵵ', 'ᵶ', 'ᵺ', 'ᵻ', 'ᵽ', 'ᵾ', 'ᶀ', 'ᶁ', 'ᶂ', 'ᶃ', 'ᶄ', 'ᶅ', 'ᶆ', 'ᶇ', 'ᶈ', 'ᶉ', 'ᶊ', 'ᶌ', 'ᶍ', 'ᶎ', 'ᶏ', 'ᶑ', 'ᶒ', 'ᶓ', 'ᶖ', 'ᶙ', 'ẚ', 'ẜ', 'ẝ', 'ẞ', 'Ỻ', 'ỻ', 'Ỽ', 'ỽ', 'Ỿ', 'ỿ', '©', '®', '₠', '₢', '₣', '₤', '₧', '₺', '₹', 'ℌ', '℞', '㎧', '㎮', '㏆', '㏗', '㏞', '㏟', '¼', '½', '¾', '⅓', '⅔', '⅕', '⅖', '⅗', '⅘', '⅙', '⅚', '⅛', '⅜', '⅝', '⅞', '⅟', '〇', '‘', '’', '‚', '‛', '“', '”', '„', '‟', '′', '″', '〝', '〞', '«', '»', '‹', '›', '‐', '‑', '‒', '–', '—', '―', '︱', '︲', '﹘', '‖', '⁄', '⁅', '⁆', '⁎', '、', '。', '〈', '〉', '《', '》', '〔', '〕', '〘', '〙', '〚', '〛', '︑', '︒', '︹', '︺', '︽', '︾', '︿', '﹀', '﹑', '﹝', '﹞', '⦅', '⦆', '。', '、', '×', '÷', '−', '∕', '∖', '∣', '∥', '≪', '≫', '⦅', '⦆']; + private const TRANSLIT_TO = ['AE', 'D', 'O', 'TH', 'ss', 'ae', 'd', 'o', 'th', 'D', 'd', 'H', 'h', 'i', 'q', 'L', 'l', 'L', 'l', '\'n', 'N', 'n', 'OE', 'oe', 'T', 't', 'b', 'B', 'B', 'b', 'C', 'c', 'D', 'D', 'D', 'd', 'E', 'F', 'f', 'G', 'hv', 'I', 'I', 'K', 'k', 'l', 'N', 'n', 'OI', 'oi', 'P', 'p', 't', 'T', 't', 'T', 'V', 'Y', 'y', 'Z', 'z', 'DZ', 'Dz', 'dz', 'G', 'g', 'd', 'Z', 'z', 'l', 'n', 't', 'j', 'db', 'qp', 'A', 'C', 'c', 'L', 'T', 's', 'z', 'B', 'U', 'E', 'e', 'J', 'j', 'R', 'r', 'Y', 'y', 'b', 'c', 'd', 'd', 'e', 'j', 'g', 'g', 'G', 'h', 'h', 'i', 'I', 'l', 'l', 'l', 'm', 'n', 'n', 'N', 'OE', 'r', 'r', 'r', 'R', 's', 't', 'u', 'v', 'Y', 'z', 'z', 'B', 'G', 'H', 'j', 'L', 'q', 'dz', 'dz', 'ts', 'ls', 'lz', 'A', 'AE', 'B', 'C', 'D', 'D', 'E', 'J', 'K', 'L', 'M', 'O', 'P', 'T', 'U', 'V', 'W', 'Z', 'ue', 'b', 'd', 'f', 'm', 'n', 'p', 'r', 'r', 's', 't', 'z', 'th', 'I', 'p', 'U', 'b', 'd', 'f', 'g', 'k', 'l', 'm', 'n', 'p', 'r', 's', 'v', 'x', 'z', 'a', 'd', 'e', 'e', 'i', 'u', 'a', 's', 's', 'SS', 'LL', 'll', 'V', 'v', 'Y', 'y', '(C)', '(R)', 'CE', 'Cr', 'Fr.', 'L.', 'Pts', 'TL', 'Rs', 'x', 'Rx', 'm/s', 'rad/s', 'C/kg', 'pH', 'V/m', 'A/m', ' 1/4', ' 1/2', ' 3/4', ' 1/3', ' 2/3', ' 1/5', ' 2/5', ' 3/5', ' 4/5', ' 1/6', ' 5/6', ' 1/8', ' 3/8', ' 5/8', ' 7/8', ' 1/', '0', '\'', '\'', ',', '\'', '"', '"', ',,', '"', '\'', '"', '"', '"', '<<', '>>', '<', '>', '-', '-', '-', '-', '-', '-', '-', '-', '-', '||', '/', '[', ']', '*', ',', '.', '<', '>', '<<', '>>', '[', ']', '[', ']', '[', ']', ',', '.', '[', ']', '<<', '>>', '<', '>', ',', '[', ']', '((', '))', '.', ',', '*', '/', '-', '/', '\\', '|', '||', '<<', '>>', '((', '))']; private static $transliterators = []; @@ -81,14 +87,14 @@ public function ascii(array $rules = []): self $s = $str->string; $str->string = ''; + array_unshift($rules, 'nfd'); + $rules[] = 'latin-ascii'; + if (\function_exists('transliterator_transliterate')) { - array_unshift($rules, 'nfd'); $rules[] = 'any-latin/bgn'; - $rules[] = 'nfkd'; - } else { - array_unshift($rules, 'nfkd'); } + $rules[] = 'nfkd'; $rules[] = '[:nonspacing mark:] remove'; while (\strlen($s) - 1 > $i = strspn($s, self::ASCII)) { @@ -110,6 +116,8 @@ public function ascii(array $rules = []): self normalizer_is_normalized($s, self::NFKD) ?: $s = normalizer_normalize($s, self::NFKD); } elseif ('[:nonspacing mark:] remove' === $rule) { $s = preg_replace('/\p{Mn}++/u', '', $s); + } elseif ('latin-ascii' === $rule) { + $s = str_replace(self::TRANSLIT_FROM, self::TRANSLIT_TO, $s); } elseif ('de-ascii' === $rule) { $s = preg_replace("/([AUO])\u{0308}(?=\p{Ll})/u", '$1e', $s); $s = str_replace(["a\u{0308}", "o\u{0308}", "u\u{0308}", "A\u{0308}", "O\u{0308}", "U\u{0308}"], ['ae', 'oe', 'ue', 'AE', 'OE', 'UE'], $s); @@ -130,12 +138,10 @@ public function ascii(array $rules = []): self $s = $transliterator->transliterate($s); } } elseif (!\function_exists('iconv')) { - $s = str_replace(self::TRANSLIT_FROM, self::TRANSLIT_TO, $s); $s = preg_replace('/[^\x00-\x7F]/u', '?', $s); } elseif (\ICONV_IMPL === 'glibc') { $s = iconv('UTF-8', 'ASCII//TRANSLIT', $s); } else { - $s = str_replace(self::TRANSLIT_FROM, self::TRANSLIT_TO, $s); $s = preg_replace_callback('/[^\x00-\x7F]/u', static function ($c) { $c = iconv('UTF-8', 'ASCII//IGNORE//TRANSLIT', $c[0]); diff --git a/src/Symfony/Component/String/Tests/SluggerTest.php b/src/Symfony/Component/String/Tests/SluggerTest.php index d796dde11b728..c1a0e61ae38d8 100644 --- a/src/Symfony/Component/String/Tests/SluggerTest.php +++ b/src/Symfony/Component/String/Tests/SluggerTest.php @@ -36,6 +36,7 @@ public static function provideSlug(): array ['Αυτή η τιμή πρέπει να είναι ψευδής', 'el', 'Avti-i-timi-prepi-na-inai-psevdhis'], ['该变量的值应为', 'zh', 'gai-bian-liang-de-zhi-ying-wei'], ['該變數的值應為', 'zh_TW', 'gai-bian-shu-de-zhi-ying-wei'], + ['Wôrķšƥáçè ~~sèťtïñğš~~', 'C', 'Workspace-settings'], ]; } diff --git a/src/Symfony/Component/String/UnicodeString.php b/src/Symfony/Component/String/UnicodeString.php index 61e8c008dcb35..d7df6f5e1400b 100644 --- a/src/Symfony/Component/String/UnicodeString.php +++ b/src/Symfony/Component/String/UnicodeString.php @@ -347,6 +347,11 @@ public function startsWith($prefix): bool return $prefix === grapheme_extract($this->string, \strlen($prefix), GRAPHEME_EXTR_MAXBYTES); } + public function __wakeup() + { + normalizer_is_normalized($this->string) ?: $this->string = normalizer_normalize($this->string); + } + public function __clone() { if (null === $this->ignoreCase) { diff --git a/src/Symfony/Component/Translation/Dumper/FileDumper.php b/src/Symfony/Component/Translation/Dumper/FileDumper.php index e257e722461d0..463a08c75b5c6 100644 --- a/src/Symfony/Component/Translation/Dumper/FileDumper.php +++ b/src/Symfony/Component/Translation/Dumper/FileDumper.php @@ -51,36 +51,37 @@ public function dump(MessageCatalogue $messages, array $options = []) throw new InvalidArgumentException('The file dumper needs a path option.'); } + $hasMessageFormatter = class_exists(\MessageFormatter::class); + // save a file for each domain foreach ($messages->getDomains() as $domain) { - $fullpath = $options['path'].'/'.$this->getRelativePath($domain, $messages->getLocale()); - if (!file_exists($fullpath)) { - $directory = \dirname($fullpath); + if ($hasMessageFormatter) { + $defaultDomain = $domain.MessageCatalogue::INTL_DOMAIN_SUFFIX; + $altDomain = $domain; + } else { + $defaultDomain = $domain; + $altDomain = $domain.MessageCatalogue::INTL_DOMAIN_SUFFIX; + } + $defaultPath = $options['path'].'/'.$this->getRelativePath($defaultDomain, $messages->getLocale()); + $altPath = $options['path'].'/'.$this->getRelativePath($altDomain, $messages->getLocale()); + + if (!file_exists($defaultPath) && file_exists($altPath)) { + [$defaultPath, $altPath] = [$altPath, $defaultPath]; + } + + if (!file_exists($defaultPath)) { + $directory = \dirname($defaultPath); if (!file_exists($directory) && !@mkdir($directory, 0777, true)) { throw new RuntimeException(sprintf('Unable to create directory "%s".', $directory)); } } - $intlDomain = $domain.MessageCatalogue::INTL_DOMAIN_SUFFIX; - $intlMessages = $messages->all($intlDomain); - - if ($intlMessages) { - $intlPath = $options['path'].'/'.$this->getRelativePath($intlDomain, $messages->getLocale()); - file_put_contents($intlPath, $this->formatCatalogue($messages, $intlDomain, $options)); - - $messages->replace([], $intlDomain); - - try { - if ($messages->all($domain)) { - file_put_contents($fullpath, $this->formatCatalogue($messages, $domain, $options)); - } - continue; - } finally { - $messages->replace($intlMessages, $intlDomain); - } + if (file_exists($altPath)) { + // clear alternative translation file + file_put_contents($altPath, $this->formatCatalogue(new MessageCatalogue($messages->getLocale()), $altDomain, $options)); } - file_put_contents($fullpath, $this->formatCatalogue($messages, $domain, $options)); + file_put_contents($defaultPath, $this->formatCatalogue($messages, $domain, $options)); } } diff --git a/src/Symfony/Component/Translation/Loader/PhpFileLoader.php b/src/Symfony/Component/Translation/Loader/PhpFileLoader.php index a0050e8db1e19..0991c3d3a28c6 100644 --- a/src/Symfony/Component/Translation/Loader/PhpFileLoader.php +++ b/src/Symfony/Component/Translation/Loader/PhpFileLoader.php @@ -18,11 +18,25 @@ */ class PhpFileLoader extends FileLoader { + private static $cache = []; + /** * {@inheritdoc} */ protected function loadResource($resource) { - return require $resource; + if ([] === self::$cache && \function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN) && (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) || filter_var(ini_get('opcache.enable_cli'), FILTER_VALIDATE_BOOLEAN))) { + self::$cache = null; + } + + if (null === self::$cache) { + return require $resource; + } + + if (isset(self::$cache[$resource])) { + return self::$cache[$resource]; + } + + return self::$cache[$resource] = require $resource; } } diff --git a/src/Symfony/Component/Translation/Tests/Dumper/FileDumperTest.php b/src/Symfony/Component/Translation/Tests/Dumper/FileDumperTest.php index 6e42b1e5683e5..9dd1377e49729 100644 --- a/src/Symfony/Component/Translation/Tests/Dumper/FileDumperTest.php +++ b/src/Symfony/Component/Translation/Tests/Dumper/FileDumperTest.php @@ -27,11 +27,15 @@ public function testDump() $dumper = new ConcreteFileDumper(); $dumper->dump($catalogue, ['path' => $tempDir]); - $this->assertFileExists($tempDir.'/messages.en.concrete'); + $suffix = class_exists(\MessageFormatter::class) ? '+intl-icu' : ''; + $this->assertFileExists($tempDir."/messages$suffix.en.concrete"); - @unlink($tempDir.'/messages.en.concrete'); + @unlink($tempDir."/messages$suffix.en.concrete"); } + /** + * @requires extension intl + */ public function testDumpIntl() { $tempDir = sys_get_temp_dir(); @@ -42,13 +46,11 @@ public function testDumpIntl() $catalogue->add(['bar' => 'foo'], 'd2+intl-icu'); $dumper = new ConcreteFileDumper(); - @unlink($tempDir.'/d2.en.concrete'); $dumper->dump($catalogue, ['path' => $tempDir]); - $this->assertStringEqualsFile($tempDir.'/d1.en.concrete', 'foo=bar'); - @unlink($tempDir.'/d1.en.concrete'); + $this->assertFileNotExists($tempDir.'/d1.en.concrete'); - $this->assertStringEqualsFile($tempDir.'/d1+intl-icu.en.concrete', 'bar=foo'); + $this->assertStringEqualsFile($tempDir.'/d1+intl-icu.en.concrete', 'bar=foo&foo=bar'); @unlink($tempDir.'/d1+intl-icu.en.concrete'); $this->assertFileNotExists($tempDir.'/d2.en.concrete'); @@ -60,7 +62,8 @@ public function testDumpCreatesNestedDirectoriesAndFile() { $tempDir = sys_get_temp_dir(); $translationsDir = $tempDir.'/test/translations'; - $file = $translationsDir.'/messages.en.concrete'; + $suffix = class_exists(\MessageFormatter::class) ? '+intl-icu' : ''; + $file = $translationsDir."/messages$suffix.en.concrete"; $catalogue = new MessageCatalogue('en'); $catalogue->add(['foo' => 'bar']); diff --git a/src/Symfony/Component/Validator/CHANGELOG.md b/src/Symfony/Component/Validator/CHANGELOG.md index 2706b6b6252b6..974bcbd36a2bc 100644 --- a/src/Symfony/Component/Validator/CHANGELOG.md +++ b/src/Symfony/Component/Validator/CHANGELOG.md @@ -21,19 +21,20 @@ CHANGELOG 4.4.0 ----- - * added `EnableAutoMapping` and `DisableAutoMapping` constraints to enable or disable auto mapping for class or a property + * [BC BREAK] using null as `$classValidatorRegexp` value in `PropertyInfoLoader::__construct` will not enable auto-mapping for all classes anymore, use `'{.*}'` instead. + * added `EnableAutoMapping` and `DisableAutoMapping` constraints to enable or disable auto mapping for class or a property * using anything else than a `string` as the code of a `ConstraintViolation` is deprecated, a `string` type-hint will be added to the constructor of the `ConstraintViolation` class and to the `ConstraintViolationBuilder::setCode()` method in 5.0 * deprecated passing an `ExpressionLanguage` instance as the second argument of `ExpressionValidator::__construct()`. Pass it as the first argument instead. - * added the `compared_value_path` parameter in violations when using any + * added the `compared_value_path` parameter in violations when using any comparison constraint with the `propertyPath` option. * added support for checking an array of types in `TypeValidator` * added a new `allowEmptyString` option to the `Length` constraint to allow rejecting empty strings when `min` is set, by setting it to `false`. * Added new `minPropertyPath` and `maxPropertyPath` options to `Range` constraint in order to get the value to compare from an array or object - * added the `min_limit_path` and `max_limit_path` parameters in violations when using + * added the `min_limit_path` and `max_limit_path` parameters in violations when using `Range` constraint with respectively the `minPropertyPath` and `maxPropertyPath` options * added a new `notInRangeMessage` option to the `Range` constraint that will diff --git a/src/Symfony/Component/Validator/ConstraintValidator.php b/src/Symfony/Component/Validator/ConstraintValidator.php index 5bcebb718117f..4d66776839bed 100644 --- a/src/Symfony/Component/Validator/ConstraintValidator.php +++ b/src/Symfony/Component/Validator/ConstraintValidator.php @@ -87,19 +87,12 @@ protected function formatValue($value, int $format = 0) { if (($format & self::PRETTY_DATE) && $value instanceof \DateTimeInterface) { if (class_exists('IntlDateFormatter')) { - $locale = \Locale::getDefault(); - $formatter = new \IntlDateFormatter($locale, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT, $value->getTimezone()); - - // neither the native nor the stub IntlDateFormatter support - // DateTimeImmutable as of yet - if (!$value instanceof \DateTime) { - $value = new \DateTime( - $value->format('Y-m-d H:i:s.u e'), - $value->getTimezone() - ); - } - - return $formatter->format($value); + $formatter = new \IntlDateFormatter(\Locale::getDefault(), \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT, 'UTC'); + + return $formatter->format(new \DateTime( + $value->format('Y-m-d H:i:s.u'), + new \DateTimeZone('UTC') + )); } return $value->format('Y-m-d H:i:s'); diff --git a/src/Symfony/Component/Validator/Constraints/AbstractComparisonValidator.php b/src/Symfony/Component/Validator/Constraints/AbstractComparisonValidator.php index dc268ebcb9e7d..a3897fcf86f14 100644 --- a/src/Symfony/Component/Validator/Constraints/AbstractComparisonValidator.php +++ b/src/Symfony/Component/Validator/Constraints/AbstractComparisonValidator.php @@ -40,7 +40,7 @@ public function __construct(PropertyAccessorInterface $propertyAccessor = null) public function validate($value, Constraint $constraint) { if (!$constraint instanceof AbstractComparison) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\AbstractComparison'); + throw new UnexpectedTypeException($constraint, AbstractComparison::class); } if (null === $value) { diff --git a/src/Symfony/Component/Validator/Constraints/AllValidator.php b/src/Symfony/Component/Validator/Constraints/AllValidator.php index 5bacdf8b95ff2..611ac8deae3e3 100644 --- a/src/Symfony/Component/Validator/Constraints/AllValidator.php +++ b/src/Symfony/Component/Validator/Constraints/AllValidator.php @@ -27,7 +27,7 @@ class AllValidator extends ConstraintValidator public function validate($value, Constraint $constraint) { if (!$constraint instanceof All) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\All'); + throw new UnexpectedTypeException($constraint, All::class); } if (null === $value) { diff --git a/src/Symfony/Component/Validator/Constraints/BicValidator.php b/src/Symfony/Component/Validator/Constraints/BicValidator.php index 3fd84e69f649d..94d345a23b739 100644 --- a/src/Symfony/Component/Validator/Constraints/BicValidator.php +++ b/src/Symfony/Component/Validator/Constraints/BicValidator.php @@ -61,7 +61,7 @@ public function __construct(PropertyAccessor $propertyAccessor = null) public function validate($value, Constraint $constraint) { if (!$constraint instanceof Bic) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Bic'); + throw new UnexpectedTypeException($constraint, Bic::class); } if (null === $value || '' === $value) { diff --git a/src/Symfony/Component/Validator/Constraints/BlankValidator.php b/src/Symfony/Component/Validator/Constraints/BlankValidator.php index ca999b5aa3961..3fd7fcc9fe1c6 100644 --- a/src/Symfony/Component/Validator/Constraints/BlankValidator.php +++ b/src/Symfony/Component/Validator/Constraints/BlankValidator.php @@ -26,7 +26,7 @@ class BlankValidator extends ConstraintValidator public function validate($value, Constraint $constraint) { if (!$constraint instanceof Blank) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Blank'); + throw new UnexpectedTypeException($constraint, Blank::class); } if ('' !== $value && null !== $value) { diff --git a/src/Symfony/Component/Validator/Constraints/CallbackValidator.php b/src/Symfony/Component/Validator/Constraints/CallbackValidator.php index b0ba21acb1776..9bb242f0de52e 100644 --- a/src/Symfony/Component/Validator/Constraints/CallbackValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CallbackValidator.php @@ -29,7 +29,7 @@ class CallbackValidator extends ConstraintValidator public function validate($object, Constraint $constraint) { if (!$constraint instanceof Callback) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Callback'); + throw new UnexpectedTypeException($constraint, Callback::class); } $method = $constraint->callback; diff --git a/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php b/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php index f62fb03997f28..478047fb8f272 100644 --- a/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php @@ -99,7 +99,7 @@ class CardSchemeValidator extends ConstraintValidator public function validate($value, Constraint $constraint) { if (!$constraint instanceof CardScheme) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\CardScheme'); + throw new UnexpectedTypeException($constraint, CardScheme::class); } if (null === $value || '' === $value) { diff --git a/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php b/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php index d1ef66eeda795..2cff8c8be61e9 100644 --- a/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php +++ b/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php @@ -32,7 +32,7 @@ class ChoiceValidator extends ConstraintValidator public function validate($value, Constraint $constraint) { if (!$constraint instanceof Choice) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Choice'); + throw new UnexpectedTypeException($constraint, Choice::class); } if (!\is_array($constraint->choices) && !$constraint->callback) { diff --git a/src/Symfony/Component/Validator/Constraints/CollectionValidator.php b/src/Symfony/Component/Validator/Constraints/CollectionValidator.php index cbc3e198a35bf..7cea7d01df963 100644 --- a/src/Symfony/Component/Validator/Constraints/CollectionValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CollectionValidator.php @@ -27,7 +27,7 @@ class CollectionValidator extends ConstraintValidator public function validate($value, Constraint $constraint) { if (!$constraint instanceof Collection) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Collection'); + throw new UnexpectedTypeException($constraint, Collection::class); } if (null === $value) { diff --git a/src/Symfony/Component/Validator/Constraints/CountValidator.php b/src/Symfony/Component/Validator/Constraints/CountValidator.php index 301358bcf714c..5c40e47b211de 100644 --- a/src/Symfony/Component/Validator/Constraints/CountValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CountValidator.php @@ -27,7 +27,7 @@ class CountValidator extends ConstraintValidator public function validate($value, Constraint $constraint) { if (!$constraint instanceof Count) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Count'); + throw new UnexpectedTypeException($constraint, Count::class); } if (null === $value) { diff --git a/src/Symfony/Component/Validator/Constraints/CountryValidator.php b/src/Symfony/Component/Validator/Constraints/CountryValidator.php index ca2867f09495e..acb966b270e0c 100644 --- a/src/Symfony/Component/Validator/Constraints/CountryValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CountryValidator.php @@ -30,7 +30,7 @@ class CountryValidator extends ConstraintValidator public function validate($value, Constraint $constraint) { if (!$constraint instanceof Country) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Country'); + throw new UnexpectedTypeException($constraint, Country::class); } if (null === $value || '' === $value) { diff --git a/src/Symfony/Component/Validator/Constraints/CurrencyValidator.php b/src/Symfony/Component/Validator/Constraints/CurrencyValidator.php index 3108f51443430..4f294e42bf7bc 100644 --- a/src/Symfony/Component/Validator/Constraints/CurrencyValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CurrencyValidator.php @@ -31,7 +31,7 @@ class CurrencyValidator extends ConstraintValidator public function validate($value, Constraint $constraint) { if (!$constraint instanceof Currency) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Currency'); + throw new UnexpectedTypeException($constraint, Currency::class); } if (null === $value || '' === $value) { diff --git a/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php b/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php index 73ff99c9dcb63..d76193aade926 100644 --- a/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php @@ -27,7 +27,7 @@ class DateTimeValidator extends DateValidator public function validate($value, Constraint $constraint) { if (!$constraint instanceof DateTime) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\DateTime'); + throw new UnexpectedTypeException($constraint, DateTime::class); } if (null === $value || '' === $value) { diff --git a/src/Symfony/Component/Validator/Constraints/DateValidator.php b/src/Symfony/Component/Validator/Constraints/DateValidator.php index 959082710390a..3f080d2313a35 100644 --- a/src/Symfony/Component/Validator/Constraints/DateValidator.php +++ b/src/Symfony/Component/Validator/Constraints/DateValidator.php @@ -39,7 +39,7 @@ public static function checkDate(int $year, int $month, int $day): bool public function validate($value, Constraint $constraint) { if (!$constraint instanceof Date) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Date'); + throw new UnexpectedTypeException($constraint, Date::class); } if (null === $value || '' === $value) { diff --git a/src/Symfony/Component/Validator/Constraints/EmailValidator.php b/src/Symfony/Component/Validator/Constraints/EmailValidator.php index 7a3a8807b9fad..37cfb715d71fe 100644 --- a/src/Symfony/Component/Validator/Constraints/EmailValidator.php +++ b/src/Symfony/Component/Validator/Constraints/EmailValidator.php @@ -48,7 +48,7 @@ public function __construct(string $defaultMode = Email::VALIDATION_MODE_LOOSE) public function validate($value, Constraint $constraint) { if (!$constraint instanceof Email) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Email'); + throw new UnexpectedTypeException($constraint, Email::class); } if (null === $value || '' === $value) { diff --git a/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php b/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php index db4d3ea8e5d8e..3ae47f48023d1 100644 --- a/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php +++ b/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php @@ -35,7 +35,7 @@ public function __construct(ExpressionLanguage $expressionLanguage = null) public function validate($value, Constraint $constraint) { if (!$constraint instanceof Expression) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Expression'); + throw new UnexpectedTypeException($constraint, Expression::class); } $variables = $constraint->values; diff --git a/src/Symfony/Component/Validator/Constraints/FileValidator.php b/src/Symfony/Component/Validator/Constraints/FileValidator.php index cc53680dcd7ae..52e937944188b 100644 --- a/src/Symfony/Component/Validator/Constraints/FileValidator.php +++ b/src/Symfony/Component/Validator/Constraints/FileValidator.php @@ -42,7 +42,7 @@ class FileValidator extends ConstraintValidator public function validate($value, Constraint $constraint) { if (!$constraint instanceof File) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\File'); + throw new UnexpectedTypeException($constraint, File::class); } if (null === $value || '' === $value) { diff --git a/src/Symfony/Component/Validator/Constraints/GreaterThanOrEqualValidator.php b/src/Symfony/Component/Validator/Constraints/GreaterThanOrEqualValidator.php index e196e688f3476..290408ac0cc3f 100644 --- a/src/Symfony/Component/Validator/Constraints/GreaterThanOrEqualValidator.php +++ b/src/Symfony/Component/Validator/Constraints/GreaterThanOrEqualValidator.php @@ -24,7 +24,7 @@ class GreaterThanOrEqualValidator extends AbstractComparisonValidator */ protected function compareValues($value1, $value2) { - return $value1 >= $value2; + return null === $value2 || $value1 >= $value2; } /** diff --git a/src/Symfony/Component/Validator/Constraints/GreaterThanValidator.php b/src/Symfony/Component/Validator/Constraints/GreaterThanValidator.php index 9029e8fc46a80..062503ab3f426 100644 --- a/src/Symfony/Component/Validator/Constraints/GreaterThanValidator.php +++ b/src/Symfony/Component/Validator/Constraints/GreaterThanValidator.php @@ -24,7 +24,7 @@ class GreaterThanValidator extends AbstractComparisonValidator */ protected function compareValues($value1, $value2) { - return $value1 > $value2; + return null === $value2 || $value1 > $value2; } /** diff --git a/src/Symfony/Component/Validator/Constraints/IbanValidator.php b/src/Symfony/Component/Validator/Constraints/IbanValidator.php index 95fed46a77721..27194ded21cb9 100644 --- a/src/Symfony/Component/Validator/Constraints/IbanValidator.php +++ b/src/Symfony/Component/Validator/Constraints/IbanValidator.php @@ -143,7 +143,7 @@ class IbanValidator extends ConstraintValidator public function validate($value, Constraint $constraint) { if (!$constraint instanceof Iban) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Iban'); + throw new UnexpectedTypeException($constraint, Iban::class); } if (null === $value || '' === $value) { diff --git a/src/Symfony/Component/Validator/Constraints/ImageValidator.php b/src/Symfony/Component/Validator/Constraints/ImageValidator.php index d41054c28bbfb..7e7df8129aac2 100644 --- a/src/Symfony/Component/Validator/Constraints/ImageValidator.php +++ b/src/Symfony/Component/Validator/Constraints/ImageValidator.php @@ -31,7 +31,7 @@ class ImageValidator extends FileValidator public function validate($value, Constraint $constraint) { if (!$constraint instanceof Image) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Image'); + throw new UnexpectedTypeException($constraint, Image::class); } $violations = \count($this->context->getViolations()); diff --git a/src/Symfony/Component/Validator/Constraints/IpValidator.php b/src/Symfony/Component/Validator/Constraints/IpValidator.php index 0f7d383587189..f965a31d4b9c1 100644 --- a/src/Symfony/Component/Validator/Constraints/IpValidator.php +++ b/src/Symfony/Component/Validator/Constraints/IpValidator.php @@ -30,7 +30,7 @@ class IpValidator extends ConstraintValidator public function validate($value, Constraint $constraint) { if (!$constraint instanceof Ip) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Ip'); + throw new UnexpectedTypeException($constraint, Ip::class); } if (null === $value || '' === $value) { diff --git a/src/Symfony/Component/Validator/Constraints/IsFalseValidator.php b/src/Symfony/Component/Validator/Constraints/IsFalseValidator.php index 95245fb97bd9d..79c42348fec68 100644 --- a/src/Symfony/Component/Validator/Constraints/IsFalseValidator.php +++ b/src/Symfony/Component/Validator/Constraints/IsFalseValidator.php @@ -26,7 +26,7 @@ class IsFalseValidator extends ConstraintValidator public function validate($value, Constraint $constraint) { if (!$constraint instanceof IsFalse) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\IsFalse'); + throw new UnexpectedTypeException($constraint, IsFalse::class); } if (null === $value || false === $value || 0 === $value || '0' === $value) { diff --git a/src/Symfony/Component/Validator/Constraints/IsNullValidator.php b/src/Symfony/Component/Validator/Constraints/IsNullValidator.php index 01b9d1e40a05e..b6e78170f92de 100644 --- a/src/Symfony/Component/Validator/Constraints/IsNullValidator.php +++ b/src/Symfony/Component/Validator/Constraints/IsNullValidator.php @@ -26,7 +26,7 @@ class IsNullValidator extends ConstraintValidator public function validate($value, Constraint $constraint) { if (!$constraint instanceof IsNull) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\IsNull'); + throw new UnexpectedTypeException($constraint, IsNull::class); } if (null !== $value) { diff --git a/src/Symfony/Component/Validator/Constraints/IsTrueValidator.php b/src/Symfony/Component/Validator/Constraints/IsTrueValidator.php index 89aa337d2c054..6088f6d7a7a64 100644 --- a/src/Symfony/Component/Validator/Constraints/IsTrueValidator.php +++ b/src/Symfony/Component/Validator/Constraints/IsTrueValidator.php @@ -26,7 +26,7 @@ class IsTrueValidator extends ConstraintValidator public function validate($value, Constraint $constraint) { if (!$constraint instanceof IsTrue) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\IsTrue'); + throw new UnexpectedTypeException($constraint, IsTrue::class); } if (null === $value) { diff --git a/src/Symfony/Component/Validator/Constraints/IsbnValidator.php b/src/Symfony/Component/Validator/Constraints/IsbnValidator.php index 53687ddc80477..5b59f3c7a8251 100644 --- a/src/Symfony/Component/Validator/Constraints/IsbnValidator.php +++ b/src/Symfony/Component/Validator/Constraints/IsbnValidator.php @@ -33,7 +33,7 @@ class IsbnValidator extends ConstraintValidator public function validate($value, Constraint $constraint) { if (!$constraint instanceof Isbn) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Isbn'); + throw new UnexpectedTypeException($constraint, Isbn::class); } if (null === $value || '' === $value) { diff --git a/src/Symfony/Component/Validator/Constraints/IssnValidator.php b/src/Symfony/Component/Validator/Constraints/IssnValidator.php index 21b6403494c3b..8766b077ba3b7 100644 --- a/src/Symfony/Component/Validator/Constraints/IssnValidator.php +++ b/src/Symfony/Component/Validator/Constraints/IssnValidator.php @@ -32,7 +32,7 @@ class IssnValidator extends ConstraintValidator public function validate($value, Constraint $constraint) { if (!$constraint instanceof Issn) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Issn'); + throw new UnexpectedTypeException($constraint, Issn::class); } if (null === $value || '' === $value) { diff --git a/src/Symfony/Component/Validator/Constraints/LanguageValidator.php b/src/Symfony/Component/Validator/Constraints/LanguageValidator.php index 96c36985a8953..54cd07da1886d 100644 --- a/src/Symfony/Component/Validator/Constraints/LanguageValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LanguageValidator.php @@ -30,7 +30,7 @@ class LanguageValidator extends ConstraintValidator public function validate($value, Constraint $constraint) { if (!$constraint instanceof Language) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Language'); + throw new UnexpectedTypeException($constraint, Language::class); } if (null === $value || '' === $value) { diff --git a/src/Symfony/Component/Validator/Constraints/LengthValidator.php b/src/Symfony/Component/Validator/Constraints/LengthValidator.php index b1b5d7c7700ee..479d23cec62c3 100644 --- a/src/Symfony/Component/Validator/Constraints/LengthValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LengthValidator.php @@ -27,7 +27,7 @@ class LengthValidator extends ConstraintValidator public function validate($value, Constraint $constraint) { if (!$constraint instanceof Length) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Length'); + throw new UnexpectedTypeException($constraint, Length::class); } if (null === $value || ('' === $value && $constraint->allowEmptyString)) { diff --git a/src/Symfony/Component/Validator/Constraints/LessThanOrEqualValidator.php b/src/Symfony/Component/Validator/Constraints/LessThanOrEqualValidator.php index 54281eef5a673..f7f4c8be5f326 100644 --- a/src/Symfony/Component/Validator/Constraints/LessThanOrEqualValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LessThanOrEqualValidator.php @@ -24,7 +24,7 @@ class LessThanOrEqualValidator extends AbstractComparisonValidator */ protected function compareValues($value1, $value2) { - return $value1 <= $value2; + return null === $value2 || $value1 <= $value2; } /** diff --git a/src/Symfony/Component/Validator/Constraints/LessThanValidator.php b/src/Symfony/Component/Validator/Constraints/LessThanValidator.php index ef7535fc99143..64e107547ac83 100644 --- a/src/Symfony/Component/Validator/Constraints/LessThanValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LessThanValidator.php @@ -24,7 +24,7 @@ class LessThanValidator extends AbstractComparisonValidator */ protected function compareValues($value1, $value2) { - return $value1 < $value2; + return null === $value2 || $value1 < $value2; } /** diff --git a/src/Symfony/Component/Validator/Constraints/LocaleValidator.php b/src/Symfony/Component/Validator/Constraints/LocaleValidator.php index 760131279a4ff..860273d4f7e35 100644 --- a/src/Symfony/Component/Validator/Constraints/LocaleValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LocaleValidator.php @@ -30,7 +30,7 @@ class LocaleValidator extends ConstraintValidator public function validate($value, Constraint $constraint) { if (!$constraint instanceof Locale) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Locale'); + throw new UnexpectedTypeException($constraint, Locale::class); } if (null === $value || '' === $value) { diff --git a/src/Symfony/Component/Validator/Constraints/LuhnValidator.php b/src/Symfony/Component/Validator/Constraints/LuhnValidator.php index 888e29cb7f10c..0f568fa6e4958 100644 --- a/src/Symfony/Component/Validator/Constraints/LuhnValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LuhnValidator.php @@ -40,7 +40,7 @@ class LuhnValidator extends ConstraintValidator public function validate($value, Constraint $constraint) { if (!$constraint instanceof Luhn) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Luhn'); + throw new UnexpectedTypeException($constraint, Luhn::class); } if (null === $value || '' === $value) { diff --git a/src/Symfony/Component/Validator/Constraints/NotBlankValidator.php b/src/Symfony/Component/Validator/Constraints/NotBlankValidator.php index d358cc90f0410..86af06123d76c 100644 --- a/src/Symfony/Component/Validator/Constraints/NotBlankValidator.php +++ b/src/Symfony/Component/Validator/Constraints/NotBlankValidator.php @@ -27,7 +27,7 @@ class NotBlankValidator extends ConstraintValidator public function validate($value, Constraint $constraint) { if (!$constraint instanceof NotBlank) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\NotBlank'); + throw new UnexpectedTypeException($constraint, NotBlank::class); } if ($constraint->allowNull && null === $value) { diff --git a/src/Symfony/Component/Validator/Constraints/NotNullValidator.php b/src/Symfony/Component/Validator/Constraints/NotNullValidator.php index d6f620713e6a6..d02fcc43988a6 100644 --- a/src/Symfony/Component/Validator/Constraints/NotNullValidator.php +++ b/src/Symfony/Component/Validator/Constraints/NotNullValidator.php @@ -26,7 +26,7 @@ class NotNullValidator extends ConstraintValidator public function validate($value, Constraint $constraint) { if (!$constraint instanceof NotNull) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\NotNull'); + throw new UnexpectedTypeException($constraint, NotNull::class); } if (null === $value) { diff --git a/src/Symfony/Component/Validator/Constraints/RangeValidator.php b/src/Symfony/Component/Validator/Constraints/RangeValidator.php index 44f54a63c0d10..e976ff30a76ac 100644 --- a/src/Symfony/Component/Validator/Constraints/RangeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/RangeValidator.php @@ -37,7 +37,7 @@ public function __construct(PropertyAccessorInterface $propertyAccessor = null) public function validate($value, Constraint $constraint) { if (!$constraint instanceof Range) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Range'); + throw new UnexpectedTypeException($constraint, Range::class); } if (null === $value) { diff --git a/src/Symfony/Component/Validator/Constraints/RegexValidator.php b/src/Symfony/Component/Validator/Constraints/RegexValidator.php index 5b8be6ec1d2b1..7fadf7682b056 100644 --- a/src/Symfony/Component/Validator/Constraints/RegexValidator.php +++ b/src/Symfony/Component/Validator/Constraints/RegexValidator.php @@ -30,7 +30,7 @@ class RegexValidator extends ConstraintValidator public function validate($value, Constraint $constraint) { if (!$constraint instanceof Regex) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Regex'); + throw new UnexpectedTypeException($constraint, Regex::class); } if (null === $value || '' === $value) { diff --git a/src/Symfony/Component/Validator/Constraints/TimeValidator.php b/src/Symfony/Component/Validator/Constraints/TimeValidator.php index 6b7466e4ba0e1..c99b235412e30 100644 --- a/src/Symfony/Component/Validator/Constraints/TimeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/TimeValidator.php @@ -39,7 +39,7 @@ public static function checkTime(int $hour, int $minute, float $second): bool public function validate($value, Constraint $constraint) { if (!$constraint instanceof Time) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Time'); + throw new UnexpectedTypeException($constraint, Time::class); } if (null === $value || '' === $value) { diff --git a/src/Symfony/Component/Validator/Constraints/TypeValidator.php b/src/Symfony/Component/Validator/Constraints/TypeValidator.php index ebcf50165e14d..99f3d9c630458 100644 --- a/src/Symfony/Component/Validator/Constraints/TypeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/TypeValidator.php @@ -26,7 +26,7 @@ class TypeValidator extends ConstraintValidator public function validate($value, Constraint $constraint) { if (!$constraint instanceof Type) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Type'); + throw new UnexpectedTypeException($constraint, Type::class); } if (null === $value) { diff --git a/src/Symfony/Component/Validator/Constraints/UrlValidator.php b/src/Symfony/Component/Validator/Constraints/UrlValidator.php index ad75ce59de483..77c39e5f5ec40 100644 --- a/src/Symfony/Component/Validator/Constraints/UrlValidator.php +++ b/src/Symfony/Component/Validator/Constraints/UrlValidator.php @@ -23,7 +23,7 @@ class UrlValidator extends ConstraintValidator { const PATTERN = '~^ (%s):// # protocol - (([\.\pL\pN-]+:)?([\.\pL\pN-]+)@)? # basic auth + (([\_\.\pL\pN-]+:)?([\_\.\pL\pN-]+)@)? # basic auth ( ([\pL\pN\pS\-\_\.])+(\.?([\pL\pN]|xn\-\-[\pL\pN-]+)+\.?) # a domain name | # or @@ -45,7 +45,7 @@ class UrlValidator extends ConstraintValidator public function validate($value, Constraint $constraint) { if (!$constraint instanceof Url) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Url'); + throw new UnexpectedTypeException($constraint, Url::class); } if (null === $value || '' === $value) { diff --git a/src/Symfony/Component/Validator/Constraints/UuidValidator.php b/src/Symfony/Component/Validator/Constraints/UuidValidator.php index 0e11e9ea28bba..49bdf8765aa2f 100644 --- a/src/Symfony/Component/Validator/Constraints/UuidValidator.php +++ b/src/Symfony/Component/Validator/Constraints/UuidValidator.php @@ -68,7 +68,7 @@ class UuidValidator extends ConstraintValidator public function validate($value, Constraint $constraint) { if (!$constraint instanceof Uuid) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Uuid'); + throw new UnexpectedTypeException($constraint, Uuid::class); } if (null === $value || '' === $value) { diff --git a/src/Symfony/Component/Validator/Constraints/ValidValidator.php b/src/Symfony/Component/Validator/Constraints/ValidValidator.php index 695ec822540ed..85eabb80ae8e2 100644 --- a/src/Symfony/Component/Validator/Constraints/ValidValidator.php +++ b/src/Symfony/Component/Validator/Constraints/ValidValidator.php @@ -23,7 +23,7 @@ class ValidValidator extends ConstraintValidator public function validate($value, Constraint $constraint) { if (!$constraint instanceof Valid) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Valid'); + throw new UnexpectedTypeException($constraint, Valid::class); } if (null === $value) { diff --git a/src/Symfony/Component/Validator/DependencyInjection/AddAutoMappingConfigurationPass.php b/src/Symfony/Component/Validator/DependencyInjection/AddAutoMappingConfigurationPass.php index f28b78650ca0e..ed4b18aab5be9 100644 --- a/src/Symfony/Component/Validator/DependencyInjection/AddAutoMappingConfigurationPass.php +++ b/src/Symfony/Component/Validator/DependencyInjection/AddAutoMappingConfigurationPass.php @@ -59,13 +59,8 @@ public function process(ContainerBuilder $container) $validatorBuilder = $container->getDefinition($this->validatorBuilderService); foreach ($container->findTaggedServiceIds($this->tag) as $id => $tags) { $regexp = $this->getRegexp(array_merge($globalNamespaces, $servicesToNamespaces[$id] ?? [])); - if (null === $regexp) { - $container->removeDefinition($id); - continue; - } - - $container->getDefinition($id)->setArgument('$classValidatorRegexp', $regexp); $validatorBuilder->addMethodCall('addLoader', [new Reference($id)]); + $container->getDefinition($id)->setArgument('$classValidatorRegexp', $regexp); } $container->getParameterBag()->remove('validator.auto_mapping'); diff --git a/src/Symfony/Component/Validator/Mapping/AutoMappingStrategy.php b/src/Symfony/Component/Validator/Mapping/AutoMappingStrategy.php new file mode 100644 index 0000000000000..4012ddcff9c05 --- /dev/null +++ b/src/Symfony/Component/Validator/Mapping/AutoMappingStrategy.php @@ -0,0 +1,42 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Validator\Mapping; + +/** + * Specifies how the auto-mapping feature should behave. + * + * @author Maxime Steinhausser + */ +final class AutoMappingStrategy +{ + /** + * Nothing explicitly set, rely on auto-mapping configured regex. + */ + public const NONE = 0; + + /** + * Explicitly enabled. + */ + public const ENABLED = 1; + + /** + * Explicitly disabled. + */ + public const DISABLED = 2; + + /** + * Not instantiable. + */ + private function __construct() + { + } +} diff --git a/src/Symfony/Component/Validator/Mapping/GenericMetadata.php b/src/Symfony/Component/Validator/Mapping/GenericMetadata.php index 5a619abe5908b..6243d9618e9af 100644 --- a/src/Symfony/Component/Validator/Mapping/GenericMetadata.php +++ b/src/Symfony/Component/Validator/Mapping/GenericMetadata.php @@ -12,6 +12,8 @@ namespace Symfony\Component\Validator\Mapping; use Symfony\Component\Validator\Constraint; +use Symfony\Component\Validator\Constraints\DisableAutoMapping; +use Symfony\Component\Validator\Constraints\EnableAutoMapping; use Symfony\Component\Validator\Constraints\Traverse; use Symfony\Component\Validator\Constraints\Valid; use Symfony\Component\Validator\Exception\ConstraintDefinitionException; @@ -73,6 +75,19 @@ class GenericMetadata implements MetadataInterface */ public $traversalStrategy = TraversalStrategy::NONE; + /** + * Is auto-mapping enabled? + * + * @var int + * + * @see AutoMappingStrategy + * + * @internal This property is public in order to reduce the size of the + * class' serialized representation. Do not access it. Use + * {@link getAutoMappingStrategy()} instead. + */ + public $autoMappingStrategy = AutoMappingStrategy::NONE; + /** * Returns the names of the properties that should be serialized. * @@ -85,6 +100,7 @@ public function __sleep() 'constraintsByGroup', 'cascadingStrategy', 'traversalStrategy', + 'autoMappingStrategy', ]; } @@ -137,6 +153,13 @@ public function addConstraint(Constraint $constraint) return $this; } + if ($constraint instanceof DisableAutoMapping || $constraint instanceof EnableAutoMapping) { + $this->autoMappingStrategy = $constraint instanceof EnableAutoMapping ? AutoMappingStrategy::ENABLED : AutoMappingStrategy::DISABLED; + + // The constraint is not added + return $this; + } + $this->constraints[] = $constraint; foreach ($constraint->groups as $group) { @@ -205,4 +228,12 @@ public function getTraversalStrategy() { return $this->traversalStrategy; } + + /** + * @see AutoMappingStrategy + */ + public function getAutoMappingStrategy(): int + { + return $this->autoMappingStrategy; + } } diff --git a/src/Symfony/Component/Validator/Mapping/Loader/AutoMappingTrait.php b/src/Symfony/Component/Validator/Mapping/Loader/AutoMappingTrait.php index 1c21810763557..f76442f06c05e 100644 --- a/src/Symfony/Component/Validator/Mapping/Loader/AutoMappingTrait.php +++ b/src/Symfony/Component/Validator/Mapping/Loader/AutoMappingTrait.php @@ -11,8 +11,7 @@ namespace Symfony\Component\Validator\Mapping\Loader; -use Symfony\Component\Validator\Constraints\DisableAutoMapping; -use Symfony\Component\Validator\Constraints\EnableAutoMapping; +use Symfony\Component\Validator\Mapping\AutoMappingStrategy; use Symfony\Component\Validator\Mapping\ClassMetadata; /** @@ -25,17 +24,11 @@ trait AutoMappingTrait private function isAutoMappingEnabledForClass(ClassMetadata $metadata, string $classValidatorRegexp = null): bool { // Check if AutoMapping constraint is set first - foreach ($metadata->getConstraints() as $constraint) { - if ($constraint instanceof DisableAutoMapping) { - return false; - } - - if ($constraint instanceof EnableAutoMapping) { - return true; - } + if (AutoMappingStrategy::NONE !== $strategy = $metadata->getAutoMappingStrategy()) { + return AutoMappingStrategy::ENABLED === $strategy; } // Fallback on the config - return null === $classValidatorRegexp || preg_match($classValidatorRegexp, $metadata->getClassName()); + return null !== $classValidatorRegexp && preg_match($classValidatorRegexp, $metadata->getClassName()); } } diff --git a/src/Symfony/Component/Validator/Mapping/Loader/PropertyInfoLoader.php b/src/Symfony/Component/Validator/Mapping/Loader/PropertyInfoLoader.php index e2ad9cb9ec9e5..530348c638448 100644 --- a/src/Symfony/Component/Validator/Mapping/Loader/PropertyInfoLoader.php +++ b/src/Symfony/Component/Validator/Mapping/Loader/PropertyInfoLoader.php @@ -16,11 +16,10 @@ use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface; use Symfony\Component\PropertyInfo\Type as PropertyInfoType; use Symfony\Component\Validator\Constraints\All; -use Symfony\Component\Validator\Constraints\DisableAutoMapping; -use Symfony\Component\Validator\Constraints\EnableAutoMapping; use Symfony\Component\Validator\Constraints\NotBlank; use Symfony\Component\Validator\Constraints\NotNull; use Symfony\Component\Validator\Constraints\Type; +use Symfony\Component\Validator\Mapping\AutoMappingStrategy; use Symfony\Component\Validator\Mapping\ClassMetadata; /** @@ -77,16 +76,16 @@ public function loadClassMetadata(ClassMetadata $metadata): bool $hasNotBlankConstraint = false; $allConstraint = null; foreach ($metadata->getPropertyMetadata($property) as $propertyMetadata) { - foreach ($propertyMetadata->getConstraints() as $constraint) { - // Enabling or disabling auto-mapping explicitly always takes precedence - if ($constraint instanceof DisableAutoMapping) { - continue 3; - } + // Enabling or disabling auto-mapping explicitly always takes precedence + if (AutoMappingStrategy::DISABLED === $propertyMetadata->getAutoMappingStrategy()) { + continue 2; + } - if ($constraint instanceof EnableAutoMapping) { - $enabledForProperty = true; - } + if (AutoMappingStrategy::ENABLED === $propertyMetadata->getAutoMappingStrategy()) { + $enabledForProperty = true; + } + foreach ($propertyMetadata->getConstraints() as $constraint) { if ($constraint instanceof Type) { $hasTypeConstraint = true; } elseif ($constraint instanceof NotNull) { diff --git a/src/Symfony/Component/Validator/Tests/ConstraintValidatorTest.php b/src/Symfony/Component/Validator/Tests/ConstraintValidatorTest.php index 96af6f13eb4e7..6ca3eab41fd6e 100644 --- a/src/Symfony/Component/Validator/Tests/ConstraintValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/ConstraintValidatorTest.php @@ -27,6 +27,9 @@ public function testFormatValue($expected, $value, $format = 0) public function formatValueProvider() { + $defaultTimezone = date_default_timezone_get(); + date_default_timezone_set('Europe/Moscow'); // GMT+3 + $data = [ ['true', true], ['false', false], @@ -36,10 +39,15 @@ public function formatValueProvider() ['array', []], ['object', $toString = new TestToStringObject()], ['ccc', $toString, ConstraintValidator::OBJECT_TO_STRING], - ['object', $dateTime = (new \DateTimeImmutable('@0'))->setTimezone(new \DateTimeZone('UTC'))], - [class_exists(\IntlDateFormatter::class) ? 'Jan 1, 1970, 12:00 AM' : '1970-01-01 00:00:00', $dateTime, ConstraintValidator::PRETTY_DATE], + ['object', $dateTime = new \DateTimeImmutable('1971-02-02T08:00:00UTC')], + [class_exists(\IntlDateFormatter::class) ? 'Oct 4, 2019, 11:02 AM' : '2019-10-04 11:02:03', new \DateTimeImmutable('2019-10-04T11:02:03+09:00'), ConstraintValidator::PRETTY_DATE], + [class_exists(\IntlDateFormatter::class) ? 'Feb 2, 1971, 8:00 AM' : '1971-02-02 08:00:00', $dateTime, ConstraintValidator::PRETTY_DATE], + [class_exists(\IntlDateFormatter::class) ? 'Jan 1, 1970, 6:00 AM' : '1970-01-01 06:00:00', new \DateTimeImmutable('1970-01-01T06:00:00Z'), ConstraintValidator::PRETTY_DATE], + [class_exists(\IntlDateFormatter::class) ? 'Jan 1, 1970, 3:00 PM' : '1970-01-01 15:00:00', (new \DateTimeImmutable('1970-01-01T23:00:00'))->setTimezone(new \DateTimeZone('America/New_York')), ConstraintValidator::PRETTY_DATE], ]; + date_default_timezone_set($defaultTimezone); + return $data; } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php b/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php index 51ea8aecd522e..2e6c47a48cb59 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php @@ -53,10 +53,7 @@ protected static function addPhp5Dot5Comparisons(array $comparisons) foreach ($comparison as $i => $value) { if ($value instanceof \DateTime) { - $comparison[$i] = new \DateTimeImmutable( - $value->format('Y-m-d H:i:s.u e'), - $value->getTimezone() - ); + $comparison[$i] = new \DateTimeImmutable($value->format('Y-m-d H:i:s.u e')); $add = true; } elseif ('DateTime' === $value) { $comparison[$i] = 'DateTimeImmutable'; @@ -250,6 +247,32 @@ public function throwsOnInvalidStringDatesProvider(): array ]; } + /** + * @dataProvider provideComparisonsToNullValueAtPropertyPath + */ + public function testCompareWithNullValueAtPropertyAt($dirtyValue, $dirtyValueAsString, $isValid) + { + $constraint = $this->createConstraint(['propertyPath' => 'value']); + $constraint->message = 'Constraint Message'; + + $object = new ComparisonTest_Class(null); + $this->setObject($object); + + $this->validator->validate($dirtyValue, $constraint); + + if ($isValid) { + $this->assertNoViolation(); + } else { + $this->buildViolation('Constraint Message') + ->setParameter('{{ value }}', $dirtyValueAsString) + ->setParameter('{{ compared_value }}', 'null') + ->setParameter('{{ compared_value_type }}', 'NULL') + ->setParameter('{{ compared_value_path }}', 'value') + ->setCode($this->getErrorCode()) + ->assertRaised(); + } + } + public function provideAllInvalidComparisons(): array { // The provider runs before setUp(), so we need to manually fix @@ -265,6 +288,8 @@ public function provideAllInvalidComparisons(): array abstract public function provideInvalidComparisons(): array; + abstract public function provideComparisonsToNullValueAtPropertyPath(); + /** * @param array|null $options Options for the constraint */ diff --git a/src/Symfony/Component/Validator/Tests/Constraints/DivisibleByValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/DivisibleByValidatorTest.php index 25187bafc89dc..f892dc93a17ac 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/DivisibleByValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/DivisibleByValidatorTest.php @@ -98,4 +98,9 @@ public function throwsOnNonNumericValuesProvider() [\ArrayIterator::class, new \ArrayIterator(), 12], ]; } + + public function provideComparisonsToNullValueAtPropertyPath() + { + $this->markTestSkipped('DivisibleByValidator rejects null values.'); + } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/EqualToValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/EqualToValidatorTest.php index 6253b3c384224..70832fc04b136 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/EqualToValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/EqualToValidatorTest.php @@ -76,4 +76,11 @@ public function provideInvalidComparisons(): array [new ComparisonTest_Class(4), '4', new ComparisonTest_Class(5), '5', __NAMESPACE__.'\ComparisonTest_Class'], ]; } + + public function provideComparisonsToNullValueAtPropertyPath() + { + return [ + [5, '5', false], + ]; + } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanOrEqualValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanOrEqualValidatorTest.php index 8cbfc269e2c93..44924c2767674 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanOrEqualValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanOrEqualValidatorTest.php @@ -79,4 +79,11 @@ public function provideInvalidComparisons(): array ['b', '"b"', 'c', '"c"', 'string'], ]; } + + public function provideComparisonsToNullValueAtPropertyPath() + { + return [ + [5, '5', true], + ]; + } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanValidatorTest.php index 8259d3a9bd62d..eef12d5570bd1 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanValidatorTest.php @@ -81,4 +81,11 @@ public function provideInvalidComparisons(): array ['22', '"22"', '22', '"22"', 'string'], ]; } + + public function provideComparisonsToNullValueAtPropertyPath() + { + return [ + [5, '5', true], + ]; + } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/IdenticalToValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/IdenticalToValidatorTest.php index edcaac3589235..e7856a8b99af2 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/IdenticalToValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/IdenticalToValidatorTest.php @@ -94,4 +94,11 @@ public function provideInvalidComparisons(): array [new ComparisonTest_Class(4), '4', new ComparisonTest_Class(5), '5', __NAMESPACE__.'\ComparisonTest_Class'], ]; } + + public function provideComparisonsToNullValueAtPropertyPath() + { + return [ + [5, '5', false], + ]; + } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LessThanOrEqualValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LessThanOrEqualValidatorTest.php index 625b996931d5d..ab05e3ca64c02 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LessThanOrEqualValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LessThanOrEqualValidatorTest.php @@ -82,4 +82,11 @@ public function provideInvalidComparisons(): array ['c', '"c"', 'b', '"b"', 'string'], ]; } + + public function provideComparisonsToNullValueAtPropertyPath() + { + return [ + [5, '5', true], + ]; + } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LessThanOrEqualValidatorWithNegativeOrZeroConstraintTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LessThanOrEqualValidatorWithNegativeOrZeroConstraintTest.php index 9e098191207ce..5e4fff253b4df 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LessThanOrEqualValidatorWithNegativeOrZeroConstraintTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LessThanOrEqualValidatorWithNegativeOrZeroConstraintTest.php @@ -110,6 +110,14 @@ public function testThrowsOnInvalidStringDates(AbstractComparison $constraint, $ $this->markTestSkipped('The compared value cannot be an invalid string date because it is hardcoded to 0.'); } + /** + * @dataProvider provideComparisonsToNullValueAtPropertyPath + */ + public function testCompareWithNullValueAtPropertyAt($dirtyValue, $dirtyValueAsString, $isValid) + { + $this->markTestSkipped('PropertyPath option is not used in NegativeOrZero constraint'); + } + public function testInvalidComparisonToPropertyPathAddsPathAsParameter() { $this->markTestSkipped('PropertyPath option is not used in NegativeOrZero constraint'); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LessThanValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LessThanValidatorTest.php index 747a7dcd79d2f..d8aaa99a982c9 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LessThanValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LessThanValidatorTest.php @@ -80,4 +80,11 @@ public function provideInvalidComparisons(): array ['333', '"333"', '22', '"22"', 'string'], ]; } + + public function provideComparisonsToNullValueAtPropertyPath() + { + return [ + [5, '5', true], + ]; + } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LessThanValidatorWithNegativeConstraintTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LessThanValidatorWithNegativeConstraintTest.php index 9150beb07a082..642bd8341f294 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LessThanValidatorWithNegativeConstraintTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LessThanValidatorWithNegativeConstraintTest.php @@ -110,6 +110,14 @@ public function testThrowsOnInvalidStringDates(AbstractComparison $constraint, $ $this->markTestSkipped('The compared value cannot be an invalid string date because it is hardcoded to 0.'); } + /** + * @dataProvider provideComparisonsToNullValueAtPropertyPath + */ + public function testCompareWithNullValueAtPropertyAt($dirtyValue, $dirtyValueAsString, $isValid) + { + $this->markTestSkipped('PropertyPath option is not used in Negative constraint'); + } + public function testInvalidComparisonToPropertyPathAddsPathAsParameter() { $this->markTestSkipped('PropertyPath option is not used in Negative constraint'); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NotEqualToValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NotEqualToValidatorTest.php index e92d22d664aa4..22f9b3b1107d3 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/NotEqualToValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/NotEqualToValidatorTest.php @@ -76,4 +76,11 @@ public function provideInvalidComparisons(): array [new ComparisonTest_Class(5), '5', new ComparisonTest_Class(5), '5', __NAMESPACE__.'\ComparisonTest_Class'], ]; } + + public function provideComparisonsToNullValueAtPropertyPath() + { + return [ + [5, '5', true], + ]; + } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NotIdenticalToValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NotIdenticalToValidatorTest.php index 93befafe85735..8a36828f1eff0 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/NotIdenticalToValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/NotIdenticalToValidatorTest.php @@ -94,4 +94,11 @@ public function provideInvalidComparisons(): array return $comparisons; } + + public function provideComparisonsToNullValueAtPropertyPath() + { + return [ + [5, '5', true], + ]; + } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php index 2dcb1f5c55899..818ae19dfc905 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php @@ -148,9 +148,11 @@ public function getValidUrls() ['http://☎.com/'], ['http://username:password@symfony.com'], ['http://user.name:password@symfony.com'], + ['http://user_name:pass_word@symfony.com'], ['http://username:pass.word@symfony.com'], ['http://user.name:pass.word@symfony.com'], ['http://user-name@symfony.com'], + ['http://user_name@symfony.com'], ['http://symfony.com?'], ['http://symfony.com?query=1'], ['http://symfony.com/?query=1'], diff --git a/src/Symfony/Component/Validator/Tests/DependencyInjection/AddAutoMappingConfigurationPassTest.php b/src/Symfony/Component/Validator/Tests/DependencyInjection/AddAutoMappingConfigurationPassTest.php index 711bf8fc4f610..4571436c12f73 100644 --- a/src/Symfony/Component/Validator/Tests/DependencyInjection/AddAutoMappingConfigurationPassTest.php +++ b/src/Symfony/Component/Validator/Tests/DependencyInjection/AddAutoMappingConfigurationPassTest.php @@ -81,6 +81,6 @@ public function testDoNotMapAllClassesWhenConfigIsEmpty() (new AddAutoMappingConfigurationPass())->process($container); - $this->assertFalse($container->hasDefinition('loader')); + $this->assertNull($container->getDefinition('loader')->getArguments()['$classValidatorRegexp'] ?? null); } } diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Loader/PropertyInfoLoaderTest.php b/src/Symfony/Component/Validator/Tests/Mapping/Loader/PropertyInfoLoaderTest.php index 8e122dcdd872e..9ae66ca980747 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/Loader/PropertyInfoLoaderTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/Loader/PropertyInfoLoaderTest.php @@ -15,13 +15,14 @@ use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface; use Symfony\Component\PropertyInfo\Type; use Symfony\Component\Validator\Constraints\All; -use Symfony\Component\Validator\Constraints\DisableAutoMapping; use Symfony\Component\Validator\Constraints\Iban; use Symfony\Component\Validator\Constraints\NotBlank; use Symfony\Component\Validator\Constraints\NotNull; use Symfony\Component\Validator\Constraints\Type as TypeConstraint; +use Symfony\Component\Validator\Mapping\AutoMappingStrategy; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\PropertyInfoLoader; +use Symfony\Component\Validator\Mapping\PropertyMetadata; use Symfony\Component\Validator\Tests\Fixtures\Entity; use Symfony\Component\Validator\Tests\Fixtures\PropertyInfoLoaderEntity; use Symfony\Component\Validator\Tests\Fixtures\PropertyInfoLoaderNoAutoMappingEntity; @@ -85,7 +86,7 @@ public function testLoadClassMetadata() )) ; - $propertyInfoLoader = new PropertyInfoLoader($propertyInfoStub, $propertyInfoStub, $propertyInfoStub); + $propertyInfoLoader = new PropertyInfoLoader($propertyInfoStub, $propertyInfoStub, $propertyInfoStub, '{.*}'); $validator = Validation::createValidatorBuilder() ->enableAnnotationMapping() @@ -164,11 +165,12 @@ public function testLoadClassMetadata() $readOnlyMetadata = $classMetadata->getPropertyMetadata('readOnly'); $this->assertEmpty($readOnlyMetadata); + /** @var PropertyMetadata[] $noAutoMappingMetadata */ $noAutoMappingMetadata = $classMetadata->getPropertyMetadata('noAutoMapping'); $this->assertCount(1, $noAutoMappingMetadata); + $this->assertSame(AutoMappingStrategy::DISABLED, $noAutoMappingMetadata[0]->getAutoMappingStrategy()); $noAutoMappingConstraints = $noAutoMappingMetadata[0]->getConstraints(); - $this->assertCount(1, $noAutoMappingConstraints); - $this->assertInstanceOf(DisableAutoMapping::class, $noAutoMappingConstraints[0]); + $this->assertCount(0, $noAutoMappingConstraints, 'DisableAutoMapping constraint is not added in the list'); } /** @@ -195,7 +197,8 @@ public function testClassValidator(bool $expected, string $classValidatorRegexp public function regexpProvider() { return [ - [true, null], + [false, null], + [true, '{.*}'], [true, '{^'.preg_quote(PropertyInfoLoaderEntity::class).'$|^'.preg_quote(Entity::class).'$}'], [false, '{^'.preg_quote(Entity::class).'$}'], ]; @@ -215,15 +218,17 @@ public function testClassNoAutoMapping() [new Type(Type::BUILTIN_TYPE_BOOL)] ); - $propertyInfoLoader = new PropertyInfoLoader($propertyInfoStub, $propertyInfoStub, $propertyInfoStub); + $propertyInfoLoader = new PropertyInfoLoader($propertyInfoStub, $propertyInfoStub, $propertyInfoStub, '{.*}'); $validator = Validation::createValidatorBuilder() ->enableAnnotationMapping() ->addLoader($propertyInfoLoader) ->getValidator() ; + /** @var ClassMetadata $classMetadata */ $classMetadata = $validator->getMetadataFor(new PropertyInfoLoaderNoAutoMappingEntity()); $this->assertEmpty($classMetadata->getPropertyMetadata('string')); - $this->assertCount(3, $classMetadata->getPropertyMetadata('autoMappingExplicitlyEnabled')[0]->constraints); + $this->assertCount(2, $classMetadata->getPropertyMetadata('autoMappingExplicitlyEnabled')[0]->constraints); + $this->assertSame(AutoMappingStrategy::ENABLED, $classMetadata->getPropertyMetadata('autoMappingExplicitlyEnabled')[0]->getAutoMappingStrategy()); } } diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Loader/StaticMethodLoaderTest.php b/src/Symfony/Component/Validator/Tests/Mapping/Loader/StaticMethodLoaderTest.php index 26d0ce3c80942..a8788e0dfdf6b 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/Loader/StaticMethodLoaderTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/Loader/StaticMethodLoaderTest.php @@ -33,7 +33,7 @@ protected function tearDown(): void public function testLoadClassMetadataReturnsTrueIfSuccessful() { $loader = new StaticMethodLoader('loadMetadata'); - $metadata = new ClassMetadata(__NAMESPACE__.'\StaticLoaderEntity'); + $metadata = new ClassMetadata(StaticLoaderEntity::class); $this->assertTrue($loader->loadClassMetadata($metadata)); } @@ -49,7 +49,7 @@ public function testLoadClassMetadataReturnsFalseIfNotSuccessful() public function testLoadClassMetadata() { $loader = new StaticMethodLoader('loadMetadata'); - $metadata = new ClassMetadata(__NAMESPACE__.'\StaticLoaderEntity'); + $metadata = new ClassMetadata(StaticLoaderEntity::class); $loader->loadClassMetadata($metadata); @@ -59,12 +59,12 @@ public function testLoadClassMetadata() public function testLoadClassMetadataDoesNotRepeatLoadWithParentClasses() { $loader = new StaticMethodLoader('loadMetadata'); - $metadata = new ClassMetadata(__NAMESPACE__.'\StaticLoaderDocument'); + $metadata = new ClassMetadata(StaticLoaderDocument::class); $loader->loadClassMetadata($metadata); $this->assertCount(0, $metadata->getConstraints()); $loader = new StaticMethodLoader('loadMetadata'); - $metadata = new ClassMetadata(__NAMESPACE__.'\BaseStaticLoaderDocument'); + $metadata = new ClassMetadata(BaseStaticLoaderDocument::class); $loader->loadClassMetadata($metadata); $this->assertCount(1, $metadata->getConstraints()); } @@ -72,7 +72,7 @@ public function testLoadClassMetadataDoesNotRepeatLoadWithParentClasses() public function testLoadClassMetadataIgnoresInterfaces() { $loader = new StaticMethodLoader('loadMetadata'); - $metadata = new ClassMetadata(__NAMESPACE__.'\StaticLoaderInterface'); + $metadata = new ClassMetadata(StaticLoaderInterface::class); $loader->loadClassMetadata($metadata); @@ -82,7 +82,7 @@ public function testLoadClassMetadataIgnoresInterfaces() public function testLoadClassMetadataInAbstractClasses() { $loader = new StaticMethodLoader('loadMetadata'); - $metadata = new ClassMetadata(__NAMESPACE__.'\AbstractStaticLoader'); + $metadata = new ClassMetadata(AbstractStaticLoader::class); $loader->loadClassMetadata($metadata); @@ -95,7 +95,7 @@ public function testLoadClassMetadataIgnoresAbstractMethods() // strict standards error error_reporting(0); - $metadata = new ClassMetadata(__NAMESPACE__.'\AbstractStaticMethodLoader'); + $metadata = new ClassMetadata(AbstractStaticMethodLoader::class); $loader = new StaticMethodLoader('loadMetadata'); $loader->loadClassMetadata($metadata); diff --git a/src/Symfony/Component/VarDumper/Caster/Caster.php b/src/Symfony/Component/VarDumper/Caster/Caster.php index ae330bc102217..5f3550fd08ac9 100644 --- a/src/Symfony/Component/VarDumper/Caster/Caster.php +++ b/src/Symfony/Component/VarDumper/Caster/Caster.php @@ -46,6 +46,15 @@ class Caster */ public static function castObject(object $obj, string $class, bool $hasDebugInfo = false): array { + if ($hasDebugInfo) { + try { + $debugInfo = $obj->__debugInfo(); + } catch (\Exception $e) { + // ignore failing __debugInfo() + $hasDebugInfo = false; + } + } + $a = $obj instanceof \Closure ? [] : (array) $obj; if ($obj instanceof \__PHP_Incomplete_Class) { @@ -81,7 +90,7 @@ public static function castObject(object $obj, string $class, bool $hasDebugInfo } } - if ($hasDebugInfo && \is_array($debugInfo = $obj->__debugInfo())) { + if ($hasDebugInfo && \is_array($debugInfo)) { foreach ($debugInfo as $k => $v) { if (!isset($k[0]) || "\0" !== $k[0]) { $k = self::PREFIX_VIRTUAL.$k; diff --git a/src/Symfony/Component/VarDumper/Caster/ClassStub.php b/src/Symfony/Component/VarDumper/Caster/ClassStub.php index b6c45456d2ae0..758fe57bb4a1b 100644 --- a/src/Symfony/Component/VarDumper/Caster/ClassStub.php +++ b/src/Symfony/Component/VarDumper/Caster/ClassStub.php @@ -56,7 +56,7 @@ public function __construct(string $identifier, $callable = null) } if (false !== strpos($identifier, "class@anonymous\0")) { - $this->value = $identifier = preg_replace_callback('/class@anonymous\x00.*?\.php0x?[0-9a-fA-F]++/', function ($m) { + $this->value = $identifier = preg_replace_callback('/class@anonymous\x00.*?\.php(?:0x?|:)[0-9a-fA-F]++/', function ($m) { return class_exists($m[0], false) ? get_parent_class($m[0]).'@anonymous' : $m[0]; }, $identifier); } diff --git a/src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php b/src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php index 1098a1fbb34f1..214026b01ba47 100644 --- a/src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php +++ b/src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php @@ -283,7 +283,7 @@ private static function filterExceptionArray(string $xClass, array $a, string $x unset($a[$xPrefix.'string'], $a[Caster::PREFIX_DYNAMIC.'xdebug_message'], $a[Caster::PREFIX_DYNAMIC.'__destructorException']); if (isset($a[Caster::PREFIX_PROTECTED.'message']) && false !== strpos($a[Caster::PREFIX_PROTECTED.'message'], "class@anonymous\0")) { - $a[Caster::PREFIX_PROTECTED.'message'] = preg_replace_callback('/class@anonymous\x00.*?\.php0x?[0-9a-fA-F]++/', function ($m) { + $a[Caster::PREFIX_PROTECTED.'message'] = preg_replace_callback('/class@anonymous\x00.*?\.php(?:0x?|:)[0-9a-fA-F]++/', function ($m) { return class_exists($m[0], false) ? get_parent_class($m[0]).'@anonymous' : $m[0]; }, $a[Caster::PREFIX_PROTECTED.'message']); } diff --git a/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php b/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php index 8e9502dfa5357..56b23840797f2 100644 --- a/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php +++ b/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php @@ -46,6 +46,7 @@ abstract class AbstractCloner implements ClonerInterface 'Doctrine\Common\Proxy\Proxy' => ['Symfony\Component\VarDumper\Caster\DoctrineCaster', 'castCommonProxy'], 'Doctrine\ORM\Proxy\Proxy' => ['Symfony\Component\VarDumper\Caster\DoctrineCaster', 'castOrmProxy'], 'Doctrine\ORM\PersistentCollection' => ['Symfony\Component\VarDumper\Caster\DoctrineCaster', 'castPersistentCollection'], + 'Doctrine\Persistence\ObjectManager' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'], 'DOMException' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castException'], 'DOMStringList' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'], diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php index 8c67d3a76d0c3..15f0b4e61d6b4 100644 --- a/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php @@ -120,7 +120,7 @@ public function testClosureCasterExcludingVerbosity() public function testReflectionParameter() { - $var = new \ReflectionParameter(__NAMESPACE__.'\reflectionParameterFixture', 0); + $var = new \ReflectionParameter(reflectionParameterFixture::class, 0); $this->assertDumpMatchesFormat( <<<'EOTXT' diff --git a/src/Symfony/Component/Yaml/Dumper.php b/src/Symfony/Component/Yaml/Dumper.php index 5175ae4d115f5..0b56779c68f10 100644 --- a/src/Symfony/Component/Yaml/Dumper.php +++ b/src/Symfony/Component/Yaml/Dumper.php @@ -70,7 +70,7 @@ public function dump($input, int $inline = 0, int $indent = 0, int $flags = 0): $blockIndentationIndicator = (' ' === substr($value, 0, 1)) ? (string) $this->indentation : ''; $output .= sprintf("%s%s%s |%s\n", $prefix, $dumpAsMap ? Inline::dump($key, $flags).':' : '-', '', $blockIndentationIndicator); - foreach (preg_split('/\n|\r\n/', $value) as $row) { + foreach (explode("\n", $value) as $row) { $output .= sprintf("%s%s%s\n", $prefix, str_repeat(' ', $this->indentation), $row); } @@ -80,6 +80,19 @@ public function dump($input, int $inline = 0, int $indent = 0, int $flags = 0): if ($value instanceof TaggedValue) { $output .= sprintf('%s%s !%s', $prefix, $dumpAsMap ? Inline::dump($key, $flags).':' : '-', $value->getTag()); + if ($inline >= 1 && Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && \is_string($value->getValue()) && false !== strpos($value->getValue(), "\n") && false === strpos($value->getValue(), "\r\n")) { + // If the first line starts with a space character, the spec requires a blockIndicationIndicator + // http://www.yaml.org/spec/1.2/spec.html#id2793979 + $blockIndentationIndicator = (' ' === substr($value->getValue(), 0, 1)) ? (string) $this->indentation : ''; + $output .= sprintf(" |%s\n", $blockIndentationIndicator); + + foreach (explode("\n", $value->getValue()) as $row) { + $output .= sprintf("%s%s%s\n", $prefix, str_repeat(' ', $this->indentation), $row); + } + + continue; + } + if ($inline - 1 <= 0 || null === $value->getValue() || is_scalar($value->getValue())) { $output .= ' '.$this->dump($value->getValue(), $inline - 1, 0, $flags)."\n"; } else { diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index 7fa4cd3cda85b..fc662b5d43ca3 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -617,11 +617,11 @@ private static function evaluateScalar(string $scalar, int $flags, array $refere // Optimize for returning strings. // no break case '+' === $scalar[0] || '-' === $scalar[0] || '.' === $scalar[0] || is_numeric($scalar[0]): + if (Parser::preg_match('{^[+-]?[0-9][0-9_]*$}', $scalar)) { + $scalar = str_replace('_', '', (string) $scalar); + } + switch (true) { - case Parser::preg_match('{^[+-]?[0-9][0-9_]*$}', $scalar): - $scalar = str_replace('_', '', (string) $scalar); - // omitting the break / return as integers are handled in the next case - // no break case ctype_digit($scalar): $raw = $scalar; $cast = (int) $scalar; @@ -631,7 +631,7 @@ private static function evaluateScalar(string $scalar, int $flags, array $refere $raw = $scalar; $cast = (int) $scalar; - return '0' == $scalar[1] ? octdec($scalar) : (((string) $raw === (string) $cast) ? $cast : $raw); + return '0' == $scalar[1] ? -octdec(substr($scalar, 1)) : (($raw === (string) $cast) ? $cast : $raw); case is_numeric($scalar): case Parser::preg_match(self::getHexRegex(), $scalar): $scalar = str_replace('_', '', $scalar); diff --git a/src/Symfony/Component/Yaml/Tests/DumperTest.php b/src/Symfony/Component/Yaml/Tests/DumperTest.php index 2b4d2853ff565..c73aedf8ed678 100644 --- a/src/Symfony/Component/Yaml/Tests/DumperTest.php +++ b/src/Symfony/Component/Yaml/Tests/DumperTest.php @@ -487,6 +487,39 @@ public function testDumpingNotInlinedNullTaggedValue() $this->assertSame($expected, $this->dumper->dump($data, 2)); } + public function testDumpingMultiLineStringAsScalarBlockTaggedValue() + { + $data = [ + 'foo' => new TaggedValue('bar', "foo\nline with trailing spaces:\n \nbar\ninteger like line:\n123456789\nempty line:\n\nbaz"), + ]; + $expected = <<assertSame($expected, $this->dumper->dump($data, 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK)); + } + + public function testDumpingInlinedMultiLineIfRnBreakLineInTaggedValue() + { + $data = [ + 'data' => [ + 'foo' => new TaggedValue('bar', "foo\r\nline with trailing spaces:\n \nbar\ninteger like line:\n123456789\nempty line:\n\nbaz"), + ], + ]; + + $this->assertSame(file_get_contents(__DIR__.'/Fixtures/multiple_lines_as_literal_block_for_tagged_values.yml'), $this->dumper->dump($data, 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK)); + } + public function testDumpMultiLineStringAsScalarBlock() { $data = [ diff --git a/src/Symfony/Component/Yaml/Tests/Fixtures/multiple_lines_as_literal_block_for_tagged_values.yml b/src/Symfony/Component/Yaml/Tests/Fixtures/multiple_lines_as_literal_block_for_tagged_values.yml new file mode 100644 index 0000000000000..f8c9112fd52a5 --- /dev/null +++ b/src/Symfony/Component/Yaml/Tests/Fixtures/multiple_lines_as_literal_block_for_tagged_values.yml @@ -0,0 +1,2 @@ +data: + foo: !bar "foo\r\nline with trailing spaces:\n \nbar\ninteger like line:\n123456789\nempty line:\n\nbaz" diff --git a/src/Symfony/Component/Yaml/Tests/InlineTest.php b/src/Symfony/Component/Yaml/Tests/InlineTest.php index 01985ece5b22d..9b07f8725d53e 100644 --- a/src/Symfony/Component/Yaml/Tests/InlineTest.php +++ b/src/Symfony/Component/Yaml/Tests/InlineTest.php @@ -720,4 +720,20 @@ public function testUnfinishedInlineMap() $this->expectExceptionMessage("Unexpected end of line, expected one of \",}\n\" at line 1 (near \"{abc: 'def'\")."); Inline::parse("{abc: 'def'"); } + + /** + * @dataProvider getTestsForOctalNumbers + */ + public function testParseOctalNumbers($expected, $yaml) + { + self::assertSame($expected, Inline::parse($yaml)); + } + + public function getTestsForOctalNumbers() + { + return [ + 'positive octal number' => [28, '034'], + 'negative octal number' => [-28, '-034'], + ]; + } }