diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 5f2d77a453eaf..d4dafb2aa0029 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,6 +1,6 @@ | Q | A | ------------- | --- -| Branch? | 7.3 for features / 6.4, and 7.2 for bug fixes +| Branch? | 7.4 for features / 6.4, 7.2, or 7.3 for bug fixes | Bug fix? | yes/no | New feature? | yes/no | Deprecations? | yes/no diff --git a/.github/build-packages.php b/.github/build-packages.php index d69a3c8198ec0..4793b8483d7ed 100644 --- a/.github/build-packages.php +++ b/.github/build-packages.php @@ -1,5 +1,15 @@ '__unset' !== $v); + }, []); + + return $expandedVersions ?? []; +} + if (3 > $_SERVER['argc']) { echo "Usage: branch version dir1 dir2 ... dirN\n"; exit(1); @@ -52,11 +62,13 @@ $packages[$package->name][$package->version] = $package; - $versions = @file_get_contents('https://repo.packagist.org/p/'.$package->name.'.json') ?: sprintf('{"packages":{"%s":{"%s":%s}}}', $package->name, $package->version, file_get_contents($dir.'/composer.json')); - $versions = json_decode($versions)->packages->{$package->name}; + foreach (['.json', '~dev.json'] as $ext) { + $versions = @file_get_contents('https://repo.packagist.org/p2/'.$package->name.$ext) ?: '[]'; + $versions = json_decode($versions, true)['packages'][$package->name] ?? []; - foreach ($versions as $v => $package) { - $packages[$package->name] += [$v => $package]; + foreach (expandComposerMetadata($versions) as $p) { + $packages[$package->name] += [$p['version'] => $p]; + } } } diff --git a/.github/expected-missing-return-types.diff b/.github/expected-missing-return-types.diff index 9faed9a44dd73..1979bba26f58c 100644 --- a/.github/expected-missing-return-types.diff +++ b/.github/expected-missing-return-types.diff @@ -7,6 +7,16 @@ git checkout src/Symfony/Contracts/Service/ResetInterface.php (echo "$head" && echo && git diff -U2 src/ | grep '^index ' -v) > .github/expected-missing-return-types.diff git checkout composer.json src/ +diff --git a/src/Symfony/Bridge/Twig/Test/Traits/RuntimeLoaderProvider.php b/src/Symfony/Bridge/Twig/Test/Traits/RuntimeLoaderProvider.php +--- a/src/Symfony/Bridge/Twig/Test/Traits/RuntimeLoaderProvider.php ++++ b/src/Symfony/Bridge/Twig/Test/Traits/RuntimeLoaderProvider.php +@@ -21,5 +21,5 @@ trait RuntimeLoaderProvider + * @return void + */ +- protected function registerTwigRuntimeLoader(Environment $environment, FormRenderer $renderer) ++ protected function registerTwigRuntimeLoader(Environment $environment, FormRenderer $renderer): void + { + $loader = $this->createMock(RuntimeLoaderInterface::class); diff --git a/src/Symfony/Component/BrowserKit/AbstractBrowser.php b/src/Symfony/Component/BrowserKit/AbstractBrowser.php --- a/src/Symfony/Component/BrowserKit/AbstractBrowser.php +++ b/src/Symfony/Component/BrowserKit/AbstractBrowser.php @@ -48,7 +58,7 @@ diff --git a/src/Symfony/Component/BrowserKit/AbstractBrowser.php b/src/Symfony/ diff --git a/src/Symfony/Component/Config/Definition/Builder/NodeDefinition.php b/src/Symfony/Component/Config/Definition/Builder/NodeDefinition.php --- a/src/Symfony/Component/Config/Definition/Builder/NodeDefinition.php +++ b/src/Symfony/Component/Config/Definition/Builder/NodeDefinition.php -@@ -94,5 +94,5 @@ abstract class NodeDefinition implements NodeParentInterface +@@ -115,5 +115,5 @@ abstract class NodeDefinition implements NodeParentInterface * @return NodeParentInterface|NodeBuilder|self|ArrayNodeDefinition|VariableNodeDefinition */ - public function end(): NodeParentInterface @@ -58,21 +68,21 @@ diff --git a/src/Symfony/Component/Config/Definition/Builder/NodeDefinition.php diff --git a/src/Symfony/Component/Console/Command/Command.php b/src/Symfony/Component/Console/Command/Command.php --- a/src/Symfony/Component/Console/Command/Command.php +++ b/src/Symfony/Component/Console/Command/Command.php -@@ -163,5 +163,5 @@ class Command +@@ -201,5 +201,5 @@ class Command implements SignalableCommandInterface * @return void */ - protected function configure() + protected function configure(): void { } -@@ -195,5 +195,5 @@ class Command +@@ -233,5 +233,5 @@ class Command implements SignalableCommandInterface * @return void */ - protected function interact(InputInterface $input, OutputInterface $output) + protected function interact(InputInterface $input, OutputInterface $output): void { } -@@ -211,5 +211,5 @@ class Command +@@ -249,5 +249,5 @@ class Command implements SignalableCommandInterface * @return void */ - protected function initialize(InputInterface $input, OutputInterface $output) @@ -474,14 +484,14 @@ diff --git a/src/Symfony/Component/HttpKernel/KernelInterface.php b/src/Symfony/ diff --git a/src/Symfony/Component/Routing/Loader/AttributeClassLoader.php b/src/Symfony/Component/Routing/Loader/AttributeClassLoader.php --- a/src/Symfony/Component/Routing/Loader/AttributeClassLoader.php +++ b/src/Symfony/Component/Routing/Loader/AttributeClassLoader.php -@@ -253,5 +253,5 @@ abstract class AttributeClassLoader implements LoaderInterface +@@ -277,5 +277,5 @@ abstract class AttributeClassLoader implements LoaderInterface * @return string */ - protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMethod $method) + protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMethod $method): string { $name = str_replace('\\', '_', $class->name).'_'.$method->name; -@@ -355,5 +355,5 @@ abstract class AttributeClassLoader implements LoaderInterface +@@ -379,5 +379,5 @@ abstract class AttributeClassLoader implements LoaderInterface * @return void */ - abstract protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, object $attr); @@ -578,7 +588,7 @@ diff --git a/src/Symfony/Component/Translation/Extractor/ExtractorInterface.php diff --git a/src/Symfony/Component/TypeInfo/Tests/Fixtures/DummyWithPhpDoc.php b/src/Symfony/Component/TypeInfo/Tests/Fixtures/DummyWithPhpDoc.php --- a/src/Symfony/Component/TypeInfo/Tests/Fixtures/DummyWithPhpDoc.php +++ b/src/Symfony/Component/TypeInfo/Tests/Fixtures/DummyWithPhpDoc.php -@@ -15,5 +15,5 @@ final class DummyWithPhpDoc +@@ -50,5 +50,5 @@ final class DummyWithPhpDoc * @return Dummy */ - public function getNextDummy(mixed $dummy): mixed @@ -610,6 +620,23 @@ diff --git a/src/Symfony/Component/VarDumper/Dumper/DataDumperInterface.php b/sr - public function dump(Data $data); + public function dump(Data $data): ?string; } +diff --git a/src/Symfony/Component/VarDumper/Test/VarDumperTestTrait.php b/src/Symfony/Component/VarDumper/Test/VarDumperTestTrait.php +--- a/src/Symfony/Component/VarDumper/Test/VarDumperTestTrait.php ++++ b/src/Symfony/Component/VarDumper/Test/VarDumperTestTrait.php +@@ -49,5 +49,5 @@ trait VarDumperTestTrait + * @return void + */ +- public function assertDumpEquals(mixed $expected, mixed $data, int $filter = 0, string $message = '') ++ public function assertDumpEquals(mixed $expected, mixed $data, int $filter = 0, string $message = ''): void + { + $this->assertSame($this->prepareExpectation($expected, $filter), $this->getDump($data, null, $filter), $message); +@@ -57,5 +57,5 @@ trait VarDumperTestTrait + * @return void + */ +- public function assertDumpMatchesFormat(mixed $expected, mixed $data, int $filter = 0, string $message = '') ++ public function assertDumpMatchesFormat(mixed $expected, mixed $data, int $filter = 0, string $message = ''): void + { + $this->assertStringMatchesFormat($this->prepareExpectation($expected, $filter), $this->getDump($data, null, $filter), $message); diff --git a/src/Symfony/Contracts/Translation/LocaleAwareInterface.php b/src/Symfony/Contracts/Translation/LocaleAwareInterface.php --- a/src/Symfony/Contracts/Translation/LocaleAwareInterface.php +++ b/src/Symfony/Contracts/Translation/LocaleAwareInterface.php diff --git a/.github/patch-types.php b/.github/patch-types.php index fc6be71995397..0a25ef95af146 100644 --- a/.github/patch-types.php +++ b/.github/patch-types.php @@ -1,5 +1,7 @@ getMethods() as $method) { if ( $method->getReturnType() - || str_contains($method->getDocComment(), '@return') + || (str_contains($method->getDocComment(), '@return') && str_contains($method->getDocComment(), 'resource')) || '__construct' === $method->getName() || '__destruct' === $method->getName() || '__clone' === $method->getName() || $method->getDeclaringClass()->getName() !== $class - || str_contains($method->getDeclaringClass()->getName(), '\\Test\\') + || str_contains($method->getDeclaringClass()->getName(), '\\Tests\\') + || str_contains($method->getDeclaringClass()->getName(), '\\Test\\') && str_starts_with($method->getName(), 'test') ) { continue; } @@ -95,6 +90,7 @@ class_exists($class); if ($missingReturnTypes) { echo \count($missingReturnTypes)." missing return types on interfaces\n\n"; echo implode("\n", $missingReturnTypes); + echo "\n"; exit(1); } diff --git a/.github/workflows/phpunit-bridge.yml b/.github/workflows/phpunit-bridge.yml index 56360c4c3d80a..5de320ee91c0e 100644 --- a/.github/workflows/phpunit-bridge.yml +++ b/.github/workflows/phpunit-bridge.yml @@ -35,4 +35,4 @@ jobs: php-version: "7.2" - name: Lint - run: find ./src/Symfony/Bridge/PhpUnit -name '*.php' | grep -v -e /Tests/ -e /Attribute/ -e /Extension/ -e /Metadata/ -e ForV7 -e ForV8 -e ForV9 -e ConstraintLogicTrait | parallel -j 4 php -l {} + run: find ./src/Symfony/Bridge/PhpUnit -name '*.php' | grep -v -e /Tests/ -e /Attribute/ -e /Extension/ -e /Metadata/ -e ForV7 -e ForV8 -e ForV9 -e ConstraintLogicTrait -e SymfonyExtension | parallel -j 4 php -l {} diff --git a/.github/workflows/scorecards.yml b/.github/workflows/scorecards.yml index a82202d055cc9..1033e761a2d0b 100644 --- a/.github/workflows/scorecards.yml +++ b/.github/workflows/scorecards.yml @@ -6,7 +6,7 @@ on: schedule: - cron: '34 4 * * 6' push: - branches: [ "7.3" ] + branches: [ "7.4" ] # Declare default permissions as read only. permissions: read-all diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index bf81825134aed..a378511725a96 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -21,7 +21,7 @@ jobs: name: Unit Tests env: - extensions: amqp,apcu,igbinary,intl,mbstring,memcached,redis,relay + extensions: amqp,apcu,brotli,igbinary,intl,mbstring,memcached,redis,relay,zstd strategy: matrix: @@ -33,9 +33,6 @@ jobs: mode: low-deps - php: '8.3' - php: '8.4' - # brotli and zstd extensions are optional, when not present the commands will be used instead, - # we must test both scenarios - extensions: amqp,apcu,brotli,igbinary,intl,mbstring,memcached,redis,relay,zstd - php: '8.5' #mode: experimental fail-fast: false @@ -101,7 +98,7 @@ jobs: # Create local composer packages for each patched components and reference them in composer.json files when cross-testing components if [[ ! "${{ matrix.mode }}" = *-deps ]]; then - php .github/build-packages.php HEAD^ $SYMFONY_VERSION src/Symfony/Bridge/PhpUnit + php .github/build-packages.php HEAD^ $SYMFONY_VERSION src/Symfony/Bridge/PhpUnit else echo SYMFONY_DEPRECATIONS_HELPER=weak >> $GITHUB_ENV cp composer.json composer.json.orig @@ -136,7 +133,7 @@ jobs: echo SYMFONY_VERSION=$SYMFONY_VERSION >> $GITHUB_ENV echo COMPOSER_ROOT_VERSION=$SYMFONY_VERSION.x-dev >> $GITHUB_ENV - echo SYMFONY_REQUIRE=">=$([ '${{ matrix.mode }}' = low-deps ] && echo 5.4 || echo $SYMFONY_VERSION)" >> $GITHUB_ENV + echo SYMFONY_REQUIRE=">=$([ '${{ matrix.mode }}' = low-deps ] && echo 6.4 || echo $SYMFONY_VERSION)" >> $GITHUB_ENV [[ "${{ matrix.mode }}" = *-deps ]] && mv composer.json.phpunit composer.json || true - name: Install dependencies @@ -154,9 +151,10 @@ jobs: run: | patch -sp1 < .github/expected-missing-return-types.diff git add . + sed -i 's/ *"\*\*\/Tests\/",//' composer.json composer install -q --optimize-autoloader || composer install --optimize-autoloader SYMFONY_PATCH_TYPE_DECLARATIONS='force=2&php=8.2' php .github/patch-types.php - git checkout src/Symfony/Contracts/Service/ResetInterface.php + git checkout composer.json src/Symfony/Contracts/Service/ResetInterface.php SYMFONY_PATCH_TYPE_DECLARATIONS='force=2&php=8.2' php .github/patch-types.php # ensure the script is idempotent git checkout src/Symfony/Contracts/Service/ResetInterface.php git diff --exit-code @@ -208,8 +206,8 @@ jobs: # get a list of the patched components (relies on .github/build-packages.php being called in the previous step) PATCHED_COMPONENTS=$(git diff --name-only src/ | grep composer.json || true) - # for 6.4 LTS, checkout and test previous major with the patched components (only for patched components) - if [[ $PATCHED_COMPONENTS && $SYMFONY_VERSION = 6.4 ]]; then + # for 7.4 LTS, checkout and test previous major with the patched components (only for patched components) + if [[ $PATCHED_COMPONENTS && $SYMFONY_VERSION = 7.4 ]]; then export FLIP='^' SYMFONY_VERSION=$(echo $SYMFONY_VERSION | awk '{print $1 - 1}') echo -e "\\n\\e[33;1mChecking out Symfony $SYMFONY_VERSION and running tests with patched components as deps\\e[0m" @@ -233,6 +231,12 @@ jobs: run: | script -e -c './phpunit --group tty' /dev/null + - name: Run AssetMapper without ext-brotli nor ext-zstd + if: "! matrix.mode" + run: | + sudo rm /etc/php/*/cli/conf.d/*-{brotli,zstd}.ini + ./phpunit src/Symfony/Component/AssetMapper + - name: Run tests with SIGCHLD enabled PHP if: "matrix.php == '8.2' && ! matrix.mode" run: | diff --git a/CHANGELOG-7.2.md b/CHANGELOG-7.2.md index 93c489ae487bd..d6d188669de42 100644 --- a/CHANGELOG-7.2.md +++ b/CHANGELOG-7.2.md @@ -7,6 +7,32 @@ in 7.2 minor versions. To get the diff for a specific change, go to https://github.com/symfony/symfony/commit/XXX where XXX is the change hash To get the diff between two versions, go to https://github.com/symfony/symfony/compare/v7.2.0...v7.2.1 +* 7.2.7 (2025-05-29) + + * bug #60549 [Translation] Add intl-icu fallback for MessageCatalogue metadata (pontus-mp) + * bug #60571 [ErrorHandler] Do not transform file to link if it does not exist (lyrixx) + * bug #60494 [Messenger] fix: Add argument as integer (overexpOG) + * bug #60524 [Notifier] Fix Clicksend transport (BafS) + * bug #60478 [Validator] add missing `$extensions` and `$extensionsMessage` to the `Image` constraint (xabbuh) + * bug #60484 [PhpUnitBridge] Clean up mocked features only when ``@group`` is present (HypeMC) + * bug #60490 [PhpUnitBridge] set path to the PHPUnit autoload file (xabbuh) + * bug #60423 [DependencyInjection] Make `DefinitionErrorExceptionPass` consider `IGNORE_ON_UNINITIALIZED_REFERENCE` and `RUNTIME_EXCEPTION_ON_INVALID_REFERENCE` the same (MatTheCat) + * bug #60439 [FrameworkBundle] Fix declaring field-attr tags in xml config files (nicolas-grekas) + * bug #60428 [DependencyInjection] Fix missing binding for ServiceCollectionInterface when declaring a service subscriber (nicolas-grekas) + * bug #60421 [VarExporter] Fixed lazy-loading ghost objects generation with property hooks (cheack) + * bug #60266 [Security] Exclude remember_me from default login authenticators (santysisi) + * bug #60400 [Config] Fix generated comment for multiline "info" (GromNaN) + * bug #60260 [Serializer] Prevent `Cannot traverse an already closed generator` error by materializing Traversable input (santysisi) + * bug #60292 [HttpFoundation] Encode path in `X-Accel-Redirect` header (Athorcis) + * bug #58643 [SecurityBundle] Use Composer `InstalledVersions` to check if flex is installed (andyexeter) + * bug #60275 [DoctrineBridge] Fix UniqueEntityValidator Stringable identifiers (GiuseppeArcuti, wkania) + * bug #60293 [Messenger] fix asking users to select an option if `--force` option is used in `messenger:failed:retry` command (W0rma) + * bug #60379 [Security] Avoid failing when PersistentRememberMeHandler handles a malformed cookie (Seldaek) + * bug #60373 [FrameworkBundle] Ensure `Email` class exists before using it (Kocal) + * bug #60365 [FrameworkBundle] ensure that all supported e-mail validation modes can be configured (xabbuh) + * bug #60350 [Security][LoginLink] Throw `InvalidLoginLinkException` on invalid parameters (davidszkiba) + * bug #60340 [String] fix EmojiTransliterator return type compatibility with PHP 8.5 (xabbuh) + * 7.2.6 (2025-05-02) * bug #60288 [VarExporter] dump default value for property hooks if present (xabbuh) diff --git a/CHANGELOG-7.3.md b/CHANGELOG-7.3.md index b88c6a58f068c..bee0295a98485 100644 --- a/CHANGELOG-7.3.md +++ b/CHANGELOG-7.3.md @@ -7,6 +7,42 @@ in 7.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/v7.3.0...v7.3.1 +* 7.3.0 (2025-05-29) + + * bug #60549 [Translation] Add intl-icu fallback for MessageCatalogue metadata (pontus-mp) + * bug #60571 [ErrorHandler] Do not transform file to link if it does not exist (lyrixx) + * bug #60542 [Webhook] Fix controller service name (HypeMC) + +* 7.3.0-RC1 (2025-05-25) + + * bug #60529 [AssetMapper] Fix SequenceParser possible infinite loop (smnandre) + * bug #60532 [Routing] Fix inline default `null` (HypeMC) + * bug #60535 [DoctrineBridge] Fix resetting the manager when using native lazy objects (HypeMC) + * bug #60500 [PhpUnitBridge] Fix cleaning up mocked features with attributes (HypeMC) + * bug #60330 [FrameworkBundle] skip messenger deduplication middleware registration when no "default" lock is configured (lyrixx) + * bug #60494 [Messenger] fix: Add argument as integer (overexpOG) + * bug #60524 [Notifier] Fix Clicksend transport (BafS) + * bug #60479 [FrameworkBundle] object mapper service definition without form (soyuka) + * bug #60478 [Validator] add missing `$extensions` and `$extensionsMessage` to the `Image` constraint (xabbuh) + * bug #60491 [ObjectMapper] added earlier skip to allow if=false when using source mapping (maciekpaprocki) + * bug #60484 [PhpUnitBridge] Clean up mocked features only when ``@group`` is present (HypeMC) + * bug #60490 [PhpUnitBridge] set path to the PHPUnit autoload file (xabbuh) + * bug #60489 [FrameworkBundle] Fix activation strategy of traceable decorators (nicolas-grekas) + * feature #60475 [Validator] Revert Slug constraint (wouterj) + * feature #60105 [JsonPath] Add `JsonPathAssertionsTrait` and related constraints (alexandre-daubois) + * bug #60423 [DependencyInjection] Make `DefinitionErrorExceptionPass` consider `IGNORE_ON_UNINITIALIZED_REFERENCE` and `RUNTIME_EXCEPTION_ON_INVALID_REFERENCE` the same (MatTheCat) + * bug #60439 [FrameworkBundle] Fix declaring field-attr tags in xml config files (nicolas-grekas) + * bug #60428 [DependencyInjection] Fix missing binding for ServiceCollectionInterface when declaring a service subscriber (nicolas-grekas) + * bug #60426 [Validator] let the `SlugValidator` accept `AsciiSlugger` results (xabbuh) + * bug #60421 [VarExporter] Fixed lazy-loading ghost objects generation with property hooks (cheack) + * bug #60419 [SecurityBundle] normalize string values to a single ExposeSecurityLevel instance (xabbuh) + * bug #60266 [Security] Exclude remember_me from default login authenticators (santysisi) + * bug #60407 [Console] Invokable command `#[Option]` adjustments (kbond) + * bug #60400 [Config] Fix generated comment for multiline "info" (GromNaN) + * bug #60260 [Serializer] Prevent `Cannot traverse an already closed generator` error by materializing Traversable input (santysisi) + * bug #60292 [HttpFoundation] Encode path in `X-Accel-Redirect` header (Athorcis) + * bug #60401 Passing more than one Security attribute is not supported (santysisi) + * 7.3.0-BETA2 (2025-05-10) * bug #58643 [SecurityBundle] Use Composer `InstalledVersions` to check if flex is installed (andyexeter) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index ee2cb2a40889b..3e7f5ec2b6e78 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -30,9 +30,9 @@ The Symfony Connect username in parenthesis allows to get more information - Kris Wallsmith (kriswallsmith) - Jakub Zalas (jakubzalas) - Yonel Ceruto (yonelceruto) + - HypeMC (hypemc) - Hugo Hamon (hhamon) - Tobias Nyholm (tobias) - - HypeMC (hypemc) - Jérôme Tamarelle (gromnan) - Antoine Lamirault (alamirault) - Samuel ROZE (sroze) @@ -96,8 +96,8 @@ The Symfony Connect username in parenthesis allows to get more information - Henrik Bjørnskov (henrikbjorn) - Ruud Kamphuis (ruudk) - David Buchmann (dbu) - - Andrej Hudec (pulzarraider) - Tomas Norkūnas (norkunas) + - Andrej Hudec (pulzarraider) - Jáchym Toušek (enumag) - Hubert Lenoir (hubert_lenoir) - Christian Raue @@ -160,12 +160,13 @@ The Symfony Connect username in parenthesis allows to get more information - Włodzimierz Gajda (gajdaw) - Javier Spagnoletti (phansys) - Adrien Brault (adrienbrault) + - Florent Morselli (spomky_) + - soyuka - Florian Voutzinos (florianv) - Teoh Han Hui (teohhanhui) - Przemysław Bogusz (przemyslaw-bogusz) - Colin Frei - excelwebzone - - Florent Morselli (spomky_) - Paráda József (paradajozsef) - Maximilian Beckers (maxbeckers) - Baptiste Clavié (talus) @@ -175,17 +176,16 @@ The Symfony Connect username in parenthesis allows to get more information - Dāvis Zālītis (k0d3r1s) - Gordon Franke (gimler) - Malte Schlüter (maltemaltesich) - - soyuka - jeremyFreeAgent (jeremyfreeagent) - Michael Babker (mbabker) - Alexis Lefebvre + - Hugo Alliaume (kocal) - Christopher Hertel (chertel) - Joshua Thijssen - Vasilij Dusko - Daniel Wehner (dawehner) - Robert Schönthal (digitalkaoz) - Smaine Milianni (ismail1432) - - Hugo Alliaume (kocal) - François-Xavier de Guillebon (de-gui_f) - Andreas Schempp (aschempp) - noniagriconomie @@ -255,6 +255,7 @@ The Symfony Connect username in parenthesis allows to get more information - Alessandro Lai (jean85) - 77web - Gocha Ossinkine (ossinkine) + - matlec - Jesse Rushlow (geeshoe) - Matthieu Ouellette-Vachon (maoueh) - Michał Pipa (michal.pipa) @@ -286,7 +287,6 @@ The Symfony Connect username in parenthesis allows to get more information - Clément JOBEILI (dator) - Andreas Möller (localheinz) - Marek Štípek (maryo) - - matlec - Daniel Espendiller - Arnaud PETITPAS (apetitpa) - Michael Käfer (michael_kaefer) @@ -310,6 +310,7 @@ The Symfony Connect username in parenthesis allows to get more information - Patrick Landolt (scube) - Karoly Gossler (connorhu) - Timo Bakx (timobakx) + - Quentin Devos - Giorgio Premi - Alan Poulain (alanpoulain) - Ruben Gonzalez (rubenrua) @@ -337,6 +338,7 @@ The Symfony Connect username in parenthesis allows to get more information - Nikolay Labinskiy (e-moe) - Martin Schuhfuß (usefulthink) - apetitpa + - wkania - Guilliam Xavier - Pierre Minnieur (pminnieur) - Dominique Bongiraud @@ -377,6 +379,7 @@ The Symfony Connect username in parenthesis allows to get more information - Pascal Montoya - Julien Brochet - François Pluchino (francoispluchino) + - W0rma - Tristan Darricau (tristandsensio) - Jan Sorgalla (jsor) - henrikbjorn @@ -401,7 +404,6 @@ The Symfony Connect username in parenthesis allows to get more information - Zan Baldwin (zanbaldwin) - Tim Goudriaan (codedmonkey) - BoShurik - - Quentin Devos - Adam Prager (padam87) - Benoît Burnichon (bburnichon) - maxime.steinhausser @@ -428,7 +430,6 @@ The Symfony Connect username in parenthesis allows to get more information - Uwe Jäger (uwej711) - javaDeveloperKid - Chris Smith (cs278) - - W0rma - Lynn van der Berg (kjarli) - Michaël Perrin (michael.perrin) - Eugene Leonovich (rybakit) @@ -438,6 +439,7 @@ The Symfony Connect username in parenthesis allows to get more information - GordonsLondon - Ray - Philipp Cordes (corphi) + - Fabien S (bafs) - Chekote - Thomas Adam - Anderson Müller @@ -471,6 +473,7 @@ The Symfony Connect username in parenthesis allows to get more information - Marcos Sánchez - Emanuele Panzeri (thepanz) - Zmey + - Santiago San Martin (santysisi) - Kim Hemsø Rasmussen (kimhemsoe) - Maximilian Reichel (phramz) - Samaël Villette (samadu61) @@ -498,6 +501,7 @@ The Symfony Connect username in parenthesis allows to get more information - Manuel Kießling (manuelkiessling) - Alexey Kopytko (sanmai) - Warxcell (warxcell) + - SiD (plbsid) - Atsuhiro KUBO (iteman) - rudy onfroy (ronfroy) - Serkan Yildiz (srknyldz) @@ -507,7 +511,6 @@ The Symfony Connect username in parenthesis allows to get more information - Gabor Toth (tgabi333) - realmfoo - Joppe De Cuyper (joppedc) - - Fabien S (bafs) - Simon Podlipsky (simpod) - Thomas Tourlourat (armetiz) - Andrey Esaulov (andremaha) @@ -612,7 +615,6 @@ The Symfony Connect username in parenthesis allows to get more information - Alex (aik099) - Kieran Brahney - Fabien Villepinte - - SiD (plbsid) - Greg Thornton (xdissent) - Alex Bowers - Kev @@ -638,6 +640,7 @@ The Symfony Connect username in parenthesis allows to get more information - Ivan Sarastov (isarastov) - flack (flack) - Shein Alexey + - Link1515 - Joe Lencioni - Daniel Tschinder - Diego Agulló (aeoris) @@ -758,6 +761,7 @@ The Symfony Connect username in parenthesis allows to get more information - Jérémy REYNAUD (babeuloula) - Faizan Akram Dar (faizanakram) - Arkadius Stefanski (arkadius) + - Andy Palmer (andyexeter) - Jonas Flodén (flojon) - AnneKir - Tobias Weichart @@ -781,6 +785,7 @@ The Symfony Connect username in parenthesis allows to get more information - Giso Stallenberg (gisostallenberg) - Rob Bast - Roberto Espinoza (respinoza) + - Steven RENAUX (steven_renaux) - Marvin Feldmann (breyndotechse) - Soufian EZ ZANTAR (soezz) - Marek Zajac @@ -867,7 +872,6 @@ The Symfony Connect username in parenthesis allows to get more information - Dariusz Ruminski - Bahman Mehrdad (bahman) - Romain Gautier (mykiwi) - - Link1515 - Matthieu Bontemps - Erik Trapman - De Cock Xavier (xdecock) @@ -1010,7 +1014,6 @@ The Symfony Connect username in parenthesis allows to get more information - Jonas Elfering - Mihai Stancu - Nahuel Cuesta (ncuesta) - - Santiago San Martin - Chris Boden (cboden) - EStyles (insidestyles) - Christophe Villeger (seragan) @@ -1065,7 +1068,6 @@ The Symfony Connect username in parenthesis allows to get more information - Pierrick VIGNAND (pierrick) - Alex Bogomazov (alebo) - aaa2000 (aaa2000) - - Andy Palmer (andyexeter) - Andrew Neil Forster (krciga22) - Stefan Warman (warmans) - Tristan Maindron (tmaindron) @@ -1865,6 +1867,7 @@ The Symfony Connect username in parenthesis allows to get more information - Philipp Fritsche - Léon Gersen - tarlepp + - Giuseppe Arcuti - Dustin Wilson - Benjamin Paap (benjaminpaap) - Claus Due (namelesscoder) @@ -1958,7 +1961,6 @@ The Symfony Connect username in parenthesis allows to get more information - Bruno MATEU - Jeremy Bush - Lucas Bäuerle - - Steven RENAUX (steven_renaux) - Laurens Laman - Thomason, James - Dario Savella @@ -2195,6 +2197,7 @@ The Symfony Connect username in parenthesis allows to get more information - Tim Ward - Adiel Cristo (arcristo) - Christian Flach (cmfcmf) + - Dennis Jaschinski (d.jaschinski) - Fabian Kropfhamer (fabiank) - Jeffrey Cafferata (jcidnl) - Junaid Farooq (junaidfarooq) @@ -2264,6 +2267,7 @@ The Symfony Connect username in parenthesis allows to get more information - wivaku - Markus Reinhold - Jingyu Wang + - es - steveYeah - Asrorbek (asrorbek) - Samy D (dinduks) @@ -2278,6 +2282,7 @@ The Symfony Connect username in parenthesis allows to get more information - Alan Scott - Juanmi Rodriguez Cerón - twifty + - David Szkiba - Andy Raines - François Poguet - Anthony Ferrara @@ -2296,6 +2301,7 @@ The Symfony Connect username in parenthesis allows to get more information - xdavidwu - Benjamin RICHARD - Raphaël Droz + - Vladimir Pakhomchik - pdommelen - Eric Stern - ShiraNai7 @@ -2710,6 +2716,7 @@ The Symfony Connect username in parenthesis allows to get more information - Marcel Siegert - ryunosuke - Bruno BOUTAREL + - Athorcis - John Stevenson - everyx - Richard Heine @@ -2767,6 +2774,7 @@ The Symfony Connect username in parenthesis allows to get more information - Abdouarrahmane FOUAD (fabdouarrahmane) - Jakub Janata (janatjak) - Jm Aribau (jmaribau) + - Maciej Paprocki (maciekpaprocki) - Matthew Foster (mfoster) - Paul Seiffert (seiffert) - Vasily Khayrulin (sirian) @@ -3114,6 +3122,7 @@ The Symfony Connect username in parenthesis allows to get more information - Darryl Hein (xmmedia) - Vladimir Sadicov (xtech) - Marcel Berteler + - Ruud Seberechts - sdkawata - Frederik Schmitt - Peter van Dommelen @@ -3151,6 +3160,7 @@ The Symfony Connect username in parenthesis allows to get more information - Pierre Rineau - Florian Morello - Maxim Lovchikov + - ivelin vasilev - adenkejawen - Florent SEVESTRE (aniki-taicho) - Ari Pringle (apringle) @@ -3327,6 +3337,7 @@ The Symfony Connect username in parenthesis allows to get more information - Kevin Verschaeve (keversc) - Kevin Herrera (kherge) - Kubicki Kamil (kubik) + - Lauris Binde (laurisb) - Luis Ramón López López (lrlopez) - Vladislav Nikolayev (luxemate) - Martin Mandl (m2mtech) @@ -3372,7 +3383,6 @@ The Symfony Connect username in parenthesis allows to get more information - Youpie - Jason Stephens - Korvin Szanto - - wkania - srsbiz - Taylan Kasap - Michael Orlitzky @@ -3585,6 +3595,7 @@ The Symfony Connect username in parenthesis allows to get more information - mieszko4 - Steve Preston - ibasaw + - koyolgecen - Wojciech Skorodecki - Kevin Frantz - Neophy7e @@ -3614,6 +3625,7 @@ The Symfony Connect username in parenthesis allows to get more information - satalaondrej - Matthias Dötsch - jonmldr + - Nowfel2501 - Yevgen Kovalienia - Lebnik - Shude @@ -3635,6 +3647,7 @@ The Symfony Connect username in parenthesis allows to get more information - Egor Gorbachev - Julian Krzefski - Derek Stephen McLean + - PatrickRedStar - Norman Soetbeer - zorn - Yuriy Potemkin @@ -3744,6 +3757,7 @@ The Symfony Connect username in parenthesis allows to get more information - Brandon Kelly (brandonkelly) - Choong Wei Tjeng (choonge) - Bermon Clément (chou666) + - Chris Shennan (chrisshennan) - Citia (citia) - Kousuke Ebihara (co3k) - Loïc Vernet (coil) @@ -3906,6 +3920,7 @@ The Symfony Connect username in parenthesis allows to get more information - Romain - Xavier REN - Kevin Meijer + - Ignacio Alveal - max - Alexander Bauer (abauer) - Ahmad Mayahi (ahmadmayahi) diff --git a/UPGRADE-7.3.md b/UPGRADE-7.3.md index 77a3f14c3445b..5fa4d18677279 100644 --- a/UPGRADE-7.3.md +++ b/UPGRADE-7.3.md @@ -8,6 +8,37 @@ Read more about this in the [Symfony documentation](https://symfony.com/doc/7.3/ If you're upgrading from a version below 7.2, follow the [7.2 upgrade guide](UPGRADE-7.2.md) first. +Table of Contents +----------------- + +Bundles + + * [FrameworkBundle](#FrameworkBundle) + * [SecurityBundle](#SecurityBundle) + * [WebProfilerBundle](#WebProfilerBundle) + +Bridges + + * [DoctrineBridge](#DoctrineBridge) + +Components + + * [AssetMapper](#AssetMapper) + * [Console](#Console) + * [DependencyInjection](#DependencyInjection) + * [HttpFoundation](#HttpFoundation) + * [Ldap](#Ldap) + * [OptionsResolver](#OptionsResolver) + * [PropertyInfo](#PropertyInfo) + * [Security](#Security) + * [Notifier](#Notifier) + * [Serializer](#Serializer) + * [TypeInfo](#TypeInfo) + * [Validator](#Validator) + * [VarDumper](#VarDumper) + * [VarExporter](#VarExporter) + * [Workflow](#Workflow) + AssetMapper ----------- @@ -179,9 +210,7 @@ Security ```php protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token, ?Vote $vote = null): bool { - $vote ??= new Vote(); - - $vote->reasons[] = 'A brief explanation of why access is granted or denied, as appropriate.'; + $vote?->addReason('A brief explanation of why access is granted or denied, as appropriate.'); } ``` @@ -195,8 +224,8 @@ SecurityBundle * Deprecate the `security.hide_user_not_found` config option in favor of `security.expose_security_errors` - Notifier - -------- +Notifier +-------- * Deprecate the `Sms77` transport, use `SevenIo` instead diff --git a/UPGRADE-7.4.md b/UPGRADE-7.4.md new file mode 100644 index 0000000000000..6623f1f6cd2bb --- /dev/null +++ b/UPGRADE-7.4.md @@ -0,0 +1,14 @@ +UPGRADE FROM 7.3 to 7.4 +======================= + +Symfony 7.4 is a minor release. According to the Symfony release process, there should be no significant +backward compatibility breaks. Minor backward compatibility breaks are prefixed in this document with +`[BC BREAK]`, make sure your code is compatible with these entries before upgrading. +Read more about this in the [Symfony documentation](https://symfony.com/doc/7.4/setup/upgrade_minor.html). + +If you're upgrading from a version below 7.3, follow the [7.3 upgrade guide](UPGRADE-7.3.md) first. + +HttpClient +---------- + + * Deprecate using amphp/http-client < 5 diff --git a/composer.json b/composer.json index 20bcb49c4b782..c21dfbfbd45c2 100644 --- a/composer.json +++ b/composer.json @@ -156,7 +156,7 @@ "seld/jsonlint": "^1.10", "symfony/amphp-http-client-meta": "^1.0|^2.0", "symfony/mercure-bundle": "^0.3", - "symfony/phpunit-bridge": "^6.4|^7.0", + "symfony/phpunit-bridge": "^6.4|^7.0|^8.0", "symfony/runtime": "self.version", "symfony/security-acl": "~2.8|~3.0", "symfony/webpack-encore-bundle": "^1.0|^2.0", diff --git a/src/Symfony/Bridge/Doctrine/ManagerRegistry.php b/src/Symfony/Bridge/Doctrine/ManagerRegistry.php index a533b3bb8d12c..fa4d88b99455d 100644 --- a/src/Symfony/Bridge/Doctrine/ManagerRegistry.php +++ b/src/Symfony/Bridge/Doctrine/ManagerRegistry.php @@ -80,21 +80,35 @@ function (&$wrappedInstance, LazyLoadingInterface $manager) use ($name) { return; } - try { - $r->resetAsLazyProxy($manager, \Closure::bind( - function () use ($name) { - $name = $this->aliases[$name] ?? $name; + $asProxy = $r->initializeLazyObject($manager) !== $manager; + $initializer = \Closure::bind( + function ($manager) use ($name, $asProxy) { + $name = $this->aliases[$name] ?? $name; + if ($asProxy) { + $manager = false; + } + + $manager = match (true) { + isset($this->fileMap[$name]) => $this->load($this->fileMap[$name], $manager), + !$method = $this->methodMap[$name] ?? null => throw new \LogicException(\sprintf('The "%s" service is synthetic and cannot be reset.', $name)), + (new \ReflectionMethod($this, $method))->isStatic() => $this->{$method}($this, $manager), + default => $this->{$method}($manager), + }; + + if ($asProxy) { + return $manager; + } + }, + $this->container, + Container::class + ); - return match (true) { - isset($this->fileMap[$name]) => $this->load($this->fileMap[$name], false), - !$method = $this->methodMap[$name] ?? null => throw new \LogicException(\sprintf('The "%s" service is synthetic and cannot be reset.', $name)), - (new \ReflectionMethod($this, $method))->isStatic() => $this->{$method}($this, false), - default => $this->{$method}(false), - }; - }, - $this->container, - Container::class - )); + try { + if ($asProxy) { + $r->resetAsLazyProxy($manager, $initializer); + } else { + $r->resetAsLazyGhost($manager, $initializer); + } } catch (\Error $e) { if (__FILE__ !== $e->getFile()) { throw $e; diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/DummyManager.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/DummyManager.php index 04e5a2acdd334..806ef032d8d5c 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/DummyManager.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/DummyManager.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Bridge\Doctrine\Tests\Fixtures; use Doctrine\Persistence\Mapping\ClassMetadata; @@ -11,6 +20,10 @@ class DummyManager implements ObjectManager { public $bar; + public function __construct() + { + } + public function find($className, $id): ?object { } diff --git a/src/Symfony/Bridge/Doctrine/Tests/ManagerRegistryTest.php b/src/Symfony/Bridge/Doctrine/Tests/ManagerRegistryTest.php index fa44ba0a00bbb..4803e6acaf0af 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/ManagerRegistryTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/ManagerRegistryTest.php @@ -22,7 +22,7 @@ class ManagerRegistryTest extends TestCase { - public static function setUpBeforeClass(): void + public function testResetService() { $container = new ContainerBuilder(); @@ -32,10 +32,7 @@ public static function setUpBeforeClass(): void $dumper = new PhpDumper($container); eval('?>'.$dumper->dump(['class' => 'LazyServiceDoctrineBridgeContainer'])); - } - public function testResetService() - { $container = new \LazyServiceDoctrineBridgeContainer(); $registry = new TestManagerRegistry('name', [], ['defaultManager' => 'foo'], 'defaultConnection', 'defaultManager', 'proxyInterfaceName'); @@ -52,6 +49,63 @@ public function testResetService() $this->assertFalse(isset($foo->bar)); } + /** + * @requires PHP 8.4 + * + * @dataProvider provideResetServiceWithNativeLazyObjectsCases + */ + public function testResetServiceWithNativeLazyObjects(string $class) + { + $container = new $class(); + + $registry = new TestManagerRegistry( + 'irrelevant', + [], + ['defaultManager' => 'foo'], + 'irrelevant', + 'defaultManager', + 'irrelevant', + ); + $registry->setTestContainer($container); + + $foo = $container->get('foo'); + self::assertSame(DummyManager::class, $foo::class); + + $foo->bar = 123; + self::assertTrue(isset($foo->bar)); + + $registry->resetManager(); + + self::assertSame($foo, $container->get('foo')); + self::assertSame(DummyManager::class, $foo::class); + self::assertFalse(isset($foo->bar)); + } + + public static function provideResetServiceWithNativeLazyObjectsCases(): iterable + { + $container = new ContainerBuilder(); + + $container->register('foo', DummyManager::class)->setPublic(true); + $container->getDefinition('foo')->setLazy(true); + $container->compile(); + + $dumper = new PhpDumper($container); + + eval('?>'.$dumper->dump(['class' => 'NativeLazyServiceDoctrineBridgeContainer'])); + + yield ['NativeLazyServiceDoctrineBridgeContainer']; + + $dumps = $dumper->dump(['class' => 'NativeLazyServiceDoctrineBridgeContainerAsFiles', 'as_files' => true]); + + $lastDump = array_pop($dumps); + foreach (array_reverse($dumps) as $dump) { + eval('?>'.$dump); + } + eval('?>'.$lastDump); + + yield ['NativeLazyServiceDoctrineBridgeContainerAsFiles']; + } + /** * When performing an entity manager lazy service reset, the reset operations may re-use the container * to create a "fresh" service: when doing so, it can happen that the "fresh" service is itself a proxy. diff --git a/src/Symfony/Bridge/Doctrine/composer.json b/src/Symfony/Bridge/Doctrine/composer.json index 9d95a8af14ca7..b2267ac5f69c3 100644 --- a/src/Symfony/Bridge/Doctrine/composer.json +++ b/src/Symfony/Bridge/Doctrine/composer.json @@ -25,24 +25,24 @@ "symfony/service-contracts": "^2.5|^3" }, "require-dev": { - "symfony/cache": "^6.4|^7.0", - "symfony/config": "^6.4|^7.0", - "symfony/dependency-injection": "^6.4|^7.0", - "symfony/doctrine-messenger": "^6.4|^7.0", - "symfony/expression-language": "^6.4|^7.0", - "symfony/form": "^6.4.6|^7.0.6", - "symfony/http-kernel": "^6.4|^7.0", - "symfony/lock": "^6.4|^7.0", - "symfony/messenger": "^6.4|^7.0", - "symfony/property-access": "^6.4|^7.0", - "symfony/property-info": "^6.4|^7.0", - "symfony/security-core": "^6.4|^7.0", - "symfony/stopwatch": "^6.4|^7.0", - "symfony/translation": "^6.4|^7.0", - "symfony/type-info": "^7.1", - "symfony/uid": "^6.4|^7.0", - "symfony/validator": "^6.4|^7.0", - "symfony/var-dumper": "^6.4|^7.0", + "symfony/cache": "^6.4|^7.0|^8.0", + "symfony/config": "^6.4|^7.0|^8.0", + "symfony/dependency-injection": "^6.4|^7.0|^8.0", + "symfony/doctrine-messenger": "^6.4|^7.0|^8.0", + "symfony/expression-language": "^6.4|^7.0|^8.0", + "symfony/form": "^6.4.6|^7.0.6|^8.0", + "symfony/http-kernel": "^6.4|^7.0|^8.0", + "symfony/lock": "^6.4|^7.0|^8.0", + "symfony/messenger": "^6.4|^7.0|^8.0", + "symfony/property-access": "^6.4|^7.0|^8.0", + "symfony/property-info": "^6.4|^7.0|^8.0", + "symfony/security-core": "^6.4|^7.0|^8.0", + "symfony/stopwatch": "^6.4|^7.0|^8.0", + "symfony/translation": "^6.4|^7.0|^8.0", + "symfony/type-info": "^7.1|^8.0", + "symfony/uid": "^6.4|^7.0|^8.0", + "symfony/validator": "^6.4|^7.0|^8.0", + "symfony/var-dumper": "^6.4|^7.0|^8.0", "doctrine/collections": "^1.8|^2.0", "doctrine/data-fixtures": "^1.1|^2", "doctrine/dbal": "^3.6|^4", diff --git a/src/Symfony/Bridge/Monolog/composer.json b/src/Symfony/Bridge/Monolog/composer.json index 50a23a5876931..745686777d1ce 100644 --- a/src/Symfony/Bridge/Monolog/composer.json +++ b/src/Symfony/Bridge/Monolog/composer.json @@ -19,16 +19,16 @@ "php": ">=8.2", "monolog/monolog": "^3", "symfony/service-contracts": "^2.5|^3", - "symfony/http-kernel": "^6.4|^7.0" + "symfony/http-kernel": "^6.4|^7.0|^8.0" }, "require-dev": { - "symfony/console": "^6.4|^7.0", - "symfony/http-client": "^6.4|^7.0", - "symfony/security-core": "^6.4|^7.0", - "symfony/var-dumper": "^6.4|^7.0", - "symfony/mailer": "^6.4|^7.0", - "symfony/mime": "^6.4|^7.0", - "symfony/messenger": "^6.4|^7.0" + "symfony/console": "^6.4|^7.0|^8.0", + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/security-core": "^6.4|^7.0|^8.0", + "symfony/var-dumper": "^6.4|^7.0|^8.0", + "symfony/mailer": "^6.4|^7.0|^8.0", + "symfony/mime": "^6.4|^7.0|^8.0", + "symfony/messenger": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/console": "<6.4", diff --git a/src/Symfony/Bridge/PhpUnit/CHANGELOG.md b/src/Symfony/Bridge/PhpUnit/CHANGELOG.md index 0b139af321f5d..579fd88af71cf 100644 --- a/src/Symfony/Bridge/PhpUnit/CHANGELOG.md +++ b/src/Symfony/Bridge/PhpUnit/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +7.4 +--- + + * Add support for mocking the `strtotime()` function + 7.3 --- diff --git a/src/Symfony/Bridge/PhpUnit/ClockMock.php b/src/Symfony/Bridge/PhpUnit/ClockMock.php index 4cca8fc26cfc6..7c76596f3a50a 100644 --- a/src/Symfony/Bridge/PhpUnit/ClockMock.php +++ b/src/Symfony/Bridge/PhpUnit/ClockMock.php @@ -109,6 +109,18 @@ public static function hrtime($asNumber = false) return [(int) self::$now, (int) $ns]; } + /** + * @return false|int + */ + public static function strtotime(string $datetime, ?int $timestamp = null) + { + if (null === $timestamp) { + $timestamp = self::time(); + } + + return \strtotime($datetime, $timestamp); + } + public static function register($class): void { $self = static::class; @@ -161,6 +173,11 @@ function hrtime(\$asNumber = false) { return \\$self::hrtime(\$asNumber); } + +function strtotime(\$datetime, \$timestamp = null) +{ + return \\$self::strtotime(\$datetime, \$timestamp); +} EOPHP ); } diff --git a/src/Symfony/Bridge/PhpUnit/SymfonyExtension.php b/src/Symfony/Bridge/PhpUnit/SymfonyExtension.php index f290a2c228865..05ff99aa8aedc 100644 --- a/src/Symfony/Bridge/PhpUnit/SymfonyExtension.php +++ b/src/Symfony/Bridge/PhpUnit/SymfonyExtension.php @@ -26,6 +26,8 @@ use PHPUnit\Runner\Extension\Facade; use PHPUnit\Runner\Extension\ParameterCollection; use PHPUnit\TextUI\Configuration\Configuration; +use Symfony\Bridge\PhpUnit\Attribute\DnsSensitive; +use Symfony\Bridge\PhpUnit\Attribute\TimeSensitive; use Symfony\Bridge\PhpUnit\Extension\EnableClockMockSubscriber; use Symfony\Bridge\PhpUnit\Extension\RegisterClockMockSubscriber; use Symfony\Bridge\PhpUnit\Extension\RegisterDnsMockSubscriber; @@ -50,35 +52,51 @@ public function bootstrap(Configuration $configuration, Facade $facade, Paramete $facade->registerSubscriber(new RegisterClockMockSubscriber($reader)); $facade->registerSubscriber(new EnableClockMockSubscriber($reader)); - $facade->registerSubscriber(new class implements ErroredSubscriber { + $facade->registerSubscriber(new class($reader) implements ErroredSubscriber { + public function __construct(private AttributeReader $reader) + { + } + public function notify(Errored $event): void { - SymfonyExtension::disableClockMock($event->test()); - SymfonyExtension::disableDnsMock($event->test()); + SymfonyExtension::disableClockMock($event->test(), $this->reader); + SymfonyExtension::disableDnsMock($event->test(), $this->reader); } }); - $facade->registerSubscriber(new class implements FinishedSubscriber { + $facade->registerSubscriber(new class($reader) implements FinishedSubscriber { + public function __construct(private AttributeReader $reader) + { + } + public function notify(Finished $event): void { - SymfonyExtension::disableClockMock($event->test()); - SymfonyExtension::disableDnsMock($event->test()); + SymfonyExtension::disableClockMock($event->test(), $this->reader); + SymfonyExtension::disableDnsMock($event->test(), $this->reader); } }); - $facade->registerSubscriber(new class implements SkippedSubscriber { + $facade->registerSubscriber(new class($reader) implements SkippedSubscriber { + public function __construct(private AttributeReader $reader) + { + } + public function notify(Skipped $event): void { - SymfonyExtension::disableClockMock($event->test()); - SymfonyExtension::disableDnsMock($event->test()); + SymfonyExtension::disableClockMock($event->test(), $this->reader); + SymfonyExtension::disableDnsMock($event->test(), $this->reader); } }); if (interface_exists(BeforeTestMethodErroredSubscriber::class)) { - $facade->registerSubscriber(new class implements BeforeTestMethodErroredSubscriber { + $facade->registerSubscriber(new class($reader) implements BeforeTestMethodErroredSubscriber { + public function __construct(private AttributeReader $reader) + { + } + public function notify(BeforeTestMethodErrored $event): void { if (method_exists($event, 'test')) { - SymfonyExtension::disableClockMock($event->test()); - SymfonyExtension::disableDnsMock($event->test()); + SymfonyExtension::disableClockMock($event->test(), $this->reader); + SymfonyExtension::disableDnsMock($event->test(), $this->reader); } else { ClockMock::withClockMock(false); DnsMock::withMockedHosts([]); @@ -99,9 +117,9 @@ public function notify(BeforeTestMethodErrored $event): void /** * @internal */ - public static function disableClockMock(Test $test): void + public static function disableClockMock(Test $test, AttributeReader $reader): void { - if (self::hasGroup($test, 'time-sensitive')) { + if (self::hasGroup($test, 'time-sensitive', $reader, TimeSensitive::class)) { ClockMock::withClockMock(false); } } @@ -109,9 +127,9 @@ public static function disableClockMock(Test $test): void /** * @internal */ - public static function disableDnsMock(Test $test): void + public static function disableDnsMock(Test $test, AttributeReader $reader): void { - if (self::hasGroup($test, 'dns-sensitive')) { + if (self::hasGroup($test, 'dns-sensitive', $reader, DnsSensitive::class)) { DnsMock::withMockedHosts([]); } } @@ -119,7 +137,7 @@ public static function disableDnsMock(Test $test): void /** * @internal */ - public static function hasGroup(Test $test, string $groupName): bool + public static function hasGroup(Test $test, string $groupName, AttributeReader $reader, string $attribute): bool { if (!$test instanceof TestMethod) { return false; @@ -131,6 +149,6 @@ public static function hasGroup(Test $test, string $groupName): bool } } - return false; + return [] !== $reader->forClassAndMethod($test->className(), $test->methodName(), $attribute); } } diff --git a/src/Symfony/Bridge/PhpUnit/Tests/ClockMockTest.php b/src/Symfony/Bridge/PhpUnit/Tests/ClockMockTest.php index 7df7865d1c9be..84241081f7ba0 100644 --- a/src/Symfony/Bridge/PhpUnit/Tests/ClockMockTest.php +++ b/src/Symfony/Bridge/PhpUnit/Tests/ClockMockTest.php @@ -79,4 +79,9 @@ public function testHrTimeAsNumber() { $this->assertSame(1234567890125000000, hrtime(true)); } + + public function testStrToTime() + { + $this->assertSame(1234567890, strtotime('now')); + } } diff --git a/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php b/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php index 18014bb180012..4d9f7667da5c2 100644 --- a/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php +++ b/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php @@ -138,6 +138,7 @@ 'COMPOSER' => 'composer.json', 'COMPOSER_VENDOR_DIR' => 'vendor', 'COMPOSER_BIN_DIR' => 'bin', + 'COMPOSER_NO_INTERACTION' => '1', 'SYMFONY_SIMPLE_PHPUNIT_BIN_DIR' => __DIR__, ]; @@ -234,10 +235,10 @@ @copy("$PHPUNIT_VERSION_DIR/phpunit.xsd", 'phpunit.xsd'); chdir("$PHPUNIT_VERSION_DIR"); if ($SYMFONY_PHPUNIT_REMOVE) { - $passthruOrFail("$COMPOSER remove --no-update --no-interaction ".$SYMFONY_PHPUNIT_REMOVE); + $passthruOrFail("$COMPOSER remove --no-update ".$SYMFONY_PHPUNIT_REMOVE); } if ($SYMFONY_PHPUNIT_REQUIRE) { - $passthruOrFail("$COMPOSER require --no-update --no-interaction ".$SYMFONY_PHPUNIT_REQUIRE); + $passthruOrFail("$COMPOSER require --no-update ".$SYMFONY_PHPUNIT_REQUIRE); } if (5.1 <= $PHPUNIT_VERSION && $PHPUNIT_VERSION < 5.4) { $passthruOrFail("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\""); diff --git a/src/Symfony/Bridge/PhpUnit/bootstrap.php b/src/Symfony/Bridge/PhpUnit/bootstrap.php index 5fddda14eb847..24d593406c87a 100644 --- a/src/Symfony/Bridge/PhpUnit/bootstrap.php +++ b/src/Symfony/Bridge/PhpUnit/bootstrap.php @@ -14,7 +14,11 @@ use Symfony\Bridge\PhpUnit\DeprecationErrorHandler; // Detect if we need to serialize deprecations to a file. -if (in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && $file = getenv('SYMFONY_DEPRECATIONS_SERIALIZE')) { +if ( + // Skip if we're using PHPUnit >=10 + !class_exists(PHPUnit\Metadata\Metadata::class) + && in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && $file = getenv('SYMFONY_DEPRECATIONS_SERIALIZE') +) { DeprecationErrorHandler::collectDeprecations($file); return; @@ -46,6 +50,10 @@ } } -if ('disabled' !== getenv('SYMFONY_DEPRECATIONS_HELPER')) { +if ( + // Skip if we're using PHPUnit >=10 + !class_exists(PHPUnit\Metadata\Metadata::class, false) + && 'disabled' !== getenv('SYMFONY_DEPRECATIONS_HELPER') +) { DeprecationErrorHandler::register(getenv('SYMFONY_DEPRECATIONS_HELPER')); } diff --git a/src/Symfony/Bridge/PhpUnit/composer.json b/src/Symfony/Bridge/PhpUnit/composer.json index 1283dfe33a9b0..169f0e63a387b 100644 --- a/src/Symfony/Bridge/PhpUnit/composer.json +++ b/src/Symfony/Bridge/PhpUnit/composer.json @@ -2,7 +2,9 @@ "name": "symfony/phpunit-bridge", "type": "symfony-bridge", "description": "Provides utilities for PHPUnit, especially user deprecation notices management", - "keywords": [], + "keywords": [ + "testing" + ], "homepage": "https://symfony.com", "license": "MIT", "authors": [ @@ -22,7 +24,7 @@ }, "require-dev": { "symfony/deprecation-contracts": "^2.5|^3.0", - "symfony/error-handler": "^5.4|^6.4|^7.0", + "symfony/error-handler": "^6.4|^7.0|^8.0", "symfony/polyfill-php81": "^1.27" }, "conflict": { diff --git a/src/Symfony/Bridge/PsrHttpMessage/composer.json b/src/Symfony/Bridge/PsrHttpMessage/composer.json index a34dfb1008e5e..1bc5fa40fe34c 100644 --- a/src/Symfony/Bridge/PsrHttpMessage/composer.json +++ b/src/Symfony/Bridge/PsrHttpMessage/composer.json @@ -18,14 +18,14 @@ "require": { "php": ">=8.2", "psr/http-message": "^1.0|^2.0", - "symfony/http-foundation": "^6.4|^7.0" + "symfony/http-foundation": "^6.4|^7.0|^8.0" }, "require-dev": { - "symfony/browser-kit": "^6.4|^7.0", - "symfony/config": "^6.4|^7.0", - "symfony/event-dispatcher": "^6.4|^7.0", - "symfony/framework-bundle": "^6.4|^7.0", - "symfony/http-kernel": "^6.4|^7.0", + "symfony/browser-kit": "^6.4|^7.0|^8.0", + "symfony/config": "^6.4|^7.0|^8.0", + "symfony/event-dispatcher": "^6.4|^7.0|^8.0", + "symfony/framework-bundle": "^6.4|^7.0|^8.0", + "symfony/http-kernel": "^6.4|^7.0|^8.0", "nyholm/psr7": "^1.1", "php-http/discovery": "^1.15", "psr/log": "^1.1.4|^2|^3" diff --git a/src/Symfony/Bridge/Twig/Test/Traits/RuntimeLoaderProvider.php b/src/Symfony/Bridge/Twig/Test/Traits/RuntimeLoaderProvider.php index 52f84a7d8f23b..5aa37c8bd0fe7 100644 --- a/src/Symfony/Bridge/Twig/Test/Traits/RuntimeLoaderProvider.php +++ b/src/Symfony/Bridge/Twig/Test/Traits/RuntimeLoaderProvider.php @@ -17,6 +17,9 @@ trait RuntimeLoaderProvider { + /** + * @return void + */ protected function registerTwigRuntimeLoader(Environment $environment, FormRenderer $renderer) { $loader = $this->createMock(RuntimeLoaderInterface::class); diff --git a/src/Symfony/Bridge/Twig/composer.json b/src/Symfony/Bridge/Twig/composer.json index dd2e55d752dc1..9fafcd55a0984 100644 --- a/src/Symfony/Bridge/Twig/composer.json +++ b/src/Symfony/Bridge/Twig/composer.json @@ -25,33 +25,33 @@ "egulias/email-validator": "^2.1.10|^3|^4", "league/html-to-markdown": "^5.0", "phpdocumentor/reflection-docblock": "^3.0|^4.0|^5.0", - "symfony/asset": "^6.4|^7.0", - "symfony/asset-mapper": "^6.4|^7.0", - "symfony/dependency-injection": "^6.4|^7.0", - "symfony/emoji": "^7.1", - "symfony/finder": "^6.4|^7.0", - "symfony/form": "^6.4.20|^7.2.5", - "symfony/html-sanitizer": "^6.4|^7.0", - "symfony/http-foundation": "^7.3", - "symfony/http-kernel": "^6.4|^7.0", - "symfony/intl": "^6.4|^7.0", - "symfony/mime": "^6.4|^7.0", + "symfony/asset": "^6.4|^7.0|^8.0", + "symfony/asset-mapper": "^6.4|^7.0|^8.0", + "symfony/dependency-injection": "^6.4|^7.0|^8.0", + "symfony/emoji": "^7.1|^8.0", + "symfony/finder": "^6.4|^7.0|^8.0", + "symfony/form": "^6.4.20|^7.2.5|^8.0", + "symfony/html-sanitizer": "^6.4|^7.0|^8.0", + "symfony/http-foundation": "^7.3|^8.0", + "symfony/http-kernel": "^6.4|^7.0|^8.0", + "symfony/intl": "^6.4|^7.0|^8.0", + "symfony/mime": "^6.4|^7.0|^8.0", "symfony/polyfill-intl-icu": "~1.0", - "symfony/property-info": "^6.4|^7.0", - "symfony/routing": "^6.4|^7.0", - "symfony/translation": "^6.4|^7.0", - "symfony/validator": "^6.4|^7.0", - "symfony/yaml": "^6.4|^7.0", + "symfony/property-info": "^6.4|^7.0|^8.0", + "symfony/routing": "^6.4|^7.0|^8.0", + "symfony/translation": "^6.4|^7.0|^8.0", + "symfony/validator": "^6.4|^7.0|^8.0", + "symfony/yaml": "^6.4|^7.0|^8.0", "symfony/security-acl": "^2.8|^3.0", - "symfony/security-core": "^6.4|^7.0", - "symfony/security-csrf": "^6.4|^7.0", - "symfony/security-http": "^6.4|^7.0", - "symfony/serializer": "^6.4.3|^7.0.3", - "symfony/stopwatch": "^6.4|^7.0", - "symfony/console": "^6.4|^7.0", - "symfony/expression-language": "^6.4|^7.0", - "symfony/web-link": "^6.4|^7.0", - "symfony/workflow": "^6.4|^7.0", + "symfony/security-core": "^6.4|^7.0|^8.0", + "symfony/security-csrf": "^6.4|^7.0|^8.0", + "symfony/security-http": "^6.4|^7.0|^8.0", + "symfony/serializer": "^6.4.3|^7.0.3|^8.0", + "symfony/stopwatch": "^6.4|^7.0|^8.0", + "symfony/console": "^6.4|^7.0|^8.0", + "symfony/expression-language": "^6.4|^7.0|^8.0", + "symfony/web-link": "^6.4|^7.0|^8.0", + "symfony/workflow": "^6.4|^7.0|^8.0", "twig/cssinliner-extra": "^3", "twig/inky-extra": "^3", "twig/markdown-extra": "^3" diff --git a/src/Symfony/Bundle/DebugBundle/composer.json b/src/Symfony/Bundle/DebugBundle/composer.json index 31b480091abdc..07d7604aa9d7b 100644 --- a/src/Symfony/Bundle/DebugBundle/composer.json +++ b/src/Symfony/Bundle/DebugBundle/composer.json @@ -19,14 +19,14 @@ "php": ">=8.2", "ext-xml": "*", "composer-runtime-api": ">=2.1", - "symfony/config": "^7.3", - "symfony/dependency-injection": "^6.4|^7.0", - "symfony/http-kernel": "^6.4|^7.0", - "symfony/twig-bridge": "^6.4|^7.0", - "symfony/var-dumper": "^6.4|^7.0" + "symfony/config": "^7.3|^8.0", + "symfony/dependency-injection": "^6.4|^7.0|^8.0", + "symfony/http-kernel": "^6.4|^7.0|^8.0", + "symfony/twig-bridge": "^6.4|^7.0|^8.0", + "symfony/var-dumper": "^6.4|^7.0|^8.0" }, "require-dev": { - "symfony/web-profiler-bundle": "^6.4|^7.0" + "symfony/web-profiler-bundle": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Bundle\\DebugBundle\\": "" }, diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 0e9b20b0ca015..f4e137f04b980 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -1290,7 +1290,7 @@ private function addPropertyInfoSection(ArrayNodeDefinition $rootNode, callable ->then(function ($v) { $v['property_info']['with_constructor_extractor'] = false; - trigger_deprecation('symfony/framework-bundle', '7.3', 'Not setting the "with_constructor_extractor" option explicitly is deprecated because its default value will change in version 8.0.'); + trigger_deprecation('symfony/framework-bundle', '7.3', 'Not setting the "property_info.with_constructor_extractor" option explicitly is deprecated because its default value will change in version 8.0.'); return $v; }) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 912282f495dac..937ba2d2c89ec 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -216,6 +216,7 @@ use Symfony\Component\Validator\ObjectInitializerInterface; use Symfony\Component\Validator\Validation; use Symfony\Component\Webhook\Controller\WebhookController; +use Symfony\Component\WebLink\HttpHeaderParser; use Symfony\Component\WebLink\HttpHeaderSerializer; use Symfony\Component\Workflow; use Symfony\Component\Workflow\WorkflowInterface; @@ -302,6 +303,10 @@ public function load(array $configs, ContainerBuilder $container): void // Load Cache configuration first as it is used by other components $loader->load('cache.php'); + if (!interface_exists(NamespacedPoolInterface::class)) { + $container->removeAlias(NamespacedPoolInterface::class); + } + $configuration = $this->getConfiguration($configs, $container); $config = $this->processConfiguration($configuration, $configs); @@ -497,6 +502,11 @@ public function load(array $configs, ContainerBuilder $container): void } $loader->load('web_link.php'); + + // Require symfony/web-link 7.4 + if (!class_exists(HttpHeaderParser::class)) { + $container->removeDefinition('web_link.http_header_parser'); + } } if ($this->readConfigEnabled('uid', $container, $config['uid'])) { @@ -569,9 +579,9 @@ public function load(array $configs, ContainerBuilder $container): void $container->removeDefinition('console.command.scheduler_debug'); } - // messenger depends on validation being registered + // messenger depends on validation, and lock being registered if ($messengerEnabled) { - $this->registerMessengerConfiguration($config['messenger'], $container, $loader, $this->readConfigEnabled('validation', $container, $config['validation']), $this->readConfigEnabled('lock', $container, $config['lock'])); + $this->registerMessengerConfiguration($config['messenger'], $container, $loader, $this->readConfigEnabled('validation', $container, $config['validation']), $this->readConfigEnabled('lock', $container, $config['lock']) && ($config['lock']['resources']['default'] ?? false)); } else { $container->removeDefinition('console.command.messenger_consume_messages'); $container->removeDefinition('console.command.messenger_stats'); @@ -2293,7 +2303,7 @@ private function registerSchedulerConfiguration(ContainerBuilder $container, Php } // BC layer Scheduler < 7.3 - if (!class_exists(SchedulerTriggerNormalizer::class)) { + if (!ContainerBuilder::willBeAvailable('symfony/serializer', DenormalizerInterface::class, ['symfony/framework-bundle', 'symfony/scheduler']) || !class_exists(SchedulerTriggerNormalizer::class)) { $container->removeDefinition('serializer.normalizer.scheduler_trigger'); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache.php index 3d96ba05994ca..ae9d426a498c6 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache.php @@ -28,6 +28,7 @@ use Symfony\Component\Cache\Messenger\EarlyExpirationHandler; use Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer; use Symfony\Contracts\Cache\CacheInterface; +use Symfony\Contracts\Cache\NamespacedPoolInterface; use Symfony\Contracts\Cache\TagAwareCacheInterface; return static function (ContainerConfigurator $container) { @@ -250,6 +251,8 @@ ->alias(CacheInterface::class, 'cache.app') + ->alias(NamespacedPoolInterface::class, 'cache.app') + ->alias(TagAwareCacheInterface::class, 'cache.app.taggable') ; }; diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing/webhook.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing/webhook.php index ea80311599fa0..177606b26214e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing/webhook.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing/webhook.php @@ -24,7 +24,7 @@ } $routes->add('_webhook_controller', '/{type}') - ->controller('webhook_controller::handle') + ->controller('webhook.controller::handle') ->requirements(['type' => '.+']) ; }; diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/web_link.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/web_link.php index 64345cc997717..df55d194734d5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/web_link.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/web_link.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Loader\Configurator; use Symfony\Component\WebLink\EventListener\AddLinkHeaderListener; +use Symfony\Component\WebLink\HttpHeaderParser; use Symfony\Component\WebLink\HttpHeaderSerializer; return static function (ContainerConfigurator $container) { @@ -20,6 +21,9 @@ ->set('web_link.http_header_serializer', HttpHeaderSerializer::class) ->alias(HttpHeaderSerializer::class, 'web_link.http_header_serializer') + ->set('web_link.http_header_parser', HttpHeaderParser::class) + ->alias(HttpHeaderParser::class, 'web_link.http_header_parser') + ->set('web_link.add_link_header_listener', AddLinkHeaderListener::class) ->args([ service('web_link.http_header_serializer'), diff --git a/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php b/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php index b2c2eb4d23089..87925f73c9b52 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php +++ b/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php @@ -39,6 +39,14 @@ protected function tearDown(): void static::$booted = false; } + public static function tearDownAfterClass(): void + { + static::ensureKernelShutdown(); + static::$class = null; + static::$kernel = null; + static::$booted = false; + } + /** * @throws \RuntimeException * @throws \LogicException diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/messenger_multiple_buses_without_deduplicate_middleware.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/messenger_multiple_buses_without_deduplicate_middleware.php index b8e7530bb3e01..fd4a008341cb4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/messenger_multiple_buses_without_deduplicate_middleware.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/messenger_multiple_buses_without_deduplicate_middleware.php @@ -5,6 +5,7 @@ 'http_method_override' => false, 'handle_all_throwables' => true, 'php_errors' => ['log' => true], + 'lock' => false, 'messenger' => [ 'default_bus' => 'messenger.bus.commands', 'buses' => [ diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/messenger_multiple_buses_without_deduplicate_middleware.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/messenger_multiple_buses_without_deduplicate_middleware.xml index dcf402e1a36ec..3f0d96249959e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/messenger_multiple_buses_without_deduplicate_middleware.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/messenger_multiple_buses_without_deduplicate_middleware.xml @@ -8,6 +8,7 @@ + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/messenger_multiple_buses_without_deduplicate_middleware.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/messenger_multiple_buses_without_deduplicate_middleware.yml index f06d534a55ec2..38fca57379fcb 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/messenger_multiple_buses_without_deduplicate_middleware.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/messenger_multiple_buses_without_deduplicate_middleware.yml @@ -4,6 +4,7 @@ framework: handle_all_throwables: true php_errors: log: true + lock: false messenger: default_bus: messenger.bus.commands buses: diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ContainerDebugCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ContainerDebugCommandTest.php index 8d3f15ba61680..d21d4d113d2e6 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ContainerDebugCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ContainerDebugCommandTest.php @@ -53,7 +53,7 @@ public function testNoDebug() public function testNoDumpedXML() { - static::bootKernel(['test_case' => 'ContainerDebug', 'root_config' => 'config.yml', 'debug' => true, 'debug.container.dump' => false]); + static::bootKernel(['test_case' => 'ContainerDebug', 'root_config' => 'no_dump.yml', 'debug' => true]); $application = new Application(static::$kernel); $application->setAutoExit(false); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/ContainerDebug/no_dump.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/ContainerDebug/no_dump.yml new file mode 100644 index 0000000000000..a9c709e9a6425 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/ContainerDebug/no_dump.yml @@ -0,0 +1,5 @@ +imports: + - { resource: config.yml } + +parameters: + debug.container.dump: false diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/MicroKernelTraitTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/MicroKernelTraitTest.php index 5c7161124bda5..159dd21eb2690 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/MicroKernelTraitTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/MicroKernelTraitTest.php @@ -14,7 +14,6 @@ use PHPUnit\Framework\TestCase; use Psr\Log\NullLogger; use Symfony\Bundle\FrameworkBundle\Console\Application; -use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\BufferedOutput; @@ -186,27 +185,3 @@ public function testDefaultKernel() $this->assertSame('OK', $response->getContent()); } } - -abstract class MinimalKernel extends Kernel -{ - use MicroKernelTrait; - - private string $cacheDir; - - public function __construct(string $cacheDir) - { - parent::__construct('test', false); - - $this->cacheDir = sys_get_temp_dir().'/'.$cacheDir; - } - - public function getCacheDir(): string - { - return $this->cacheDir; - } - - public function getLogDir(): string - { - return $this->cacheDir; - } -} diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/MinimalKernel.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/MinimalKernel.php new file mode 100644 index 0000000000000..df2c97e6a0be8 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/MinimalKernel.php @@ -0,0 +1,39 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\Tests\Kernel; + +use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; +use Symfony\Component\HttpKernel\Kernel; + +abstract class MinimalKernel extends Kernel +{ + use MicroKernelTrait; + + private string $cacheDir; + + public function __construct(string $cacheDir) + { + parent::__construct('test', false); + + $this->cacheDir = sys_get_temp_dir().'/'.$cacheDir; + } + + public function getCacheDir(): string + { + return $this->cacheDir; + } + + public function getLogDir(): string + { + return $this->cacheDir; + } +} diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index 316c595ffa2bb..4814cc601c84b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -19,61 +19,61 @@ "php": ">=8.2", "composer-runtime-api": ">=2.1", "ext-xml": "*", - "symfony/cache": "^6.4|^7.0", - "symfony/config": "^7.3", - "symfony/dependency-injection": "^7.2", + "symfony/cache": "^6.4|^7.0|^8.0", + "symfony/config": "^7.3|^8.0", + "symfony/dependency-injection": "^7.2|^8.0", "symfony/deprecation-contracts": "^2.5|^3", - "symfony/error-handler": "^7.3", - "symfony/event-dispatcher": "^6.4|^7.0", - "symfony/http-foundation": "^7.3", - "symfony/http-kernel": "^7.2", + "symfony/error-handler": "^7.3|^8.0", + "symfony/event-dispatcher": "^6.4|^7.0|^8.0", + "symfony/http-foundation": "^7.3|^8.0", + "symfony/http-kernel": "^7.2|^8.0", "symfony/polyfill-mbstring": "~1.0", - "symfony/filesystem": "^7.1", - "symfony/finder": "^6.4|^7.0", - "symfony/routing": "^6.4|^7.0" + "symfony/filesystem": "^7.1|^8.0", + "symfony/finder": "^6.4|^7.0|^8.0", + "symfony/routing": "^6.4|^7.0|^8.0" }, "require-dev": { "doctrine/persistence": "^1.3|^2|^3", "dragonmantank/cron-expression": "^3.1", "seld/jsonlint": "^1.10", - "symfony/asset": "^6.4|^7.0", - "symfony/asset-mapper": "^6.4|^7.0", - "symfony/browser-kit": "^6.4|^7.0", - "symfony/console": "^6.4|^7.0", - "symfony/clock": "^6.4|^7.0", - "symfony/css-selector": "^6.4|^7.0", - "symfony/dom-crawler": "^6.4|^7.0", - "symfony/dotenv": "^6.4|^7.0", + "symfony/asset": "^6.4|^7.0|^8.0", + "symfony/asset-mapper": "^6.4|^7.0|^8.0", + "symfony/browser-kit": "^6.4|^7.0|^8.0", + "symfony/console": "^6.4|^7.0|^8.0", + "symfony/clock": "^6.4|^7.0|^8.0", + "symfony/css-selector": "^6.4|^7.0|^8.0", + "symfony/dom-crawler": "^6.4|^7.0|^8.0", + "symfony/dotenv": "^6.4|^7.0|^8.0", "symfony/polyfill-intl-icu": "~1.0", - "symfony/form": "^6.4|^7.0", - "symfony/expression-language": "^6.4|^7.0", - "symfony/html-sanitizer": "^6.4|^7.0", - "symfony/http-client": "^6.4|^7.0", - "symfony/lock": "^6.4|^7.0", - "symfony/mailer": "^6.4|^7.0", - "symfony/messenger": "^6.4|^7.0", - "symfony/mime": "^6.4|^7.0", - "symfony/notifier": "^6.4|^7.0", - "symfony/object-mapper": "^v7.3.0-beta2", - "symfony/process": "^6.4|^7.0", - "symfony/rate-limiter": "^6.4|^7.0", - "symfony/scheduler": "^6.4.4|^7.0.4", - "symfony/security-bundle": "^6.4|^7.0", - "symfony/semaphore": "^6.4|^7.0", - "symfony/serializer": "^7.2.5", - "symfony/stopwatch": "^6.4|^7.0", - "symfony/string": "^6.4|^7.0", - "symfony/translation": "^7.3", - "symfony/twig-bundle": "^6.4|^7.0", - "symfony/type-info": "^7.1", - "symfony/validator": "^6.4|^7.0", - "symfony/workflow": "^7.3", - "symfony/yaml": "^6.4|^7.0", - "symfony/property-info": "^6.4|^7.0", - "symfony/json-streamer": "7.3.*", - "symfony/uid": "^6.4|^7.0", - "symfony/web-link": "^6.4|^7.0", - "symfony/webhook": "^7.2", + "symfony/form": "^6.4|^7.0|^8.0", + "symfony/expression-language": "^6.4|^7.0|^8.0", + "symfony/html-sanitizer": "^6.4|^7.0|^8.0", + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/lock": "^6.4|^7.0|^8.0", + "symfony/mailer": "^6.4|^7.0|^8.0", + "symfony/messenger": "^6.4|^7.0|^8.0", + "symfony/mime": "^6.4|^7.0|^8.0", + "symfony/notifier": "^6.4|^7.0|^8.0", + "symfony/object-mapper": "^7.3|^8.0", + "symfony/process": "^6.4|^7.0|^8.0", + "symfony/rate-limiter": "^6.4|^7.0|^8.0", + "symfony/scheduler": "^6.4.4|^7.0.4|^8.0", + "symfony/security-bundle": "^6.4|^7.0|^8.0", + "symfony/semaphore": "^6.4|^7.0|^8.0", + "symfony/serializer": "^7.2.5|^8.0", + "symfony/stopwatch": "^6.4|^7.0|^8.0", + "symfony/string": "^6.4|^7.0|^8.0", + "symfony/translation": "^7.3|^8.0", + "symfony/twig-bundle": "^6.4|^7.0|^8.0", + "symfony/type-info": "^7.1|^8.0", + "symfony/validator": "^6.4|^7.0|^8.0", + "symfony/workflow": "^7.3|^8.0", + "symfony/yaml": "^6.4|^7.0|^8.0", + "symfony/property-info": "^6.4|^7.0|^8.0", + "symfony/json-streamer": "^7.3|^8.0", + "symfony/uid": "^6.4|^7.0|^8.0", + "symfony/web-link": "^6.4|^7.0|^8.0", + "symfony/webhook": "^7.2|^8.0", "phpdocumentor/reflection-docblock": "^3.0|^4.0|^5.0", "twig/twig": "^3.12" }, @@ -89,7 +89,6 @@ "symfony/dom-crawler": "<6.4", "symfony/http-client": "<6.4", "symfony/form": "<6.4", - "symfony/json-streamer": ">=7.4", "symfony/lock": "<6.4", "symfony/mailer": "<6.4", "symfony/messenger": "<6.4", diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php index f1888bd7a2928..1711964b3472f 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php @@ -321,7 +321,7 @@ private function createFirewalls(array $config, ContainerBuilder $container): vo $authenticators[$name] = ServiceLocatorTagPass::register($container, $firewallAuthenticatorRefs); } $contextId = 'security.firewall.map.context.'.$name; - $isLazy = !$firewall['stateless'] && (!empty($firewall['anonymous']['lazy']) || $firewall['lazy']); + $isLazy = !$firewall['stateless'] && $firewall['lazy']; $context = new ChildDefinition($isLazy ? 'security.firewall.lazy_context' : 'security.firewall.context'); $context = $container->setDefinition($contextId, $context); $context @@ -683,7 +683,7 @@ private function getUserProvider(ContainerBuilder $container, string $id, array return $this->createMissingUserProvider($container, $id, $factoryKey); } - if ('remember_me' === $factoryKey || 'anonymous' === $factoryKey) { + if ('remember_me' === $factoryKey) { return 'security.user_providers'; } diff --git a/src/Symfony/Bundle/SecurityBundle/composer.json b/src/Symfony/Bundle/SecurityBundle/composer.json index 7459b0175b95f..66bc512f1d1ff 100644 --- a/src/Symfony/Bundle/SecurityBundle/composer.json +++ b/src/Symfony/Bundle/SecurityBundle/composer.json @@ -19,37 +19,37 @@ "php": ">=8.2", "composer-runtime-api": ">=2.1", "ext-xml": "*", - "symfony/clock": "^6.4|^7.0", - "symfony/config": "^7.3", - "symfony/dependency-injection": "^6.4.11|^7.1.4", - "symfony/event-dispatcher": "^6.4|^7.0", - "symfony/http-kernel": "^6.4|^7.0", - "symfony/http-foundation": "^6.4|^7.0", - "symfony/password-hasher": "^6.4|^7.0", - "symfony/security-core": "^7.3", - "symfony/security-csrf": "^6.4|^7.0", - "symfony/security-http": "^7.3", + "symfony/clock": "^6.4|^7.0|^8.0", + "symfony/config": "^7.3|^8.0", + "symfony/dependency-injection": "^6.4.11|^7.1.4|^8.0", + "symfony/event-dispatcher": "^6.4|^7.0|^8.0", + "symfony/http-kernel": "^6.4|^7.0|^8.0", + "symfony/http-foundation": "^6.4|^7.0|^8.0", + "symfony/password-hasher": "^6.4|^7.0|^8.0", + "symfony/security-core": "^7.3|^8.0", + "symfony/security-csrf": "^6.4|^7.0|^8.0", + "symfony/security-http": "^7.3|^8.0", "symfony/service-contracts": "^2.5|^3" }, "require-dev": { - "symfony/asset": "^6.4|^7.0", - "symfony/browser-kit": "^6.4|^7.0", - "symfony/console": "^6.4|^7.0", - "symfony/css-selector": "^6.4|^7.0", - "symfony/dom-crawler": "^6.4|^7.0", - "symfony/expression-language": "^6.4|^7.0", - "symfony/form": "^6.4|^7.0", - "symfony/framework-bundle": "^6.4|^7.0", - "symfony/http-client": "^6.4|^7.0", - "symfony/ldap": "^6.4|^7.0", - "symfony/process": "^6.4|^7.0", - "symfony/rate-limiter": "^6.4|^7.0", - "symfony/serializer": "^6.4|^7.0", - "symfony/translation": "^6.4|^7.0", - "symfony/twig-bundle": "^6.4|^7.0", - "symfony/twig-bridge": "^6.4|^7.0", - "symfony/validator": "^6.4|^7.0", - "symfony/yaml": "^6.4|^7.0", + "symfony/asset": "^6.4|^7.0|^8.0", + "symfony/browser-kit": "^6.4|^7.0|^8.0", + "symfony/console": "^6.4|^7.0|^8.0", + "symfony/css-selector": "^6.4|^7.0|^8.0", + "symfony/dom-crawler": "^6.4|^7.0|^8.0", + "symfony/expression-language": "^6.4|^7.0|^8.0", + "symfony/form": "^6.4|^7.0|^8.0", + "symfony/framework-bundle": "^6.4|^7.0|^8.0", + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/ldap": "^6.4|^7.0|^8.0", + "symfony/process": "^6.4|^7.0|^8.0", + "symfony/rate-limiter": "^6.4|^7.0|^8.0", + "symfony/serializer": "^6.4|^7.0|^8.0", + "symfony/translation": "^6.4|^7.0|^8.0", + "symfony/twig-bundle": "^6.4|^7.0|^8.0", + "symfony/twig-bridge": "^6.4|^7.0|^8.0", + "symfony/validator": "^6.4|^7.0|^8.0", + "symfony/yaml": "^6.4|^7.0|^8.0", "twig/twig": "^3.12", "web-token/jwt-library": "^3.3.2|^4.0" }, diff --git a/src/Symfony/Bundle/TwigBundle/composer.json b/src/Symfony/Bundle/TwigBundle/composer.json index 221a7f471290e..6fc30ca79a8cd 100644 --- a/src/Symfony/Bundle/TwigBundle/composer.json +++ b/src/Symfony/Bundle/TwigBundle/composer.json @@ -18,24 +18,24 @@ "require": { "php": ">=8.2", "composer-runtime-api": ">=2.1", - "symfony/config": "^7.3", - "symfony/dependency-injection": "^6.4|^7.0", - "symfony/twig-bridge": "^7.3", - "symfony/http-foundation": "^6.4|^7.0", - "symfony/http-kernel": "^6.4|^7.0", + "symfony/config": "^7.3|^8.0", + "symfony/dependency-injection": "^6.4|^7.0|^8.0", + "symfony/twig-bridge": "^7.3|^8.0", + "symfony/http-foundation": "^6.4|^7.0|^8.0", + "symfony/http-kernel": "^6.4|^7.0|^8.0", "twig/twig": "^3.12" }, "require-dev": { - "symfony/asset": "^6.4|^7.0", - "symfony/stopwatch": "^6.4|^7.0", - "symfony/expression-language": "^6.4|^7.0", - "symfony/finder": "^6.4|^7.0", - "symfony/form": "^6.4|^7.0", - "symfony/routing": "^6.4|^7.0", - "symfony/translation": "^6.4|^7.0", - "symfony/yaml": "^6.4|^7.0", - "symfony/framework-bundle": "^6.4|^7.0", - "symfony/web-link": "^6.4|^7.0" + "symfony/asset": "^6.4|^7.0|^8.0", + "symfony/stopwatch": "^6.4|^7.0|^8.0", + "symfony/expression-language": "^6.4|^7.0|^8.0", + "symfony/finder": "^6.4|^7.0|^8.0", + "symfony/form": "^6.4|^7.0|^8.0", + "symfony/routing": "^6.4|^7.0|^8.0", + "symfony/translation": "^6.4|^7.0|^8.0", + "symfony/yaml": "^6.4|^7.0|^8.0", + "symfony/framework-bundle": "^6.4|^7.0|^8.0", + "symfony/web-link": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/framework-bundle": "<6.4", diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/profiler.php b/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/profiler.php index 46175d1d1f82e..09e022be922b0 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/profiler.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/profiler.php @@ -16,7 +16,7 @@ foreach (debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT) as $trace) { if (isset($trace['object']) && $trace['object'] instanceof XmlFileLoader && 'doImport' === $trace['function']) { if (__DIR__ === dirname(realpath($trace['args'][3]))) { - trigger_deprecation('symfony/routing', '7.3', 'The "profiler.xml" routing configuration file is deprecated, import "profile.php" instead.'); + trigger_deprecation('symfony/routing', '7.3', 'The "profiler.xml" routing configuration file is deprecated, import "profiler.php" instead.'); break; } diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/wdt.php b/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/wdt.php index 81b471d228c05..d0383ee8fbef9 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/wdt.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/wdt.php @@ -16,7 +16,7 @@ foreach (debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT) as $trace) { if (isset($trace['object']) && $trace['object'] instanceof XmlFileLoader && 'doImport' === $trace['function']) { if (__DIR__ === dirname(realpath($trace['args'][3]))) { - trigger_deprecation('symfony/routing', '7.3', 'The "xdt.xml" routing configuration file is deprecated, import "xdt.php" instead.'); + trigger_deprecation('symfony/routing', '7.3', 'The "wdt.xml" routing configuration file is deprecated, import "wdt.php" instead.'); break; } diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_js.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_js.html.twig index 91e6dc05e658c..5adfd27796acf 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_js.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_js.html.twig @@ -144,7 +144,7 @@ var ajaxToolbarPanel = document.querySelector('.sf-toolbar-block-ajax'); if (requestStack.length) { - ajaxToolbarPanel.style.display = 'block'; + ajaxToolbarPanel.style.display = ''; } else { ajaxToolbarPanel.style.display = 'none'; } diff --git a/src/Symfony/Bundle/WebProfilerBundle/composer.json b/src/Symfony/Bundle/WebProfilerBundle/composer.json index 00269dd279d45..4bcc0e01c4fc0 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/composer.json +++ b/src/Symfony/Bundle/WebProfilerBundle/composer.json @@ -18,19 +18,19 @@ "require": { "php": ">=8.2", "composer-runtime-api": ">=2.1", - "symfony/config": "^7.3", + "symfony/config": "^7.3|^8.0", "symfony/deprecation-contracts": "^2.5|^3", - "symfony/framework-bundle": "^6.4|^7.0", - "symfony/http-kernel": "^6.4|^7.0", - "symfony/routing": "^6.4|^7.0", - "symfony/twig-bundle": "^6.4|^7.0", + "symfony/framework-bundle": "^6.4|^7.0|^8.0", + "symfony/http-kernel": "^6.4|^7.0|^8.0", + "symfony/routing": "^6.4|^7.0|^8.0", + "symfony/twig-bundle": "^6.4|^7.0|^8.0", "twig/twig": "^3.12" }, "require-dev": { - "symfony/browser-kit": "^6.4|^7.0", - "symfony/console": "^6.4|^7.0", - "symfony/css-selector": "^6.4|^7.0", - "symfony/stopwatch": "^6.4|^7.0" + "symfony/browser-kit": "^6.4|^7.0|^8.0", + "symfony/console": "^6.4|^7.0|^8.0", + "symfony/css-selector": "^6.4|^7.0|^8.0", + "symfony/stopwatch": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/form": "<6.4", diff --git a/src/Symfony/Component/Asset/composer.json b/src/Symfony/Component/Asset/composer.json index e8e1368f0e01c..d0107ed898d70 100644 --- a/src/Symfony/Component/Asset/composer.json +++ b/src/Symfony/Component/Asset/composer.json @@ -19,9 +19,9 @@ "php": ">=8.2" }, "require-dev": { - "symfony/http-client": "^6.4|^7.0", - "symfony/http-foundation": "^6.4|^7.0", - "symfony/http-kernel": "^6.4|^7.0" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/http-foundation": "^6.4|^7.0|^8.0", + "symfony/http-kernel": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/http-foundation": "<6.4" diff --git a/src/Symfony/Component/AssetMapper/Compiler/Parser/JavascriptSequenceParser.php b/src/Symfony/Component/AssetMapper/Compiler/Parser/JavascriptSequenceParser.php index 943c0eea14f51..7531221a8e5ee 100644 --- a/src/Symfony/Component/AssetMapper/Compiler/Parser/JavascriptSequenceParser.php +++ b/src/Symfony/Component/AssetMapper/Compiler/Parser/JavascriptSequenceParser.php @@ -133,36 +133,35 @@ public function parseUntil(int $position): void continue; } - // Single-line string - if ('"' === $matchChar || "'" === $matchChar) { - if (false === $endPos = strpos($this->content, $matchChar, $matchPos + 1)) { - $this->endsWithSequence(self::STATE_STRING, $position); - - return; - } - while (false !== $endPos && '\\' == $this->content[$endPos - 1]) { - $endPos = strpos($this->content, $matchChar, $endPos + 1); + if ('"' === $matchChar || "'" === $matchChar || '`' === $matchChar) { + $endPos = $matchPos + 1; + while (false !== $endPos = strpos($this->content, $matchChar, $endPos)) { + $backslashes = 0; + $i = $endPos - 1; + while ($i >= 0 && $this->content[$i] === '\\') { + $backslashes++; + $i--; + } + + if (0 === $backslashes % 2) { + break; + } + + $endPos++; } - $this->cursor = min($endPos + 1, $position); - $this->setSequence(self::STATE_STRING, $endPos + 1); - continue; - } - - // Multi-line string - if ('`' === $matchChar) { - if (false === $endPos = strpos($this->content, $matchChar, $matchPos + 1)) { + if (false === $endPos) { $this->endsWithSequence(self::STATE_STRING, $position); - return; } - while (false !== $endPos && '\\' == $this->content[$endPos - 1]) { - $endPos = strpos($this->content, $matchChar, $endPos + 1); - } $this->cursor = min($endPos + 1, $position); $this->setSequence(self::STATE_STRING, $endPos + 1); + continue; } + + // Fallback + $this->cursor = $matchPos + 1; } } diff --git a/src/Symfony/Component/AssetMapper/Tests/Compiler/Parser/JavascriptSequenceParserTest.php b/src/Symfony/Component/AssetMapper/Tests/Compiler/Parser/JavascriptSequenceParserTest.php index cd9c88ff72593..794b7bbf61d94 100644 --- a/src/Symfony/Component/AssetMapper/Tests/Compiler/Parser/JavascriptSequenceParserTest.php +++ b/src/Symfony/Component/AssetMapper/Tests/Compiler/Parser/JavascriptSequenceParserTest.php @@ -230,5 +230,10 @@ public static function provideStringCases(): iterable 3, false, ]; + yield 'after unclosed string' => [ + '"hello', + 6, + true, + ]; } } diff --git a/src/Symfony/Component/AssetMapper/composer.json b/src/Symfony/Component/AssetMapper/composer.json index 1286eefc09081..076f3bb9769d2 100644 --- a/src/Symfony/Component/AssetMapper/composer.json +++ b/src/Symfony/Component/AssetMapper/composer.json @@ -19,20 +19,20 @@ "php": ">=8.2", "composer/semver": "^3.0", "symfony/deprecation-contracts": "^2.1|^3", - "symfony/filesystem": "^7.1", - "symfony/http-client": "^6.4|^7.0" + "symfony/filesystem": "^7.1|^8.0", + "symfony/http-client": "^6.4|^7.0|^8.0" }, "require-dev": { - "symfony/asset": "^6.4|^7.0", - "symfony/browser-kit": "^6.4|^7.0", - "symfony/console": "^6.4|^7.0", + "symfony/asset": "^6.4|^7.0|^8.0", + "symfony/browser-kit": "^6.4|^7.0|^8.0", + "symfony/console": "^6.4|^7.0|^8.0", "symfony/event-dispatcher-contracts": "^3.0", - "symfony/finder": "^6.4|^7.0", - "symfony/framework-bundle": "^6.4|^7.0", - "symfony/http-foundation": "^6.4|^7.0", - "symfony/http-kernel": "^6.4|^7.0", - "symfony/process": "^6.4|^7.0", - "symfony/web-link": "^6.4|^7.0" + "symfony/finder": "^6.4|^7.0|^8.0", + "symfony/framework-bundle": "^6.4|^7.0|^8.0", + "symfony/http-foundation": "^6.4|^7.0|^8.0", + "symfony/http-kernel": "^6.4|^7.0|^8.0", + "symfony/process": "^6.4|^7.0|^8.0", + "symfony/web-link": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/framework-bundle": "<6.4" diff --git a/src/Symfony/Component/BrowserKit/composer.json b/src/Symfony/Component/BrowserKit/composer.json index e145984e64eab..b2e6761dab249 100644 --- a/src/Symfony/Component/BrowserKit/composer.json +++ b/src/Symfony/Component/BrowserKit/composer.json @@ -17,13 +17,13 @@ ], "require": { "php": ">=8.2", - "symfony/dom-crawler": "^6.4|^7.0" + "symfony/dom-crawler": "^6.4|^7.0|^8.0" }, "require-dev": { - "symfony/css-selector": "^6.4|^7.0", - "symfony/http-client": "^6.4|^7.0", - "symfony/mime": "^6.4|^7.0", - "symfony/process": "^6.4|^7.0" + "symfony/css-selector": "^6.4|^7.0|^8.0", + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/mime": "^6.4|^7.0|^8.0", + "symfony/process": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\BrowserKit\\": "" }, diff --git a/src/Symfony/Component/Cache/composer.json b/src/Symfony/Component/Cache/composer.json index c89d667288286..d56cec522a60c 100644 --- a/src/Symfony/Component/Cache/composer.json +++ b/src/Symfony/Component/Cache/composer.json @@ -27,20 +27,20 @@ "symfony/cache-contracts": "^3.6", "symfony/deprecation-contracts": "^2.5|^3.0", "symfony/service-contracts": "^2.5|^3", - "symfony/var-exporter": "^6.4|^7.0" + "symfony/var-exporter": "^6.4|^7.0|^8.0" }, "require-dev": { "cache/integration-tests": "dev-master", "doctrine/dbal": "^3.6|^4", "predis/predis": "^1.1|^2.0", "psr/simple-cache": "^1.0|^2.0|^3.0", - "symfony/clock": "^6.4|^7.0", - "symfony/config": "^6.4|^7.0", - "symfony/dependency-injection": "^6.4|^7.0", - "symfony/filesystem": "^6.4|^7.0", - "symfony/http-kernel": "^6.4|^7.0", - "symfony/messenger": "^6.4|^7.0", - "symfony/var-dumper": "^6.4|^7.0" + "symfony/clock": "^6.4|^7.0|^8.0", + "symfony/config": "^6.4|^7.0|^8.0", + "symfony/dependency-injection": "^6.4|^7.0|^8.0", + "symfony/filesystem": "^6.4|^7.0|^8.0", + "symfony/http-kernel": "^6.4|^7.0|^8.0", + "symfony/messenger": "^6.4|^7.0|^8.0", + "symfony/var-dumper": "^6.4|^7.0|^8.0" }, "conflict": { "doctrine/dbal": "<3.6", diff --git a/src/Symfony/Component/Config/composer.json b/src/Symfony/Component/Config/composer.json index 37206042aa8b0..af999bafa38ff 100644 --- a/src/Symfony/Component/Config/composer.json +++ b/src/Symfony/Component/Config/composer.json @@ -18,15 +18,15 @@ "require": { "php": ">=8.2", "symfony/deprecation-contracts": "^2.5|^3", - "symfony/filesystem": "^7.1", + "symfony/filesystem": "^7.1|^8.0", "symfony/polyfill-ctype": "~1.8" }, "require-dev": { - "symfony/event-dispatcher": "^6.4|^7.0", - "symfony/finder": "^6.4|^7.0", - "symfony/messenger": "^6.4|^7.0", + "symfony/event-dispatcher": "^6.4|^7.0|^8.0", + "symfony/finder": "^6.4|^7.0|^8.0", + "symfony/messenger": "^6.4|^7.0|^8.0", "symfony/service-contracts": "^2.5|^3", - "symfony/yaml": "^6.4|^7.0" + "symfony/yaml": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/finder": "<6.4", diff --git a/src/Symfony/Component/Console/Attribute/Argument.php b/src/Symfony/Component/Console/Attribute/Argument.php index 22bfbf48b762d..e6a94d2f10e4c 100644 --- a/src/Symfony/Component/Console/Attribute/Argument.php +++ b/src/Symfony/Component/Console/Attribute/Argument.php @@ -26,6 +26,7 @@ class Argument private string|bool|int|float|array|null $default = null; private array|\Closure $suggestedValues; private ?int $mode = null; + private string $function = ''; /** * Represents a console command definition. @@ -52,17 +53,23 @@ public static function tryFrom(\ReflectionParameter $parameter): ?self return null; } + if (($function = $parameter->getDeclaringFunction()) instanceof \ReflectionMethod) { + $self->function = $function->class.'::'.$function->name; + } else { + $self->function = $function->name; + } + $type = $parameter->getType(); $name = $parameter->getName(); if (!$type instanceof \ReflectionNamedType) { - throw new LogicException(\sprintf('The parameter "$%s" must have a named type. Untyped, Union or Intersection types are not supported for command arguments.', $name)); + throw new LogicException(\sprintf('The parameter "$%s" of "%s()" must have a named type. Untyped, Union or Intersection types are not supported for command arguments.', $name, $self->function)); } $parameterTypeName = $type->getName(); if (!\in_array($parameterTypeName, self::ALLOWED_TYPES, true)) { - throw new LogicException(\sprintf('The type "%s" of parameter "$%s" is not supported as a command argument. Only "%s" types are allowed.', $parameterTypeName, $name, implode('", "', self::ALLOWED_TYPES))); + throw new LogicException(\sprintf('The type "%s" on parameter "$%s" of "%s()" is not supported as a command argument. Only "%s" types are allowed.', $parameterTypeName, $name, $self->function, implode('", "', self::ALLOWED_TYPES))); } if (!$self->name) { diff --git a/src/Symfony/Component/Console/Attribute/Option.php b/src/Symfony/Component/Console/Attribute/Option.php index 19c82317033c4..2f0256b177658 100644 --- a/src/Symfony/Component/Console/Attribute/Option.php +++ b/src/Symfony/Component/Console/Attribute/Option.php @@ -29,6 +29,7 @@ class Option private ?int $mode = null; private string $typeName = ''; private bool $allowNull = false; + private string $function = ''; /** * Represents a console command --option definition. @@ -57,11 +58,17 @@ public static function tryFrom(\ReflectionParameter $parameter): ?self return null; } + if (($function = $parameter->getDeclaringFunction()) instanceof \ReflectionMethod) { + $self->function = $function->class.'::'.$function->name; + } else { + $self->function = $function->name; + } + $name = $parameter->getName(); $type = $parameter->getType(); if (!$parameter->isDefaultValueAvailable()) { - throw new LogicException(\sprintf('The option parameter "$%s" must declare a default value.', $name)); + throw new LogicException(\sprintf('The option parameter "$%s" of "%s()" must declare a default value.', $name, $self->function)); } if (!$self->name) { @@ -76,21 +83,21 @@ public static function tryFrom(\ReflectionParameter $parameter): ?self } if (!$type instanceof \ReflectionNamedType) { - throw new LogicException(\sprintf('The parameter "$%s" must have a named type. Untyped or Intersection types are not supported for command options.', $name)); + throw new LogicException(\sprintf('The parameter "$%s" of "%s()" must have a named type. Untyped or Intersection types are not supported for command options.', $name, $self->function)); } $self->typeName = $type->getName(); if (!\in_array($self->typeName, self::ALLOWED_TYPES, true)) { - throw new LogicException(\sprintf('The type "%s" of parameter "$%s" is not supported as a command option. Only "%s" types are allowed.', $self->typeName, $name, implode('", "', self::ALLOWED_TYPES))); + throw new LogicException(\sprintf('The type "%s" on parameter "$%s" of "%s()" is not supported as a command option. Only "%s" types are allowed.', $self->typeName, $name, $self->function, implode('", "', self::ALLOWED_TYPES))); } if ('bool' === $self->typeName && $self->allowNull && \in_array($self->default, [true, false], true)) { - throw new LogicException(\sprintf('The option parameter "$%s" must not be nullable when it has a default boolean value.', $name)); + throw new LogicException(\sprintf('The option parameter "$%s" of "%s()" must not be nullable when it has a default boolean value.', $name, $self->function)); } if ($self->allowNull && null !== $self->default) { - throw new LogicException(\sprintf('The option parameter "$%s" must either be not-nullable or have a default of null.', $name)); + throw new LogicException(\sprintf('The option parameter "$%s" of "%s()" must either be not-nullable or have a default of null.', $name, $self->function)); } if ('bool' === $self->typeName) { @@ -160,11 +167,11 @@ private function handleUnion(\ReflectionUnionType $type): self $this->typeName = implode('|', array_filter($types)); if (!\in_array($this->typeName, self::ALLOWED_UNION_TYPES, true)) { - throw new LogicException(\sprintf('The union type for parameter "$%s" is not supported as a command option. Only "%s" types are allowed.', $this->name, implode('", "', self::ALLOWED_UNION_TYPES))); + throw new LogicException(\sprintf('The union type for parameter "$%s" of "%s()" is not supported as a command option. Only "%s" types are allowed.', $this->name, $this->function, implode('", "', self::ALLOWED_UNION_TYPES))); } if (false !== $this->default) { - throw new LogicException(\sprintf('The option parameter "$%s" must have a default value of false.', $this->name)); + throw new LogicException(\sprintf('The option parameter "$%s" of "%s()" must have a default value of false.', $this->name, $this->function)); } $this->mode = InputOption::VALUE_OPTIONAL; diff --git a/src/Symfony/Component/Console/Debug/CliRequest.php b/src/Symfony/Component/Console/Debug/CliRequest.php index b023db07af95e..6e2c1012b16ef 100644 --- a/src/Symfony/Component/Console/Debug/CliRequest.php +++ b/src/Symfony/Component/Console/Debug/CliRequest.php @@ -24,7 +24,7 @@ public function __construct( public readonly TraceableCommand $command, ) { parent::__construct( - attributes: ['_controller' => \get_class($command->command), '_virtual_type' => 'command'], + attributes: ['_controller' => $command->command::class, '_virtual_type' => 'command'], server: $_SERVER, ); } diff --git a/src/Symfony/Component/Console/Tests/Command/InvokableCommandTest.php b/src/Symfony/Component/Console/Tests/Command/InvokableCommandTest.php index 917e2f88f1655..5ab7951e7f575 100644 --- a/src/Symfony/Component/Console/Tests/Command/InvokableCommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/InvokableCommandTest.php @@ -138,7 +138,6 @@ public function testInvalidArgumentType() $command->setCode(function (#[Argument] object $any) {}); $this->expectException(LogicException::class); - $this->expectExceptionMessage('The type "object" of parameter "$any" is not supported as a command argument. Only "string", "bool", "int", "float", "array" types are allowed.'); $command->getDefinition(); } @@ -149,7 +148,6 @@ public function testInvalidOptionType() $command->setCode(function (#[Option] ?object $any = null) {}); $this->expectException(LogicException::class); - $this->expectExceptionMessage('The type "object" of parameter "$any" is not supported as a command option. Only "string", "bool", "int", "float", "array" types are allowed.'); $command->getDefinition(); } @@ -322,13 +320,12 @@ public static function provideNonBinaryInputOptions(): \Generator /** * @dataProvider provideInvalidOptionDefinitions */ - public function testInvalidOptionDefinition(callable $code, string $expectedMessage) + public function testInvalidOptionDefinition(callable $code) { $command = new Command('foo'); $command->setCode($code); $this->expectException(LogicException::class); - $this->expectExceptionMessage($expectedMessage); $command->getDefinition(); } @@ -336,40 +333,31 @@ public function testInvalidOptionDefinition(callable $code, string $expectedMess public static function provideInvalidOptionDefinitions(): \Generator { yield 'no-default' => [ - function (#[Option] string $a) {}, - 'The option parameter "$a" must declare a default value.', + function (#[Option] string $a) {} ]; yield 'nullable-bool-default-true' => [ - function (#[Option] ?bool $a = true) {}, - 'The option parameter "$a" must not be nullable when it has a default boolean value.', + function (#[Option] ?bool $a = true) {} ]; yield 'nullable-bool-default-false' => [ - function (#[Option] ?bool $a = false) {}, - 'The option parameter "$a" must not be nullable when it has a default boolean value.', + function (#[Option] ?bool $a = false) {} ]; yield 'invalid-union-type' => [ - function (#[Option] array|bool $a = false) {}, - 'The union type for parameter "$a" is not supported as a command option. Only "bool|string", "bool|int", "bool|float" types are allowed.', + function (#[Option] array|bool $a = false) {} ]; yield 'union-type-cannot-allow-null' => [ function (#[Option] string|bool|null $a = null) {}, - 'The union type for parameter "$a" is not supported as a command option. Only "bool|string", "bool|int", "bool|float" types are allowed.', ]; yield 'union-type-default-true' => [ function (#[Option] string|bool $a = true) {}, - 'The option parameter "$a" must have a default value of false.', ]; yield 'union-type-default-string' => [ function (#[Option] string|bool $a = 'foo') {}, - 'The option parameter "$a" must have a default value of false.', ]; yield 'nullable-string-not-null-default' => [ function (#[Option] ?string $a = 'foo') {}, - 'The option parameter "$a" must either be not-nullable or have a default of null.', ]; yield 'nullable-array-not-null-default' => [ function (#[Option] ?array $a = []) {}, - 'The option parameter "$a" must either be not-nullable or have a default of null.', ]; } diff --git a/src/Symfony/Component/Console/composer.json b/src/Symfony/Component/Console/composer.json index 65d69913aa218..109cdd762f625 100644 --- a/src/Symfony/Component/Console/composer.json +++ b/src/Symfony/Component/Console/composer.json @@ -20,19 +20,19 @@ "symfony/deprecation-contracts": "^2.5|^3", "symfony/polyfill-mbstring": "~1.0", "symfony/service-contracts": "^2.5|^3", - "symfony/string": "^7.2" + "symfony/string": "^7.2|^8.0" }, "require-dev": { - "symfony/config": "^6.4|^7.0", - "symfony/event-dispatcher": "^6.4|^7.0", - "symfony/http-foundation": "^6.4|^7.0", - "symfony/http-kernel": "^6.4|^7.0", - "symfony/dependency-injection": "^6.4|^7.0", - "symfony/lock": "^6.4|^7.0", - "symfony/messenger": "^6.4|^7.0", - "symfony/process": "^6.4|^7.0", - "symfony/stopwatch": "^6.4|^7.0", - "symfony/var-dumper": "^6.4|^7.0", + "symfony/config": "^6.4|^7.0|^8.0", + "symfony/event-dispatcher": "^6.4|^7.0|^8.0", + "symfony/http-foundation": "^6.4|^7.0|^8.0", + "symfony/http-kernel": "^6.4|^7.0|^8.0", + "symfony/dependency-injection": "^6.4|^7.0|^8.0", + "symfony/lock": "^6.4|^7.0|^8.0", + "symfony/messenger": "^6.4|^7.0|^8.0", + "symfony/process": "^6.4|^7.0|^8.0", + "symfony/stopwatch": "^6.4|^7.0|^8.0", + "symfony/var-dumper": "^6.4|^7.0|^8.0", "psr/log": "^1|^2|^3" }, "provide": { diff --git a/src/Symfony/Component/DependencyInjection/Attribute/AsTaggedItem.php b/src/Symfony/Component/DependencyInjection/Attribute/AsTaggedItem.php index cc3306c739638..de751213acad5 100644 --- a/src/Symfony/Component/DependencyInjection/Attribute/AsTaggedItem.php +++ b/src/Symfony/Component/DependencyInjection/Attribute/AsTaggedItem.php @@ -20,8 +20,8 @@ class AsTaggedItem { /** - * @param string|null $index The property or method to use to index the item in the locator - * @param int|null $priority The priority of the item; the higher the number, the earlier the tagged service will be located in the locator + * @param string|null $index The property or method to use to index the item in the iterator/locator + * @param int|null $priority The priority of the item; the higher the number, the earlier the tagged service will be located in the iterator/locator */ public function __construct( public ?string $index = null, diff --git a/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php b/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php index 4befef860a66e..8c6b5b582770d 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php @@ -88,8 +88,7 @@ private function findAndSortTaggedServices(string|TaggedIteratorArgument $tagNam if (null === $index && null === $defaultIndex && $defaultPriorityMethod && $reflector) { $defaultIndex = PriorityTaggedServiceUtil::getDefault($serviceId, $reflector, $defaultIndexMethod ?? 'getDefaultName', $tagName, $indexAttribute, $checkTaggedItem); } - $decorated = $definition->getTag('container.decorator')[0]['id'] ?? null; - $index = $index ?? $defaultIndex ?? $defaultIndex = $decorated ?? $serviceId; + $index ??= $defaultIndex ??= $definition->getTag('container.decorator')[0]['id'] ?? $serviceId; $services[] = [$priority, ++$i, $index, $serviceId, $class]; } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ServiceLocatorTagPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ServiceLocatorTagPass.php index 81c14ac5cc4d0..eedc0f484243c 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ServiceLocatorTagPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ServiceLocatorTagPass.php @@ -54,17 +54,41 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed $value->setClass(ServiceLocator::class); } - $services = $value->getArguments()[0] ?? null; + $values = $value->getArguments()[0] ?? null; + $services = []; - if ($services instanceof TaggedIteratorArgument) { - $services = $this->findAndSortTaggedServices($services, $this->container); - } - - if (!\is_array($services)) { + if ($values instanceof TaggedIteratorArgument) { + foreach ($this->findAndSortTaggedServices($values, $this->container) as $k => $v) { + $services[$k] = new ServiceClosureArgument($v); + } + } elseif (!\is_array($values)) { throw new InvalidArgumentException(\sprintf('Invalid definition for service "%s": an array of references is expected as first argument when the "container.service_locator" tag is set.', $this->currentId)); + } else { + $i = 0; + + foreach ($values as $k => $v) { + if ($v instanceof ServiceClosureArgument) { + $services[$k] = $v; + continue; + } + + if ($i === $k) { + if ($v instanceof Reference) { + $k = (string) $v; + } + ++$i; + } elseif (\is_int($k)) { + $i = null; + } + + $services[$k] = new ServiceClosureArgument($v); + } + if (\count($services) === $i) { + ksort($services); + } } - $value->setArgument(0, self::map($services)); + $value->setArgument(0, $services); $id = '.service_locator.'.ContainerBuilder::hash($value); @@ -83,8 +107,12 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed public static function register(ContainerBuilder $container, array $map, ?string $callerId = null): Reference { + foreach ($map as $k => $v) { + $map[$k] = new ServiceClosureArgument($v); + } + $locator = (new Definition(ServiceLocator::class)) - ->addArgument(self::map($map)) + ->addArgument($map) ->addTag('container.service_locator'); if (null !== $callerId && $container->hasDefinition($callerId)) { @@ -109,29 +137,4 @@ public static function register(ContainerBuilder $container, array $map, ?string return new Reference($id); } - - public static function map(array $services): array - { - $i = 0; - - foreach ($services as $k => $v) { - if ($v instanceof ServiceClosureArgument) { - continue; - } - - if ($i === $k) { - if ($v instanceof Reference) { - unset($services[$k]); - $k = (string) $v; - } - ++$i; - } elseif (\is_int($k)) { - $i = null; - } - - $services[$k] = new ServiceClosureArgument($v); - } - - return $services; - } } diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index 47202cf7d9e9a..0389003d20856 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -790,10 +790,11 @@ public function parameterCannotBeEmpty(string $name, string $message): void * * The parameter bag is frozen; * * Extension loading is disabled. * - * @param bool $resolveEnvPlaceholders Whether %env()% parameters should be resolved using the current - * env vars or be replaced by uniquely identifiable placeholders. - * Set to "true" when you want to use the current ContainerBuilder - * directly, keep to "false" when the container is dumped instead. + * @param bool $resolveEnvPlaceholders Whether %env()% parameters should be resolved at build time using + * the current env var values (true), or be resolved at runtime based + * on the environment (false). In general, this should be set to "true" + * when you want to use the current ContainerBuilder directly, and to + * "false" when the container is dumped instead. */ public function compile(bool $resolveEnvPlaceholders = false): void { diff --git a/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php index ec115500bb0cf..d79e7b90408b2 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php @@ -50,18 +50,18 @@ public function dump(array $options = []): string $this->dumper ??= new YmlDumper(); - return $this->container->resolveEnvPlaceholders($this->addParameters()."\n".$this->addServices()); + return $this->addParameters()."\n".$this->addServices(); } private function addService(string $id, Definition $definition): string { - $code = " $id:\n"; + $code = " {$this->dumper->dump($id)}:\n"; if ($class = $definition->getClass()) { if (str_starts_with($class, '\\')) { $class = substr($class, 1); } - $code .= \sprintf(" class: %s\n", $this->dumper->dump($class)); + $code .= \sprintf(" class: %s\n", $this->dumper->dump($this->container->resolveEnvPlaceholders($class))); } if (!$definition->isPrivate()) { @@ -87,7 +87,7 @@ private function addService(string $id, Definition $definition): string } if ($definition->getFile()) { - $code .= \sprintf(" file: %s\n", $this->dumper->dump($definition->getFile())); + $code .= \sprintf(" file: %s\n", $this->dumper->dump($this->container->resolveEnvPlaceholders($definition->getFile()))); } if ($definition->isSynthetic()) { @@ -238,7 +238,7 @@ private function dumpCallable(mixed $callable): mixed } } - return $callable; + return $this->container->resolveEnvPlaceholders($callable); } /** @@ -299,7 +299,7 @@ private function dumpValue(mixed $value): mixed if (\is_array($value)) { $code = []; foreach ($value as $k => $v) { - $code[$k] = $this->dumpValue($v); + $code[$this->container->resolveEnvPlaceholders($k)] = $this->dumpValue($v); } return $code; @@ -319,7 +319,7 @@ private function dumpValue(mixed $value): mixed throw new RuntimeException(\sprintf('Unable to dump a service container if a parameter is an object or a resource, got "%s".', get_debug_type($value))); } - return $value; + return $this->container->resolveEnvPlaceholders($value); } private function getServiceCall(string $id, ?Reference $reference = null): string @@ -359,7 +359,7 @@ private function prepareParameters(array $parameters, bool $escape = true): arra $filtered[$key] = $value; } - return $escape ? $this->escape($filtered) : $filtered; + return $escape ? $this->container->resolveEnvPlaceholders($this->escape($filtered)) : $filtered; } private function escape(array $arguments): array diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ServiceLocatorTagPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ServiceLocatorTagPassTest.php index 812b47c7a6f1f..ad9c62d9b387f 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ServiceLocatorTagPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ServiceLocatorTagPassTest.php @@ -83,7 +83,27 @@ public function testProcessValue() $this->assertSame(CustomDefinition::class, $locator('bar')::class); $this->assertSame(CustomDefinition::class, $locator('baz')::class); $this->assertSame(CustomDefinition::class, $locator('some.service')::class); - $this->assertSame(CustomDefinition::class, \get_class($locator('inlines.service'))); + $this->assertSame(CustomDefinition::class, $locator('inlines.service')::class); + } + + public function testServiceListIsOrdered() + { + $container = new ContainerBuilder(); + + $container->register('bar', CustomDefinition::class); + $container->register('baz', CustomDefinition::class); + + $container->register('foo', ServiceLocator::class) + ->setArguments([[ + new Reference('baz'), + new Reference('bar'), + ]]) + ->addTag('container.service_locator') + ; + + (new ServiceLocatorTagPass())->process($container); + + $this->assertSame(['bar', 'baz'], array_keys($container->getDefinition('foo')->getArgument(0))); } public function testServiceWithKeyOverwritesPreviousInheritedKey() @@ -170,6 +190,27 @@ public function testTaggedServices() $this->assertSame(TestDefinition2::class, $locator('baz')::class); } + public function testTaggedServicesKeysAreKept() + { + $container = new ContainerBuilder(); + + $container->register('bar', TestDefinition1::class)->addTag('test_tag', ['index' => 0]); + $container->register('baz', TestDefinition2::class)->addTag('test_tag', ['index' => 1]); + + $container->register('foo', ServiceLocator::class) + ->setArguments([new TaggedIteratorArgument('test_tag', 'index', null, true)]) + ->addTag('container.service_locator') + ; + + (new ServiceLocatorTagPass())->process($container); + + /** @var ServiceLocator $locator */ + $locator = $container->get('foo'); + + $this->assertSame(TestDefinition1::class, $locator(0)::class); + $this->assertSame(TestDefinition2::class, $locator(1)::class); + } + public function testIndexedByServiceIdWithDecoration() { $container = new ContainerBuilder(); @@ -201,15 +242,33 @@ public function testIndexedByServiceIdWithDecoration() static::assertInstanceOf(DecoratedService::class, $locator->get(Service::class)); } - public function testDefinitionOrderIsTheSame() + public function testServicesKeysAreKept() { $container = new ContainerBuilder(); $container->register('service-1'); $container->register('service-2'); + $container->register('service-3'); $locator = ServiceLocatorTagPass::register($container, [ - new Reference('service-2'), new Reference('service-1'), + 'service-2' => new Reference('service-2'), + 'foo' => new Reference('service-3'), + ]); + $locator = $container->getDefinition($locator); + $factories = $locator->getArguments()[0]; + + static::assertSame([0, 'service-2', 'foo'], array_keys($factories)); + } + + public function testDefinitionOrderIsTheSame() + { + $container = new ContainerBuilder(); + $container->register('service-1'); + $container->register('service-2'); + + $locator = ServiceLocatorTagPass::register($container, [ + 'service-2' => new Reference('service-2'), + 'service-1' => new Reference('service-1'), ]); $locator = $container->getDefinition($locator); $factories = $locator->getArguments()[0]; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/YamlDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/YamlDumperTest.php index f9ff3fff786a3..3a21d7aa9a9c5 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/YamlDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/YamlDumperTest.php @@ -215,6 +215,26 @@ public function testDumpNonScalarTags() $this->assertEquals(file_get_contents(self::$fixturesPath.'/yaml/services_with_array_tags.yml'), $dumper->dump()); } + public function testDumpResolvedEnvPlaceholders() + { + $container = new ContainerBuilder(); + $container->setParameter('%env(PARAMETER_NAME)%', '%env(PARAMETER_VALUE)%'); + $container + ->register('service', '%env(SERVICE_CLASS)%') + ->setFile('%env(SERVICE_FILE)%') + ->addArgument('%env(SERVICE_ARGUMENT)%') + ->setProperty('%env(SERVICE_PROPERTY_NAME)%', '%env(SERVICE_PROPERTY_VALUE)%') + ->addMethodCall('%env(SERVICE_METHOD_NAME)%', ['%env(SERVICE_METHOD_ARGUMENT)%']) + ->setFactory('%env(SERVICE_FACTORY)%') + ->setConfigurator('%env(SERVICE_CONFIGURATOR)%') + ->setPublic(true) + ; + $container->compile(); + $dumper = new YamlDumper($container); + + $this->assertEquals(file_get_contents(self::$fixturesPath.'/yaml/container_with_env_placeholders.yml'), $dumper->dump()); + } + private function assertEqualYamlStructure(string $expected, string $yaml, string $message = '') { $parser = new Parser(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/container_with_env_placeholders.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/container_with_env_placeholders.yml new file mode 100644 index 0000000000000..46c91130faecd --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/container_with_env_placeholders.yml @@ -0,0 +1,19 @@ +parameters: + '%env(PARAMETER_NAME)%': '%env(PARAMETER_VALUE)%' + +services: + service_container: + class: Symfony\Component\DependencyInjection\ContainerInterface + public: true + synthetic: true + service: + class: '%env(SERVICE_CLASS)%' + public: true + file: '%env(SERVICE_FILE)%' + arguments: ['%env(SERVICE_ARGUMENT)%'] + properties: { '%env(SERVICE_PROPERTY_NAME)%': '%env(SERVICE_PROPERTY_VALUE)%' } + calls: + - ['%env(SERVICE_METHOD_NAME)%', ['%env(SERVICE_METHOD_ARGUMENT)%']] + + factory: '%env(SERVICE_FACTORY)%' + configurator: '%env(SERVICE_CONFIGURATOR)%' diff --git a/src/Symfony/Component/DependencyInjection/composer.json b/src/Symfony/Component/DependencyInjection/composer.json index 460751088f451..7b1e731b7d2eb 100644 --- a/src/Symfony/Component/DependencyInjection/composer.json +++ b/src/Symfony/Component/DependencyInjection/composer.json @@ -20,12 +20,12 @@ "psr/container": "^1.1|^2.0", "symfony/deprecation-contracts": "^2.5|^3", "symfony/service-contracts": "^3.5", - "symfony/var-exporter": "^6.4.20|^7.2.5" + "symfony/var-exporter": "^6.4.20|^7.2.5|^8.0" }, "require-dev": { - "symfony/yaml": "^6.4|^7.0", - "symfony/config": "^6.4|^7.0", - "symfony/expression-language": "^6.4|^7.0" + "symfony/yaml": "^6.4|^7.0|^8.0", + "symfony/config": "^6.4|^7.0|^8.0", + "symfony/expression-language": "^6.4|^7.0|^8.0" }, "conflict": { "ext-psr": "<1.1|>=2", diff --git a/src/Symfony/Component/DomCrawler/composer.json b/src/Symfony/Component/DomCrawler/composer.json index c47482794d0a0..0e5c984d09be2 100644 --- a/src/Symfony/Component/DomCrawler/composer.json +++ b/src/Symfony/Component/DomCrawler/composer.json @@ -22,7 +22,7 @@ "masterminds/html5": "^2.6" }, "require-dev": { - "symfony/css-selector": "^6.4|^7.0" + "symfony/css-selector": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\DomCrawler\\": "" }, diff --git a/src/Symfony/Component/Dotenv/README.md b/src/Symfony/Component/Dotenv/README.md index 2a1cc02ccfcb8..67ff66a07a802 100644 --- a/src/Symfony/Component/Dotenv/README.md +++ b/src/Symfony/Component/Dotenv/README.md @@ -11,6 +11,15 @@ Getting Started composer require symfony/dotenv ``` +Usage +----- + +> For an .env file with this format: + +```env +YOUR_VARIABLE_NAME=my-string +``` + ```php use Symfony\Component\Dotenv\Dotenv; @@ -25,6 +34,12 @@ $dotenv->overload(__DIR__.'/.env'); // loads .env, .env.local, and .env.$APP_ENV.local or .env.$APP_ENV $dotenv->loadEnv(__DIR__.'/.env'); + +// Usage with $_ENV +$envVariable = $_ENV['YOUR_VARIABLE_NAME']; + +// Usage with $_SERVER +$envVariable = $_SERVER['YOUR_VARIABLE_NAME']; ``` Resources diff --git a/src/Symfony/Component/Dotenv/composer.json b/src/Symfony/Component/Dotenv/composer.json index 34c4718a76aeb..fe887ff0a31c5 100644 --- a/src/Symfony/Component/Dotenv/composer.json +++ b/src/Symfony/Component/Dotenv/composer.json @@ -19,8 +19,8 @@ "php": ">=8.2" }, "require-dev": { - "symfony/console": "^6.4|^7.0", - "symfony/process": "^6.4|^7.0" + "symfony/console": "^6.4|^7.0|^8.0", + "symfony/process": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/console": "<6.4", diff --git a/src/Symfony/Component/Emoji/Resources/bin/composer.json b/src/Symfony/Component/Emoji/Resources/bin/composer.json index 29bf4d6466941..a120970a9bfb9 100644 --- a/src/Symfony/Component/Emoji/Resources/bin/composer.json +++ b/src/Symfony/Component/Emoji/Resources/bin/composer.json @@ -15,9 +15,9 @@ ], "minimum-stability": "dev", "require": { - "symfony/filesystem": "^6.4|^7.0", - "symfony/finder": "^6.4|^7.0", - "symfony/var-exporter": "^6.4|^7.0", + "symfony/filesystem": "^6.4|^7.0|^8.0", + "symfony/finder": "^6.4|^7.0|^8.0", + "symfony/var-exporter": "^6.4|^7.0|^8.0", "unicode-org/cldr": "*" } } diff --git a/src/Symfony/Component/Emoji/composer.json b/src/Symfony/Component/Emoji/composer.json index 9d9414c224aac..d4a6a083a108b 100644 --- a/src/Symfony/Component/Emoji/composer.json +++ b/src/Symfony/Component/Emoji/composer.json @@ -20,9 +20,9 @@ "ext-intl": "*" }, "require-dev": { - "symfony/filesystem": "^7.1", - "symfony/finder": "^6.4|^7.0", - "symfony/var-exporter": "^6.4|^7.0" + "symfony/filesystem": "^7.1|^8.0", + "symfony/finder": "^6.4|^7.0|^8.0", + "symfony/var-exporter": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Emoji\\": "" }, diff --git a/src/Symfony/Component/ErrorHandler/ErrorRenderer/HtmlErrorRenderer.php b/src/Symfony/Component/ErrorHandler/ErrorRenderer/HtmlErrorRenderer.php index d0d1246a1ddbd..7bd9a083e53a4 100644 --- a/src/Symfony/Component/ErrorHandler/ErrorRenderer/HtmlErrorRenderer.php +++ b/src/Symfony/Component/ErrorHandler/ErrorRenderer/HtmlErrorRenderer.php @@ -233,6 +233,10 @@ private function formatFile(string $file, int $line, ?string $text = null): stri $text .= ' at line '.$line; } + if (!file_exists($file)) { + return $text; + } + $link = $this->fileLinkFormat->format($file, $line); return \sprintf('%s', $this->escape($link), $text); diff --git a/src/Symfony/Component/ErrorHandler/composer.json b/src/Symfony/Component/ErrorHandler/composer.json index 98b94328364e8..dc56a36e414d0 100644 --- a/src/Symfony/Component/ErrorHandler/composer.json +++ b/src/Symfony/Component/ErrorHandler/composer.json @@ -18,12 +18,12 @@ "require": { "php": ">=8.2", "psr/log": "^1|^2|^3", - "symfony/var-dumper": "^6.4|^7.0" + "symfony/var-dumper": "^6.4|^7.0|^8.0" }, "require-dev": { - "symfony/console": "^6.4|^7.0", - "symfony/http-kernel": "^6.4|^7.0", - "symfony/serializer": "^6.4|^7.0", + "symfony/console": "^6.4|^7.0|^8.0", + "symfony/http-kernel": "^6.4|^7.0|^8.0", + "symfony/serializer": "^6.4|^7.0|^8.0", "symfony/deprecation-contracts": "^2.5|^3", "symfony/webpack-encore-bundle": "^1.0|^2.0" }, diff --git a/src/Symfony/Component/EventDispatcher/composer.json b/src/Symfony/Component/EventDispatcher/composer.json index 598bbdc5489a4..d125e7608f25f 100644 --- a/src/Symfony/Component/EventDispatcher/composer.json +++ b/src/Symfony/Component/EventDispatcher/composer.json @@ -20,13 +20,13 @@ "symfony/event-dispatcher-contracts": "^2.5|^3" }, "require-dev": { - "symfony/dependency-injection": "^6.4|^7.0", - "symfony/expression-language": "^6.4|^7.0", - "symfony/config": "^6.4|^7.0", - "symfony/error-handler": "^6.4|^7.0", - "symfony/http-foundation": "^6.4|^7.0", + "symfony/dependency-injection": "^6.4|^7.0|^8.0", + "symfony/expression-language": "^6.4|^7.0|^8.0", + "symfony/config": "^6.4|^7.0|^8.0", + "symfony/error-handler": "^6.4|^7.0|^8.0", + "symfony/http-foundation": "^6.4|^7.0|^8.0", "symfony/service-contracts": "^2.5|^3", - "symfony/stopwatch": "^6.4|^7.0", + "symfony/stopwatch": "^6.4|^7.0|^8.0", "psr/log": "^1|^2|^3" }, "conflict": { diff --git a/src/Symfony/Component/ExpressionLanguage/composer.json b/src/Symfony/Component/ExpressionLanguage/composer.json index e24a315dae873..e3989cdefbf08 100644 --- a/src/Symfony/Component/ExpressionLanguage/composer.json +++ b/src/Symfony/Component/ExpressionLanguage/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": ">=8.2", - "symfony/cache": "^6.4|^7.0", + "symfony/cache": "^6.4|^7.0|^8.0", "symfony/deprecation-contracts": "^2.5|^3", "symfony/service-contracts": "^2.5|^3" }, diff --git a/src/Symfony/Component/Filesystem/composer.json b/src/Symfony/Component/Filesystem/composer.json index c781e55b18438..42bbfa08a7a00 100644 --- a/src/Symfony/Component/Filesystem/composer.json +++ b/src/Symfony/Component/Filesystem/composer.json @@ -21,7 +21,7 @@ "symfony/polyfill-mbstring": "~1.8" }, "require-dev": { - "symfony/process": "^6.4|^7.0" + "symfony/process": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Filesystem\\": "" }, diff --git a/src/Symfony/Component/Finder/composer.json b/src/Symfony/Component/Finder/composer.json index 2b70600d097cd..52bdb48162417 100644 --- a/src/Symfony/Component/Finder/composer.json +++ b/src/Symfony/Component/Finder/composer.json @@ -19,7 +19,7 @@ "php": ">=8.2" }, "require-dev": { - "symfony/filesystem": "^6.4|^7.0" + "symfony/filesystem": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Finder\\": "" }, diff --git a/src/Symfony/Component/Form/CHANGELOG.md b/src/Symfony/Component/Form/CHANGELOG.md index 00d3b2fc4027b..b74d43e79d23f 100644 --- a/src/Symfony/Component/Form/CHANGELOG.md +++ b/src/Symfony/Component/Form/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +7.4 +--- + + * Add `input=date_point` to `DateTimeType`, `DateType` and `TimeType` + 7.3 --- diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/DatePointToDateTimeTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DatePointToDateTimeTransformer.php new file mode 100644 index 0000000000000..dc1f7506822f9 --- /dev/null +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DatePointToDateTimeTransformer.php @@ -0,0 +1,64 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form\Extension\Core\DataTransformer; + +use Symfony\Component\Clock\DatePoint; +use Symfony\Component\Form\DataTransformerInterface; +use Symfony\Component\Form\Exception\TransformationFailedException; + +/** + * Transforms between a DatePoint object and a DateTime object. + * + * @implements DataTransformerInterface + */ +final class DatePointToDateTimeTransformer implements DataTransformerInterface +{ + /** + * Transforms a DatePoint into a DateTime object. + * + * @param DatePoint|null $value A DatePoint object + * + * @throws TransformationFailedException If the given value is not a DatePoint + */ + public function transform(mixed $value): ?\DateTime + { + if (null === $value) { + return null; + } + + if (!$value instanceof DatePoint) { + throw new TransformationFailedException(\sprintf('Expected a "%s".', DatePoint::class)); + } + + return \DateTime::createFromImmutable($value); + } + + /** + * Transforms a DateTime object into a DatePoint object. + * + * @param \DateTime|null $value A DateTime object + * + * @throws TransformationFailedException If the given value is not a \DateTime + */ + public function reverseTransform(mixed $value): ?DatePoint + { + if (null === $value) { + return null; + } + + if (!$value instanceof \DateTime) { + throw new TransformationFailedException('Expected a \DateTime.'); + } + + return DatePoint::createFromMutable($value); + } +} diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformer.php index e9c9cb9e55259..a0b3434a6b828 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformer.php @@ -39,14 +39,14 @@ public function __construct( /** * Transforms a normalized format into a localized money string. * - * @param int|float|null $value Normalized number + * @param int|float|string|null $value Normalized number * * @throws TransformationFailedException if the given value is not numeric or * if the value cannot be transformed */ public function transform(mixed $value): string { - if (null !== $value && 1 !== $this->divisor) { + if (null !== $value && '' !== $value && 1 !== $this->divisor) { if (!is_numeric($value)) { throw new TransformationFailedException('Expected a numeric.'); } diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php index 3020dd1483c28..ffcbc1feee6d7 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php @@ -41,14 +41,14 @@ public function __construct( /** * Transforms a number type into localized number. * - * @param int|float|null $value Number value + * @param int|float|string|null $value Number value * * @throws TransformationFailedException if the given value is not numeric * or if the value cannot be transformed */ public function transform(mixed $value): string { - if (null === $value) { + if (null === $value || '' === $value) { return ''; } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php b/src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php index cf4c2b7416be9..8ecaa63c078b8 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php @@ -11,10 +11,12 @@ namespace Symfony\Component\Form\Extension\Core\Type; +use Symfony\Component\Clock\DatePoint; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Exception\LogicException; use Symfony\Component\Form\Extension\Core\DataTransformer\ArrayToPartsTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DataTransformerChain; +use Symfony\Component\Form\Extension\Core\DataTransformer\DatePointToDateTimeTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeImmutableToDateTimeTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToHtml5LocalDateTimeTransformer; @@ -178,7 +180,12 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ; } - if ('datetime_immutable' === $options['input']) { + if ('date_point' === $options['input']) { + if (!class_exists(DatePoint::class)) { + throw new LogicException(\sprintf('The "symfony/clock" component is required to use "%s" with option "input=date_point". Try running "composer require symfony/clock".', self::class)); + } + $builder->addModelTransformer(new DatePointToDateTimeTransformer()); + } elseif ('datetime_immutable' === $options['input']) { $builder->addModelTransformer(new DateTimeImmutableToDateTimeTransformer()); } elseif ('string' === $options['input']) { $builder->addModelTransformer(new ReversedTransformer( @@ -194,7 +201,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void )); } - if (\in_array($options['input'], ['datetime', 'datetime_immutable'], true) && null !== $options['model_timezone']) { + if (\in_array($options['input'], ['datetime', 'datetime_immutable', 'date_point'], true) && null !== $options['model_timezone']) { $builder->addEventListener(FormEvents::POST_SET_DATA, static function (FormEvent $event) use ($options): void { $date = $event->getData(); @@ -283,6 +290,7 @@ public function configureOptions(OptionsResolver $resolver): void $resolver->setAllowedValues('input', [ 'datetime', 'datetime_immutable', + 'date_point', 'string', 'timestamp', 'array', diff --git a/src/Symfony/Component/Form/Extension/Core/Type/DateType.php b/src/Symfony/Component/Form/Extension/Core/Type/DateType.php index 36b430e144b58..5c8dfaa3c2b10 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/DateType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/DateType.php @@ -11,8 +11,10 @@ namespace Symfony\Component\Form\Extension\Core\Type; +use Symfony\Component\Clock\DatePoint; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Exception\LogicException; +use Symfony\Component\Form\Extension\Core\DataTransformer\DatePointToDateTimeTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeImmutableToDateTimeTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToLocalizedStringTransformer; @@ -156,7 +158,12 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ; } - if ('datetime_immutable' === $options['input']) { + if ('date_point' === $options['input']) { + if (!class_exists(DatePoint::class)) { + throw new LogicException(\sprintf('The "symfony/clock" component is required to use "%s" with option "input=date_point". Try running "composer require symfony/clock".', self::class)); + } + $builder->addModelTransformer(new DatePointToDateTimeTransformer()); + } elseif ('datetime_immutable' === $options['input']) { $builder->addModelTransformer(new DateTimeImmutableToDateTimeTransformer()); } elseif ('string' === $options['input']) { $builder->addModelTransformer(new ReversedTransformer( @@ -172,7 +179,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void )); } - if (\in_array($options['input'], ['datetime', 'datetime_immutable'], true) && null !== $options['model_timezone']) { + if (\in_array($options['input'], ['datetime', 'datetime_immutable', 'date_point'], true) && null !== $options['model_timezone']) { $builder->addEventListener(FormEvents::POST_SET_DATA, static function (FormEvent $event) use ($options): void { $date = $event->getData(); @@ -298,6 +305,7 @@ public function configureOptions(OptionsResolver $resolver): void $resolver->setAllowedValues('input', [ 'datetime', 'datetime_immutable', + 'date_point', 'string', 'timestamp', 'array', diff --git a/src/Symfony/Component/Form/Extension/Core/Type/TimeType.php b/src/Symfony/Component/Form/Extension/Core/Type/TimeType.php index 92cf42d963e74..1622301aed631 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/TimeType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/TimeType.php @@ -11,9 +11,11 @@ namespace Symfony\Component\Form\Extension\Core\Type; +use Symfony\Component\Clock\DatePoint; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Exception\InvalidConfigurationException; use Symfony\Component\Form\Exception\LogicException; +use Symfony\Component\Form\Extension\Core\DataTransformer\DatePointToDateTimeTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeImmutableToDateTimeTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer; @@ -190,7 +192,12 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $builder->addViewTransformer(new DateTimeToArrayTransformer($options['model_timezone'], $options['view_timezone'], $parts, 'text' === $options['widget'], $options['reference_date'])); } - if ('datetime_immutable' === $options['input']) { + if ('date_point' === $options['input']) { + if (!class_exists(DatePoint::class)) { + throw new LogicException(\sprintf('The "symfony/clock" component is required to use "%s" with option "input=date_point". Try running "composer require symfony/clock".', self::class)); + } + $builder->addModelTransformer(new DatePointToDateTimeTransformer()); + } elseif ('datetime_immutable' === $options['input']) { $builder->addModelTransformer(new DateTimeImmutableToDateTimeTransformer()); } elseif ('string' === $options['input']) { $builder->addModelTransformer(new ReversedTransformer( @@ -206,7 +213,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void )); } - if (\in_array($options['input'], ['datetime', 'datetime_immutable'], true) && null !== $options['model_timezone']) { + if (\in_array($options['input'], ['datetime', 'datetime_immutable', 'date_point'], true) && null !== $options['model_timezone']) { $builder->addEventListener(FormEvents::POST_SET_DATA, static function (FormEvent $event) use ($options): void { $date = $event->getData(); @@ -354,6 +361,7 @@ public function configureOptions(OptionsResolver $resolver): void $resolver->setAllowedValues('input', [ 'datetime', 'datetime_immutable', + 'date_point', 'string', 'timestamp', 'array', diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformerTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformerTest.php index e5733ad96abb5..689c6f0d4da32 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformerTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformerTest.php @@ -54,6 +54,13 @@ public function testTransformExpectsNumeric() $transformer->transform('abcd'); } + public function testTransformEmptyString() + { + $transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100); + + $this->assertSame('', $transformer->transform('')); + } + public function testTransformEmpty() { $transformer = new MoneyToLocalizedStringTransformer(); diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php index 37448db51030a..c0344b9f232ea 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php @@ -49,6 +49,7 @@ public static function provideTransformations() { return [ [null, '', 'de_AT'], + ['', '', 'de_AT'], [1, '1', 'de_AT'], [1.5, '1,5', 'de_AT'], [1234.5, '1234,5', 'de_AT'], diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php index 5067bb05e7258..e655af51f7cef 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Form\Tests\Extension\Core\Type; +use Symfony\Component\Clock\DatePoint; use Symfony\Component\Form\Exception\LogicException; use Symfony\Component\Form\Extension\Core\Type\DateTimeType; use Symfony\Component\Form\FormError; @@ -62,6 +63,37 @@ public function testSubmitDateTime() $this->assertEquals($dateTime, $form->getData()); } + public function testSubmitDatePoint() + { + $form = $this->factory->create(static::TESTED_TYPE, null, [ + 'model_timezone' => 'UTC', + 'view_timezone' => 'UTC', + 'date_widget' => 'choice', + 'years' => [2010], + 'time_widget' => 'choice', + 'input' => 'date_point', + ]); + + $input = [ + 'date' => [ + 'day' => '2', + 'month' => '6', + 'year' => '2010', + ], + 'time' => [ + 'hour' => '3', + 'minute' => '4', + ], + ]; + + $form->submit($input); + + $this->assertInstanceOf(DatePoint::class, $form->getData()); + $datePoint = DatePoint::createFromMutable(new \DateTime('2010-06-02 03:04:00 UTC')); + $this->assertEquals($datePoint, $form->getData()); + $this->assertEquals($input, $form->getViewData()); + } + public function testSubmitDateTimeImmutable() { $form = $this->factory->create(static::TESTED_TYPE, null, [ diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php index 5f4f896b5daed..b2af6f4bf8b13 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Form\Tests\Extension\Core\Type; +use Symfony\Component\Clock\DatePoint; use Symfony\Component\Form\ChoiceList\View\ChoiceView; use Symfony\Component\Form\Exception\LogicException; use Symfony\Component\Form\Extension\Core\Type\DateType; @@ -115,6 +116,27 @@ public function testSubmitFromSingleTextDateTime() $this->assertEquals('02.06.2010', $form->getViewData()); } + public function testSubmitFromSingleTextDatePoint() + { + if (!class_exists(DatePoint::class)) { + self::markTestSkipped('The DatePoint class is not available.'); + } + + $form = $this->factory->create(static::TESTED_TYPE, null, [ + 'html5' => false, + 'model_timezone' => 'UTC', + 'view_timezone' => 'UTC', + 'widget' => 'single_text', + 'input' => 'date_point', + ]); + + $form->submit('2010-06-02'); + + $this->assertInstanceOf(DatePoint::class, $form->getData()); + $this->assertEquals(DatePoint::createFromMutable(new \DateTime('2010-06-02 UTC')), $form->getData()); + $this->assertEquals('2010-06-02', $form->getViewData()); + } + public function testSubmitFromSingleTextDateTimeImmutable() { // we test against "de_DE", so we need the full implementation diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php index 8a2baf1b4c708..6711fa55b6322 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Form\Tests\Extension\Core\Type; +use Symfony\Component\Clock\DatePoint; use Symfony\Component\Form\ChoiceList\View\ChoiceView; use Symfony\Component\Form\Exception\InvalidConfigurationException; use Symfony\Component\Form\Exception\LogicException; @@ -45,6 +46,32 @@ public function testSubmitDateTime() $this->assertEquals($input, $form->getViewData()); } + public function testSubmitDatePoint() + { + if (!class_exists(DatePoint::class)) { + self::markTestSkipped('The DatePoint class is not available.'); + } + + $form = $this->factory->create(static::TESTED_TYPE, null, [ + 'model_timezone' => 'UTC', + 'view_timezone' => 'UTC', + 'widget' => 'choice', + 'input' => 'date_point', + ]); + + $input = [ + 'hour' => '3', + 'minute' => '4', + ]; + + $form->submit($input); + + $this->assertInstanceOf(DatePoint::class, $form->getData()); + $datePoint = DatePoint::createFromMutable(new \DateTime('1970-01-01 03:04:00 UTC')); + $this->assertEquals($datePoint, $form->getData()); + $this->assertEquals($input, $form->getViewData()); + } + public function testSubmitDateTimeImmutable() { $form = $this->factory->create(static::TESTED_TYPE, null, [ diff --git a/src/Symfony/Component/Form/composer.json b/src/Symfony/Component/Form/composer.json index f4403ba74d878..8ed9a50124d6f 100644 --- a/src/Symfony/Component/Form/composer.json +++ b/src/Symfony/Component/Form/composer.json @@ -18,30 +18,31 @@ "require": { "php": ">=8.2", "symfony/deprecation-contracts": "^2.5|^3", - "symfony/event-dispatcher": "^6.4|^7.0", - "symfony/options-resolver": "^7.3", + "symfony/event-dispatcher": "^6.4|^7.0|^8.0", + "symfony/options-resolver": "^7.3|^8.0", "symfony/polyfill-ctype": "~1.8", "symfony/polyfill-intl-icu": "^1.21", "symfony/polyfill-mbstring": "~1.0", - "symfony/property-access": "^6.4|^7.0", + "symfony/property-access": "^6.4|^7.0|^8.0", "symfony/service-contracts": "^2.5|^3" }, "require-dev": { "doctrine/collections": "^1.0|^2.0", - "symfony/validator": "^6.4|^7.0", - "symfony/dependency-injection": "^6.4|^7.0", - "symfony/expression-language": "^6.4|^7.0", - "symfony/config": "^6.4|^7.0", - "symfony/console": "^6.4|^7.0", - "symfony/html-sanitizer": "^6.4|^7.0", - "symfony/http-foundation": "^6.4|^7.0", - "symfony/http-kernel": "^6.4|^7.0", - "symfony/intl": "^6.4|^7.0", - "symfony/security-core": "^6.4|^7.0", - "symfony/security-csrf": "^6.4|^7.0", - "symfony/translation": "^6.4.3|^7.0.3", - "symfony/var-dumper": "^6.4|^7.0", - "symfony/uid": "^6.4|^7.0" + "symfony/validator": "^6.4|^7.0|^8.0", + "symfony/dependency-injection": "^6.4|^7.0|^8.0", + "symfony/expression-language": "^6.4|^7.0|^8.0", + "symfony/clock": "^6.4|^7.0|^8.0", + "symfony/config": "^6.4|^7.0|^8.0", + "symfony/console": "^6.4|^7.0|^8.0", + "symfony/html-sanitizer": "^6.4|^7.0|^8.0", + "symfony/http-foundation": "^6.4|^7.0|^8.0", + "symfony/http-kernel": "^6.4|^7.0|^8.0", + "symfony/intl": "^6.4|^7.0|^8.0", + "symfony/security-core": "^6.4|^7.0|^8.0", + "symfony/security-csrf": "^6.4|^7.0|^8.0", + "symfony/translation": "^6.4.3|^7.0.3|^8.0", + "symfony/var-dumper": "^6.4|^7.0|^8.0", + "symfony/uid": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/console": "<6.4", diff --git a/src/Symfony/Component/HttpClient/AmpHttpClient.php b/src/Symfony/Component/HttpClient/AmpHttpClient.php index 4c73fbaf3db24..b45229fa8d6b9 100644 --- a/src/Symfony/Component/HttpClient/AmpHttpClient.php +++ b/src/Symfony/Component/HttpClient/AmpHttpClient.php @@ -33,7 +33,7 @@ use Symfony\Contracts\Service\ResetInterface; if (!interface_exists(DelegateHttpClient::class)) { - throw new \LogicException('You cannot use "Symfony\Component\HttpClient\AmpHttpClient" as the "amphp/http-client" package is not installed. Try running "composer require amphp/http-client:^4.2.1".'); + throw new \LogicException('You cannot use "Symfony\Component\HttpClient\AmpHttpClient" as the "amphp/http-client" package is not installed. Try running "composer require amphp/http-client:^5".'); } if (\PHP_VERSION_ID < 80400 && is_subclass_of(Request::class, HttpMessage::class)) { @@ -78,6 +78,9 @@ public function __construct(array $defaultOptions = [], ?callable $clientConfigu if (is_subclass_of(Request::class, HttpMessage::class)) { $this->multi = new AmpClientStateV5($clientConfigurator, $maxHostConnections, $maxPendingPushes, $this->logger); } else { + if (\PHP_VERSION_ID >= 80400) { + trigger_deprecation('symfony/http-client', '7.4', 'Using amphp/http-client < 5 is deprecated. Try running "composer require amphp/http-client:^5".'); + } $this->multi = new AmpClientStateV4($clientConfigurator, $maxHostConnections, $maxPendingPushes, $this->logger); } } diff --git a/src/Symfony/Component/HttpClient/CHANGELOG.md b/src/Symfony/Component/HttpClient/CHANGELOG.md index 40dc2ec5d5445..8a44989783c8d 100644 --- a/src/Symfony/Component/HttpClient/CHANGELOG.md +++ b/src/Symfony/Component/HttpClient/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +7.4 +--- + + * Deprecate using amphp/http-client < 5 + 7.3 --- diff --git a/src/Symfony/Component/HttpClient/HttpClient.php b/src/Symfony/Component/HttpClient/HttpClient.php index 3eb3665614fd7..27659358bce4c 100644 --- a/src/Symfony/Component/HttpClient/HttpClient.php +++ b/src/Symfony/Component/HttpClient/HttpClient.php @@ -62,7 +62,7 @@ public static function create(array $defaultOptions = [], int $maxHostConnection return new AmpHttpClient($defaultOptions, null, $maxHostConnections, $maxPendingPushes); } - @trigger_error((\extension_loaded('curl') ? 'Upgrade' : 'Install').' the curl extension or run "composer require amphp/http-client:^4.2.1" to perform async HTTP operations, including full HTTP/2 support', \E_USER_NOTICE); + @trigger_error((\extension_loaded('curl') ? 'Upgrade' : 'Install').' the curl extension or run "composer require amphp/http-client:^5" to perform async HTTP operations, including full HTTP/2 support', \E_USER_NOTICE); return new NativeHttpClient($defaultOptions, $maxHostConnections); } diff --git a/src/Symfony/Component/HttpClient/composer.json b/src/Symfony/Component/HttpClient/composer.json index 7ca008fd01f13..7d9e7dd287028 100644 --- a/src/Symfony/Component/HttpClient/composer.json +++ b/src/Symfony/Component/HttpClient/composer.json @@ -31,21 +31,21 @@ "require-dev": { "amphp/http-client": "^4.2.1|^5.0", "amphp/http-tunnel": "^1.0|^2.0", - "amphp/socket": "^1.1", "guzzlehttp/promises": "^1.4|^2.0", "nyholm/psr7": "^1.0", "php-http/httplug": "^1.0|^2.0", "psr/http-client": "^1.0", "symfony/amphp-http-client-meta": "^1.0|^2.0", - "symfony/dependency-injection": "^6.4|^7.0", - "symfony/http-kernel": "^6.4|^7.0", - "symfony/messenger": "^6.4|^7.0", - "symfony/process": "^6.4|^7.0", - "symfony/rate-limiter": "^6.4|^7.0", - "symfony/stopwatch": "^6.4|^7.0" + "symfony/dependency-injection": "^6.4|^7.0|^8.0", + "symfony/http-kernel": "^6.4|^7.0|^8.0", + "symfony/messenger": "^6.4|^7.0|^8.0", + "symfony/process": "^6.4|^7.0|^8.0", + "symfony/rate-limiter": "^6.4|^7.0|^8.0", + "symfony/stopwatch": "^6.4|^7.0|^8.0" }, "conflict": { "amphp/amp": "<2.5", + "amphp/socket": "<1.1", "php-http/discovery": "<1.15", "symfony/http-foundation": "<6.4" }, diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 9f421525dacd5..dba930a242672 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -1384,7 +1384,7 @@ public function isMethodCacheable(): bool public function getProtocolVersion(): ?string { if ($this->isFromTrustedProxy()) { - preg_match('~^(HTTP/)?([1-9]\.[0-9]) ~', $this->headers->get('Via') ?? '', $matches); + preg_match('~^(HTTP/)?([1-9]\.[0-9])\b~', $this->headers->get('Via') ?? '', $matches); if ($matches) { return 'HTTP/'.$matches[2]; diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index 84c8629db039c..5cfb980a7b43b 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -2417,6 +2417,8 @@ public static function protocolVersionProvider() 'trusted with via and protocol name' => ['HTTP/2.0', true, 'HTTP/1.0 fred, HTTP/1.1 nowhere.com (Apache/1.1)', 'HTTP/1.0'], 'trusted with broken via' => ['HTTP/2.0', true, 'HTTP/1^0 foo', 'HTTP/2.0'], 'trusted with partially-broken via' => ['HTTP/2.0', true, '1.0 fred, foo', 'HTTP/1.0'], + 'trusted with simple via' => ['HTTP/2.0', true, 'HTTP/1.0', 'HTTP/1.0'], + 'trusted with only version via' => ['HTTP/2.0', true, '1.0', 'HTTP/1.0'], ]; } diff --git a/src/Symfony/Component/HttpFoundation/composer.json b/src/Symfony/Component/HttpFoundation/composer.json index a86b21b7c728a..9fe4c1a4ba44a 100644 --- a/src/Symfony/Component/HttpFoundation/composer.json +++ b/src/Symfony/Component/HttpFoundation/composer.json @@ -24,13 +24,13 @@ "require-dev": { "doctrine/dbal": "^3.6|^4", "predis/predis": "^1.1|^2.0", - "symfony/cache": "^6.4.12|^7.1.5", - "symfony/clock": "^6.4|^7.0", - "symfony/dependency-injection": "^6.4|^7.0", - "symfony/http-kernel": "^6.4|^7.0", - "symfony/mime": "^6.4|^7.0", - "symfony/expression-language": "^6.4|^7.0", - "symfony/rate-limiter": "^6.4|^7.0" + "symfony/cache": "^6.4.12|^7.1.5|^8.0", + "symfony/clock": "^6.4|^7.0|^8.0", + "symfony/dependency-injection": "^6.4|^7.0|^8.0", + "symfony/http-kernel": "^6.4|^7.0|^8.0", + "symfony/mime": "^6.4|^7.0|^8.0", + "symfony/expression-language": "^6.4|^7.0|^8.0", + "symfony/rate-limiter": "^6.4|^7.0|^8.0" }, "conflict": { "doctrine/dbal": "<3.6", diff --git a/src/Symfony/Component/HttpKernel/CHANGELOG.md b/src/Symfony/Component/HttpKernel/CHANGELOG.md index 6bf1a60ebc6e2..5df71549449f3 100644 --- a/src/Symfony/Component/HttpKernel/CHANGELOG.md +++ b/src/Symfony/Component/HttpKernel/CHANGELOG.md @@ -4,11 +4,12 @@ CHANGELOG 7.3 --- + * Record a `waiting` trace in the `HttpCache` when the cache had to wait for another request to finish * Add `$key` argument to `#[MapQueryString]` that allows using a specific key for argument resolving * Support `Uid` in `#[MapQueryParameter]` * Add `ServicesResetterInterface`, implemented by `ServicesResetter` * Allow configuring the logging channel per type of exceptions in ErrorListener - + 7.2 --- diff --git a/src/Symfony/Component/HttpKernel/EventListener/CacheAttributeListener.php b/src/Symfony/Component/HttpKernel/EventListener/CacheAttributeListener.php index e913edf9e538a..436e031bbbcac 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/CacheAttributeListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/CacheAttributeListener.php @@ -165,7 +165,6 @@ public function onKernelResponse(ResponseEvent $event): void } if (true === $cache->noStore) { - $response->setPrivate(); $response->headers->addCacheControlDirective('no-store'); } diff --git a/src/Symfony/Component/HttpKernel/EventListener/ErrorListener.php b/src/Symfony/Component/HttpKernel/EventListener/ErrorListener.php index 18e8bff4413d8..2599b27de0c97 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/ErrorListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/ErrorListener.php @@ -161,15 +161,15 @@ public static function getSubscribedEvents(): array /** * Logs an exception. - * + * * @param ?string $logChannel */ protected function logException(\Throwable $exception, string $message, ?string $logLevel = null, /* ?string $logChannel = null */): void { $logChannel = (3 < \func_num_args() ? \func_get_arg(3) : null) ?? $this->resolveLogChannel($exception); - + $logLevel ??= $this->resolveLogLevel($exception); - + if(!$logger = $this->getLogger($logChannel)) { return; } @@ -218,7 +218,7 @@ protected function duplicateRequest(\Throwable $exception, Request $request): Re $attributes = [ '_controller' => $this->controller, 'exception' => $exception, - 'logger' => DebugLoggerConfigurator::getDebugLogger($this->getLogger($exception)), + 'logger' => DebugLoggerConfigurator::getDebugLogger($this->getLogger($this->resolveLogChannel($exception))), ]; $request = $request->duplicate(null, null, $attributes); $request->setMethod('GET'); diff --git a/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php b/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php index 3ef1b8dcb821f..d5ed6d65597ac 100644 --- a/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php +++ b/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php @@ -558,6 +558,8 @@ protected function lock(Request $request, Response $entry): bool return true; } + $this->record($request, 'waiting'); + // wait for the lock to be released if ($this->waitForLock($request)) { // replace the current entry with the fresh one diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index b5a41236d1899..49c6ecbac1cb1 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -73,15 +73,15 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl */ private static array $freshCache = []; - public const VERSION = '7.3.0-DEV'; - public const VERSION_ID = 70300; + public const VERSION = '7.4.0-DEV'; + public const VERSION_ID = 70400; public const MAJOR_VERSION = 7; - public const MINOR_VERSION = 3; + public const MINOR_VERSION = 4; public const RELEASE_VERSION = 0; public const EXTRA_VERSION = 'DEV'; - public const END_OF_MAINTENANCE = '05/2025'; - public const END_OF_LIFE = '01/2026'; + public const END_OF_MAINTENANCE = '11/2028'; + public const END_OF_LIFE = '11/2029'; public function __construct( protected string $environment, diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/CacheAttributeListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/CacheAttributeListenerTest.php index b185ea8994b1f..d2c8ed0db63d5 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/CacheAttributeListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/CacheAttributeListenerTest.php @@ -102,18 +102,18 @@ public function testResponseIsPublicIfConfigurationIsPublicTrueNoStoreFalse() $this->assertFalse($this->response->headers->hasCacheControlDirective('no-store')); } - public function testResponseIsPrivateIfConfigurationIsPublicTrueNoStoreTrue() + public function testResponseKeepPublicIfConfigurationIsPublicTrueNoStoreTrue() { $request = $this->createRequest(new Cache(public: true, noStore: true)); $this->listener->onKernelResponse($this->createEventMock($request, $this->response)); - $this->assertFalse($this->response->headers->hasCacheControlDirective('public')); - $this->assertTrue($this->response->headers->hasCacheControlDirective('private')); + $this->assertTrue($this->response->headers->hasCacheControlDirective('public')); + $this->assertFalse($this->response->headers->hasCacheControlDirective('private')); $this->assertTrue($this->response->headers->hasCacheControlDirective('no-store')); } - public function testResponseIsPrivateNoStoreIfConfigurationIsNoStoreTrue() + public function testResponseKeepPrivateNoStoreIfConfigurationIsNoStoreTrue() { $request = $this->createRequest(new Cache(noStore: true)); @@ -124,14 +124,14 @@ public function testResponseIsPrivateNoStoreIfConfigurationIsNoStoreTrue() $this->assertTrue($this->response->headers->hasCacheControlDirective('no-store')); } - public function testResponseIsPrivateIfSharedMaxAgeSetAndNoStoreIsTrue() + public function testResponseIsPublicIfSharedMaxAgeSetAndNoStoreIsTrue() { $request = $this->createRequest(new Cache(smaxage: 1, noStore: true)); $this->listener->onKernelResponse($this->createEventMock($request, $this->response)); - $this->assertFalse($this->response->headers->hasCacheControlDirective('public')); - $this->assertTrue($this->response->headers->hasCacheControlDirective('private')); + $this->assertTrue($this->response->headers->hasCacheControlDirective('public')); + $this->assertFalse($this->response->headers->hasCacheControlDirective('private')); $this->assertTrue($this->response->headers->hasCacheControlDirective('no-store')); } diff --git a/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php b/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php index e82e8fd81b481..2b553dc875d39 100644 --- a/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php @@ -17,6 +17,7 @@ use Symfony\Component\HttpKernel\Event\TerminateEvent; use Symfony\Component\HttpKernel\HttpCache\Esi; use Symfony\Component\HttpKernel\HttpCache\HttpCache; +use Symfony\Component\HttpKernel\HttpCache\Store; use Symfony\Component\HttpKernel\HttpCache\StoreInterface; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\Kernel; @@ -662,6 +663,7 @@ public function testDegradationWhenCacheLocked() */ sleep(10); + $this->store = $this->createStore(); // create another store instance that does not hold the current lock $this->request('GET', '/'); $this->assertHttpKernelIsNotCalled(); $this->assertEquals(200, $this->response->getStatusCode()); @@ -680,6 +682,32 @@ public function testDegradationWhenCacheLocked() $this->assertEquals('Old response', $this->response->getContent()); } + public function testTraceAddedWhenCacheLocked() + { + if ('\\' === \DIRECTORY_SEPARATOR) { + $this->markTestSkipped('Skips on windows to avoid permissions issues.'); + } + + // Disable stale-while-revalidate, which circumvents blocking access + $this->cacheConfig['stale_while_revalidate'] = 0; + + // The presence of Last-Modified makes this cacheable + $this->setNextResponse(200, ['Cache-Control' => 'public, no-cache', 'Last-Modified' => 'some while ago'], 'Old response'); + $this->request('GET', '/'); // warm the cache + + $primedStore = $this->store; + + $this->store = $this->createMock(Store::class); + $this->store->method('lookup')->willReturnCallback(fn (Request $request) => $primedStore->lookup($request)); + // Assume the cache is locked at the first attempt, but immediately treat the lock as released afterwards + $this->store->method('lock')->willReturnOnConsecutiveCalls(false, true); + $this->store->method('isLocked')->willReturn(false); + + $this->request('GET', '/'); + + $this->assertTraceContains('waiting'); + } + public function testHitsCachedResponseWithSMaxAgeDirective() { $time = \DateTimeImmutable::createFromFormat('U', time() - 5); diff --git a/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTestCase.php b/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTestCase.php index 26a29f16b2b75..b05d9136661c3 100644 --- a/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTestCase.php +++ b/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTestCase.php @@ -30,7 +30,7 @@ abstract class HttpCacheTestCase extends TestCase protected $responses; protected $catch; protected $esi; - protected Store $store; + protected ?Store $store = null; protected function setUp(): void { @@ -115,7 +115,9 @@ public function request($method, $uri = '/', $server = [], $cookies = [], $esi = $this->kernel->reset(); - $this->store = new Store(sys_get_temp_dir().'/http_cache'); + if (!$this->store) { + $this->store = $this->createStore(); + } if (!isset($this->cacheConfig['debug'])) { $this->cacheConfig['debug'] = true; @@ -183,4 +185,9 @@ public static function clearDirectory($directory) closedir($fp); } + + protected function createStore(): Store + { + return new Store(sys_get_temp_dir().'/http_cache'); + } } diff --git a/src/Symfony/Component/HttpKernel/composer.json b/src/Symfony/Component/HttpKernel/composer.json index bb9f4ba6175de..e3a8b9657d9e7 100644 --- a/src/Symfony/Component/HttpKernel/composer.json +++ b/src/Symfony/Component/HttpKernel/composer.json @@ -18,34 +18,34 @@ "require": { "php": ">=8.2", "symfony/deprecation-contracts": "^2.5|^3", - "symfony/error-handler": "^6.4|^7.0", - "symfony/event-dispatcher": "^7.3", - "symfony/http-foundation": "^7.3", + "symfony/error-handler": "^6.4|^7.0|^8.0", + "symfony/event-dispatcher": "^7.3|^8.0", + "symfony/http-foundation": "^7.3|^8.0", "symfony/polyfill-ctype": "^1.8", "psr/log": "^1|^2|^3" }, "require-dev": { - "symfony/browser-kit": "^6.4|^7.0", - "symfony/clock": "^6.4|^7.0", - "symfony/config": "^6.4|^7.0", - "symfony/console": "^6.4|^7.0", - "symfony/css-selector": "^6.4|^7.0", - "symfony/dependency-injection": "^6.4|^7.0", - "symfony/dom-crawler": "^6.4|^7.0", - "symfony/expression-language": "^6.4|^7.0", - "symfony/finder": "^6.4|^7.0", + "symfony/browser-kit": "^6.4|^7.0|^8.0", + "symfony/clock": "^6.4|^7.0|^8.0", + "symfony/config": "^6.4|^7.0|^8.0", + "symfony/console": "^6.4|^7.0|^8.0", + "symfony/css-selector": "^6.4|^7.0|^8.0", + "symfony/dependency-injection": "^6.4|^7.0|^8.0", + "symfony/dom-crawler": "^6.4|^7.0|^8.0", + "symfony/expression-language": "^6.4|^7.0|^8.0", + "symfony/finder": "^6.4|^7.0|^8.0", "symfony/http-client-contracts": "^2.5|^3", - "symfony/process": "^6.4|^7.0", - "symfony/property-access": "^7.1", - "symfony/routing": "^6.4|^7.0", - "symfony/serializer": "^7.1", - "symfony/stopwatch": "^6.4|^7.0", - "symfony/translation": "^6.4|^7.0", + "symfony/process": "^6.4|^7.0|^8.0", + "symfony/property-access": "^7.1|^8.0", + "symfony/routing": "^6.4|^7.0|^8.0", + "symfony/serializer": "^7.1|^8.0", + "symfony/stopwatch": "^6.4|^7.0|^8.0", + "symfony/translation": "^6.4|^7.0|^8.0", "symfony/translation-contracts": "^2.5|^3", - "symfony/uid": "^6.4|^7.0", - "symfony/validator": "^6.4|^7.0", - "symfony/var-dumper": "^6.4|^7.0", - "symfony/var-exporter": "^6.4|^7.0", + "symfony/uid": "^6.4|^7.0|^8.0", + "symfony/validator": "^6.4|^7.0|^8.0", + "symfony/var-dumper": "^6.4|^7.0|^8.0", + "symfony/var-exporter": "^6.4|^7.0|^8.0", "psr/cache": "^1.0|^2.0|^3.0", "twig/twig": "^3.12" }, diff --git a/src/Symfony/Component/Intl/Data/Generator/RegionDataGenerator.php b/src/Symfony/Component/Intl/Data/Generator/RegionDataGenerator.php index 745e074157974..5d484edacc1b7 100644 --- a/src/Symfony/Component/Intl/Data/Generator/RegionDataGenerator.php +++ b/src/Symfony/Component/Intl/Data/Generator/RegionDataGenerator.php @@ -160,7 +160,7 @@ protected function generateDataForMeta(BundleEntryReaderInterface $reader, strin $alpha3ToAlpha2 = array_flip($alpha2ToAlpha3); asort($alpha3ToAlpha2); - $alpha2ToNumeric = $this->generateAlpha2ToNumericMapping($metadataBundle); + $alpha2ToNumeric = $this->generateAlpha2ToNumericMapping(array_flip($this->regionCodes), $metadataBundle); $numericToAlpha2 = []; foreach ($alpha2ToNumeric as $alpha2 => $numeric) { // Add underscore prefix to force keys with leading zeros to remain as string keys. @@ -231,7 +231,7 @@ private function generateAlpha2ToAlpha3Mapping(array $countries, ArrayAccessible return $alpha2ToAlpha3; } - private function generateAlpha2ToNumericMapping(ArrayAccessibleResourceBundle $metadataBundle): array + private function generateAlpha2ToNumericMapping(array $countries, ArrayAccessibleResourceBundle $metadataBundle): array { $aliases = iterator_to_array($metadataBundle['alias']['territory']); @@ -250,6 +250,10 @@ private function generateAlpha2ToNumericMapping(ArrayAccessibleResourceBundle $m continue; } + if (!isset($countries[$data['replacement']])) { + continue; + } + if ('deprecated' === $data['reason']) { continue; } diff --git a/src/Symfony/Component/Intl/Resources/data/currencies/en_NO.php b/src/Symfony/Component/Intl/Resources/data/currencies/en_NO.php new file mode 100644 index 0000000000000..dc28340678e53 --- /dev/null +++ b/src/Symfony/Component/Intl/Resources/data/currencies/en_NO.php @@ -0,0 +1,10 @@ + [ + 'NOK' => [ + 'kr', + 'Norwegian Krone', + ], + ], +]; diff --git a/src/Symfony/Component/Intl/Resources/data/regions/meta.php b/src/Symfony/Component/Intl/Resources/data/regions/meta.php index 1c9f233273af7..e0a99ccb7f5a8 100644 --- a/src/Symfony/Component/Intl/Resources/data/regions/meta.php +++ b/src/Symfony/Component/Intl/Resources/data/regions/meta.php @@ -755,7 +755,6 @@ 'ZWE' => 'ZW', ], 'Alpha2ToNumeric' => [ - 'AA' => '958', 'AD' => '020', 'AE' => '784', 'AF' => '004', @@ -943,18 +942,6 @@ 'PW' => '585', 'PY' => '600', 'QA' => '634', - 'QM' => '959', - 'QN' => '960', - 'QP' => '962', - 'QQ' => '963', - 'QR' => '964', - 'QS' => '965', - 'QT' => '966', - 'QV' => '968', - 'QW' => '969', - 'QX' => '970', - 'QY' => '971', - 'QZ' => '972', 'RE' => '638', 'RO' => '642', 'RS' => '688', @@ -1012,29 +999,6 @@ 'VU' => '548', 'WF' => '876', 'WS' => '882', - 'XC' => '975', - 'XD' => '976', - 'XE' => '977', - 'XF' => '978', - 'XG' => '979', - 'XH' => '980', - 'XI' => '981', - 'XJ' => '982', - 'XL' => '984', - 'XM' => '985', - 'XN' => '986', - 'XO' => '987', - 'XP' => '988', - 'XQ' => '989', - 'XR' => '990', - 'XS' => '991', - 'XT' => '992', - 'XU' => '993', - 'XV' => '994', - 'XW' => '995', - 'XX' => '996', - 'XY' => '997', - 'XZ' => '998', 'YE' => '887', 'YT' => '175', 'ZA' => '710', @@ -1042,7 +1006,6 @@ 'ZW' => '716', ], 'NumericToAlpha2' => [ - '_958' => 'AA', '_020' => 'AD', '_784' => 'AE', '_004' => 'AF', @@ -1230,18 +1193,6 @@ '_585' => 'PW', '_600' => 'PY', '_634' => 'QA', - '_959' => 'QM', - '_960' => 'QN', - '_962' => 'QP', - '_963' => 'QQ', - '_964' => 'QR', - '_965' => 'QS', - '_966' => 'QT', - '_968' => 'QV', - '_969' => 'QW', - '_970' => 'QX', - '_971' => 'QY', - '_972' => 'QZ', '_638' => 'RE', '_642' => 'RO', '_688' => 'RS', @@ -1299,29 +1250,6 @@ '_548' => 'VU', '_876' => 'WF', '_882' => 'WS', - '_975' => 'XC', - '_976' => 'XD', - '_977' => 'XE', - '_978' => 'XF', - '_979' => 'XG', - '_980' => 'XH', - '_981' => 'XI', - '_982' => 'XJ', - '_984' => 'XL', - '_985' => 'XM', - '_986' => 'XN', - '_987' => 'XO', - '_988' => 'XP', - '_989' => 'XQ', - '_990' => 'XR', - '_991' => 'XS', - '_992' => 'XT', - '_993' => 'XU', - '_994' => 'XV', - '_995' => 'XW', - '_996' => 'XX', - '_997' => 'XY', - '_998' => 'XZ', '_887' => 'YE', '_175' => 'YT', '_710' => 'ZA', diff --git a/src/Symfony/Component/Intl/Tests/CountriesTest.php b/src/Symfony/Component/Intl/Tests/CountriesTest.php index 7b921036b2a00..01f0f76f2e40a 100644 --- a/src/Symfony/Component/Intl/Tests/CountriesTest.php +++ b/src/Symfony/Component/Intl/Tests/CountriesTest.php @@ -527,7 +527,6 @@ class CountriesTest extends ResourceBundleTestCase ]; private const ALPHA2_TO_NUMERIC = [ - 'AA' => '958', 'AD' => '020', 'AE' => '784', 'AF' => '004', @@ -715,18 +714,6 @@ class CountriesTest extends ResourceBundleTestCase 'PW' => '585', 'PY' => '600', 'QA' => '634', - 'QM' => '959', - 'QN' => '960', - 'QP' => '962', - 'QQ' => '963', - 'QR' => '964', - 'QS' => '965', - 'QT' => '966', - 'QV' => '968', - 'QW' => '969', - 'QX' => '970', - 'QY' => '971', - 'QZ' => '972', 'RE' => '638', 'RO' => '642', 'RS' => '688', @@ -784,29 +771,6 @@ class CountriesTest extends ResourceBundleTestCase 'VU' => '548', 'WF' => '876', 'WS' => '882', - 'XC' => '975', - 'XD' => '976', - 'XE' => '977', - 'XF' => '978', - 'XG' => '979', - 'XH' => '980', - 'XI' => '981', - 'XJ' => '982', - 'XL' => '984', - 'XM' => '985', - 'XN' => '986', - 'XO' => '987', - 'XP' => '988', - 'XQ' => '989', - 'XR' => '990', - 'XS' => '991', - 'XT' => '992', - 'XU' => '993', - 'XV' => '994', - 'XW' => '995', - 'XX' => '996', - 'XY' => '997', - 'XZ' => '998', 'YE' => '887', 'YT' => '175', 'ZA' => '710', @@ -814,6 +778,19 @@ class CountriesTest extends ResourceBundleTestCase 'ZW' => '716', ]; + public function testAllGettersGenerateTheSameDataSetCount() + { + $alpha2Count = count(Countries::getCountryCodes()); + $alpha3Count = count(Countries::getAlpha3Codes()); + $numericCodesCount = count(Countries::getNumericCodes()); + $namesCount = count(Countries::getNames()); + + // we base all on Name count since it is the first to be generated + $this->assertEquals($namesCount, $alpha2Count, 'Alpha 2 count does not match'); + $this->assertEquals($namesCount, $alpha3Count, 'Alpha 3 count does not match'); + $this->assertEquals($namesCount, $numericCodesCount, 'Numeric codes count does not match'); + } + public function testGetCountryCodes() { $this->assertSame(self::COUNTRIES, Countries::getCountryCodes()); @@ -992,7 +969,7 @@ public function testGetNumericCode() public function testNumericCodeExists() { $this->assertTrue(Countries::numericCodeExists('250')); - $this->assertTrue(Countries::numericCodeExists('982')); + $this->assertTrue(Countries::numericCodeExists('008')); $this->assertTrue(Countries::numericCodeExists('716')); $this->assertTrue(Countries::numericCodeExists('036')); $this->assertFalse(Countries::numericCodeExists('667')); diff --git a/src/Symfony/Component/Intl/composer.json b/src/Symfony/Component/Intl/composer.json index b2101cfe5f728..34a948bc0a621 100644 --- a/src/Symfony/Component/Intl/composer.json +++ b/src/Symfony/Component/Intl/composer.json @@ -28,8 +28,8 @@ "symfony/deprecation-contracts": "^2.5|^3" }, "require-dev": { - "symfony/filesystem": "^6.4|^7.0", - "symfony/var-exporter": "^6.4|^7.0" + "symfony/filesystem": "^6.4|^7.0|^8.0", + "symfony/var-exporter": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/string": "<7.1" diff --git a/src/Symfony/Component/JsonPath/JsonCrawler.php b/src/Symfony/Component/JsonPath/JsonCrawler.php index 75c61e14f79d7..492f56e77bba7 100644 --- a/src/Symfony/Component/JsonPath/JsonCrawler.php +++ b/src/Symfony/Component/JsonPath/JsonCrawler.php @@ -222,7 +222,7 @@ private function evaluateBracket(string $expr, mixed $value): array throw new JsonCrawlerException($expr, 'Invalid filter expression'); } - // remove outrer filter parentheses + // remove outer filter parentheses $innerExpr = substr(substr($filterExpr, 1), 0, -1); return $this->evaluateFilter($innerExpr, $value); @@ -230,7 +230,7 @@ private function evaluateBracket(string $expr, mixed $value): array // quoted strings for object keys if (preg_match('/^([\'"])(.*)\1$/', $expr, $matches)) { - $key = stripslashes($matches[2]); + $key = JsonPathUtils::unescapeString($matches[2], $matches[1]); return \array_key_exists($key, $value) ? [$value[$key]] : []; } @@ -335,7 +335,7 @@ private function evaluateScalar(string $expr, array $context): mixed // string literals if (preg_match('/^([\'"])(.*)\1$/', $expr, $matches)) { - return $matches[2]; + return JsonPathUtils::unescapeString($matches[2], $matches[1]); } // current node references diff --git a/src/Symfony/Component/JsonPath/JsonCrawlerInterface.php b/src/Symfony/Component/JsonPath/JsonCrawlerInterface.php index 3e8a222f0ba8e..4859c2bde076b 100644 --- a/src/Symfony/Component/JsonPath/JsonCrawlerInterface.php +++ b/src/Symfony/Component/JsonPath/JsonCrawlerInterface.php @@ -25,7 +25,7 @@ interface JsonCrawlerInterface * @return list * * @throws InvalidArgumentException When the JSON string provided to the crawler cannot be decoded - * @throws JsonCrawlerException When a syntax error occurs in the provided JSON path + * @throws JsonCrawlerException When a syntax error occurs in the provided JSON path */ public function find(string|JsonPath $query): array; } diff --git a/src/Symfony/Component/JsonPath/JsonPath.php b/src/Symfony/Component/JsonPath/JsonPath.php index 1009369b0a56d..e36fc9ffd2ef1 100644 --- a/src/Symfony/Component/JsonPath/JsonPath.php +++ b/src/Symfony/Component/JsonPath/JsonPath.php @@ -30,7 +30,9 @@ public function __construct( public function key(string $key): static { - return new self($this->path.(str_ends_with($this->path, '..') ? '' : '.').$key); + $escaped = $this->escapeKey($key); + + return new self($this->path.'["'.$escaped.'"]'); } public function index(int $index): static @@ -80,4 +82,25 @@ public function __toString(): string { return $this->path; } + + private function escapeKey(string $key): string + { + $key = strtr($key, [ + '\\' => '\\\\', + '"' => '\\"', + "\n" => '\\n', + "\r" => '\\r', + "\t" => '\\t', + "\b" => '\\b', + "\f" => '\\f', + ]); + + for ($i = 0; $i <= 31; ++$i) { + if ($i < 8 || $i > 13) { + $key = str_replace(\chr($i), \sprintf('\\u%04x', $i), $key); + } + } + + return $key; + } } diff --git a/src/Symfony/Component/JsonPath/JsonPathUtils.php b/src/Symfony/Component/JsonPath/JsonPathUtils.php index b5ac2ae6b8d0a..6f971d20115b2 100644 --- a/src/Symfony/Component/JsonPath/JsonPathUtils.php +++ b/src/Symfony/Component/JsonPath/JsonPathUtils.php @@ -85,4 +85,78 @@ public static function findSmallestDeserializableStringAndPath(array $tokens, mi 'tokens' => $remainingTokens, ]; } + + public static function unescapeString(string $str, string $quoteChar): string + { + if ('"' === $quoteChar) { + // try JSON decoding first for unicode sequences + $jsonStr = '"'.$str.'"'; + $decoded = json_decode($jsonStr, true); + + if (null !== $decoded) { + return $decoded; + } + } + + $result = ''; + $length = \strlen($str); + + for ($i = 0; $i < $length; ++$i) { + if ('\\' === $str[$i] && $i + 1 < $length) { + $result .= match ($str[$i + 1]) { + '"' => '"', + "'" => "'", + '\\' => '\\', + '/' => '/', + 'b' => "\b", + 'f' => "\f", + 'n' => "\n", + 'r' => "\r", + 't' => "\t", + 'u' => self::unescapeUnicodeSequence($str, $length, $i), + default => $str[$i].$str[$i + 1], // keep the backslash + }; + + ++$i; + } else { + $result .= $str[$i]; + } + } + + return $result; + } + + private static function unescapeUnicodeSequence(string $str, int $length, int &$i): string + { + if ($i + 5 >= $length) { + // not enough characters for Unicode escape, treat as literal + return $str[$i]; + } + + $hex = substr($str, $i + 2, 4); + if (!ctype_xdigit($hex)) { + // invalid hex, treat as literal + return $str[$i]; + } + + $codepoint = hexdec($hex); + // looks like a valid Unicode codepoint, string length is sufficient and it starts with \u + if (0xD800 <= $codepoint && $codepoint <= 0xDBFF && $i + 11 < $length && '\\' === $str[$i + 6] && 'u' === $str[$i + 7]) { + $lowHex = substr($str, $i + 8, 4); + if (ctype_xdigit($lowHex)) { + $lowSurrogate = hexdec($lowHex); + if (0xDC00 <= $lowSurrogate && $lowSurrogate <= 0xDFFF) { + $codepoint = 0x10000 + (($codepoint & 0x3FF) << 10) + ($lowSurrogate & 0x3FF); + $i += 10; // skip surrogate pair + + return mb_chr($codepoint, 'UTF-8'); + } + } + } + + // single Unicode character or invalid surrogate, skip the sequence + $i += 4; + + return mb_chr($codepoint, 'UTF-8'); + } } diff --git a/src/Symfony/Component/JsonPath/Tests/JsonCrawlerTest.php b/src/Symfony/Component/JsonPath/Tests/JsonCrawlerTest.php index 6871a56511890..213ae06afa7db 100644 --- a/src/Symfony/Component/JsonPath/Tests/JsonCrawlerTest.php +++ b/src/Symfony/Component/JsonPath/Tests/JsonCrawlerTest.php @@ -49,6 +49,19 @@ public function testAllAuthors() ], $result); } + public function testAllAuthorsWithBrackets() + { + $result = self::getBookstoreCrawler()->find('$..["author"]'); + + $this->assertCount(4, $result); + $this->assertSame([ + 'Nigel Rees', + 'Evelyn Waugh', + 'Herman Melville', + 'J. R. R. Tolkien', + ], $result); + } + public function testAllThingsInStore() { $result = self::getBookstoreCrawler()->find('$.store.*'); @@ -58,6 +71,15 @@ public function testAllThingsInStore() $this->assertArrayHasKey('color', $result[1]); } + public function testAllThingsInStoreWithBrackets() + { + $result = self::getBookstoreCrawler()->find('$["store"][*]'); + + $this->assertCount(2, $result); + $this->assertCount(4, $result[0]); + $this->assertArrayHasKey('color', $result[1]); + } + public function testEscapedDoubleQuotesInFieldName() { $crawler = new JsonCrawler(<<assertSame('Nigel Rees', $result[0]['author']); } + public function testBasicNameSelectorWithBrackts() + { + $result = self::getBookstoreCrawler()->find('$["store"]["book"]')[0]; + + $this->assertCount(4, $result); + $this->assertSame('Nigel Rees', $result[0]['author']); + } + public function testAllPrices() { $result = self::getBookstoreCrawler()->find('$.store..price'); @@ -121,6 +151,17 @@ public function testBooksWithIsbn() ], [$result[0]['isbn'], $result[1]['isbn']]); } + public function testBooksWithBracketsAndFilter() + { + $result = self::getBookstoreCrawler()->find('$..["book"][?(@.isbn)]'); + + $this->assertCount(2, $result); + $this->assertSame([ + '0-553-21311-3', + '0-395-19395-8', + ], [$result[0]['isbn'], $result[1]['isbn']]); + } + public function testBooksLessThanTenDollars() { $result = self::getBookstoreCrawler()->find('$..book[?(@.price < 10)]'); @@ -216,6 +257,14 @@ public function testEverySecondElementReverseSlice() $this->assertSame([6, 2, 5], $result); } + public function testEverySecondElementReverseSliceAndBrackets() + { + $crawler = self::getSimpleCollectionCrawler(); + + $result = $crawler->find('$["a"][::-2]'); + $this->assertSame([6, 2, 5], $result); + } + public function testEmptyResults() { $crawler = self::getSimpleCollectionCrawler(); @@ -404,6 +453,264 @@ public function testAcceptsJsonPath() $this->assertSame('red', $result[0]['color']); } + public function testStarAsKey() + { + $crawler = new JsonCrawler(<<find('$["*"]'); + + $this->assertCount(1, $result); + $this->assertSame(['a' => 1, 'b' => 2], $result[0]); + } + + /** + * @dataProvider provideUnicodeEscapeSequencesProvider + */ + public function testUnicodeEscapeSequences(string $jsonPath, array $expected) + { + $this->assertSame($expected, self::getUnicodeDocumentCrawler()->find($jsonPath)); + } + + public static function provideUnicodeEscapeSequencesProvider(): array + { + return [ + [ + '$["caf\u00e9"]', + ['coffee'], + ], + [ + '$["\u65e5\u672c"]', + ['Japan'], + ], + [ + '$["M\u00fcller"]', + [], + ], + [ + '$["emoji\ud83d\ude00"]', + ['smiley'], + ], + [ + '$["tab\there"]', + ['with tab'], + ], + [ + '$["new\nline"]', + ['with newline'], + ], + [ + '$["quote\"here"]', + ['with quote'], + ], + [ + '$["backslash\\\\here"]', + ['with backslash'], + ], + [ + '$["apostrophe\'here"]', + ['with apostrophe'], + ], + [ + '$["control\u0001char"]', + ['with control char'], + ], + [ + '$["\u0063af\u00e9"]', + ['coffee'], + ], + ]; + } + + /** + * @dataProvider provideSingleQuotedStringProvider + */ + public function testSingleQuotedStrings(string $jsonPath, array $expected) + { + $this->assertSame($expected, self::getUnicodeDocumentCrawler()->find($jsonPath)); + } + + public static function provideSingleQuotedStringProvider(): array + { + return [ + [ + "$['caf\\u00e9']", + ['coffee'], + ], + [ + "$['\\u65e5\\u672c']", + ['Japan'], + ], + [ + "$['quote\"here']", + ['with quote'], + ], + [ + "$['M\\u00fcller']", + [], + ], + [ + "$['emoji\\ud83d\\ude00']", + ['smiley'], + ], + [ + "$['tab\\there']", + ['with tab'], + ], + [ + "$['quote\\\"here']", + ['with quote'], + ], + [ + "$['backslash\\\\here']", + ['with backslash'], + ], + [ + "$['apostrophe\\'here']", + ['with apostrophe'], + ], + [ + "$['control\\u0001char']", + ['with control char'], + ], + [ + "$['\\u0063af\\u00e9']", + ['coffee'], + ], + ]; + } + + /** + * @dataProvider provideFilterWithUnicodeProvider + */ + public function testFilterWithUnicodeStrings(string $jsonPath, int $expectedCount, string $expectedCountry) + { + $result = self::getUnicodeDocumentCrawler()->find($jsonPath); + + $this->assertCount($expectedCount, $result); + + if ($expectedCount > 0) { + $this->assertSame($expectedCountry, $result[0]['country']); + } + } + + public static function provideFilterWithUnicodeProvider(): array + { + return [ + [ + '$.users[?(@.name == "caf\u00e9")]', + 1, + 'France', + ], + [ + '$.users[?(@.name == "\u65e5\u672c\u592a\u90ce")]', + 1, + 'Japan', + ], + [ + '$.users[?(@.name == "Jos\u00e9")]', + 1, + 'Spain', + ], + [ + '$.users[?(@.name == "John")]', + 1, + 'USA', + ], + [ + '$.users[?(@.name == "NonExistent\u0020Name")]', + 0, + '', + ], + ]; + } + + /** + * @dataProvider provideInvalidUnicodeSequenceProvider + */ + public function testInvalidUnicodeSequencesAreProcessedAsLiterals(string $jsonPath) + { + $this->assertIsArray(self::getUnicodeDocumentCrawler()->find($jsonPath), 'invalid unicode sequence should be treated as literal and not throw'); + } + + public static function provideInvalidUnicodeSequenceProvider(): array + { + return [ + [ + '$["test\uZZZZ"]', + ], + [ + '$["test\u123"]', + ], + [ + '$["test\u"]', + ], + ]; + } + + /** + * @dataProvider provideComplexUnicodePath + */ + public function testComplexUnicodePaths(string $jsonPath, array $expected) + { + $complexJson = [ + 'データ' => [ + 'ユーザー' => [ + ['名前' => 'テスト', 'ID' => 1], + ['名前' => 'サンプル', 'ID' => 2], + ], + ], + 'special🔑' => [ + 'value💎' => 'treasure', + ], + ]; + + $crawler = new JsonCrawler(json_encode($complexJson)); + + $this->assertSame($expected, $crawler->find($jsonPath)); + } + + public static function provideComplexUnicodePath(): array + { + return [ + [ + '$["\u30c7\u30fc\u30bf"]["\u30e6\u30fc\u30b6\u30fc"][0]["\u540d\u524d"]', + ['テスト'], + ], + [ + '$["special\ud83d\udd11"]["value\ud83d\udc8e"]', + ['treasure'], + ], + [ + '$["\u30c7\u30fc\u30bf"]["\u30e6\u30fc\u30b6\u30fc"][*]["\u540d\u524d"]', + ['テスト', 'サンプル'], + ], + ]; + } + + public function testSurrogatePairHandling() + { + $json = ['𝒽𝑒𝓁𝓁𝑜' => 'mathematical script hello']; + $crawler = new JsonCrawler(json_encode($json)); + + // mathematical script "hello" requires surrogate pairs for each character + $result = $crawler->find('$["\ud835\udcbd\ud835\udc52\ud835\udcc1\ud835\udcc1\ud835\udc5c"]'); + $this->assertSame(['mathematical script hello'], $result); + } + + public function testMixedQuoteTypes() + { + $json = ['key"with"quotes' => 'value1', "key'with'apostrophes" => 'value2']; + $crawler = new JsonCrawler(json_encode($json)); + + $result = $crawler->find('$[\'key"with"quotes\']'); + $this->assertSame(['value1'], $result); + + $result = $crawler->find('$["key\'with\'apostrophes"]'); + $this->assertSame(['value2'], $result); + } + private static function getBookstoreCrawler(): JsonCrawler { return new JsonCrawler(<< 'coffee', + '日本' => 'Japan', + 'emoji😀' => 'smiley', + 'tab here' => 'with tab', + "new\nline" => 'with newline', + 'quote"here' => 'with quote', + 'backslash\\here' => 'with backslash', + 'apostrophe\'here' => 'with apostrophe', + "control\x01char" => 'with control char', + 'users' => [ + ['name' => 'café', 'country' => 'France'], + ['name' => '日本太郎', 'country' => 'Japan'], + ['name' => 'John', 'country' => 'USA'], + ['name' => 'Müller', 'country' => 'Germany'], + ['name' => 'José', 'country' => 'Spain'], + ], + ]; + + return new JsonCrawler(json_encode($json)); + } } diff --git a/src/Symfony/Component/JsonPath/Tests/JsonPathTest.php b/src/Symfony/Component/JsonPath/Tests/JsonPathTest.php index 52d05bdaeb813..cbe6f20d17c0b 100644 --- a/src/Symfony/Component/JsonPath/Tests/JsonPathTest.php +++ b/src/Symfony/Component/JsonPath/Tests/JsonPathTest.php @@ -23,8 +23,8 @@ public function testBuildPath() ->index(0) ->key('address'); - $this->assertSame('$.users[0].address', (string) $path); - $this->assertSame('$.users[0].address..city', (string) $path->deepScan()->key('city')); + $this->assertSame('$["users"][0]["address"]', (string) $path); + $this->assertSame('$["users"][0]["address"]..["city"]', (string) $path->deepScan()->key('city')); } public function testBuildWithFilter() @@ -33,7 +33,7 @@ public function testBuildWithFilter() $path = $path->key('users') ->filter('@.age > 18'); - $this->assertSame('$.users[?(@.age > 18)]', (string) $path); + $this->assertSame('$["users"][?(@.age > 18)]', (string) $path); } public function testAll() @@ -42,7 +42,7 @@ public function testAll() $path = $path->key('users') ->all(); - $this->assertSame('$.users[*]', (string) $path); + $this->assertSame('$["users"][*]', (string) $path); } public function testFirst() @@ -51,7 +51,7 @@ public function testFirst() $path = $path->key('users') ->first(); - $this->assertSame('$.users[0]', (string) $path); + $this->assertSame('$["users"][0]', (string) $path); } public function testLast() @@ -60,6 +60,47 @@ public function testLast() $path = $path->key('users') ->last(); - $this->assertSame('$.users[-1]', (string) $path); + $this->assertSame('$["users"][-1]', (string) $path); + } + + /** + * @dataProvider provideKeysToEscape + */ + public function testEscapedKey(string $key, string $expectedPath) + { + $path = new JsonPath(); + $path = $path->key($key); + + $this->assertSame($expectedPath, (string) $path); + } + + public static function provideKeysToEscape(): iterable + { + yield ['simple_key', '$["simple_key"]']; + yield ['key"with"quotes', '$["key\\"with\\"quotes"]']; + yield ['path\\backslash', '$["path\\backslash"]']; + yield ['mixed\\"case', '$["mixed\\\\\\"case"]']; + yield ['unicode_🔑', '$["unicode_🔑"]']; + yield ['"quotes_only"', '$["\\"quotes_only\\""]']; + yield ['\\\\multiple\\\\backslashes', '$["\\\\\\\\multiple\\\\\\backslashes"]']; + yield ["control\x00\x1f\x1echar", '$["control\u0000\u001f\u001echar"]']; + + yield ['key"with\\"mixed', '$["key\\"with\\\\\\"mixed"]']; + yield ['\\"complex\\"case\\"', '$["\\\\\\"complex\\\\\\"case\\\\\\""]']; + yield ['json_like":{"value":"test"}', '$["json_like\\":{\\"value\\":\\"test\\"}"]']; + yield ['C:\\Program Files\\"App Name"', '$["C:\\\\Program Files\\\\\\"App Name\\""]']; + + yield ['key_with_é_accents', '$["key_with_é_accents"]']; + yield ['unicode_→_arrows', '$["unicode_→_arrows"]']; + yield ['chinese_中文_key', '$["chinese_中文_key"]']; + + yield ['', '$[""]']; + yield [' ', '$[" "]']; + yield [' spaces ', '$[" spaces "]']; + yield ["\t\n\r", '$["\\t\\n\\r"]']; + yield ["control\x00char", '$["control\u0000char"]']; + yield ["newline\nkey", '$["newline\\nkey"]']; + yield ["tab\tkey", '$["tab\\tkey"]']; + yield ["carriage\rreturn", '$["carriage\\rreturn"]']; } } diff --git a/src/Symfony/Component/JsonPath/Tests/Test/JsonPathAssertionsTraitTest.php b/src/Symfony/Component/JsonPath/Tests/Test/JsonPathAssertionsTraitTest.php index 62d64b53e1e8d..1044e7658672b 100644 --- a/src/Symfony/Component/JsonPath/Tests/Test/JsonPathAssertionsTraitTest.php +++ b/src/Symfony/Component/JsonPath/Tests/Test/JsonPathAssertionsTraitTest.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\JsonPath\Tests\Test; use PHPUnit\Framework\AssertionFailedError; diff --git a/src/Symfony/Component/JsonPath/composer.json b/src/Symfony/Component/JsonPath/composer.json index 95b02675e7459..809739d2eaa11 100644 --- a/src/Symfony/Component/JsonPath/composer.json +++ b/src/Symfony/Component/JsonPath/composer.json @@ -17,10 +17,11 @@ ], "require": { "php": ">=8.2", + "symfony/polyfill-ctype": "^1.8", "symfony/polyfill-mbstring": "~1.0" }, "require-dev": { - "symfony/json-streamer": "^7.3" + "symfony/json-streamer": "^7.3|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\JsonPath\\": "" }, diff --git a/src/Symfony/Component/JsonStreamer/CHANGELOG.md b/src/Symfony/Component/JsonStreamer/CHANGELOG.md index 5294c5b5f3637..87f1e74c951da 100644 --- a/src/Symfony/Component/JsonStreamer/CHANGELOG.md +++ b/src/Symfony/Component/JsonStreamer/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +7.4 +--- + + * Remove `nikic/php-parser` dependency + 7.3 --- diff --git a/src/Symfony/Component/JsonStreamer/DataModel/DataAccessorInterface.php b/src/Symfony/Component/JsonStreamer/DataModel/DataAccessorInterface.php deleted file mode 100644 index 99f3dbfd0e9b8..0000000000000 --- a/src/Symfony/Component/JsonStreamer/DataModel/DataAccessorInterface.php +++ /dev/null @@ -1,29 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\JsonStreamer\DataModel; - -use PhpParser\Node\Expr; - -/** - * Represents a way to access data on PHP. - * - * @author Mathias Arlaud - * - * @internal - */ -interface DataAccessorInterface -{ - /** - * Converts to "nikic/php-parser" PHP expression. - */ - public function toPhpExpr(): Expr; -} diff --git a/src/Symfony/Component/JsonStreamer/DataModel/FunctionDataAccessor.php b/src/Symfony/Component/JsonStreamer/DataModel/FunctionDataAccessor.php deleted file mode 100644 index 8ad8960674d57..0000000000000 --- a/src/Symfony/Component/JsonStreamer/DataModel/FunctionDataAccessor.php +++ /dev/null @@ -1,57 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\JsonStreamer\DataModel; - -use PhpParser\BuilderFactory; -use PhpParser\Node\Expr; - -/** - * Defines the way to access data using a function (or a method). - * - * @author Mathias Arlaud - * - * @internal - */ -final class FunctionDataAccessor implements DataAccessorInterface -{ - /** - * @param list $arguments - */ - public function __construct( - private string $functionName, - private array $arguments, - private ?DataAccessorInterface $objectAccessor = null, - ) { - } - - public function getObjectAccessor(): ?DataAccessorInterface - { - return $this->objectAccessor; - } - - public function withObjectAccessor(?DataAccessorInterface $accessor): self - { - return new self($this->functionName, $this->arguments, $accessor); - } - - public function toPhpExpr(): Expr - { - $builder = new BuilderFactory(); - $arguments = array_map(static fn (DataAccessorInterface $argument): Expr => $argument->toPhpExpr(), $this->arguments); - - if (null === $this->objectAccessor) { - return $builder->funcCall($this->functionName, $arguments); - } - - return $builder->methodCall($this->objectAccessor->toPhpExpr(), $this->functionName, $arguments); - } -} diff --git a/src/Symfony/Component/JsonStreamer/DataModel/PhpExprDataAccessor.php b/src/Symfony/Component/JsonStreamer/DataModel/PhpExprDataAccessor.php deleted file mode 100644 index 9806b94ed0a9f..0000000000000 --- a/src/Symfony/Component/JsonStreamer/DataModel/PhpExprDataAccessor.php +++ /dev/null @@ -1,34 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\JsonStreamer\DataModel; - -use PhpParser\Node\Expr; - -/** - * Defines the way to access data using PHP AST. - * - * @author Mathias Arlaud - * - * @internal - */ -final class PhpExprDataAccessor implements DataAccessorInterface -{ - public function __construct( - private Expr $php, - ) { - } - - public function toPhpExpr(): Expr - { - return $this->php; - } -} diff --git a/src/Symfony/Component/JsonStreamer/DataModel/PropertyDataAccessor.php b/src/Symfony/Component/JsonStreamer/DataModel/PropertyDataAccessor.php deleted file mode 100644 index f48c98064bb65..0000000000000 --- a/src/Symfony/Component/JsonStreamer/DataModel/PropertyDataAccessor.php +++ /dev/null @@ -1,46 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\JsonStreamer\DataModel; - -use PhpParser\BuilderFactory; -use PhpParser\Node\Expr; - -/** - * Defines the way to access data using an object property. - * - * @author Mathias Arlaud - * - * @internal - */ -final class PropertyDataAccessor implements DataAccessorInterface -{ - public function __construct( - private DataAccessorInterface $objectAccessor, - private string $propertyName, - ) { - } - - public function getObjectAccessor(): DataAccessorInterface - { - return $this->objectAccessor; - } - - public function withObjectAccessor(DataAccessorInterface $accessor): self - { - return new self($accessor, $this->propertyName); - } - - public function toPhpExpr(): Expr - { - return (new BuilderFactory())->propertyFetch($this->objectAccessor->toPhpExpr(), $this->propertyName); - } -} diff --git a/src/Symfony/Component/JsonStreamer/DataModel/Read/ObjectNode.php b/src/Symfony/Component/JsonStreamer/DataModel/Read/ObjectNode.php index 25d53c15fff60..e1a7e68927a6e 100644 --- a/src/Symfony/Component/JsonStreamer/DataModel/Read/ObjectNode.php +++ b/src/Symfony/Component/JsonStreamer/DataModel/Read/ObjectNode.php @@ -11,7 +11,6 @@ namespace Symfony\Component\JsonStreamer\DataModel\Read; -use Symfony\Component\JsonStreamer\DataModel\DataAccessorInterface; use Symfony\Component\TypeInfo\Type\ObjectType; use Symfony\Component\TypeInfo\Type\UnionType; @@ -25,7 +24,7 @@ final class ObjectNode implements DataModelNodeInterface { /** - * @param array $properties + * @param array $properties */ public function __construct( private ObjectType $type, @@ -50,7 +49,7 @@ public function getType(): ObjectType } /** - * @return array + * @return array */ public function getProperties(): array { diff --git a/src/Symfony/Component/JsonStreamer/DataModel/ScalarDataAccessor.php b/src/Symfony/Component/JsonStreamer/DataModel/ScalarDataAccessor.php deleted file mode 100644 index f60220dd82e7a..0000000000000 --- a/src/Symfony/Component/JsonStreamer/DataModel/ScalarDataAccessor.php +++ /dev/null @@ -1,35 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\JsonStreamer\DataModel; - -use PhpParser\BuilderFactory; -use PhpParser\Node\Expr; - -/** - * Defines the way to access a scalar value. - * - * @author Mathias Arlaud - * - * @internal - */ -final class ScalarDataAccessor implements DataAccessorInterface -{ - public function __construct( - private mixed $value, - ) { - } - - public function toPhpExpr(): Expr - { - return (new BuilderFactory())->val($this->value); - } -} diff --git a/src/Symfony/Component/JsonStreamer/DataModel/VariableDataAccessor.php b/src/Symfony/Component/JsonStreamer/DataModel/VariableDataAccessor.php deleted file mode 100644 index 0046f55b4e7e0..0000000000000 --- a/src/Symfony/Component/JsonStreamer/DataModel/VariableDataAccessor.php +++ /dev/null @@ -1,35 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\JsonStreamer\DataModel; - -use PhpParser\BuilderFactory; -use PhpParser\Node\Expr; - -/** - * Defines the way to access data using a variable. - * - * @author Mathias Arlaud - * - * @internal - */ -final class VariableDataAccessor implements DataAccessorInterface -{ - public function __construct( - private string $name, - ) { - } - - public function toPhpExpr(): Expr - { - return (new BuilderFactory())->var($this->name); - } -} diff --git a/src/Symfony/Component/JsonStreamer/DataModel/Write/BackedEnumNode.php b/src/Symfony/Component/JsonStreamer/DataModel/Write/BackedEnumNode.php index ba96b98319d1e..5a3b74861c3cd 100644 --- a/src/Symfony/Component/JsonStreamer/DataModel/Write/BackedEnumNode.php +++ b/src/Symfony/Component/JsonStreamer/DataModel/Write/BackedEnumNode.php @@ -11,7 +11,6 @@ namespace Symfony\Component\JsonStreamer\DataModel\Write; -use Symfony\Component\JsonStreamer\DataModel\DataAccessorInterface; use Symfony\Component\TypeInfo\Type\BackedEnumType; /** @@ -26,12 +25,12 @@ final class BackedEnumNode implements DataModelNodeInterface { public function __construct( - private DataAccessorInterface $accessor, + private string $accessor, private BackedEnumType $type, ) { } - public function withAccessor(DataAccessorInterface $accessor): self + public function withAccessor(string $accessor): self { return new self($accessor, $this->type); } @@ -41,7 +40,7 @@ public function getIdentifier(): string return (string) $this->getType(); } - public function getAccessor(): DataAccessorInterface + public function getAccessor(): string { return $this->accessor; } diff --git a/src/Symfony/Component/JsonStreamer/DataModel/Write/CollectionNode.php b/src/Symfony/Component/JsonStreamer/DataModel/Write/CollectionNode.php index 2f324fb404908..a334437c6891b 100644 --- a/src/Symfony/Component/JsonStreamer/DataModel/Write/CollectionNode.php +++ b/src/Symfony/Component/JsonStreamer/DataModel/Write/CollectionNode.php @@ -11,7 +11,6 @@ namespace Symfony\Component\JsonStreamer\DataModel\Write; -use Symfony\Component\JsonStreamer\DataModel\DataAccessorInterface; use Symfony\Component\TypeInfo\Type\CollectionType; /** @@ -24,13 +23,13 @@ final class CollectionNode implements DataModelNodeInterface { public function __construct( - private DataAccessorInterface $accessor, + private string $accessor, private CollectionType $type, private DataModelNodeInterface $item, ) { } - public function withAccessor(DataAccessorInterface $accessor): self + public function withAccessor(string $accessor): self { return new self($accessor, $this->type, $this->item); } @@ -40,7 +39,7 @@ public function getIdentifier(): string return (string) $this->getType(); } - public function getAccessor(): DataAccessorInterface + public function getAccessor(): string { return $this->accessor; } diff --git a/src/Symfony/Component/JsonStreamer/DataModel/Write/CompositeNode.php b/src/Symfony/Component/JsonStreamer/DataModel/Write/CompositeNode.php index 705d610fe7932..2469fbfb0e14c 100644 --- a/src/Symfony/Component/JsonStreamer/DataModel/Write/CompositeNode.php +++ b/src/Symfony/Component/JsonStreamer/DataModel/Write/CompositeNode.php @@ -11,7 +11,6 @@ namespace Symfony\Component\JsonStreamer\DataModel\Write; -use Symfony\Component\JsonStreamer\DataModel\DataAccessorInterface; use Symfony\Component\JsonStreamer\Exception\InvalidArgumentException; use Symfony\Component\TypeInfo\Type; use Symfony\Component\TypeInfo\Type\UnionType; @@ -43,7 +42,7 @@ final class CompositeNode implements DataModelNodeInterface * @param list $nodes */ public function __construct( - private DataAccessorInterface $accessor, + private string $accessor, array $nodes, ) { if (\count($nodes) < 2) { @@ -60,7 +59,7 @@ public function __construct( $this->nodes = $nodes; } - public function withAccessor(DataAccessorInterface $accessor): self + public function withAccessor(string $accessor): self { return new self($accessor, array_map(static fn (DataModelNodeInterface $n): DataModelNodeInterface => $n->withAccessor($accessor), $this->nodes)); } @@ -70,7 +69,7 @@ public function getIdentifier(): string return (string) $this->getType(); } - public function getAccessor(): DataAccessorInterface + public function getAccessor(): string { return $this->accessor; } diff --git a/src/Symfony/Component/JsonStreamer/DataModel/Write/DataModelNodeInterface.php b/src/Symfony/Component/JsonStreamer/DataModel/Write/DataModelNodeInterface.php index fa94649cda40a..7768cd4179a85 100644 --- a/src/Symfony/Component/JsonStreamer/DataModel/Write/DataModelNodeInterface.php +++ b/src/Symfony/Component/JsonStreamer/DataModel/Write/DataModelNodeInterface.php @@ -11,7 +11,6 @@ namespace Symfony\Component\JsonStreamer\DataModel\Write; -use Symfony\Component\JsonStreamer\DataModel\DataAccessorInterface; use Symfony\Component\TypeInfo\Type; /** @@ -27,7 +26,7 @@ public function getIdentifier(): string; public function getType(): Type; - public function getAccessor(): DataAccessorInterface; + public function getAccessor(): string; - public function withAccessor(DataAccessorInterface $accessor): self; + public function withAccessor(string $accessor): self; } diff --git a/src/Symfony/Component/JsonStreamer/DataModel/Write/ObjectNode.php b/src/Symfony/Component/JsonStreamer/DataModel/Write/ObjectNode.php index 56dfcad38c0fe..1f8f79a171067 100644 --- a/src/Symfony/Component/JsonStreamer/DataModel/Write/ObjectNode.php +++ b/src/Symfony/Component/JsonStreamer/DataModel/Write/ObjectNode.php @@ -11,9 +11,6 @@ namespace Symfony\Component\JsonStreamer\DataModel\Write; -use Symfony\Component\JsonStreamer\DataModel\DataAccessorInterface; -use Symfony\Component\JsonStreamer\DataModel\FunctionDataAccessor; -use Symfony\Component\JsonStreamer\DataModel\PropertyDataAccessor; use Symfony\Component\TypeInfo\Type\ObjectType; /** @@ -29,29 +26,23 @@ final class ObjectNode implements DataModelNodeInterface * @param array $properties */ public function __construct( - private DataAccessorInterface $accessor, + private string $accessor, private ObjectType $type, private array $properties, private bool $mock = false, ) { } - public static function createMock(DataAccessorInterface $accessor, ObjectType $type): self + public static function createMock(string $accessor, ObjectType $type): self { return new self($accessor, $type, [], true); } - public function withAccessor(DataAccessorInterface $accessor): self + public function withAccessor(string $accessor): self { $properties = []; foreach ($this->properties as $key => $property) { - $propertyAccessor = $property->getAccessor(); - - if ($propertyAccessor instanceof PropertyDataAccessor || $propertyAccessor instanceof FunctionDataAccessor && $propertyAccessor->getObjectAccessor()) { - $propertyAccessor = $propertyAccessor->withObjectAccessor($accessor); - } - - $properties[$key] = $property->withAccessor($propertyAccessor); + $properties[$key] = $property->withAccessor(str_replace($this->accessor, $accessor, $property->getAccessor())); } return new self($accessor, $this->type, $properties, $this->mock); @@ -62,7 +53,7 @@ public function getIdentifier(): string return (string) $this->getType(); } - public function getAccessor(): DataAccessorInterface + public function getAccessor(): string { return $this->accessor; } diff --git a/src/Symfony/Component/JsonStreamer/DataModel/Write/ScalarNode.php b/src/Symfony/Component/JsonStreamer/DataModel/Write/ScalarNode.php index 53dc88b321d3f..d40319e0e5013 100644 --- a/src/Symfony/Component/JsonStreamer/DataModel/Write/ScalarNode.php +++ b/src/Symfony/Component/JsonStreamer/DataModel/Write/ScalarNode.php @@ -11,7 +11,6 @@ namespace Symfony\Component\JsonStreamer\DataModel\Write; -use Symfony\Component\JsonStreamer\DataModel\DataAccessorInterface; use Symfony\Component\TypeInfo\Type\BuiltinType; /** @@ -26,12 +25,12 @@ final class ScalarNode implements DataModelNodeInterface { public function __construct( - private DataAccessorInterface $accessor, + private string $accessor, private BuiltinType $type, ) { } - public function withAccessor(DataAccessorInterface $accessor): self + public function withAccessor(string $accessor): self { return new self($accessor, $this->type); } @@ -41,7 +40,7 @@ public function getIdentifier(): string return (string) $this->getType(); } - public function getAccessor(): DataAccessorInterface + public function getAccessor(): string { return $this->accessor; } diff --git a/src/Symfony/Component/JsonStreamer/JsonStreamReader.php b/src/Symfony/Component/JsonStreamer/JsonStreamReader.php index b2f2fabaa3dad..e813f4a8a5408 100644 --- a/src/Symfony/Component/JsonStreamer/JsonStreamReader.php +++ b/src/Symfony/Component/JsonStreamer/JsonStreamReader.php @@ -45,7 +45,7 @@ public function __construct( private ContainerInterface $valueTransformers, PropertyMetadataLoaderInterface $propertyMetadataLoader, string $streamReadersDir, - string $lazyGhostsDir, + ?string $lazyGhostsDir = null, ) { $this->streamReaderGenerator = new StreamReaderGenerator($propertyMetadataLoader, $streamReadersDir); $this->instantiator = new Instantiator(); diff --git a/src/Symfony/Component/JsonStreamer/Mapping/Read/DateTimeTypePropertyMetadataLoader.php b/src/Symfony/Component/JsonStreamer/Mapping/Read/DateTimeTypePropertyMetadataLoader.php index 11ce2b4f93962..26bc022cae2e3 100644 --- a/src/Symfony/Component/JsonStreamer/Mapping/Read/DateTimeTypePropertyMetadataLoader.php +++ b/src/Symfony/Component/JsonStreamer/Mapping/Read/DateTimeTypePropertyMetadataLoader.php @@ -38,7 +38,7 @@ public function load(string $className, array $options = [], array $context = [] $type = $metadata->getType(); if ($type instanceof ObjectType && is_a($type->getClassName(), \DateTimeInterface::class, true)) { - if (\DateTime::class === $type->getClassName()) { + if (is_a($type->getClassName(), \DateTime::class, true)) { throw new InvalidArgumentException('The "DateTime" class is not supported. Use "DateTimeImmutable" instead.'); } diff --git a/src/Symfony/Component/JsonStreamer/Read/PhpAstBuilder.php b/src/Symfony/Component/JsonStreamer/Read/PhpAstBuilder.php deleted file mode 100644 index 7a6e23762beca..0000000000000 --- a/src/Symfony/Component/JsonStreamer/Read/PhpAstBuilder.php +++ /dev/null @@ -1,590 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\JsonStreamer\Read; - -use PhpParser\BuilderFactory; -use PhpParser\Node; -use PhpParser\Node\Expr; -use PhpParser\Node\Expr\Array_; -use PhpParser\Node\Expr\ArrayDimFetch; -use PhpParser\Node\Expr\ArrayItem; -use PhpParser\Node\Expr\Assign; -use PhpParser\Node\Expr\BinaryOp\BooleanAnd; -use PhpParser\Node\Expr\BinaryOp\Coalesce; -use PhpParser\Node\Expr\BinaryOp\Identical; -use PhpParser\Node\Expr\BinaryOp\NotIdentical; -use PhpParser\Node\Expr\Cast\Object_ as ObjectCast; -use PhpParser\Node\Expr\Cast\String_ as StringCast; -use PhpParser\Node\Expr\ClassConstFetch; -use PhpParser\Node\Expr\Closure; -use PhpParser\Node\Expr\ClosureUse; -use PhpParser\Node\Expr\Match_; -use PhpParser\Node\Expr\Ternary; -use PhpParser\Node\Expr\Throw_; -use PhpParser\Node\Expr\Yield_; -use PhpParser\Node\Identifier; -use PhpParser\Node\MatchArm; -use PhpParser\Node\Name\FullyQualified; -use PhpParser\Node\Param; -use PhpParser\Node\Stmt; -use PhpParser\Node\Stmt\Expression; -use PhpParser\Node\Stmt\Foreach_; -use PhpParser\Node\Stmt\If_; -use PhpParser\Node\Stmt\Return_; -use Psr\Container\ContainerInterface; -use Symfony\Component\JsonStreamer\DataModel\PhpExprDataAccessor; -use Symfony\Component\JsonStreamer\DataModel\Read\BackedEnumNode; -use Symfony\Component\JsonStreamer\DataModel\Read\CollectionNode; -use Symfony\Component\JsonStreamer\DataModel\Read\CompositeNode; -use Symfony\Component\JsonStreamer\DataModel\Read\DataModelNodeInterface; -use Symfony\Component\JsonStreamer\DataModel\Read\ObjectNode; -use Symfony\Component\JsonStreamer\DataModel\Read\ScalarNode; -use Symfony\Component\JsonStreamer\Exception\LogicException; -use Symfony\Component\JsonStreamer\Exception\UnexpectedValueException; -use Symfony\Component\TypeInfo\Type\BackedEnumType; -use Symfony\Component\TypeInfo\Type\BuiltinType; -use Symfony\Component\TypeInfo\Type\CollectionType; -use Symfony\Component\TypeInfo\Type\ObjectType; -use Symfony\Component\TypeInfo\Type\WrappingTypeInterface; -use Symfony\Component\TypeInfo\TypeIdentifier; - -/** - * Builds a PHP syntax tree that reads JSON stream. - * - * @author Mathias Arlaud - * - * @internal - */ -final class PhpAstBuilder -{ - private BuilderFactory $builder; - - public function __construct() - { - $this->builder = new BuilderFactory(); - } - - /** - * @param array $options - * @param array $context - * - * @return list - */ - public function build(DataModelNodeInterface $dataModel, bool $decodeFromStream, array $options = [], array $context = []): array - { - if ($decodeFromStream) { - return [new Return_(new Closure([ - 'static' => true, - 'params' => [ - new Param($this->builder->var('stream'), type: new Identifier('mixed')), - new Param($this->builder->var('valueTransformers'), type: new FullyQualified(ContainerInterface::class)), - new Param($this->builder->var('instantiator'), type: new FullyQualified(LazyInstantiator::class)), - new Param($this->builder->var('options'), type: new Identifier('array')), - ], - 'returnType' => new Identifier('mixed'), - 'stmts' => [ - ...$this->buildProvidersStatements($dataModel, $decodeFromStream, $context), - new Return_( - $this->nodeOnlyNeedsDecode($dataModel, $decodeFromStream) - ? $this->builder->staticCall(new FullyQualified(Decoder::class), 'decodeStream', [ - $this->builder->var('stream'), - $this->builder->val(0), - $this->builder->val(null), - ]) - : $this->builder->funcCall(new ArrayDimFetch($this->builder->var('providers'), $this->builder->val($dataModel->getIdentifier())), [ - $this->builder->var('stream'), - $this->builder->val(0), - $this->builder->val(null), - ]), - ), - ], - ]))]; - } - - return [new Return_(new Closure([ - 'static' => true, - 'params' => [ - new Param($this->builder->var('string'), type: new Identifier('string|\\Stringable')), - new Param($this->builder->var('valueTransformers'), type: new FullyQualified(ContainerInterface::class)), - new Param($this->builder->var('instantiator'), type: new FullyQualified(Instantiator::class)), - new Param($this->builder->var('options'), type: new Identifier('array')), - ], - 'returnType' => new Identifier('mixed'), - 'stmts' => [ - ...$this->buildProvidersStatements($dataModel, $decodeFromStream, $context), - new Return_( - $this->nodeOnlyNeedsDecode($dataModel, $decodeFromStream) - ? $this->builder->staticCall(new FullyQualified(Decoder::class), 'decodeString', [new StringCast($this->builder->var('string'))]) - : $this->builder->funcCall(new ArrayDimFetch($this->builder->var('providers'), $this->builder->val($dataModel->getIdentifier())), [ - $this->builder->staticCall(new FullyQualified(Decoder::class), 'decodeString', [new StringCast($this->builder->var('string'))]), - ]), - ), - ], - ]))]; - } - - /** - * @param array $context - * - * @return list - */ - private function buildProvidersStatements(DataModelNodeInterface $node, bool $decodeFromStream, array &$context): array - { - if ($context['providers'][$node->getIdentifier()] ?? false) { - return []; - } - - $context['providers'][$node->getIdentifier()] = true; - - if ($this->nodeOnlyNeedsDecode($node, $decodeFromStream)) { - return []; - } - - return match (true) { - $node instanceof ScalarNode || $node instanceof BackedEnumNode => $this->buildLeafProviderStatements($node, $decodeFromStream), - $node instanceof CompositeNode => $this->buildCompositeNodeStatements($node, $decodeFromStream, $context), - $node instanceof CollectionNode => $this->buildCollectionNodeStatements($node, $decodeFromStream, $context), - $node instanceof ObjectNode => $this->buildObjectNodeStatements($node, $decodeFromStream, $context), - default => throw new LogicException(\sprintf('Unexpected "%s" data model node.', $node::class)), - }; - } - - /** - * @return list - */ - private function buildLeafProviderStatements(ScalarNode|BackedEnumNode $node, bool $decodeFromStream): array - { - $accessor = $decodeFromStream - ? $this->builder->staticCall(new FullyQualified(Decoder::class), 'decodeStream', [ - $this->builder->var('stream'), - $this->builder->var('offset'), - $this->builder->var('length'), - ]) - : $this->builder->var('data'); - - $params = $decodeFromStream - ? [new Param($this->builder->var('stream')), new Param($this->builder->var('offset')), new Param($this->builder->var('length'))] - : [new Param($this->builder->var('data'))]; - - return [ - new Expression(new Assign( - new ArrayDimFetch($this->builder->var('providers'), $this->builder->val($node->getIdentifier())), - new Closure([ - 'static' => true, - 'params' => $params, - 'stmts' => [new Return_($this->buildFormatValueStatement($node, $accessor))], - ]), - )), - ]; - } - - private function buildFormatValueStatement(DataModelNodeInterface $node, Expr $accessor): Node - { - if ($node instanceof BackedEnumNode) { - /** @var ObjectType $type */ - $type = $node->getType(); - - return $this->builder->staticCall(new FullyQualified($type->getClassName()), 'from', [$accessor]); - } - - if ($node instanceof ScalarNode) { - /** @var BuiltinType $type */ - $type = $node->getType(); - - return match (true) { - TypeIdentifier::NULL === $type->getTypeIdentifier() => $this->builder->val(null), - TypeIdentifier::OBJECT === $type->getTypeIdentifier() => new ObjectCast($accessor), - default => $accessor, - }; - } - - return $accessor; - } - - /** - * @param array $context - * - * @return list - */ - private function buildCompositeNodeStatements(CompositeNode $node, bool $decodeFromStream, array &$context): array - { - $prepareDataStmts = $decodeFromStream ? [ - new Expression(new Assign($this->builder->var('data'), $this->builder->staticCall(new FullyQualified(Decoder::class), 'decodeStream', [ - $this->builder->var('stream'), - $this->builder->var('offset'), - $this->builder->var('length'), - ]))), - ] : []; - - $providersStmts = []; - $nodesStmts = []; - - $nodeCondition = function (DataModelNodeInterface $node, Expr $accessor): Expr { - $type = $node->getType(); - - if ($type->isIdentifiedBy(TypeIdentifier::NULL)) { - return new Identical($this->builder->val(null), $this->builder->var('data')); - } - - if ($type->isIdentifiedBy(TypeIdentifier::TRUE)) { - return new Identical($this->builder->val(true), $this->builder->var('data')); - } - - if ($type->isIdentifiedBy(TypeIdentifier::FALSE)) { - return new Identical($this->builder->val(false), $this->builder->var('data')); - } - - if ($type->isIdentifiedBy(TypeIdentifier::MIXED)) { - return $this->builder->val(true); - } - - if ($type instanceof CollectionType) { - return $type->isList() - ? new BooleanAnd($this->builder->funcCall('\is_array', [$this->builder->var('data')]), $this->builder->funcCall('\array_is_list', [$this->builder->var('data')])) - : $this->builder->funcCall('\is_array', [$this->builder->var('data')]); - } - - while ($type instanceof WrappingTypeInterface) { - $type = $type->getWrappedType(); - } - - if ($type instanceof BackedEnumType) { - return $this->builder->funcCall('\is_'.$type->getBackingType()->getTypeIdentifier()->value, [$this->builder->var('data')]); - } - - if ($type instanceof ObjectType) { - return $this->builder->funcCall('\is_array', [$this->builder->var('data')]); - } - - if ($type instanceof BuiltinType) { - return $this->builder->funcCall('\is_'.$type->getTypeIdentifier()->value, [$this->builder->var('data')]); - } - - throw new LogicException(\sprintf('Unexpected "%s" type.', $type::class)); - }; - - foreach ($node->getNodes() as $n) { - if ($this->nodeOnlyNeedsDecode($n, $decodeFromStream)) { - $nodeValueStmt = $this->buildFormatValueStatement($n, $this->builder->var('data')); - } else { - $providersStmts = [...$providersStmts, ...$this->buildProvidersStatements($n, $decodeFromStream, $context)]; - $nodeValueStmt = $this->builder->funcCall( - new ArrayDimFetch($this->builder->var('providers'), $this->builder->val($n->getIdentifier())), - [$this->builder->var('data')], - ); - } - - $nodesStmts[] = new If_($nodeCondition($n, $this->builder->var('data')), ['stmts' => [new Return_($nodeValueStmt)]]); - } - - $params = $decodeFromStream - ? [new Param($this->builder->var('stream')), new Param($this->builder->var('offset')), new Param($this->builder->var('length'))] - : [new Param($this->builder->var('data'))]; - - return [ - ...$providersStmts, - new Expression(new Assign( - new ArrayDimFetch($this->builder->var('providers'), $this->builder->val($node->getIdentifier())), - new Closure([ - 'static' => true, - 'params' => $params, - 'uses' => [ - new ClosureUse($this->builder->var('options')), - new ClosureUse($this->builder->var('valueTransformers')), - new ClosureUse($this->builder->var('instantiator')), - new ClosureUse($this->builder->var('providers'), byRef: true), - ], - 'stmts' => [ - ...$prepareDataStmts, - ...$nodesStmts, - new Expression(new Throw_($this->builder->new(new FullyQualified(UnexpectedValueException::class), [$this->builder->funcCall('\sprintf', [ - $this->builder->val(\sprintf('Unexpected "%%s" value for "%s".', $node->getIdentifier())), - $this->builder->funcCall('\get_debug_type', [$this->builder->var('data')]), - ])]))), - ], - ]), - )), - ]; - } - - /** - * @param array $context - * - * @return list - */ - private function buildCollectionNodeStatements(CollectionNode $node, bool $decodeFromStream, array &$context): array - { - if ($decodeFromStream) { - $itemValueStmt = $this->nodeOnlyNeedsDecode($node->getItemNode(), $decodeFromStream) - ? $this->buildFormatValueStatement( - $node->getItemNode(), - $this->builder->staticCall(new FullyQualified(Decoder::class), 'decodeStream', [ - $this->builder->var('stream'), - new ArrayDimFetch($this->builder->var('v'), $this->builder->val(0)), - new ArrayDimFetch($this->builder->var('v'), $this->builder->val(1)), - ]), - ) - : $this->builder->funcCall( - new ArrayDimFetch($this->builder->var('providers'), $this->builder->val($node->getItemNode()->getIdentifier())), [ - $this->builder->var('stream'), - new ArrayDimFetch($this->builder->var('v'), $this->builder->val(0)), - new ArrayDimFetch($this->builder->var('v'), $this->builder->val(1)), - ], - ); - } else { - $itemValueStmt = $this->nodeOnlyNeedsDecode($node->getItemNode(), $decodeFromStream) - ? $this->builder->var('v') - : $this->builder->funcCall( - new ArrayDimFetch($this->builder->var('providers'), $this->builder->val($node->getItemNode()->getIdentifier())), - [$this->builder->var('v')], - ); - } - - $iterableClosureParams = $decodeFromStream - ? [new Param($this->builder->var('stream')), new Param($this->builder->var('data'))] - : [new Param($this->builder->var('data'))]; - - $iterableClosureStmts = [ - new Expression(new Assign( - $this->builder->var('iterable'), - new Closure([ - 'static' => true, - 'params' => $iterableClosureParams, - 'uses' => [ - new ClosureUse($this->builder->var('options')), - new ClosureUse($this->builder->var('valueTransformers')), - new ClosureUse($this->builder->var('instantiator')), - new ClosureUse($this->builder->var('providers'), byRef: true), - ], - 'stmts' => [ - new Foreach_($this->builder->var('data'), $this->builder->var('v'), [ - 'keyVar' => $this->builder->var('k'), - 'stmts' => [new Expression(new Yield_($itemValueStmt, $this->builder->var('k')))], - ]), - ], - ]), - )), - ]; - - $iterableValueStmt = $decodeFromStream - ? $this->builder->funcCall($this->builder->var('iterable'), [$this->builder->var('stream'), $this->builder->var('data')]) - : $this->builder->funcCall($this->builder->var('iterable'), [$this->builder->var('data')]); - - $prepareDataStmts = $decodeFromStream ? [ - new Expression(new Assign($this->builder->var('data'), $this->builder->staticCall( - new FullyQualified(Splitter::class), - $node->getType()->isList() ? 'splitList' : 'splitDict', - [$this->builder->var('stream'), $this->builder->var('offset'), $this->builder->var('length')], - ))), - ] : []; - - $params = $decodeFromStream - ? [new Param($this->builder->var('stream')), new Param($this->builder->var('offset')), new Param($this->builder->var('length'))] - : [new Param($this->builder->var('data'))]; - - return [ - new Expression(new Assign( - new ArrayDimFetch($this->builder->var('providers'), $this->builder->val($node->getIdentifier())), - new Closure([ - 'static' => true, - 'params' => $params, - 'uses' => [ - new ClosureUse($this->builder->var('options')), - new ClosureUse($this->builder->var('valueTransformers')), - new ClosureUse($this->builder->var('instantiator')), - new ClosureUse($this->builder->var('providers'), byRef: true), - ], - 'stmts' => [ - ...$prepareDataStmts, - ...$iterableClosureStmts, - new Return_($node->getType()->isIdentifiedBy(TypeIdentifier::ARRAY) ? $this->builder->funcCall('\iterator_to_array', [$iterableValueStmt]) : $iterableValueStmt), - ], - ]), - )), - ...($this->nodeOnlyNeedsDecode($node->getItemNode(), $decodeFromStream) ? [] : $this->buildProvidersStatements($node->getItemNode(), $decodeFromStream, $context)), - ]; - } - - /** - * @param array $context - * - * @return list - */ - private function buildObjectNodeStatements(ObjectNode $node, bool $decodeFromStream, array &$context): array - { - if ($node->isMock()) { - return []; - } - - $propertyValueProvidersStmts = []; - $stringPropertiesValuesStmts = []; - $streamPropertiesValuesStmts = []; - - foreach ($node->getProperties() as $streamedName => $property) { - $propertyValueProvidersStmts = [ - ...$propertyValueProvidersStmts, - ...($this->nodeOnlyNeedsDecode($property['value'], $decodeFromStream) ? [] : $this->buildProvidersStatements($property['value'], $decodeFromStream, $context)), - ]; - - if ($decodeFromStream) { - $propertyValueStmt = $this->nodeOnlyNeedsDecode($property['value'], $decodeFromStream) - ? $this->buildFormatValueStatement( - $property['value'], - $this->builder->staticCall(new FullyQualified(Decoder::class), 'decodeStream', [ - $this->builder->var('stream'), - new ArrayDimFetch($this->builder->var('v'), $this->builder->val(0)), - new ArrayDimFetch($this->builder->var('v'), $this->builder->val(1)), - ]), - ) - : $this->builder->funcCall( - new ArrayDimFetch($this->builder->var('providers'), $this->builder->val($property['value']->getIdentifier())), [ - $this->builder->var('stream'), - new ArrayDimFetch($this->builder->var('v'), $this->builder->val(0)), - new ArrayDimFetch($this->builder->var('v'), $this->builder->val(1)), - ], - ); - - $streamPropertiesValuesStmts[] = new MatchArm([$this->builder->val($streamedName)], new Assign( - $this->builder->propertyFetch($this->builder->var('object'), $property['name']), - $property['accessor'](new PhpExprDataAccessor($propertyValueStmt))->toPhpExpr(), - )); - } else { - $propertyValueStmt = $this->nodeOnlyNeedsDecode($property['value'], $decodeFromStream) - ? new Coalesce(new ArrayDimFetch($this->builder->var('data'), $this->builder->val($streamedName)), $this->builder->val('_symfony_missing_value')) - : new Ternary( - $this->builder->funcCall('\array_key_exists', [$this->builder->val($streamedName), $this->builder->var('data')]), - $this->builder->funcCall( - new ArrayDimFetch($this->builder->var('providers'), $this->builder->val($property['value']->getIdentifier())), - [new ArrayDimFetch($this->builder->var('data'), $this->builder->val($streamedName))], - ), - $this->builder->val('_symfony_missing_value'), - ); - - $stringPropertiesValuesStmts[] = new ArrayItem( - $property['accessor'](new PhpExprDataAccessor($propertyValueStmt))->toPhpExpr(), - $this->builder->val($property['name']), - ); - } - } - - $params = $decodeFromStream - ? [new Param($this->builder->var('stream')), new Param($this->builder->var('offset')), new Param($this->builder->var('length'))] - : [new Param($this->builder->var('data'))]; - - $prepareDataStmts = $decodeFromStream ? [ - new Expression(new Assign($this->builder->var('data'), $this->builder->staticCall( - new FullyQualified(Splitter::class), - 'splitDict', - [$this->builder->var('stream'), $this->builder->var('offset'), $this->builder->var('length')], - ))), - ] : []; - - if ($decodeFromStream) { - $instantiateStmts = [ - new Return_($this->builder->methodCall($this->builder->var('instantiator'), 'instantiate', [ - new ClassConstFetch(new FullyQualified($node->getType()->getClassName()), 'class'), - new Closure([ - 'static' => true, - 'params' => [new Param($this->builder->var('object'))], - 'uses' => [ - new ClosureUse($this->builder->var('stream')), - new ClosureUse($this->builder->var('data')), - new ClosureUse($this->builder->var('options')), - new ClosureUse($this->builder->var('valueTransformers')), - new ClosureUse($this->builder->var('instantiator')), - new ClosureUse($this->builder->var('providers'), byRef: true), - ], - 'stmts' => [ - new Foreach_($this->builder->var('data'), $this->builder->var('v'), [ - 'keyVar' => $this->builder->var('k'), - 'stmts' => [new Expression(new Match_( - $this->builder->var('k'), - [...$streamPropertiesValuesStmts, new MatchArm(null, $this->builder->val(null))], - ))], - ]), - ], - ]), - ])), - ]; - } else { - $instantiateStmts = [ - new Return_($this->builder->methodCall($this->builder->var('instantiator'), 'instantiate', [ - new ClassConstFetch(new FullyQualified($node->getType()->getClassName()), 'class'), - $this->builder->funcCall('\array_filter', [ - new Array_($stringPropertiesValuesStmts, ['kind' => Array_::KIND_SHORT]), - new Closure([ - 'static' => true, - 'params' => [new Param($this->builder->var('v'))], - 'stmts' => [new Return_(new NotIdentical($this->builder->val('_symfony_missing_value'), $this->builder->var('v')))], - ]), - ]), - ])), - ]; - } - - return [ - new Expression(new Assign( - new ArrayDimFetch($this->builder->var('providers'), $this->builder->val($node->getIdentifier())), - new Closure([ - 'static' => true, - 'params' => $params, - 'uses' => [ - new ClosureUse($this->builder->var('options')), - new ClosureUse($this->builder->var('valueTransformers')), - new ClosureUse($this->builder->var('instantiator')), - new ClosureUse($this->builder->var('providers'), byRef: true), - ], - 'stmts' => [ - ...$prepareDataStmts, - ...$instantiateStmts, - ], - ]), - )), - ...$propertyValueProvidersStmts, - ]; - } - - private function nodeOnlyNeedsDecode(DataModelNodeInterface $node, bool $decodeFromStream): bool - { - if ($node instanceof CompositeNode) { - foreach ($node->getNodes() as $n) { - if (!$this->nodeOnlyNeedsDecode($n, $decodeFromStream)) { - return false; - } - } - - return true; - } - - if ($node instanceof CollectionNode) { - if ($decodeFromStream) { - return false; - } - - return $this->nodeOnlyNeedsDecode($node->getItemNode(), $decodeFromStream); - } - - if ($node instanceof ObjectNode) { - return false; - } - - if ($node instanceof BackedEnumNode) { - return false; - } - - if ($node instanceof ScalarNode) { - return !$node->getType()->isIdentifiedBy(TypeIdentifier::OBJECT); - } - - return true; - } -} diff --git a/src/Symfony/Component/JsonStreamer/Read/PhpGenerator.php b/src/Symfony/Component/JsonStreamer/Read/PhpGenerator.php new file mode 100644 index 0000000000000..28a9cc9200121 --- /dev/null +++ b/src/Symfony/Component/JsonStreamer/Read/PhpGenerator.php @@ -0,0 +1,337 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\JsonStreamer\Read; + +use Psr\Container\ContainerInterface; +use Symfony\Component\JsonStreamer\DataModel\Read\BackedEnumNode; +use Symfony\Component\JsonStreamer\DataModel\Read\CollectionNode; +use Symfony\Component\JsonStreamer\DataModel\Read\CompositeNode; +use Symfony\Component\JsonStreamer\DataModel\Read\DataModelNodeInterface; +use Symfony\Component\JsonStreamer\DataModel\Read\ObjectNode; +use Symfony\Component\JsonStreamer\DataModel\Read\ScalarNode; +use Symfony\Component\JsonStreamer\Exception\LogicException; +use Symfony\Component\JsonStreamer\Exception\UnexpectedValueException; +use Symfony\Component\TypeInfo\Type\BackedEnumType; +use Symfony\Component\TypeInfo\Type\BuiltinType; +use Symfony\Component\TypeInfo\Type\CollectionType; +use Symfony\Component\TypeInfo\Type\ObjectType; +use Symfony\Component\TypeInfo\Type\WrappingTypeInterface; +use Symfony\Component\TypeInfo\TypeIdentifier; + +/** + * Generates PHP code that reads JSON stream. + * + * @author Mathias Arlaud + * + * @internal + */ +final class PhpGenerator +{ + /** + * @param array $options + * @param array $context + */ + public function generate(DataModelNodeInterface $dataModel, bool $decodeFromStream, array $options = [], array $context = []): string + { + $context['indentation_level'] = 1; + + $providers = $this->generateProviders($dataModel, $decodeFromStream, $context); + + $context['indentation_level'] = 0; + + if ($decodeFromStream) { + return $this->line('line('', $context) + .$this->line('return static function (mixed $stream, \\'.ContainerInterface::class.' $valueTransformers, \\'.LazyInstantiator::class.' $instantiator, array $options): mixed {', $context) + .$providers + .($this->canBeDecodedWithJsonDecode($dataModel, $decodeFromStream) + ? $this->line(' return \\'.Decoder::class.'::decodeStream($stream, 0, null);', $context) + : $this->line(' return $providers[\''.$dataModel->getIdentifier().'\']($stream, 0, null);', $context)) + .$this->line('};', $context); + } + + return $this->line('line('', $context) + .$this->line('return static function (string|\\Stringable $string, \\'.ContainerInterface::class.' $valueTransformers, \\'.Instantiator::class.' $instantiator, array $options): mixed {', $context) + .$providers + .($this->canBeDecodedWithJsonDecode($dataModel, $decodeFromStream) + ? $this->line(' return \\'.Decoder::class.'::decodeString((string) $string);', $context) + : $this->line(' return $providers[\''.$dataModel->getIdentifier().'\'](\\'.Decoder::class.'::decodeString((string) $string));', $context)) + .$this->line('};', $context); + } + + /** + * @param array $context + */ + private function generateProviders(DataModelNodeInterface $node, bool $decodeFromStream, array $context): string + { + if ($context['providers'][$node->getIdentifier()] ?? false) { + return ''; + } + + $context['providers'][$node->getIdentifier()] = true; + + if ($this->canBeDecodedWithJsonDecode($node, $decodeFromStream)) { + return ''; + } + + if ($node instanceof ScalarNode || $node instanceof BackedEnumNode) { + $accessor = $decodeFromStream ? '\\'.Decoder::class.'::decodeStream($stream, $offset, $length)' : '$data'; + $arguments = $decodeFromStream ? '$stream, $offset, $length' : '$data'; + + return $this->line("\$providers['".$node->getIdentifier()."'] = static function ($arguments) {", $context) + .$this->line(' return '.$this->generateValueFormat($node, $accessor).';', $context) + .$this->line('};', $context); + } + + if ($node instanceof CompositeNode) { + $php = ''; + foreach ($node->getNodes() as $n) { + if (!$this->canBeDecodedWithJsonDecode($n, $decodeFromStream)) { + $php .= $this->generateProviders($n, $decodeFromStream, $context); + } + } + + $arguments = $decodeFromStream ? '$stream, $offset, $length' : '$data'; + + $php .= $this->line("\$providers['".$node->getIdentifier()."'] = static function ($arguments) use (\$options, \$valueTransformers, \$instantiator, &\$providers) {", $context); + + ++$context['indentation_level']; + + $php .= $decodeFromStream ? $this->line('$data = \\'.Decoder::class.'::decodeStream($stream, $offset, $length);', $context) : ''; + + foreach ($node->getNodes() as $n) { + $value = $this->canBeDecodedWithJsonDecode($n, $decodeFromStream) ? $this->generateValueFormat($n, '$data') : '$providers[\''.$n->getIdentifier().'\']($data)'; + $php .= $this->line('if ('.$this->generateCompositeNodeItemCondition($n, '$data').') {', $context) + .$this->line(" return $value;", $context) + .$this->line('}', $context); + } + + $php .= $this->line('throw new \\'.UnexpectedValueException::class.'(\\sprintf(\'Unexpected "%s" value for "'.$node->getIdentifier().'".\', \\get_debug_type($data)));', $context); + + --$context['indentation_level']; + + return $php.$this->line('};', $context); + } + + if ($node instanceof CollectionNode) { + $arguments = $decodeFromStream ? '$stream, $offset, $length' : '$data'; + + $php = $this->line("\$providers['".$node->getIdentifier()."'] = static function ($arguments) use (\$options, \$valueTransformers, \$instantiator, &\$providers) {", $context); + + ++$context['indentation_level']; + + $arguments = $decodeFromStream ? '$stream, $data' : '$data'; + $php .= ($decodeFromStream ? $this->line('$data = \\'.Splitter::class.'::'.($node->getType()->isList() ? 'splitList' : 'splitDict').'($stream, $offset, $length);', $context) : '') + .$this->line("\$iterable = static function ($arguments) use (\$options, \$valueTransformers, \$instantiator, &\$providers) {", $context) + .$this->line(' foreach ($data as $k => $v) {', $context); + + if ($decodeFromStream) { + $php .= $this->canBeDecodedWithJsonDecode($node->getItemNode(), $decodeFromStream) + ? $this->line(' yield $k => '.$this->generateValueFormat($node->getItemNode(), '\\'.Decoder::class.'::decodeStream($stream, $v[0], $v[1]);'), $context) + : $this->line(' yield $k => $providers[\''.$node->getItemNode()->getIdentifier().'\']($stream, $v[0], $v[1]);', $context); + } else { + $php .= $this->canBeDecodedWithJsonDecode($node->getItemNode(), $decodeFromStream) + ? $this->line(' yield $k => $v;', $context) + : $this->line(' yield $k => $providers[\''.$node->getItemNode()->getIdentifier().'\']($v);', $context); + } + + $php .= $this->line(' }', $context) + .$this->line('};', $context) + .$this->line('return '.($node->getType()->isIdentifiedBy(TypeIdentifier::ARRAY) ? "\\iterator_to_array(\$iterable($arguments))" : "\$iterable($arguments)").';', $context); + + --$context['indentation_level']; + + $php .= $this->line('};', $context); + + if (!$this->canBeDecodedWithJsonDecode($node->getItemNode(), $decodeFromStream)) { + $php .= $this->generateProviders($node->getItemNode(), $decodeFromStream, $context); + } + + return $php; + } + + if ($node instanceof ObjectNode) { + if ($node->isMock()) { + return ''; + } + + $arguments = $decodeFromStream ? '$stream, $offset, $length' : '$data'; + + $php = $this->line("\$providers['".$node->getIdentifier()."'] = static function ($arguments) use (\$options, \$valueTransformers, \$instantiator, &\$providers) {", $context); + + ++$context['indentation_level']; + + $php .= $decodeFromStream ? $this->line('$data = \\'.Splitter::class.'::splitDict($stream, $offset, $length);', $context) : ''; + + if ($decodeFromStream) { + $php .= $this->line('return $instantiator->instantiate(\\'.$node->getType()->getClassName().'::class, static function ($object) use ($stream, $data, $options, $valueTransformers, $instantiator, &$providers) {', $context) + .$this->line(' foreach ($data as $k => $v) {', $context) + .$this->line(' match ($k) {', $context); + + foreach ($node->getProperties() as $streamedName => $property) { + $propertyValuePhp = $this->canBeDecodedWithJsonDecode($property['value'], $decodeFromStream) + ? $this->generateValueFormat($property['value'], '\\'.Decoder::class.'::decodeStream($stream, $v[0], $v[1])') + : '$providers[\''.$property['value']->getIdentifier().'\']($stream, $v[0], $v[1])'; + + $php .= $this->line(" '$streamedName' => \$object->".$property['name'].' = '.$property['accessor']($propertyValuePhp).',', $context); + } + + $php .= $this->line(' default => null,', $context) + .$this->line(' };', $context) + .$this->line(' }', $context) + .$this->line('});', $context); + } else { + $propertiesValuePhp = '['; + $separator = ''; + foreach ($node->getProperties() as $streamedName => $property) { + $propertyValuePhp = $this->canBeDecodedWithJsonDecode($property['value'], $decodeFromStream) + ? "\$data['$streamedName'] ?? '_symfony_missing_value'" + : "\\array_key_exists('$streamedName', \$data) ? \$providers['".$property['value']->getIdentifier()."'](\$data['$streamedName']) : '_symfony_missing_value'"; + $propertiesValuePhp .= "$separator'".$property['name']."' => ".$property['accessor']($propertyValuePhp); + $separator = ', '; + } + $propertiesValuePhp .= ']'; + + $php .= $this->line('return $instantiator->instantiate(\\'.$node->getType()->getClassName()."::class, \\array_filter($propertiesValuePhp, static function (\$v) {", $context) + .$this->line(' return \'_symfony_missing_value\' !== $v;', $context) + .$this->line('}));', $context); + } + + --$context['indentation_level']; + + $php .= $this->line('};', $context); + + foreach ($node->getProperties() as $streamedName => $property) { + if (!$this->canBeDecodedWithJsonDecode($property['value'], $decodeFromStream)) { + $php .= $this->generateProviders($property['value'], $decodeFromStream, $context); + } + } + + return $php; + } + + throw new LogicException(\sprintf('Unexpected "%s" data model node.', $node::class)); + } + + private function generateValueFormat(DataModelNodeInterface $node, string $accessor): string + { + if ($node instanceof BackedEnumNode) { + /** @var ObjectType $type */ + $type = $node->getType(); + + return '\\'.$type->getClassName()."::from($accessor)"; + } + + if ($node instanceof ScalarNode) { + /** @var BuiltinType $type */ + $type = $node->getType(); + + return match (true) { + TypeIdentifier::NULL === $type->getTypeIdentifier() => 'null', + TypeIdentifier::OBJECT === $type->getTypeIdentifier() => "(object) $accessor", + default => $accessor, + }; + } + + return $accessor; + } + + private function generateCompositeNodeItemCondition(DataModelNodeInterface $node, string $accessor): string + { + $type = $node->getType(); + + if ($type->isIdentifiedBy(TypeIdentifier::NULL)) { + return "null === $accessor"; + } + + if ($type->isIdentifiedBy(TypeIdentifier::TRUE)) { + return "true === $accessor"; + } + + if ($type->isIdentifiedBy(TypeIdentifier::FALSE)) { + return "false === $accessor"; + } + + if ($type->isIdentifiedBy(TypeIdentifier::MIXED)) { + return 'true'; + } + + if ($type instanceof CollectionType) { + return $type->isList() ? "\\is_array($accessor) && \\array_is_list($accessor)" : "\\is_array($accessor)"; + } + + while ($type instanceof WrappingTypeInterface) { + $type = $type->getWrappedType(); + } + + if ($type instanceof BackedEnumType) { + return '\\is_'.$type->getBackingType()->getTypeIdentifier()->value."($accessor)"; + } + + if ($type instanceof ObjectType) { + return "\\is_array($accessor)"; + } + + if ($type instanceof BuiltinType) { + return '\\is_'.$type->getTypeIdentifier()->value."($accessor)"; + } + + throw new LogicException(\sprintf('Unexpected "%s" type.', $type::class)); + } + + /** + * @param array $context + */ + private function line(string $line, array $context): string + { + return str_repeat(' ', $context['indentation_level']).$line."\n"; + } + + /** + * Determines if the $node can be decoded using a simple "json_decode". + */ + private function canBeDecodedWithJsonDecode(DataModelNodeInterface $node, bool $decodeFromStream): bool + { + if ($node instanceof CompositeNode) { + foreach ($node->getNodes() as $n) { + if (!$this->canBeDecodedWithJsonDecode($n, $decodeFromStream)) { + return false; + } + } + + return true; + } + + if ($node instanceof CollectionNode) { + if ($decodeFromStream) { + return false; + } + + return $this->canBeDecodedWithJsonDecode($node->getItemNode(), $decodeFromStream); + } + + if ($node instanceof ObjectNode) { + return false; + } + + if ($node instanceof BackedEnumNode) { + return false; + } + + if ($node instanceof ScalarNode) { + return !$node->getType()->isIdentifiedBy(TypeIdentifier::OBJECT); + } + + return true; + } +} diff --git a/src/Symfony/Component/JsonStreamer/Read/StreamReaderGenerator.php b/src/Symfony/Component/JsonStreamer/Read/StreamReaderGenerator.php index 18720297b16c6..8f4dc27685351 100644 --- a/src/Symfony/Component/JsonStreamer/Read/StreamReaderGenerator.php +++ b/src/Symfony/Component/JsonStreamer/Read/StreamReaderGenerator.php @@ -11,21 +11,14 @@ namespace Symfony\Component\JsonStreamer\Read; -use PhpParser\PhpVersion; -use PhpParser\PrettyPrinter; -use PhpParser\PrettyPrinter\Standard; use Symfony\Component\Filesystem\Exception\IOException; use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\JsonStreamer\DataModel\DataAccessorInterface; -use Symfony\Component\JsonStreamer\DataModel\FunctionDataAccessor; use Symfony\Component\JsonStreamer\DataModel\Read\BackedEnumNode; use Symfony\Component\JsonStreamer\DataModel\Read\CollectionNode; use Symfony\Component\JsonStreamer\DataModel\Read\CompositeNode; use Symfony\Component\JsonStreamer\DataModel\Read\DataModelNodeInterface; use Symfony\Component\JsonStreamer\DataModel\Read\ObjectNode; use Symfony\Component\JsonStreamer\DataModel\Read\ScalarNode; -use Symfony\Component\JsonStreamer\DataModel\ScalarDataAccessor; -use Symfony\Component\JsonStreamer\DataModel\VariableDataAccessor; use Symfony\Component\JsonStreamer\Exception\RuntimeException; use Symfony\Component\JsonStreamer\Exception\UnsupportedException; use Symfony\Component\JsonStreamer\Mapping\PropertyMetadataLoaderInterface; @@ -47,8 +40,7 @@ */ final class StreamReaderGenerator { - private ?PhpAstBuilder $phpAstBuilder = null; - private ?PrettyPrinter $phpPrinter = null; + private ?PhpGenerator $phpGenerator = null; private ?Filesystem $fs = null; public function __construct( @@ -69,13 +61,11 @@ public function generate(Type $type, bool $decodeFromStream, array $options = [] return $path; } - $this->phpAstBuilder ??= new PhpAstBuilder(); - $this->phpPrinter ??= new Standard(['phpVersion' => PhpVersion::fromComponents(8, 2)]); + $this->phpGenerator ??= new PhpGenerator(); $this->fs ??= new Filesystem(); $dataModel = $this->createDataModel($type, $options); - $nodes = $this->phpAstBuilder->build($dataModel, $decodeFromStream, $options); - $content = $this->phpPrinter->prettyPrintFile($nodes)."\n"; + $php = $this->phpGenerator->generate($dataModel, $decodeFromStream, $options); if (!$this->fs->exists($this->streamReadersDir)) { $this->fs->mkdir($this->streamReadersDir); @@ -84,7 +74,7 @@ public function generate(Type $type, bool $decodeFromStream, array $options = [] $tmpFile = $this->fs->tempnam(\dirname($path), basename($path)); try { - $this->fs->dumpFile($tmpFile, $content); + $this->fs->dumpFile($tmpFile, $php); $this->fs->rename($tmpFile, $path); $this->fs->chmod($path, 0666 & ~umask()); } catch (IOException $e) { @@ -103,7 +93,7 @@ private function getPath(Type $type, bool $decodeFromStream): string * @param array $options * @param array $context */ - public function createDataModel(Type $type, array $options = [], array $context = []): DataModelNodeInterface + private function createDataModel(Type $type, array $options = [], array $context = []): DataModelNodeInterface { $context['original_type'] ??= $type; @@ -140,11 +130,10 @@ public function createDataModel(Type $type, array $options = [], array $context $propertiesNodes[$streamedName] = [ 'name' => $propertyMetadata->getName(), 'value' => $this->createDataModel($propertyMetadata->getType(), $options, $context), - 'accessor' => function (DataAccessorInterface $accessor) use ($propertyMetadata): DataAccessorInterface { + 'accessor' => function (string $accessor) use ($propertyMetadata): string { foreach ($propertyMetadata->getStreamToNativeValueTransformers() as $valueTransformer) { if (\is_string($valueTransformer)) { - $valueTransformerServiceAccessor = new FunctionDataAccessor('get', [new ScalarDataAccessor($valueTransformer)], new VariableDataAccessor('valueTransformers')); - $accessor = new FunctionDataAccessor('transform', [$accessor, new VariableDataAccessor('options')], $valueTransformerServiceAccessor); + $accessor = "\$valueTransformers->get('$valueTransformer')->transform($accessor, \$options)"; continue; } @@ -158,9 +147,9 @@ public function createDataModel(Type $type, array $options = [], array $context $functionName = !$functionReflection->getClosureCalledClass() ? $functionReflection->getName() : \sprintf('%s::%s', $functionReflection->getClosureCalledClass()->getName(), $functionReflection->getName()); - $arguments = $functionReflection->isUserDefined() ? [$accessor, new VariableDataAccessor('options')] : [$accessor]; + $arguments = $functionReflection->isUserDefined() ? "$accessor, \$options" : $accessor; - $accessor = new FunctionDataAccessor($functionName, $arguments); + $accessor = "$functionName($arguments)"; } return $accessor; diff --git a/src/Symfony/Component/JsonStreamer/Tests/DataModel/Write/CompositeNodeTest.php b/src/Symfony/Component/JsonStreamer/Tests/DataModel/Write/CompositeNodeTest.php index a7ef7df343d6f..fb57df19ff044 100644 --- a/src/Symfony/Component/JsonStreamer/Tests/DataModel/Write/CompositeNodeTest.php +++ b/src/Symfony/Component/JsonStreamer/Tests/DataModel/Write/CompositeNodeTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\JsonStreamer\Tests\DataModel\Write; use PHPUnit\Framework\TestCase; -use Symfony\Component\JsonStreamer\DataModel\VariableDataAccessor; use Symfony\Component\JsonStreamer\DataModel\Write\CollectionNode; use Symfony\Component\JsonStreamer\DataModel\Write\CompositeNode; use Symfony\Component\JsonStreamer\DataModel\Write\ObjectNode; @@ -27,7 +26,7 @@ public function testCannotCreateWithOnlyOneType() $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage(\sprintf('"%s" expects at least 2 nodes.', CompositeNode::class)); - new CompositeNode(new VariableDataAccessor('data'), [new ScalarNode(new VariableDataAccessor('data'), Type::int())]); + new CompositeNode('$data', [new ScalarNode('$data', Type::int())]); } public function testCannotCreateWithCompositeNodeParts() @@ -35,21 +34,21 @@ public function testCannotCreateWithCompositeNodeParts() $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage(\sprintf('Cannot set "%s" as a "%s" node.', CompositeNode::class, CompositeNode::class)); - new CompositeNode(new VariableDataAccessor('data'), [ - new CompositeNode(new VariableDataAccessor('data'), [ - new ScalarNode(new VariableDataAccessor('data'), Type::int()), - new ScalarNode(new VariableDataAccessor('data'), Type::int()), + new CompositeNode('$data', [ + new CompositeNode('$data', [ + new ScalarNode('$data', Type::int()), + new ScalarNode('$data', Type::int()), ]), - new ScalarNode(new VariableDataAccessor('data'), Type::int()), + new ScalarNode('$data', Type::int()), ]); } public function testSortNodesOnCreation() { - $composite = new CompositeNode(new VariableDataAccessor('data'), [ - $scalar = new ScalarNode(new VariableDataAccessor('data'), Type::int()), - $object = new ObjectNode(new VariableDataAccessor('data'), Type::object(self::class), []), - $collection = new CollectionNode(new VariableDataAccessor('data'), Type::list(), new ScalarNode(new VariableDataAccessor('data'), Type::int())), + $composite = new CompositeNode('$data', [ + $scalar = new ScalarNode('$data', Type::int()), + $object = new ObjectNode('$data', Type::object(self::class), []), + $collection = new CollectionNode('$data', Type::list(), new ScalarNode('$data', Type::int())), ]); $this->assertSame([$collection, $object, $scalar], $composite->getNodes()); @@ -57,14 +56,14 @@ public function testSortNodesOnCreation() public function testWithAccessor() { - $composite = new CompositeNode(new VariableDataAccessor('data'), [ - new ScalarNode(new VariableDataAccessor('foo'), Type::int()), - new ScalarNode(new VariableDataAccessor('bar'), Type::int()), + $composite = new CompositeNode('$data', [ + new ScalarNode('$foo', Type::int()), + new ScalarNode('$bar', Type::int()), ]); - $composite = $composite->withAccessor($newAccessor = new VariableDataAccessor('baz')); + $composite = $composite->withAccessor('$baz'); foreach ($composite->getNodes() as $node) { - $this->assertSame($newAccessor, $node->getAccessor()); + $this->assertSame('$baz', $node->getAccessor()); } } } diff --git a/src/Symfony/Component/JsonStreamer/Tests/DataModel/Write/ObjectNodeTest.php b/src/Symfony/Component/JsonStreamer/Tests/DataModel/Write/ObjectNodeTest.php index 0667f731e3d9f..cdc6bf71f4a15 100644 --- a/src/Symfony/Component/JsonStreamer/Tests/DataModel/Write/ObjectNodeTest.php +++ b/src/Symfony/Component/JsonStreamer/Tests/DataModel/Write/ObjectNodeTest.php @@ -12,9 +12,6 @@ namespace Symfony\Component\JsonStreamer\Tests\DataModel\Write; use PHPUnit\Framework\TestCase; -use Symfony\Component\JsonStreamer\DataModel\FunctionDataAccessor; -use Symfony\Component\JsonStreamer\DataModel\PropertyDataAccessor; -use Symfony\Component\JsonStreamer\DataModel\VariableDataAccessor; use Symfony\Component\JsonStreamer\DataModel\Write\ObjectNode; use Symfony\Component\JsonStreamer\DataModel\Write\ScalarNode; use Symfony\Component\TypeInfo\Type; @@ -23,18 +20,18 @@ class ObjectNodeTest extends TestCase { public function testWithAccessor() { - $object = new ObjectNode(new VariableDataAccessor('foo'), Type::object(self::class), [ - new ScalarNode(new PropertyDataAccessor(new VariableDataAccessor('foo'), 'property'), Type::int()), - new ScalarNode(new FunctionDataAccessor('function', [], new VariableDataAccessor('foo')), Type::int()), - new ScalarNode(new FunctionDataAccessor('function', []), Type::int()), - new ScalarNode(new VariableDataAccessor('bar'), Type::int()), + $object = new ObjectNode('$foo', Type::object(self::class), [ + new ScalarNode('$foo->property', Type::int()), + new ScalarNode('$foo->method()', Type::int()), + new ScalarNode('function()', Type::int()), + new ScalarNode('$bar', Type::int()), ]); - $object = $object->withAccessor($newAccessor = new VariableDataAccessor('baz')); + $object = $object->withAccessor('$baz'); - $this->assertSame($newAccessor, $object->getAccessor()); - $this->assertSame($newAccessor, $object->getProperties()[0]->getAccessor()->getObjectAccessor()); - $this->assertSame($newAccessor, $object->getProperties()[1]->getAccessor()->getObjectAccessor()); - $this->assertNull($object->getProperties()[2]->getAccessor()->getObjectAccessor()); - $this->assertNotSame($newAccessor, $object->getProperties()[3]->getAccessor()); + $this->assertSame('$baz', $object->getAccessor()); + $this->assertSame('$baz->property', $object->getProperties()[0]->getAccessor()); + $this->assertSame('$baz->method()', $object->getProperties()[1]->getAccessor()); + $this->assertSame('function()', $object->getProperties()[2]->getAccessor()); + $this->assertSame('$bar', $object->getProperties()[3]->getAccessor()); } } diff --git a/src/Symfony/Component/JsonStreamer/Tests/Mapping/Read/DateTimeTypePropertyMetadataLoaderTest.php b/src/Symfony/Component/JsonStreamer/Tests/Mapping/Read/DateTimeTypePropertyMetadataLoaderTest.php index c71189815be29..779499adf21c2 100644 --- a/src/Symfony/Component/JsonStreamer/Tests/Mapping/Read/DateTimeTypePropertyMetadataLoaderTest.php +++ b/src/Symfony/Component/JsonStreamer/Tests/Mapping/Read/DateTimeTypePropertyMetadataLoaderTest.php @@ -47,6 +47,18 @@ public function testThrowWhenDateTimeType() $loader->load(self::class); } + public function testThrowWhenDateTimeSubclassType() + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('The "DateTime" class is not supported. Use "DateTimeImmutable" instead.'); + + $loader = new DateTimeTypePropertyMetadataLoader(self::propertyMetadataLoader([ + 'mutable' => new PropertyMetadata('mutable', Type::object(DateTimeChild::class)), + ])); + + $loader->load(self::class); + } + /** * @param array $propertiesMetadata */ @@ -64,3 +76,7 @@ public function load(string $className, array $options = [], array $context = [] }; } } + +class DateTimeChild extends \DateTime +{ +} diff --git a/src/Symfony/Component/JsonStreamer/Write/MergingStringVisitor.php b/src/Symfony/Component/JsonStreamer/Write/MergingStringVisitor.php deleted file mode 100644 index 289448ba465e8..0000000000000 --- a/src/Symfony/Component/JsonStreamer/Write/MergingStringVisitor.php +++ /dev/null @@ -1,60 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\JsonStreamer\Write; - -use PhpParser\Node; -use PhpParser\Node\Expr\Yield_; -use PhpParser\Node\Scalar\String_; -use PhpParser\Node\Stmt\Expression; -use PhpParser\NodeVisitor; -use PhpParser\NodeVisitorAbstract; - -/** - * Merges strings that are yielded consequently - * to reduce the call instructions amount. - * - * @author Mathias Arlaud - * - * @internal - */ -final class MergingStringVisitor extends NodeVisitorAbstract -{ - private string $buffer = ''; - - public function leaveNode(Node $node): int|Node|array|null - { - if (!$this->isMergeableNode($node)) { - return null; - } - - /** @var Node|null $next */ - $next = $node->getAttribute('next'); - - if ($next && $this->isMergeableNode($next)) { - $this->buffer .= $node->expr->value->value; - - return NodeVisitor::REMOVE_NODE; - } - - $string = $this->buffer.$node->expr->value->value; - $this->buffer = ''; - - return new Expression(new Yield_(new String_($string))); - } - - private function isMergeableNode(Node $node): bool - { - return $node instanceof Expression - && $node->expr instanceof Yield_ - && $node->expr->value instanceof String_; - } -} diff --git a/src/Symfony/Component/JsonStreamer/Write/PhpAstBuilder.php b/src/Symfony/Component/JsonStreamer/Write/PhpAstBuilder.php deleted file mode 100644 index f0b429b42c8f3..0000000000000 --- a/src/Symfony/Component/JsonStreamer/Write/PhpAstBuilder.php +++ /dev/null @@ -1,436 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\JsonStreamer\Write; - -use PhpParser\BuilderFactory; -use PhpParser\Node\ClosureUse; -use PhpParser\Node\Expr; -use PhpParser\Node\Expr\ArrayDimFetch; -use PhpParser\Node\Expr\Assign; -use PhpParser\Node\Expr\BinaryOp\GreaterOrEqual; -use PhpParser\Node\Expr\BinaryOp\Identical; -use PhpParser\Node\Expr\BinaryOp\Plus; -use PhpParser\Node\Expr\Closure; -use PhpParser\Node\Expr\Instanceof_; -use PhpParser\Node\Expr\PropertyFetch; -use PhpParser\Node\Expr\Ternary; -use PhpParser\Node\Expr\Throw_; -use PhpParser\Node\Expr\Yield_; -use PhpParser\Node\Expr\YieldFrom; -use PhpParser\Node\Identifier; -use PhpParser\Node\Name\FullyQualified; -use PhpParser\Node\Param; -use PhpParser\Node\Scalar\Encapsed; -use PhpParser\Node\Scalar\EncapsedStringPart; -use PhpParser\Node\Stmt; -use PhpParser\Node\Stmt\Catch_; -use PhpParser\Node\Stmt\Else_; -use PhpParser\Node\Stmt\ElseIf_; -use PhpParser\Node\Stmt\Expression; -use PhpParser\Node\Stmt\Foreach_; -use PhpParser\Node\Stmt\If_; -use PhpParser\Node\Stmt\Return_; -use PhpParser\Node\Stmt\TryCatch; -use Psr\Container\ContainerInterface; -use Symfony\Component\JsonStreamer\DataModel\VariableDataAccessor; -use Symfony\Component\JsonStreamer\DataModel\Write\BackedEnumNode; -use Symfony\Component\JsonStreamer\DataModel\Write\CollectionNode; -use Symfony\Component\JsonStreamer\DataModel\Write\CompositeNode; -use Symfony\Component\JsonStreamer\DataModel\Write\DataModelNodeInterface; -use Symfony\Component\JsonStreamer\DataModel\Write\ObjectNode; -use Symfony\Component\JsonStreamer\DataModel\Write\ScalarNode; -use Symfony\Component\JsonStreamer\Exception\LogicException; -use Symfony\Component\JsonStreamer\Exception\NotEncodableValueException; -use Symfony\Component\JsonStreamer\Exception\RuntimeException; -use Symfony\Component\JsonStreamer\Exception\UnexpectedValueException; -use Symfony\Component\TypeInfo\Type\BuiltinType; -use Symfony\Component\TypeInfo\Type\ObjectType; -use Symfony\Component\TypeInfo\Type\WrappingTypeInterface; -use Symfony\Component\TypeInfo\TypeIdentifier; - -/** - * Builds a PHP syntax tree that writes data to JSON stream. - * - * @author Mathias Arlaud - * - * @internal - */ -final class PhpAstBuilder -{ - private BuilderFactory $builder; - - public function __construct() - { - $this->builder = new BuilderFactory(); - } - - /** - * @param array $options - * @param array $context - * - * @return list - */ - public function build(DataModelNodeInterface $dataModel, array $options = [], array $context = []): array - { - $context['depth'] = 0; - - $generatorStmts = $this->buildGeneratorStatementsByIdentifiers($dataModel, $options, $context); - - // filter generators to mock only - $generatorStmts = array_merge(...array_values(array_intersect_key($generatorStmts, $context['mocks'] ?? []))); - $context['generators'] = array_intersect_key($context['generators'] ?? [], $context['mocks'] ?? []); - - return [new Return_(new Closure([ - 'static' => true, - 'params' => [ - new Param($this->builder->var('data'), type: new Identifier('mixed')), - new Param($this->builder->var('valueTransformers'), type: new FullyQualified(ContainerInterface::class)), - new Param($this->builder->var('options'), type: new Identifier('array')), - ], - 'returnType' => new FullyQualified(\Traversable::class), - 'stmts' => [ - ...$generatorStmts, - new TryCatch( - $this->buildYieldStatements($dataModel, $options, $context), - [new Catch_([new FullyQualified(\JsonException::class)], $this->builder->var('e'), [ - new Expression(new Throw_($this->builder->new(new FullyQualified(NotEncodableValueException::class), [ - $this->builder->methodCall($this->builder->var('e'), 'getMessage'), - $this->builder->val(0), - $this->builder->var('e'), - ]))), - ])] - ), - ], - ]))]; - } - - /** - * @param array $options - * @param array $context - * - * @return array> - */ - private function buildGeneratorStatementsByIdentifiers(DataModelNodeInterface $node, array $options, array &$context): array - { - if ($context['generators'][$node->getIdentifier()] ?? false) { - return []; - } - - if ($node instanceof CollectionNode) { - return $this->buildGeneratorStatementsByIdentifiers($node->getItemNode(), $options, $context); - } - - if ($node instanceof CompositeNode) { - $stmts = []; - - foreach ($node->getNodes() as $n) { - $stmts = [ - ...$stmts, - ...$this->buildGeneratorStatementsByIdentifiers($n, $options, $context), - ]; - } - - return $stmts; - } - - if (!$node instanceof ObjectNode) { - return []; - } - - if ($node->isMock()) { - $context['mocks'][$node->getIdentifier()] = true; - - return []; - } - - $context['building_generator'] = true; - - $stmts = [ - $node->getIdentifier() => [ - new Expression(new Assign( - new ArrayDimFetch($this->builder->var('generators'), $this->builder->val($node->getIdentifier())), - new Closure([ - 'static' => true, - 'params' => [ - new Param($this->builder->var('data')), - new Param($this->builder->var('depth')), - ], - 'uses' => [ - new ClosureUse($this->builder->var('valueTransformers')), - new ClosureUse($this->builder->var('options')), - new ClosureUse($this->builder->var('generators'), byRef: true), - ], - 'stmts' => [ - new If_(new GreaterOrEqual($this->builder->var('depth'), $this->builder->val(512)), [ - 'stmts' => [new Expression(new Throw_($this->builder->new(new FullyQualified(NotEncodableValueException::class), [$this->builder->val('Maximum stack depth exceeded')])))], - ]), - ...$this->buildYieldStatements($node->withAccessor(new VariableDataAccessor('data')), $options, $context), - ], - ]), - )), - ], - ]; - - foreach ($node->getProperties() as $n) { - $stmts = [ - ...$stmts, - ...$this->buildGeneratorStatementsByIdentifiers($n, $options, $context), - ]; - } - - unset($context['building_generator']); - $context['generators'][$node->getIdentifier()] = true; - - return $stmts; - } - - /** - * @param array $options - * @param array $context - * - * @return list - */ - private function buildYieldStatements(DataModelNodeInterface $dataModelNode, array $options, array $context): array - { - $accessor = $dataModelNode->getAccessor()->toPhpExpr(); - - if ($this->dataModelOnlyNeedsEncode($dataModelNode)) { - return [ - new Expression(new Yield_($this->encodeValue($accessor, $context))), - ]; - } - - if ($context['depth'] >= 512) { - return [ - new Expression(new Throw_($this->builder->new(new FullyQualified(NotEncodableValueException::class), [$this->builder->val('Maximum stack depth exceeded')]))), - ]; - } - - if ($dataModelNode instanceof ScalarNode) { - $scalarAccessor = match (true) { - TypeIdentifier::NULL === $dataModelNode->getType()->getTypeIdentifier() => $this->builder->val('null'), - TypeIdentifier::BOOL === $dataModelNode->getType()->getTypeIdentifier() => new Ternary($accessor, $this->builder->val('true'), $this->builder->val('false')), - default => $this->encodeValue($accessor, $context), - }; - - return [ - new Expression(new Yield_($scalarAccessor)), - ]; - } - - if ($dataModelNode instanceof BackedEnumNode) { - return [ - new Expression(new Yield_($this->encodeValue(new PropertyFetch($accessor, 'value'), $context))), - ]; - } - - if ($dataModelNode instanceof CompositeNode) { - $nodeCondition = function (DataModelNodeInterface $node): Expr { - $accessor = $node->getAccessor()->toPhpExpr(); - $type = $node->getType(); - - if ($type->isIdentifiedBy(TypeIdentifier::NULL, TypeIdentifier::NEVER, TypeIdentifier::VOID)) { - return new Identical($this->builder->val(null), $accessor); - } - - if ($type->isIdentifiedBy(TypeIdentifier::TRUE)) { - return new Identical($this->builder->val(true), $accessor); - } - - if ($type->isIdentifiedBy(TypeIdentifier::FALSE)) { - return new Identical($this->builder->val(false), $accessor); - } - - if ($type->isIdentifiedBy(TypeIdentifier::MIXED)) { - return $this->builder->val(true); - } - - while ($type instanceof WrappingTypeInterface) { - $type = $type->getWrappedType(); - } - - if ($type instanceof ObjectType) { - return new Instanceof_($accessor, new FullyQualified($type->getClassName())); - } - - if ($type instanceof BuiltinType) { - return $this->builder->funcCall('\is_'.$type->getTypeIdentifier()->value, [$accessor]); - } - - throw new LogicException(\sprintf('Unexpected "%s" type.', $type::class)); - }; - - $stmtsAndConditions = array_map(fn (DataModelNodeInterface $n): array => [ - 'condition' => $nodeCondition($n), - 'stmts' => $this->buildYieldStatements($n, $options, $context), - ], $dataModelNode->getNodes()); - - $if = $stmtsAndConditions[0]; - unset($stmtsAndConditions[0]); - - return [ - new If_($if['condition'], [ - 'stmts' => $if['stmts'], - 'elseifs' => array_map(fn (array $s): ElseIf_ => new ElseIf_($s['condition'], $s['stmts']), $stmtsAndConditions), - 'else' => new Else_([ - new Expression(new Throw_($this->builder->new(new FullyQualified(UnexpectedValueException::class), [$this->builder->funcCall('\sprintf', [ - $this->builder->val('Unexpected "%s" value.'), - $this->builder->funcCall('\get_debug_type', [$accessor]), - ])]))), - ]), - ]), - ]; - } - - if ($dataModelNode instanceof CollectionNode) { - ++$context['depth']; - - if ($dataModelNode->getType()->isList()) { - return [ - new Expression(new Yield_($this->builder->val('['))), - new Expression(new Assign($this->builder->var('prefix'), $this->builder->val(''))), - new Foreach_($accessor, $dataModelNode->getItemNode()->getAccessor()->toPhpExpr(), [ - 'stmts' => [ - new Expression(new Yield_($this->builder->var('prefix'))), - ...$this->buildYieldStatements($dataModelNode->getItemNode(), $options, $context), - new Expression(new Assign($this->builder->var('prefix'), $this->builder->val(','))), - ], - ]), - new Expression(new Yield_($this->builder->val(']'))), - ]; - } - - $escapedKey = $dataModelNode->getType()->getCollectionKeyType()->isIdentifiedBy(TypeIdentifier::INT) - ? new Ternary($this->builder->funcCall('is_int', [$this->builder->var('key')]), $this->builder->var('key'), $this->escapeString($this->builder->var('key'))) - : $this->escapeString($this->builder->var('key')); - - return [ - new Expression(new Yield_($this->builder->val('{'))), - new Expression(new Assign($this->builder->var('prefix'), $this->builder->val(''))), - new Foreach_($accessor, $dataModelNode->getItemNode()->getAccessor()->toPhpExpr(), [ - 'keyVar' => $this->builder->var('key'), - 'stmts' => [ - new Expression(new Assign($this->builder->var('key'), $escapedKey)), - new Expression(new Yield_(new Encapsed([ - $this->builder->var('prefix'), - new EncapsedStringPart('"'), - $this->builder->var('key'), - new EncapsedStringPart('":'), - ]))), - ...$this->buildYieldStatements($dataModelNode->getItemNode(), $options, $context), - new Expression(new Assign($this->builder->var('prefix'), $this->builder->val(','))), - ], - ]), - new Expression(new Yield_($this->builder->val('}'))), - ]; - } - - if ($dataModelNode instanceof ObjectNode) { - if (isset($context['generators'][$dataModelNode->getIdentifier()]) || $dataModelNode->isMock()) { - $depthArgument = ($context['building_generator'] ?? false) - ? new Plus($this->builder->var('depth'), $this->builder->val(1)) - : $this->builder->val($context['depth']); - - return [ - new Expression(new YieldFrom($this->builder->funcCall( - new ArrayDimFetch($this->builder->var('generators'), $this->builder->val($dataModelNode->getIdentifier())), - [$accessor, $depthArgument], - ))), - ]; - } - - $objectStmts = [new Expression(new Yield_($this->builder->val('{')))]; - $separator = ''; - - ++$context['depth']; - - foreach ($dataModelNode->getProperties() as $name => $propertyNode) { - $encodedName = json_encode($name); - if (false === $encodedName) { - throw new RuntimeException(\sprintf('Cannot encode "%s"', $name)); - } - - $encodedName = substr($encodedName, 1, -1); - - $objectStmts = [ - ...$objectStmts, - new Expression(new Yield_($this->builder->val($separator))), - new Expression(new Yield_($this->builder->val('"'))), - new Expression(new Yield_($this->builder->val($encodedName))), - new Expression(new Yield_($this->builder->val('":'))), - ...$this->buildYieldStatements($propertyNode, $options, $context), - ]; - - $separator = ','; - } - - $objectStmts[] = new Expression(new Yield_($this->builder->val('}'))); - - return $objectStmts; - } - - throw new LogicException(\sprintf('Unexpected "%s" node', $dataModelNode::class)); - } - - /** - * @param array $context - */ - private function encodeValue(Expr $value, array $context): Expr - { - return $this->builder->funcCall('\json_encode', [ - $value, - $this->builder->constFetch('\\JSON_THROW_ON_ERROR'), - $this->builder->val(512 - $context['depth']), - ]); - } - - private function escapeString(Expr $string): Expr - { - return $this->builder->funcCall('\substr', [ - $this->builder->funcCall('\json_encode', [$string]), - $this->builder->val(1), - $this->builder->val(-1), - ]); - } - - private function dataModelOnlyNeedsEncode(DataModelNodeInterface $dataModel, int $depth = 0): bool - { - if ($dataModel instanceof CompositeNode) { - foreach ($dataModel->getNodes() as $node) { - if (!$this->dataModelOnlyNeedsEncode($node, $depth)) { - return false; - } - } - - return true; - } - - if ($dataModel instanceof CollectionNode) { - return $this->dataModelOnlyNeedsEncode($dataModel->getItemNode(), $depth + 1); - } - - if (!$dataModel instanceof ScalarNode) { - return false; - } - - $type = $dataModel->getType(); - - // "null" will be written directly using the "null" string - // "bool" will be written directly using the "true" or "false" string - // but it must not prevent any json_encode if nested - if ($type->isIdentifiedBy(TypeIdentifier::NULL) || $type->isIdentifiedBy(TypeIdentifier::BOOL)) { - return $depth > 0; - } - - return true; - } -} diff --git a/src/Symfony/Component/JsonStreamer/Write/PhpGenerator.php b/src/Symfony/Component/JsonStreamer/Write/PhpGenerator.php new file mode 100644 index 0000000000000..0e79481007a65 --- /dev/null +++ b/src/Symfony/Component/JsonStreamer/Write/PhpGenerator.php @@ -0,0 +1,388 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\JsonStreamer\Write; + +use Psr\Container\ContainerInterface; +use Symfony\Component\JsonStreamer\DataModel\Write\BackedEnumNode; +use Symfony\Component\JsonStreamer\DataModel\Write\CollectionNode; +use Symfony\Component\JsonStreamer\DataModel\Write\CompositeNode; +use Symfony\Component\JsonStreamer\DataModel\Write\DataModelNodeInterface; +use Symfony\Component\JsonStreamer\DataModel\Write\ObjectNode; +use Symfony\Component\JsonStreamer\DataModel\Write\ScalarNode; +use Symfony\Component\JsonStreamer\Exception\LogicException; +use Symfony\Component\JsonStreamer\Exception\NotEncodableValueException; +use Symfony\Component\JsonStreamer\Exception\RuntimeException; +use Symfony\Component\JsonStreamer\Exception\UnexpectedValueException; +use Symfony\Component\TypeInfo\Type\BuiltinType; +use Symfony\Component\TypeInfo\Type\ObjectType; +use Symfony\Component\TypeInfo\Type\WrappingTypeInterface; +use Symfony\Component\TypeInfo\TypeIdentifier; + +/** + * Generates PHP code that writes data to JSON stream. + * + * @author Mathias Arlaud + * + * @internal + */ +final class PhpGenerator +{ + private string $yieldBuffer = ''; + + /** + * @param array $options + * @param array $context + */ + public function generate(DataModelNodeInterface $dataModel, array $options = [], array $context = []): string + { + $context['depth'] = 0; + $context['indentation_level'] = 1; + + $generators = $this->generateObjectGenerators($dataModel, $options, $context); + + // filter generators to mock only + $generators = array_intersect_key($generators, $context['mocks'] ?? []); + $context['generated_generators'] = array_intersect_key($context['generated_generators'] ?? [], $context['mocks'] ?? []); + + $context['indentation_level'] = 2; + $yields = $this->generateYields($dataModel, $options, $context) + .$this->flushYieldBuffer($context); + + $context['indentation_level'] = 0; + + return $this->line('line('', $context) + .$this->line('return static function (mixed $data, \\'.ContainerInterface::class.' $valueTransformers, array $options): \\Traversable {', $context) + .implode('', $generators) + .$this->line(' try {', $context) + .$yields + .$this->line(' } catch (\\JsonException $e) {', $context) + .$this->line(' throw new \\'.NotEncodableValueException::class.'($e->getMessage(), 0, $e);', $context) + .$this->line(' }', $context) + .$this->line('};', $context); + } + + /** + * @param array $options + * @param array $context + * + * @return array + */ + private function generateObjectGenerators(DataModelNodeInterface $node, array $options, array &$context): array + { + if ($context['generated_generators'][$node->getIdentifier()] ?? false) { + return []; + } + + if ($node instanceof CollectionNode) { + return $this->generateObjectGenerators($node->getItemNode(), $options, $context); + } + + if ($node instanceof CompositeNode) { + $generators = []; + foreach ($node->getNodes() as $n) { + $generators = [ + ...$generators, + ...$this->generateObjectGenerators($n, $options, $context), + ]; + } + + return $generators; + } + + if ($node instanceof ObjectNode) { + if ($node->isMock()) { + $context['mocks'][$node->getIdentifier()] = true; + + return []; + } + + $context['generating_generator'] = true; + + ++$context['indentation_level']; + $yields = $this->generateYields($node->withAccessor('$data'), $options, $context) + .$this->flushYieldBuffer($context); + --$context['indentation_level']; + + $generators = [ + $node->getIdentifier() => $this->line('$generators[\''.$node->getIdentifier().'\'] = static function ($data, $depth) use ($valueTransformers, $options, &$generators) {', $context) + .$this->line(' if ($depth >= 512) {', $context) + .$this->line(' throw new \\'.NotEncodableValueException::class.'(\'Maximum stack depth exceeded\');', $context) + .$this->line(' }', $context) + .$yields + .$this->line('};', $context), + ]; + + foreach ($node->getProperties() as $n) { + $generators = [ + ...$generators, + ...$this->generateObjectGenerators($n, $options, $context), + ]; + } + + unset($context['generating_generator']); + $context['generated_generators'][$node->getIdentifier()] = true; + + return $generators; + } + + return []; + } + + /** + * @param array $options + * @param array $context + */ + private function generateYields(DataModelNodeInterface $dataModelNode, array $options, array $context): string + { + $accessor = $dataModelNode->getAccessor(); + + if ($this->canBeEncodedWithJsonEncode($dataModelNode)) { + return $this->yield($this->encode($accessor, $context), $context); + } + + if ($context['depth'] >= 512) { + return $this->line('throw new '.NotEncodableValueException::class.'(\'Maximum stack depth exceeded\');', $context); + } + + if ($dataModelNode instanceof ScalarNode) { + return match (true) { + TypeIdentifier::NULL === $dataModelNode->getType()->getTypeIdentifier() => $this->yieldString('null', $context), + TypeIdentifier::BOOL === $dataModelNode->getType()->getTypeIdentifier() => $this->yield("$accessor ? 'true' : 'false'", $context), + default => $this->yield($this->encode($accessor, $context), $context), + }; + } + + if ($dataModelNode instanceof BackedEnumNode) { + return $this->yield($this->encode("{$accessor}->value", $context), $context); + } + + if ($dataModelNode instanceof CompositeNode) { + $php = $this->flushYieldBuffer($context); + foreach ($dataModelNode->getNodes() as $i => $node) { + $php .= $this->line((0 === $i ? 'if' : '} elseif').' ('.$this->generateCompositeNodeItemCondition($node).') {', $context); + + ++$context['indentation_level']; + $php .= $this->generateYields($node, $options, $context) + .$this->flushYieldBuffer($context); + --$context['indentation_level']; + } + + return $php + .$this->flushYieldBuffer($context) + .$this->line('} else {', $context) + .$this->line(' throw new \\'.UnexpectedValueException::class."(\\sprintf('Unexpected \"%s\" value.', \get_debug_type($accessor)));", $context) + .$this->line('}', $context); + } + + if ($dataModelNode instanceof CollectionNode) { + ++$context['depth']; + + if ($dataModelNode->getType()->isList()) { + $php = $this->yieldString('[', $context) + .$this->flushYieldBuffer($context) + .$this->line('$prefix = \'\';', $context) + .$this->line("foreach ($accessor as ".$dataModelNode->getItemNode()->getAccessor().') {', $context); + + ++$context['indentation_level']; + $php .= $this->yield('$prefix', $context) + .$this->generateYields($dataModelNode->getItemNode(), $options, $context) + .$this->flushYieldBuffer($context) + .$this->line('$prefix = \',\';', $context); + + --$context['indentation_level']; + + return $php + .$this->line('}', $context) + .$this->yieldString(']', $context); + } + + $escapedKey = $dataModelNode->getType()->getCollectionKeyType()->isIdentifiedBy(TypeIdentifier::INT) + ? '$key = is_int($key) ? $key : \substr(\json_encode($key), 1, -1);' + : '$key = \substr(\json_encode($key), 1, -1);'; + + $php = $this->yieldString('{', $context) + .$this->flushYieldBuffer($context) + .$this->line('$prefix = \'\';', $context) + .$this->line("foreach ($accessor as \$key => ".$dataModelNode->getItemNode()->getAccessor().') {', $context); + + ++$context['indentation_level']; + $php .= $this->line($escapedKey, $context) + .$this->yield('"{$prefix}\"{$key}\":"', $context) + .$this->generateYields($dataModelNode->getItemNode(), $options, $context) + .$this->flushYieldBuffer($context) + .$this->line('$prefix = \',\';', $context); + + --$context['indentation_level']; + + return $php + .$this->line('}', $context) + .$this->yieldString('}', $context); + } + + if ($dataModelNode instanceof ObjectNode) { + if (isset($context['generated_generators'][$dataModelNode->getIdentifier()]) || $dataModelNode->isMock()) { + $depthArgument = ($context['generating_generator'] ?? false) ? '$depth + 1' : (string) $context['depth']; + + return $this->line('yield from $generators[\''.$dataModelNode->getIdentifier().'\']('.$accessor.', '.$depthArgument.');', $context); + } + + $php = $this->yieldString('{', $context); + $separator = ''; + + ++$context['depth']; + + foreach ($dataModelNode->getProperties() as $name => $propertyNode) { + $encodedName = json_encode($name); + if (false === $encodedName) { + throw new RuntimeException(\sprintf('Cannot encode "%s"', $name)); + } + + $encodedName = substr($encodedName, 1, -1); + + $php .= $this->yieldString($separator, $context) + .$this->yieldString('"', $context) + .$this->yieldString($encodedName, $context) + .$this->yieldString('":', $context) + .$this->generateYields($propertyNode, $options, $context); + + $separator = ','; + } + + return $php + .$this->yieldString('}', $context); + } + + throw new LogicException(\sprintf('Unexpected "%s" node', $dataModelNode::class)); + } + + /** + * @param array $context + */ + private function encode(string $value, array $context): string + { + return "\json_encode($value, \\JSON_THROW_ON_ERROR, ". 512 - $context['depth'].')'; + } + + /** + * @param array $context + */ + private function yield(string $value, array $context): string + { + return $this->flushYieldBuffer($context) + .$this->line("yield $value;", $context); + } + + /** + * @param array $context + */ + private function yieldString(string $string, array $context): string + { + $this->yieldBuffer .= $string; + + return ''; + } + + /** + * @param array $context + */ + private function flushYieldBuffer(array $context): string + { + if ('' === $this->yieldBuffer) { + return ''; + } + + $yieldBuffer = $this->yieldBuffer; + $this->yieldBuffer = ''; + + return $this->yield("'$yieldBuffer'", $context); + } + + private function generateCompositeNodeItemCondition(DataModelNodeInterface $node): string + { + $accessor = $node->getAccessor(); + $type = $node->getType(); + + if ($type->isIdentifiedBy(TypeIdentifier::NULL, TypeIdentifier::NEVER, TypeIdentifier::VOID)) { + return "null === $accessor"; + } + + if ($type->isIdentifiedBy(TypeIdentifier::TRUE)) { + return "true === $accessor"; + } + + if ($type->isIdentifiedBy(TypeIdentifier::FALSE)) { + return "false === $accessor"; + } + + if ($type->isIdentifiedBy(TypeIdentifier::MIXED)) { + return 'true'; + } + + while ($type instanceof WrappingTypeInterface) { + $type = $type->getWrappedType(); + } + + if ($type instanceof ObjectType) { + return "$accessor instanceof \\".$type->getClassName(); + } + + if ($type instanceof BuiltinType) { + return '\\is_'.$type->getTypeIdentifier()->value."($accessor)"; + } + + throw new LogicException(\sprintf('Unexpected "%s" type.', $type::class)); + } + + /** + * @param array $context + */ + private function line(string $line, array $context): string + { + return str_repeat(' ', $context['indentation_level']).$line."\n"; + } + + /** + * Determines if the $node can be encoded using a simple "json_encode". + */ + private function canBeEncodedWithJsonEncode(DataModelNodeInterface $node, int $depth = 0): bool + { + if ($node instanceof CompositeNode) { + foreach ($node->getNodes() as $n) { + if (!$this->canBeEncodedWithJsonEncode($n, $depth)) { + return false; + } + } + + return true; + } + + if ($node instanceof CollectionNode) { + return $this->canBeEncodedWithJsonEncode($node->getItemNode(), $depth + 1); + } + + if (!$node instanceof ScalarNode) { + return false; + } + + $type = $node->getType(); + + // "null" will be written directly using the "null" string + // "bool" will be written directly using the "true" or "false" string + // but it must not prevent any json_encode if nested + if ($type->isIdentifiedBy(TypeIdentifier::NULL) || $type->isIdentifiedBy(TypeIdentifier::BOOL)) { + return $depth > 0; + } + + return true; + } +} diff --git a/src/Symfony/Component/JsonStreamer/Write/PhpOptimizer.php b/src/Symfony/Component/JsonStreamer/Write/PhpOptimizer.php deleted file mode 100644 index 4dddaf47aac70..0000000000000 --- a/src/Symfony/Component/JsonStreamer/Write/PhpOptimizer.php +++ /dev/null @@ -1,43 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\JsonStreamer\Write; - -use PhpParser\Node; -use PhpParser\NodeTraverser; -use PhpParser\NodeVisitor\NodeConnectingVisitor; - -/** - * Optimizes a PHP syntax tree. - * - * @author Mathias Arlaud - * - * @internal - */ -final class PhpOptimizer -{ - /** - * @param list $nodes - * - * @return list - */ - public function optimize(array $nodes): array - { - $traverser = new NodeTraverser(); - $traverser->addVisitor(new NodeConnectingVisitor()); - $nodes = $traverser->traverse($nodes); - - $traverser = new NodeTraverser(); - $traverser->addVisitor(new MergingStringVisitor()); - - return $traverser->traverse($nodes); - } -} diff --git a/src/Symfony/Component/JsonStreamer/Write/StreamWriterGenerator.php b/src/Symfony/Component/JsonStreamer/Write/StreamWriterGenerator.php index c437ca0d179f5..4035d84770fbf 100644 --- a/src/Symfony/Component/JsonStreamer/Write/StreamWriterGenerator.php +++ b/src/Symfony/Component/JsonStreamer/Write/StreamWriterGenerator.php @@ -11,16 +11,8 @@ namespace Symfony\Component\JsonStreamer\Write; -use PhpParser\PhpVersion; -use PhpParser\PrettyPrinter; -use PhpParser\PrettyPrinter\Standard; use Symfony\Component\Filesystem\Exception\IOException; use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\JsonStreamer\DataModel\DataAccessorInterface; -use Symfony\Component\JsonStreamer\DataModel\FunctionDataAccessor; -use Symfony\Component\JsonStreamer\DataModel\PropertyDataAccessor; -use Symfony\Component\JsonStreamer\DataModel\ScalarDataAccessor; -use Symfony\Component\JsonStreamer\DataModel\VariableDataAccessor; use Symfony\Component\JsonStreamer\DataModel\Write\BackedEnumNode; use Symfony\Component\JsonStreamer\DataModel\Write\CollectionNode; use Symfony\Component\JsonStreamer\DataModel\Write\CompositeNode; @@ -48,9 +40,7 @@ */ final class StreamWriterGenerator { - private ?PhpAstBuilder $phpAstBuilder = null; - private ?PhpOptimizer $phpOptimizer = null; - private ?PrettyPrinter $phpPrinter = null; + private ?PhpGenerator $phpGenerator = null; private ?Filesystem $fs = null; public function __construct( @@ -71,17 +61,11 @@ public function generate(Type $type, array $options = []): string return $path; } - $this->phpAstBuilder ??= new PhpAstBuilder(); - $this->phpOptimizer ??= new PhpOptimizer(); - $this->phpPrinter ??= new Standard(['phpVersion' => PhpVersion::fromComponents(8, 2)]); + $this->phpGenerator ??= new PhpGenerator(); $this->fs ??= new Filesystem(); - $dataModel = $this->createDataModel($type, new VariableDataAccessor('data'), $options); - - $nodes = $this->phpAstBuilder->build($dataModel, $options); - $nodes = $this->phpOptimizer->optimize($nodes); - - $content = $this->phpPrinter->prettyPrintFile($nodes)."\n"; + $dataModel = $this->createDataModel($type, '$data', $options); + $php = $this->phpGenerator->generate($dataModel, $options); if (!$this->fs->exists($this->streamWritersDir)) { $this->fs->mkdir($this->streamWritersDir); @@ -90,7 +74,7 @@ public function generate(Type $type, array $options = []): string $tmpFile = $this->fs->tempnam(\dirname($path), basename($path)); try { - $this->fs->dumpFile($tmpFile, $content); + $this->fs->dumpFile($tmpFile, $php); $this->fs->rename($tmpFile, $path); $this->fs->chmod($path, 0666 & ~umask()); } catch (IOException $e) { @@ -109,7 +93,7 @@ private function getPath(Type $type): string * @param array $options * @param array $context */ - private function createDataModel(Type $type, DataAccessorInterface $accessor, array $options = [], array $context = []): DataModelNodeInterface + private function createDataModel(Type $type, string $accessor, array $options = [], array $context = []): DataModelNodeInterface { $context['original_type'] ??= $type; @@ -149,12 +133,12 @@ private function createDataModel(Type $type, DataAccessorInterface $accessor, ar $propertiesNodes = []; foreach ($propertiesMetadata as $streamedName => $propertyMetadata) { - $propertyAccessor = new PropertyDataAccessor($accessor, $propertyMetadata->getName()); + $propertyAccessor = $accessor.'->'.$propertyMetadata->getName(); foreach ($propertyMetadata->getNativeToStreamValueTransformer() as $valueTransformer) { if (\is_string($valueTransformer)) { - $valueTransformerServiceAccessor = new FunctionDataAccessor('get', [new ScalarDataAccessor($valueTransformer)], new VariableDataAccessor('valueTransformers')); - $propertyAccessor = new FunctionDataAccessor('transform', [$propertyAccessor, new VariableDataAccessor('options')], $valueTransformerServiceAccessor); + $valueTransformerServiceAccessor = "\$valueTransformers->get('$valueTransformer')"; + $propertyAccessor = "{$valueTransformerServiceAccessor}->transform($propertyAccessor, \$options)"; continue; } @@ -168,9 +152,9 @@ private function createDataModel(Type $type, DataAccessorInterface $accessor, ar $functionName = !$functionReflection->getClosureCalledClass() ? $functionReflection->getName() : \sprintf('%s::%s', $functionReflection->getClosureCalledClass()->getName(), $functionReflection->getName()); - $arguments = $functionReflection->isUserDefined() ? [$propertyAccessor, new VariableDataAccessor('options')] : [$propertyAccessor]; + $arguments = $functionReflection->isUserDefined() ? "$propertyAccessor, \$options" : $propertyAccessor; - $propertyAccessor = new FunctionDataAccessor($functionName, $arguments); + $propertyAccessor = "$functionName($arguments)"; } $propertiesNodes[$streamedName] = $this->createDataModel($propertyMetadata->getType(), $propertyAccessor, $options, $context); @@ -183,7 +167,7 @@ private function createDataModel(Type $type, DataAccessorInterface $accessor, ar return new CollectionNode( $accessor, $type, - $this->createDataModel($type->getCollectionValueType(), new VariableDataAccessor('value'), $options, $context), + $this->createDataModel($type->getCollectionValueType(), '$value', $options, $context), ); } diff --git a/src/Symfony/Component/JsonStreamer/composer.json b/src/Symfony/Component/JsonStreamer/composer.json index ba02d9fbc9172..ac3af9ee36b0a 100644 --- a/src/Symfony/Component/JsonStreamer/composer.json +++ b/src/Symfony/Component/JsonStreamer/composer.json @@ -16,18 +16,17 @@ } ], "require": { - "nikic/php-parser": "^5.3", "php": ">=8.2", "psr/container": "^1.1|^2.0", "psr/log": "^1|^2|^3", - "symfony/filesystem": "^7.2", - "symfony/type-info": "^7.2", - "symfony/var-exporter": "^7.2" + "symfony/filesystem": "^7.2|^8.0", + "symfony/type-info": "^7.2|^8.0", + "symfony/var-exporter": "^7.2|^8.0" }, "require-dev": { "phpstan/phpdoc-parser": "^1.0", - "symfony/dependency-injection": "^7.2", - "symfony/http-kernel": "^7.2" + "symfony/dependency-injection": "^7.2|^8.0", + "symfony/http-kernel": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\JsonStreamer\\": "" }, diff --git a/src/Symfony/Component/Ldap/Security/LdapUser.php b/src/Symfony/Component/Ldap/Security/LdapUser.php index ef73b82422d0b..020fcb5441596 100644 --- a/src/Symfony/Component/Ldap/Security/LdapUser.php +++ b/src/Symfony/Component/Ldap/Security/LdapUser.php @@ -47,7 +47,7 @@ public function getRoles(): array public function getPassword(): ?string { - return $this->password; + return $this->password ?? null; } public function getSalt(): ?string @@ -89,7 +89,7 @@ public function isEqualTo(UserInterface $user): bool return false; } - if ($this->getPassword() !== $user->getPassword()) { + if (($this->getPassword() ?? $user->getPassword()) !== $user->getPassword()) { return false; } diff --git a/src/Symfony/Component/Ldap/Tests/Security/LdapUserTest.php b/src/Symfony/Component/Ldap/Tests/Security/LdapUserTest.php new file mode 100644 index 0000000000000..0a696bcd0c29d --- /dev/null +++ b/src/Symfony/Component/Ldap/Tests/Security/LdapUserTest.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Ldap\Tests\Security; + +use PHPUnit\Framework\TestCase; +use Symfony\Component\Ldap\Entry; +use Symfony\Component\Ldap\Security\LdapUser; + +class LdapUserTest extends TestCase +{ + public function testIsEqualToWorksOnUnserializedUser() + { + $user = new LdapUser(new Entry('uid=jonhdoe,ou=MyBusiness,dc=symfony,dc=com', []), 'jonhdoe', 'p455w0rd'); + $unserializedUser = unserialize(serialize($user)); + + $this->assertTrue($unserializedUser->isEqualTo($user)); + } +} diff --git a/src/Symfony/Component/Ldap/composer.json b/src/Symfony/Component/Ldap/composer.json index 535ad186207ec..32a9ab27552d7 100644 --- a/src/Symfony/Component/Ldap/composer.json +++ b/src/Symfony/Component/Ldap/composer.json @@ -18,11 +18,11 @@ "require": { "php": ">=8.2", "ext-ldap": "*", - "symfony/options-resolver": "^7.3" + "symfony/options-resolver": "^7.3|^8.0" }, "require-dev": { - "symfony/security-core": "^6.4|^7.0", - "symfony/security-http": "^6.4|^7.0" + "symfony/security-core": "^6.4|^7.0|^8.0", + "symfony/security-http": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/security-core": "<6.4" diff --git a/src/Symfony/Component/Mailer/Bridge/AhaSend/composer.json b/src/Symfony/Component/Mailer/Bridge/AhaSend/composer.json index 65fae0816c89d..3eeaa278a962d 100644 --- a/src/Symfony/Component/Mailer/Bridge/AhaSend/composer.json +++ b/src/Symfony/Component/Mailer/Bridge/AhaSend/composer.json @@ -18,11 +18,11 @@ "require": { "php": ">=8.2", "psr/event-dispatcher": "^1", - "symfony/mailer": "^7.3" + "symfony/mailer": "^7.3|^8.0" }, "require-dev": { - "symfony/http-client": "^6.4|^7.0", - "symfony/webhook": "^6.4|^7.0" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/webhook": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Mailer\\Bridge\\AhaSend\\": "" }, diff --git a/src/Symfony/Component/Mailer/Bridge/Amazon/composer.json b/src/Symfony/Component/Mailer/Bridge/Amazon/composer.json index 3b8cd7cd49cb9..323b03519608e 100644 --- a/src/Symfony/Component/Mailer/Bridge/Amazon/composer.json +++ b/src/Symfony/Component/Mailer/Bridge/Amazon/composer.json @@ -18,10 +18,10 @@ "require": { "php": ">=8.2", "async-aws/ses": "^1.8", - "symfony/mailer": "^7.2" + "symfony/mailer": "^7.2|^8.0" }, "require-dev": { - "symfony/http-client": "^6.4|^7.0" + "symfony/http-client": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Mailer\\Bridge\\Amazon\\": "" }, diff --git a/src/Symfony/Component/Mailer/Bridge/Azure/composer.json b/src/Symfony/Component/Mailer/Bridge/Azure/composer.json index c8396c21913e0..2772c273ef38e 100644 --- a/src/Symfony/Component/Mailer/Bridge/Azure/composer.json +++ b/src/Symfony/Component/Mailer/Bridge/Azure/composer.json @@ -17,10 +17,10 @@ ], "require": { "php": ">=8.2", - "symfony/mailer": "^7.2" + "symfony/mailer": "^7.2|^8.0" }, "require-dev": { - "symfony/http-client": "^6.4|^7.0" + "symfony/http-client": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Mailer\\Bridge\\Azure\\": "" }, diff --git a/src/Symfony/Component/Mailer/Bridge/Brevo/composer.json b/src/Symfony/Component/Mailer/Bridge/Brevo/composer.json index 441dada9ef97d..2fa9bfa4905be 100644 --- a/src/Symfony/Component/Mailer/Bridge/Brevo/composer.json +++ b/src/Symfony/Component/Mailer/Bridge/Brevo/composer.json @@ -16,12 +16,12 @@ } ], "require": { - "php": ">=8.1", - "symfony/mailer": "^7.2" + "php": ">=8.2", + "symfony/mailer": "^7.2|^8.0" }, "require-dev": { - "symfony/http-client": "^6.3|^7.0", - "symfony/webhook": "^6.3|^7.0" + "symfony/http-client": "^6.3|^7.0|^8.0", + "symfony/webhook": "^6.3|^7.0|^8.0" }, "conflict": { "symfony/mime": "<6.2" diff --git a/src/Symfony/Component/Mailer/Bridge/Google/composer.json b/src/Symfony/Component/Mailer/Bridge/Google/composer.json index 13ba43762d942..c60576d8fb9d4 100644 --- a/src/Symfony/Component/Mailer/Bridge/Google/composer.json +++ b/src/Symfony/Component/Mailer/Bridge/Google/composer.json @@ -17,10 +17,10 @@ ], "require": { "php": ">=8.2", - "symfony/mailer": "^7.2" + "symfony/mailer": "^7.2|^8.0" }, "require-dev": { - "symfony/http-client": "^6.4|^7.0" + "symfony/http-client": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Mailer\\Bridge\\Google\\": "" }, diff --git a/src/Symfony/Component/Mailer/Bridge/Infobip/composer.json b/src/Symfony/Component/Mailer/Bridge/Infobip/composer.json index e15a7a3d17f4a..5d94ecc9e8c80 100644 --- a/src/Symfony/Component/Mailer/Bridge/Infobip/composer.json +++ b/src/Symfony/Component/Mailer/Bridge/Infobip/composer.json @@ -21,11 +21,11 @@ ], "require": { "php": ">=8.2", - "symfony/mailer": "^7.2", - "symfony/mime": "^6.4|^7.0" + "symfony/mailer": "^7.2|^8.0", + "symfony/mime": "^6.4|^7.0|^8.0" }, "require-dev": { - "symfony/http-client": "^6.4|^7.0" + "symfony/http-client": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/mime": "<6.4" diff --git a/src/Symfony/Component/Mailer/Bridge/MailPace/composer.json b/src/Symfony/Component/Mailer/Bridge/MailPace/composer.json index 9e962e28fc17f..77332cf2cc438 100644 --- a/src/Symfony/Component/Mailer/Bridge/MailPace/composer.json +++ b/src/Symfony/Component/Mailer/Bridge/MailPace/composer.json @@ -22,10 +22,10 @@ "require": { "php": ">=8.2", "psr/event-dispatcher": "^1", - "symfony/mailer": "^7.2" + "symfony/mailer": "^7.2|^8.0" }, "require-dev": { - "symfony/http-client": "^6.4|^7.0" + "symfony/http-client": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Mailer\\Bridge\\MailPace\\": "" }, diff --git a/src/Symfony/Component/Mailer/Bridge/Mailchimp/composer.json b/src/Symfony/Component/Mailer/Bridge/Mailchimp/composer.json index 081b5998e6206..29ffb27b889b1 100644 --- a/src/Symfony/Component/Mailer/Bridge/Mailchimp/composer.json +++ b/src/Symfony/Component/Mailer/Bridge/Mailchimp/composer.json @@ -17,11 +17,11 @@ ], "require": { "php": ">=8.2", - "symfony/mailer": "^7.2" + "symfony/mailer": "^7.2|^8.0" }, "require-dev": { - "symfony/http-client": "^6.4|^7.0", - "symfony/webhook": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/webhook": "^7.2|^8.0" }, "conflict": { "symfony/webhook": "<7.2" diff --git a/src/Symfony/Component/Mailer/Bridge/MailerSend/Transport/MailerSendSmtpTransport.php b/src/Symfony/Component/Mailer/Bridge/MailerSend/Transport/MailerSendSmtpTransport.php index 84e2553a627cc..e5bfb4daddc2e 100644 --- a/src/Symfony/Component/Mailer/Bridge/MailerSend/Transport/MailerSendSmtpTransport.php +++ b/src/Symfony/Component/Mailer/Bridge/MailerSend/Transport/MailerSendSmtpTransport.php @@ -22,7 +22,7 @@ final class MailerSendSmtpTransport extends EsmtpTransport { public function __construct(string $username, #[\SensitiveParameter] string $password, ?EventDispatcherInterface $dispatcher = null, ?LoggerInterface $logger = null) { - parent::__construct('smtp.mailersend.net', 587, true, $dispatcher, $logger); + parent::__construct('smtp.mailersend.net', 587, false, $dispatcher, $logger); $this->setUsername($username); $this->setPassword($password); diff --git a/src/Symfony/Component/Mailer/Bridge/MailerSend/composer.json b/src/Symfony/Component/Mailer/Bridge/MailerSend/composer.json index 96357327da187..23831dc41c80e 100644 --- a/src/Symfony/Component/Mailer/Bridge/MailerSend/composer.json +++ b/src/Symfony/Component/Mailer/Bridge/MailerSend/composer.json @@ -21,11 +21,11 @@ ], "require": { "php": ">=8.2", - "symfony/mailer": "^7.2" + "symfony/mailer": "^7.2|^8.0" }, "require-dev": { - "symfony/http-client": "^6.4|^7.0", - "symfony/webhook": "^6.3|^7.0" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/webhook": "^6.3|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Mailer\\Bridge\\MailerSend\\": "" }, diff --git a/src/Symfony/Component/Mailer/Bridge/Mailgun/composer.json b/src/Symfony/Component/Mailer/Bridge/Mailgun/composer.json index 3a5a475e3e44b..b68dbb7152fae 100644 --- a/src/Symfony/Component/Mailer/Bridge/Mailgun/composer.json +++ b/src/Symfony/Component/Mailer/Bridge/Mailgun/composer.json @@ -17,11 +17,11 @@ ], "require": { "php": ">=8.2", - "symfony/mailer": "^7.2" + "symfony/mailer": "^7.2|^8.0" }, "require-dev": { - "symfony/http-client": "^6.4|^7.0", - "symfony/webhook": "^6.4|^7.0" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/webhook": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/http-foundation": "<6.4" diff --git a/src/Symfony/Component/Mailer/Bridge/Mailjet/composer.json b/src/Symfony/Component/Mailer/Bridge/Mailjet/composer.json index 3abc7eb31c135..f4877458b212a 100644 --- a/src/Symfony/Component/Mailer/Bridge/Mailjet/composer.json +++ b/src/Symfony/Component/Mailer/Bridge/Mailjet/composer.json @@ -17,11 +17,11 @@ ], "require": { "php": ">=8.2", - "symfony/mailer": "^7.3" + "symfony/mailer": "^7.3|^8.0" }, "require-dev": { - "symfony/http-client": "^6.4|^7.0", - "symfony/webhook": "^6.4|^7.0" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/webhook": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Mailer\\Bridge\\Mailjet\\": "" }, diff --git a/src/Symfony/Component/Mailer/Bridge/Mailomat/composer.json b/src/Symfony/Component/Mailer/Bridge/Mailomat/composer.json index 2d4cc3f1c8515..dd8e043a2a9c2 100644 --- a/src/Symfony/Component/Mailer/Bridge/Mailomat/composer.json +++ b/src/Symfony/Component/Mailer/Bridge/Mailomat/composer.json @@ -17,12 +17,12 @@ ], "require": { "php": ">=8.2", - "symfony/mailer": "^7.2" + "symfony/mailer": "^7.2|^8.0" }, "require-dev": { - "symfony/http-client": "^6.4|^7.0", - "symfony/http-foundation": "^7.1", - "symfony/webhook": "^6.4|^7.0" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/http-foundation": "^7.1|^8.0", + "symfony/webhook": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/http-foundation": "<7.1" diff --git a/src/Symfony/Component/Mailer/Bridge/Mailtrap/composer.json b/src/Symfony/Component/Mailer/Bridge/Mailtrap/composer.json index 7d448e7c40768..3fa19c63a89ed 100644 --- a/src/Symfony/Component/Mailer/Bridge/Mailtrap/composer.json +++ b/src/Symfony/Component/Mailer/Bridge/Mailtrap/composer.json @@ -18,11 +18,11 @@ "require": { "php": ">=8.2", "psr/event-dispatcher": "^1", - "symfony/mailer": "^7.2" + "symfony/mailer": "^7.2|^8.0" }, "require-dev": { - "symfony/http-client": "^6.4|^7.0", - "symfony/webhook": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/webhook": "^7.2|^8.0" }, "conflict": { "symfony/webhook": "<7.2" diff --git a/src/Symfony/Component/Mailer/Bridge/Postal/composer.json b/src/Symfony/Component/Mailer/Bridge/Postal/composer.json index 8c3d3dfe8eda4..62fa6bf19db95 100644 --- a/src/Symfony/Component/Mailer/Bridge/Postal/composer.json +++ b/src/Symfony/Component/Mailer/Bridge/Postal/composer.json @@ -17,10 +17,10 @@ ], "require": { "php": ">=8.2", - "symfony/mailer": "^7.2" + "symfony/mailer": "^7.2|^8.0" }, "require-dev": { - "symfony/http-client": "^6.4|^7.0" + "symfony/http-client": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Mailer\\Bridge\\Postal\\": "" }, diff --git a/src/Symfony/Component/Mailer/Bridge/Postmark/composer.json b/src/Symfony/Component/Mailer/Bridge/Postmark/composer.json index 0451fec7f96ce..45bc2c17b6630 100644 --- a/src/Symfony/Component/Mailer/Bridge/Postmark/composer.json +++ b/src/Symfony/Component/Mailer/Bridge/Postmark/composer.json @@ -18,11 +18,11 @@ "require": { "php": ">=8.2", "psr/event-dispatcher": "^1", - "symfony/mailer": "^7.2" + "symfony/mailer": "^7.2|^8.0" }, "require-dev": { - "symfony/http-client": "^6.4|^7.0", - "symfony/webhook": "^6.4|^7.0" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/webhook": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/http-foundation": "<6.4" diff --git a/src/Symfony/Component/Mailer/Bridge/Resend/composer.json b/src/Symfony/Component/Mailer/Bridge/Resend/composer.json index 0fe9a6f79df3c..66cdd2efbaa27 100644 --- a/src/Symfony/Component/Mailer/Bridge/Resend/composer.json +++ b/src/Symfony/Component/Mailer/Bridge/Resend/composer.json @@ -16,13 +16,13 @@ } ], "require": { - "php": ">=8.1", - "symfony/mailer": "^7.2" + "php": ">=8.2", + "symfony/mailer": "^7.2|^8.0" }, "require-dev": { - "symfony/http-client": "^6.4|^7.0", - "symfony/http-foundation": "^7.1", - "symfony/webhook": "^6.4|^7.0" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/http-foundation": "^7.1|^8.0", + "symfony/webhook": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/http-foundation": "<7.1" diff --git a/src/Symfony/Component/Mailer/Bridge/Scaleway/composer.json b/src/Symfony/Component/Mailer/Bridge/Scaleway/composer.json index 1ad65e470f641..f4c3e825d86d1 100644 --- a/src/Symfony/Component/Mailer/Bridge/Scaleway/composer.json +++ b/src/Symfony/Component/Mailer/Bridge/Scaleway/composer.json @@ -16,11 +16,11 @@ } ], "require": { - "php": ">=8.1", - "symfony/mailer": "^7.2" + "php": ">=8.2", + "symfony/mailer": "^7.2|^8.0" }, "require-dev": { - "symfony/http-client": "^6.4|^7.0" + "symfony/http-client": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Mailer\\Bridge\\Scaleway\\": "" }, diff --git a/src/Symfony/Component/Mailer/Bridge/Sendgrid/composer.json b/src/Symfony/Component/Mailer/Bridge/Sendgrid/composer.json index 700aabef20a7d..899b4f6d9d4d0 100644 --- a/src/Symfony/Component/Mailer/Bridge/Sendgrid/composer.json +++ b/src/Symfony/Component/Mailer/Bridge/Sendgrid/composer.json @@ -17,11 +17,11 @@ ], "require": { "php": ">=8.2", - "symfony/mailer": "^7.2" + "symfony/mailer": "^7.2|^8.0" }, "require-dev": { - "symfony/http-client": "^6.4|^7.0", - "symfony/webhook": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/webhook": "^7.2|^8.0" }, "conflict": { "symfony/mime": "<6.4", diff --git a/src/Symfony/Component/Mailer/Bridge/Sweego/composer.json b/src/Symfony/Component/Mailer/Bridge/Sweego/composer.json index 4fbe23334d574..4db381b4a9816 100644 --- a/src/Symfony/Component/Mailer/Bridge/Sweego/composer.json +++ b/src/Symfony/Component/Mailer/Bridge/Sweego/composer.json @@ -16,13 +16,13 @@ } ], "require": { - "php": ">=8.1", - "symfony/mailer": "^7.2" + "php": ">=8.2", + "symfony/mailer": "^7.2|^8.0" }, "require-dev": { - "symfony/http-client": "^6.4|^7.0", - "symfony/http-foundation": "^7.1", - "symfony/webhook": "^6.4|^7.0" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/http-foundation": "^7.1|^8.0", + "symfony/webhook": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/http-foundation": "<7.1" diff --git a/src/Symfony/Component/Mailer/composer.json b/src/Symfony/Component/Mailer/composer.json index 4336e725133fc..105fa39cd46bb 100644 --- a/src/Symfony/Component/Mailer/composer.json +++ b/src/Symfony/Component/Mailer/composer.json @@ -20,15 +20,15 @@ "egulias/email-validator": "^2.1.10|^3|^4", "psr/event-dispatcher": "^1", "psr/log": "^1|^2|^3", - "symfony/event-dispatcher": "^6.4|^7.0", - "symfony/mime": "^7.2", + "symfony/event-dispatcher": "^6.4|^7.0|^8.0", + "symfony/mime": "^7.2|^8.0", "symfony/service-contracts": "^2.5|^3" }, "require-dev": { - "symfony/console": "^6.4|^7.0", - "symfony/http-client": "^6.4|^7.0", - "symfony/messenger": "^6.4|^7.0", - "symfony/twig-bridge": "^6.4|^7.0" + "symfony/console": "^6.4|^7.0|^8.0", + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/messenger": "^6.4|^7.0|^8.0", + "symfony/twig-bridge": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/http-client-contracts": "<2.5", diff --git a/src/Symfony/Component/Messenger/Bridge/AmazonSqs/composer.json b/src/Symfony/Component/Messenger/Bridge/AmazonSqs/composer.json index f334cd349c969..9e6904978670d 100644 --- a/src/Symfony/Component/Messenger/Bridge/AmazonSqs/composer.json +++ b/src/Symfony/Component/Messenger/Bridge/AmazonSqs/composer.json @@ -19,14 +19,14 @@ "php": ">=8.2", "async-aws/core": "^1.7", "async-aws/sqs": "^1.0|^2.0", - "symfony/messenger": "^7.3", + "symfony/messenger": "^7.3|^8.0", "symfony/service-contracts": "^2.5|^3", "psr/log": "^1|^2|^3" }, "require-dev": { "symfony/http-client-contracts": "^2.5|^3", - "symfony/property-access": "^6.4|^7.0", - "symfony/serializer": "^6.4|^7.0" + "symfony/property-access": "^6.4|^7.0|^8.0", + "symfony/serializer": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/http-client-contracts": "<2.5" diff --git a/src/Symfony/Component/Messenger/Bridge/Amqp/Transport/Connection.php b/src/Symfony/Component/Messenger/Bridge/Amqp/Transport/Connection.php index d5a6b666075f7..2599586f8f3d8 100644 --- a/src/Symfony/Component/Messenger/Bridge/Amqp/Transport/Connection.php +++ b/src/Symfony/Component/Messenger/Bridge/Amqp/Transport/Connection.php @@ -31,6 +31,7 @@ class Connection 'x-max-length-bytes', 'x-max-priority', 'x-message-ttl', + 'x-delivery-limit', ]; /** diff --git a/src/Symfony/Component/Messenger/Bridge/Amqp/composer.json b/src/Symfony/Component/Messenger/Bridge/Amqp/composer.json index 7e078f524fb9f..fcc2ceba9906e 100644 --- a/src/Symfony/Component/Messenger/Bridge/Amqp/composer.json +++ b/src/Symfony/Component/Messenger/Bridge/Amqp/composer.json @@ -18,13 +18,13 @@ "require": { "php": ">=8.2", "ext-amqp": "*", - "symfony/messenger": "^7.3" + "symfony/messenger": "^7.3|^8.0" }, "require-dev": { - "symfony/event-dispatcher": "^6.4|^7.0", - "symfony/process": "^6.4|^7.0", - "symfony/property-access": "^6.4|^7.0", - "symfony/serializer": "^6.4|^7.0" + "symfony/event-dispatcher": "^6.4|^7.0|^8.0", + "symfony/process": "^6.4|^7.0|^8.0", + "symfony/property-access": "^6.4|^7.0|^8.0", + "symfony/serializer": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Messenger\\Bridge\\Amqp\\": "" }, diff --git a/src/Symfony/Component/Messenger/Bridge/Beanstalkd/composer.json b/src/Symfony/Component/Messenger/Bridge/Beanstalkd/composer.json index bed9817cedab3..a96066c79790b 100644 --- a/src/Symfony/Component/Messenger/Bridge/Beanstalkd/composer.json +++ b/src/Symfony/Component/Messenger/Bridge/Beanstalkd/composer.json @@ -14,11 +14,11 @@ "require": { "php": ">=8.2", "pda/pheanstalk": "^5.1|^7.0", - "symfony/messenger": "^7.3" + "symfony/messenger": "^7.3|^8.0" }, "require-dev": { - "symfony/property-access": "^6.4|^7.0", - "symfony/serializer": "^6.4|^7.0" + "symfony/property-access": "^6.4|^7.0|^8.0", + "symfony/serializer": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Messenger\\Bridge\\Beanstalkd\\": "" }, diff --git a/src/Symfony/Component/Messenger/Bridge/Doctrine/composer.json b/src/Symfony/Component/Messenger/Bridge/Doctrine/composer.json index eabf0a9138c91..8f98bfc979092 100644 --- a/src/Symfony/Component/Messenger/Bridge/Doctrine/composer.json +++ b/src/Symfony/Component/Messenger/Bridge/Doctrine/composer.json @@ -18,13 +18,13 @@ "require": { "php": ">=8.2", "doctrine/dbal": "^3.6|^4", - "symfony/messenger": "^7.2", + "symfony/messenger": "^7.2|^8.0", "symfony/service-contracts": "^2.5|^3" }, "require-dev": { "doctrine/persistence": "^1.3|^2|^3", - "symfony/property-access": "^6.4|^7.0", - "symfony/serializer": "^6.4|^7.0" + "symfony/property-access": "^6.4|^7.0|^8.0", + "symfony/serializer": "^6.4|^7.0|^8.0" }, "conflict": { "doctrine/persistence": "<1.3" diff --git a/src/Symfony/Component/Messenger/Bridge/Redis/composer.json b/src/Symfony/Component/Messenger/Bridge/Redis/composer.json index 050211bb2d36a..d02f4ec0df1be 100644 --- a/src/Symfony/Component/Messenger/Bridge/Redis/composer.json +++ b/src/Symfony/Component/Messenger/Bridge/Redis/composer.json @@ -18,11 +18,11 @@ "require": { "php": ">=8.2", "ext-redis": "*", - "symfony/messenger": "^7.3" + "symfony/messenger": "^7.3|^8.0" }, "require-dev": { - "symfony/property-access": "^6.4|^7.0", - "symfony/serializer": "^6.4|^7.0" + "symfony/property-access": "^6.4|^7.0|^8.0", + "symfony/serializer": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Messenger\\Bridge\\Redis\\": "" }, diff --git a/src/Symfony/Component/Messenger/composer.json b/src/Symfony/Component/Messenger/composer.json index 94de9f2439c95..523513be77651 100644 --- a/src/Symfony/Component/Messenger/composer.json +++ b/src/Symfony/Component/Messenger/composer.json @@ -18,24 +18,24 @@ "require": { "php": ">=8.2", "psr/log": "^1|^2|^3", - "symfony/clock": "^6.4|^7.0", + "symfony/clock": "^6.4|^7.0|^8.0", "symfony/deprecation-contracts": "^2.5|^3" }, "require-dev": { "psr/cache": "^1.0|^2.0|^3.0", - "symfony/console": "^7.2", - "symfony/dependency-injection": "^6.4|^7.0", - "symfony/event-dispatcher": "^6.4|^7.0", - "symfony/http-kernel": "^6.4|^7.0", - "symfony/process": "^6.4|^7.0", - "symfony/property-access": "^6.4|^7.0", - "symfony/lock": "^6.4|^7.0", - "symfony/rate-limiter": "^6.4|^7.0", - "symfony/routing": "^6.4|^7.0", - "symfony/serializer": "^6.4|^7.0", + "symfony/console": "^7.2|^8.0", + "symfony/dependency-injection": "^6.4|^7.0|^8.0", + "symfony/event-dispatcher": "^6.4|^7.0|^8.0", + "symfony/http-kernel": "^6.4|^7.0|^8.0", + "symfony/process": "^6.4|^7.0|^8.0", + "symfony/property-access": "^6.4|^7.0|^8.0", + "symfony/lock": "^6.4|^7.0|^8.0", + "symfony/rate-limiter": "^6.4|^7.0|^8.0", + "symfony/routing": "^6.4|^7.0|^8.0", + "symfony/serializer": "^6.4|^7.0|^8.0", "symfony/service-contracts": "^2.5|^3", - "symfony/stopwatch": "^6.4|^7.0", - "symfony/validator": "^6.4|^7.0" + "symfony/stopwatch": "^6.4|^7.0|^8.0", + "symfony/validator": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/console": "<7.2", diff --git a/src/Symfony/Component/Mime/composer.json b/src/Symfony/Component/Mime/composer.json index 5304bdf36d90b..e5cbc3cb651a4 100644 --- a/src/Symfony/Component/Mime/composer.json +++ b/src/Symfony/Component/Mime/composer.json @@ -24,11 +24,11 @@ "egulias/email-validator": "^2.1.10|^3.1|^4", "league/html-to-markdown": "^5.0", "phpdocumentor/reflection-docblock": "^3.0|^4.0|^5.0", - "symfony/dependency-injection": "^6.4|^7.0", - "symfony/process": "^6.4|^7.0", - "symfony/property-access": "^6.4|^7.0", - "symfony/property-info": "^6.4|^7.0", - "symfony/serializer": "^6.4.3|^7.0.3" + "symfony/dependency-injection": "^6.4|^7.0|^8.0", + "symfony/process": "^6.4|^7.0|^8.0", + "symfony/property-access": "^6.4|^7.0|^8.0", + "symfony/property-info": "^6.4|^7.0|^8.0", + "symfony/serializer": "^6.4.3|^7.0.3|^8.0" }, "conflict": { "egulias/email-validator": "~3.0.0", diff --git a/src/Symfony/Component/Notifier/Bridge/AllMySms/composer.json b/src/Symfony/Component/Notifier/Bridge/AllMySms/composer.json index cdfed6cfc1f8c..d3e2a3756b51f 100644 --- a/src/Symfony/Component/Notifier/Bridge/AllMySms/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/AllMySms/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.3" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.3|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\AllMySms\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/AmazonSns/composer.json b/src/Symfony/Component/Notifier/Bridge/AmazonSns/composer.json index 7c75c725424f1..8bbd2e750db1e 100644 --- a/src/Symfony/Component/Notifier/Bridge/AmazonSns/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/AmazonSns/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2", + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0", "async-aws/sns": "^1.0" }, "autoload": { diff --git a/src/Symfony/Component/Notifier/Bridge/Bandwidth/composer.json b/src/Symfony/Component/Notifier/Bridge/Bandwidth/composer.json index 3dae426e42b46..4255e3d08a571 100644 --- a/src/Symfony/Component/Notifier/Bridge/Bandwidth/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Bandwidth/composer.json @@ -20,11 +20,11 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "require-dev": { - "symfony/event-dispatcher": "^6.4|^7.0" + "symfony/event-dispatcher": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Bandwidth\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Bluesky/composer.json b/src/Symfony/Component/Notifier/Bridge/Bluesky/composer.json index b6f2a542b6258..82aab39f5f248 100644 --- a/src/Symfony/Component/Notifier/Bridge/Bluesky/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Bluesky/composer.json @@ -22,13 +22,13 @@ "require": { "php": ">=8.2", "psr/log": "^1|^2|^3", - "symfony/clock": "^6.4|^7.0", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.3", - "symfony/string": "^6.4|^7.0" + "symfony/clock": "^6.4|^7.0|^8.0", + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.3|^8.0", + "symfony/string": "^6.4|^7.0|^8.0" }, "require-dev": { - "symfony/mime": "^6.4|^7.0" + "symfony/mime": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Bluesky\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Brevo/composer.json b/src/Symfony/Component/Notifier/Bridge/Brevo/composer.json index 96da9a51281de..fa530a5ebadab 100644 --- a/src/Symfony/Component/Notifier/Bridge/Brevo/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Brevo/composer.json @@ -17,11 +17,11 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.3" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.3|^8.0" }, "require-dev": { - "symfony/event-dispatcher": "^5.4|^6.0|^7.0" + "symfony/event-dispatcher": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Brevo\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Chatwork/composer.json b/src/Symfony/Component/Notifier/Bridge/Chatwork/composer.json index c1cbe7a01adaa..edc0c6395dc06 100644 --- a/src/Symfony/Component/Notifier/Bridge/Chatwork/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Chatwork/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Chatwork\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/ClickSend/ClickSendTransport.php b/src/Symfony/Component/Notifier/Bridge/ClickSend/ClickSendTransport.php index 8d8987e4f7c7a..65f48bcd7ac19 100644 --- a/src/Symfony/Component/Notifier/Bridge/ClickSend/ClickSendTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/ClickSend/ClickSendTransport.php @@ -75,19 +75,19 @@ protected function doSend(MessageInterface $message): SentMessage $options['from'] = $message->getFrom() ?: $this->from; $options['source'] ??= $this->source; $options['list_id'] ??= $this->listId; - $options['from_email'] ?? $this->fromEmail; + $options['from_email'] ??= $this->fromEmail; if (isset($options['from']) && !preg_match('/^[a-zA-Z0-9\s]{3,11}$/', $options['from']) && !preg_match('/^\+[1-9]\d{1,14}$/', $options['from'])) { throw new InvalidArgumentException(\sprintf('The "From" number "%s" is not a valid phone number, shortcode, or alphanumeric sender ID.', $options['from'])); } - if ($options['list_id'] ?? false) { + if (!$options['list_id']) { $options['to'] = $message->getPhone(); } $response = $this->client->request('POST', $endpoint, [ 'auth_basic' => [$this->apiUsername, $this->apiKey], - 'json' => array_filter($options), + 'json' => ['messages' => [array_filter($options)]], ]); try { diff --git a/src/Symfony/Component/Notifier/Bridge/ClickSend/Tests/ClickSendTransportTest.php b/src/Symfony/Component/Notifier/Bridge/ClickSend/Tests/ClickSendTransportTest.php index 6afae4409fa57..532c5aceba3aa 100644 --- a/src/Symfony/Component/Notifier/Bridge/ClickSend/Tests/ClickSendTransportTest.php +++ b/src/Symfony/Component/Notifier/Bridge/ClickSend/Tests/ClickSendTransportTest.php @@ -24,7 +24,7 @@ final class ClickSendTransportTest extends TransportTestCase { - public static function createTransport(?HttpClientInterface $client = null, string $from = 'test_from', string $source = 'test_source', int $listId = 99, string $fromEmail = 'foo@bar.com'): ClickSendTransport + public static function createTransport(?HttpClientInterface $client = null, ?string $from = 'test_from', ?string $source = 'test_source', ?int $listId = 99, ?string $fromEmail = 'foo@bar.com'): ClickSendTransport { return new ClickSendTransport('test_username', 'test_key', $from, $source, $listId, $fromEmail, $client ?? new MockHttpClient()); } @@ -63,16 +63,47 @@ public function testNoInvalidArgumentExceptionIsThrownIfFromIsValid(string $from $response = $this->createMock(ResponseInterface::class); $response->expects(self::exactly(2))->method('getStatusCode')->willReturn(200); $response->expects(self::once())->method('getContent')->willReturn(''); - $client = new MockHttpClient(function (string $method, string $url) use ($response): ResponseInterface { + $client = new MockHttpClient(function (string $method, string $url, array $options) use ($response): ResponseInterface { self::assertSame('POST', $method); self::assertSame('https://rest.clicksend.com/v3/sms/send', $url); + $body = json_decode($options['body'], true); + self::assertIsArray($body); + self::assertArrayHasKey('messages', $body); + $message = reset($body['messages']); + self::assertArrayHasKey('from_email', $message); + self::assertArrayHasKey('list_id', $message); + self::assertArrayNotHasKey('to', $message); + return $response; }); $transport = $this->createTransport($client, $from); $transport->send($message); } + public function testNoInvalidArgumentExceptionIsThrownIfFromIsValidWithoutOptionalParameters() + { + $message = new SmsMessage('+33612345678', 'Hello!'); + $response = $this->createMock(ResponseInterface::class); + $response->expects(self::exactly(2))->method('getStatusCode')->willReturn(200); + $response->expects(self::once())->method('getContent')->willReturn(''); + $client = new MockHttpClient(function (string $method, string $url, array $options) use ($response): ResponseInterface { + self::assertSame('POST', $method); + self::assertSame('https://rest.clicksend.com/v3/sms/send', $url); + + $body = json_decode($options['body'], true); + self::assertIsArray($body); + self::assertArrayHasKey('messages', $body); + $message = reset($body['messages']); + self::assertArrayNotHasKey('list_id', $message); + self::assertArrayHasKey('to', $message); + + return $response; + }); + $transport = $this->createTransport($client, null, null, null, null); + $transport->send($message); + } + public static function toStringProvider(): iterable { yield ['clicksend://rest.clicksend.com?from=test_from&source=test_source&list_id=99&from_email=foo%40bar.com', self::createTransport()]; diff --git a/src/Symfony/Component/Notifier/Bridge/ClickSend/composer.json b/src/Symfony/Component/Notifier/Bridge/ClickSend/composer.json index 1676fea9e458f..5f264d6403adf 100644 --- a/src/Symfony/Component/Notifier/Bridge/ClickSend/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/ClickSend/composer.json @@ -20,11 +20,11 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "require-dev": { - "symfony/event-dispatcher": "^6.4|^7.0" + "symfony/event-dispatcher": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\ClickSend\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Clickatell/composer.json b/src/Symfony/Component/Notifier/Bridge/Clickatell/composer.json index 020ce41f9ca12..1f7c9d08b1605 100644 --- a/src/Symfony/Component/Notifier/Bridge/Clickatell/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Clickatell/composer.json @@ -21,8 +21,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Clickatell\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/ContactEveryone/composer.json b/src/Symfony/Component/Notifier/Bridge/ContactEveryone/composer.json index 6e18ed4424747..3ccdab9f9ebc4 100644 --- a/src/Symfony/Component/Notifier/Bridge/ContactEveryone/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/ContactEveryone/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\ContactEveryone\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Discord/composer.json b/src/Symfony/Component/Notifier/Bridge/Discord/composer.json index 4567a41f14f65..76ac74d512119 100644 --- a/src/Symfony/Component/Notifier/Bridge/Discord/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Discord/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2", + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0", "symfony/polyfill-mbstring": "^1.0" }, "autoload": { diff --git a/src/Symfony/Component/Notifier/Bridge/Engagespot/composer.json b/src/Symfony/Component/Notifier/Bridge/Engagespot/composer.json index 917b8304e9636..dd9be4b9bba3f 100644 --- a/src/Symfony/Component/Notifier/Bridge/Engagespot/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Engagespot/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Engagespot\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Esendex/composer.json b/src/Symfony/Component/Notifier/Bridge/Esendex/composer.json index a7beb52075fa3..584c309000367 100644 --- a/src/Symfony/Component/Notifier/Bridge/Esendex/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Esendex/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Esendex\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Expo/composer.json b/src/Symfony/Component/Notifier/Bridge/Expo/composer.json index 002a08c0152a2..015e98d1f6c03 100644 --- a/src/Symfony/Component/Notifier/Bridge/Expo/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Expo/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Expo\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/FakeChat/composer.json b/src/Symfony/Component/Notifier/Bridge/FakeChat/composer.json index 24e05807ec32d..447436ba0fd71 100644 --- a/src/Symfony/Component/Notifier/Bridge/FakeChat/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/FakeChat/composer.json @@ -22,12 +22,12 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "require-dev": { "psr/log": "^1|^2|^3", - "symfony/mailer": "^6.4|^7.0" + "symfony/mailer": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\FakeChat\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/FakeSms/composer.json b/src/Symfony/Component/Notifier/Bridge/FakeSms/composer.json index 366ec1b8c48fb..4b5a022065e0f 100644 --- a/src/Symfony/Component/Notifier/Bridge/FakeSms/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/FakeSms/composer.json @@ -22,12 +22,12 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "require-dev": { "psr/log": "^1|^2|^3", - "symfony/mailer": "^6.4|^7.0" + "symfony/mailer": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\FakeSms\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Firebase/composer.json b/src/Symfony/Component/Notifier/Bridge/Firebase/composer.json index fa18127a3f874..af23aabbec7b8 100644 --- a/src/Symfony/Component/Notifier/Bridge/Firebase/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Firebase/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Firebase\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/FortySixElks/composer.json b/src/Symfony/Component/Notifier/Bridge/FortySixElks/composer.json index 05a1311febf52..83991430bca7c 100644 --- a/src/Symfony/Component/Notifier/Bridge/FortySixElks/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/FortySixElks/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\FortySixElks\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/FreeMobile/composer.json b/src/Symfony/Component/Notifier/Bridge/FreeMobile/composer.json index 8067f44f261f9..1853af7e319c7 100644 --- a/src/Symfony/Component/Notifier/Bridge/FreeMobile/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/FreeMobile/composer.json @@ -18,8 +18,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\FreeMobile\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/GatewayApi/composer.json b/src/Symfony/Component/Notifier/Bridge/GatewayApi/composer.json index 7abffe9ba4581..1a2f8290944f4 100644 --- a/src/Symfony/Component/Notifier/Bridge/GatewayApi/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/GatewayApi/composer.json @@ -21,8 +21,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\GatewayApi\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/GoIp/composer.json b/src/Symfony/Component/Notifier/Bridge/GoIp/composer.json index 166675db8ca9b..a643c08361450 100644 --- a/src/Symfony/Component/Notifier/Bridge/GoIp/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/GoIp/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.3" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.3|^8.0" }, "autoload": { "psr-4": { diff --git a/src/Symfony/Component/Notifier/Bridge/GoogleChat/composer.json b/src/Symfony/Component/Notifier/Bridge/GoogleChat/composer.json index 645b5320b552a..37ab7ee264bbe 100644 --- a/src/Symfony/Component/Notifier/Bridge/GoogleChat/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/GoogleChat/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.3" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.3|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\GoogleChat\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Infobip/composer.json b/src/Symfony/Component/Notifier/Bridge/Infobip/composer.json index a76a85aefd36b..15b41d40a2cd1 100644 --- a/src/Symfony/Component/Notifier/Bridge/Infobip/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Infobip/composer.json @@ -21,8 +21,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Infobip\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Iqsms/composer.json b/src/Symfony/Component/Notifier/Bridge/Iqsms/composer.json index d36db5d2bebf3..f18db7b4f44f8 100644 --- a/src/Symfony/Component/Notifier/Bridge/Iqsms/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Iqsms/composer.json @@ -21,8 +21,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Iqsms\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Isendpro/composer.json b/src/Symfony/Component/Notifier/Bridge/Isendpro/composer.json index b7ee9fdbf95f1..efa8ecc0dde24 100644 --- a/src/Symfony/Component/Notifier/Bridge/Isendpro/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Isendpro/composer.json @@ -21,11 +21,11 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.3" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.3|^8.0" }, "require-dev": { - "symfony/event-dispatcher": "^6.4|^7.0" + "symfony/event-dispatcher": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Isendpro\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/JoliNotif/composer.json b/src/Symfony/Component/Notifier/Bridge/JoliNotif/composer.json index e6512df786dc0..66e34613f96b2 100644 --- a/src/Symfony/Component/Notifier/Bridge/JoliNotif/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/JoliNotif/composer.json @@ -23,8 +23,8 @@ "require": { "php": ">=8.2", "jolicode/jolinotif": "^2.7.2|^3.0", - "symfony/http-client": "^7.2", - "symfony/notifier": "^7.3" + "symfony/http-client": "^7.2|^8.0", + "symfony/notifier": "^7.3|^8.0" }, "autoload": { "psr-4": { diff --git a/src/Symfony/Component/Notifier/Bridge/KazInfoTeh/composer.json b/src/Symfony/Component/Notifier/Bridge/KazInfoTeh/composer.json index aa2a2d126bf4c..38ea6acc5535b 100644 --- a/src/Symfony/Component/Notifier/Bridge/KazInfoTeh/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/KazInfoTeh/composer.json @@ -19,8 +19,8 @@ "require": { "php": ">=8.2", "ext-simplexml": "*", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\KazInfoTeh\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/composer.json b/src/Symfony/Component/Notifier/Bridge/LightSms/composer.json index 18a3d52027894..9cb0e2e092ff6 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\LightSms\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/LineBot/composer.json b/src/Symfony/Component/Notifier/Bridge/LineBot/composer.json index 7e200237c7cfa..f5bb1102e4f13 100644 --- a/src/Symfony/Component/Notifier/Bridge/LineBot/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/LineBot/composer.json @@ -17,11 +17,11 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "require-dev": { - "symfony/event-dispatcher": "^6.4|^7.0" + "symfony/event-dispatcher": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\LineBot\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/LineNotify/composer.json b/src/Symfony/Component/Notifier/Bridge/LineNotify/composer.json index c7af719ead66d..93aceb6388d60 100644 --- a/src/Symfony/Component/Notifier/Bridge/LineNotify/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/LineNotify/composer.json @@ -17,11 +17,11 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "require-dev": { - "symfony/event-dispatcher": "^6.4|^7.0" + "symfony/event-dispatcher": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\LineNotify\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/LinkedIn/composer.json b/src/Symfony/Component/Notifier/Bridge/LinkedIn/composer.json index 2886f0eba9b68..dea4cd68b967e 100644 --- a/src/Symfony/Component/Notifier/Bridge/LinkedIn/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/LinkedIn/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.3" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.3|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\LinkedIn\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Lox24/composer.json b/src/Symfony/Component/Notifier/Bridge/Lox24/composer.json index 98f09a409937d..3664936585b35 100644 --- a/src/Symfony/Component/Notifier/Bridge/Lox24/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Lox24/composer.json @@ -10,12 +10,12 @@ "homepage": "https://symfony.com", "license": "MIT", "require": { - "php": ">=8.1", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "php": ">=8.2", + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "require-dev": { - "symfony/webhook": "^6.4|^7.0" + "symfony/webhook": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { diff --git a/src/Symfony/Component/Notifier/Bridge/Mailjet/composer.json b/src/Symfony/Component/Notifier/Bridge/Mailjet/composer.json index 9aa215e815fb2..fdf8269bf2360 100644 --- a/src/Symfony/Component/Notifier/Bridge/Mailjet/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Mailjet/composer.json @@ -21,8 +21,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Mailjet\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Mastodon/composer.json b/src/Symfony/Component/Notifier/Bridge/Mastodon/composer.json index d09d403fc7b36..190e279e84f4d 100644 --- a/src/Symfony/Component/Notifier/Bridge/Mastodon/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Mastodon/composer.json @@ -17,11 +17,11 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "require-dev": { - "symfony/mime": "^6.4|^7.0" + "symfony/mime": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Mastodon\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Matrix/composer.json b/src/Symfony/Component/Notifier/Bridge/Matrix/composer.json index 22ce807af3364..f51c3804bfae7 100644 --- a/src/Symfony/Component/Notifier/Bridge/Matrix/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Matrix/composer.json @@ -17,9 +17,9 @@ ], "require": { "php": ">=8.2", - "symfony/notifier": "^7.3", - "symfony/uid": "^7.2", - "symfony/http-client": "^6.4|^7.0" + "symfony/notifier": "^7.3|^8.0", + "symfony/uid": "^7.2|^8.0", + "symfony/http-client": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { diff --git a/src/Symfony/Component/Notifier/Bridge/Mattermost/composer.json b/src/Symfony/Component/Notifier/Bridge/Mattermost/composer.json index 958d64f42f865..0a0a72c535669 100644 --- a/src/Symfony/Component/Notifier/Bridge/Mattermost/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Mattermost/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Mattermost\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Mercure/composer.json b/src/Symfony/Component/Notifier/Bridge/Mercure/composer.json index ac965af31ca78..9920fe60f2abd 100644 --- a/src/Symfony/Component/Notifier/Bridge/Mercure/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Mercure/composer.json @@ -18,7 +18,7 @@ "require": { "php": ">=8.2", "symfony/mercure": "^0.5.2|^0.6", - "symfony/notifier": "^7.3", + "symfony/notifier": "^7.3|^8.0", "symfony/service-contracts": "^2.5|^3" }, "autoload": { diff --git a/src/Symfony/Component/Notifier/Bridge/MessageBird/composer.json b/src/Symfony/Component/Notifier/Bridge/MessageBird/composer.json index c1729e047f3fd..bffc9b345c13a 100644 --- a/src/Symfony/Component/Notifier/Bridge/MessageBird/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/MessageBird/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\MessageBird\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/MessageMedia/composer.json b/src/Symfony/Component/Notifier/Bridge/MessageMedia/composer.json index 187f9ed1fde88..e46a9e69de6fa 100644 --- a/src/Symfony/Component/Notifier/Bridge/MessageMedia/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/MessageMedia/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\MessageMedia\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/MicrosoftTeams/composer.json b/src/Symfony/Component/Notifier/Bridge/MicrosoftTeams/composer.json index 37722b03ec16a..28b83814f49ee 100644 --- a/src/Symfony/Component/Notifier/Bridge/MicrosoftTeams/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/MicrosoftTeams/composer.json @@ -21,8 +21,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\MicrosoftTeams\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Mobyt/composer.json b/src/Symfony/Component/Notifier/Bridge/Mobyt/composer.json index 1317236985478..1f14286f128a6 100644 --- a/src/Symfony/Component/Notifier/Bridge/Mobyt/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Mobyt/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Mobyt\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Novu/composer.json b/src/Symfony/Component/Notifier/Bridge/Novu/composer.json index 999320b21523b..7a303afdb4aca 100644 --- a/src/Symfony/Component/Notifier/Bridge/Novu/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Novu/composer.json @@ -16,9 +16,9 @@ } ], "require": { - "php": ">=8.1", - "symfony/http-client": "^5.4|^6.0|^7.0", - "symfony/notifier": "^7.2" + "php": ">=8.2", + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Novu\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Ntfy/composer.json b/src/Symfony/Component/Notifier/Bridge/Ntfy/composer.json index e15e8d511b973..6e7c25249dd27 100644 --- a/src/Symfony/Component/Notifier/Bridge/Ntfy/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Ntfy/composer.json @@ -17,9 +17,9 @@ ], "require": { "php": ">=8.2", - "symfony/clock": "^6.4|^7.0", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.3" + "symfony/clock": "^6.4|^7.0|^8.0", + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.3|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Ntfy\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Octopush/composer.json b/src/Symfony/Component/Notifier/Bridge/Octopush/composer.json index d081b539bc179..91f9e9fc6d7a0 100644 --- a/src/Symfony/Component/Notifier/Bridge/Octopush/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Octopush/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Octopush\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/OneSignal/composer.json b/src/Symfony/Component/Notifier/Bridge/OneSignal/composer.json index 2d3d243cf3884..35be562c547d6 100644 --- a/src/Symfony/Component/Notifier/Bridge/OneSignal/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/OneSignal/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\OneSignal\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/OrangeSms/composer.json b/src/Symfony/Component/Notifier/Bridge/OrangeSms/composer.json index 24923f1bc0bb9..a26866587b53b 100644 --- a/src/Symfony/Component/Notifier/Bridge/OrangeSms/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/OrangeSms/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\OrangeSms\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/OvhCloud/composer.json b/src/Symfony/Component/Notifier/Bridge/OvhCloud/composer.json index c105fcccdf9e0..ae82ed77dcc81 100644 --- a/src/Symfony/Component/Notifier/Bridge/OvhCloud/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/OvhCloud/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.3" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.3|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\OvhCloud\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/PagerDuty/composer.json b/src/Symfony/Component/Notifier/Bridge/PagerDuty/composer.json index b75ee3960c62a..f1f14ae047d52 100644 --- a/src/Symfony/Component/Notifier/Bridge/PagerDuty/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/PagerDuty/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\PagerDuty\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Plivo/composer.json b/src/Symfony/Component/Notifier/Bridge/Plivo/composer.json index 4a4c3cb13fd21..ead7c057ae552 100644 --- a/src/Symfony/Component/Notifier/Bridge/Plivo/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Plivo/composer.json @@ -20,11 +20,11 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "require-dev": { - "symfony/event-dispatcher": "^6.4|^7.0" + "symfony/event-dispatcher": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Plivo\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Primotexto/composer.json b/src/Symfony/Component/Notifier/Bridge/Primotexto/composer.json index e89e378e144e0..094a05b1e321d 100644 --- a/src/Symfony/Component/Notifier/Bridge/Primotexto/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Primotexto/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Primotexto\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Pushover/composer.json b/src/Symfony/Component/Notifier/Bridge/Pushover/composer.json index 926267eee9dc8..70c14694afe0a 100644 --- a/src/Symfony/Component/Notifier/Bridge/Pushover/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Pushover/composer.json @@ -20,11 +20,11 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "require-dev": { - "symfony/event-dispatcher": "^6.4|^7.0" + "symfony/event-dispatcher": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Pushover\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Pushy/composer.json b/src/Symfony/Component/Notifier/Bridge/Pushy/composer.json index e207e4b3a2811..e774ee4c52b71 100644 --- a/src/Symfony/Component/Notifier/Bridge/Pushy/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Pushy/composer.json @@ -21,11 +21,11 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "require-dev": { - "symfony/event-dispatcher": "^6.4|^7.0" + "symfony/event-dispatcher": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Pushy\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Redlink/composer.json b/src/Symfony/Component/Notifier/Bridge/Redlink/composer.json index e56215f7b36ba..6398c1ea913ef 100644 --- a/src/Symfony/Component/Notifier/Bridge/Redlink/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Redlink/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Redlink\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/RingCentral/composer.json b/src/Symfony/Component/Notifier/Bridge/RingCentral/composer.json index df9f13c56189c..c05948b79acdb 100644 --- a/src/Symfony/Component/Notifier/Bridge/RingCentral/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/RingCentral/composer.json @@ -20,11 +20,11 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "require-dev": { - "symfony/event-dispatcher": "^6.4|^7.0" + "symfony/event-dispatcher": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\RingCentral\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/RocketChat/composer.json b/src/Symfony/Component/Notifier/Bridge/RocketChat/composer.json index bc7bd923340a8..31e312222c67d 100644 --- a/src/Symfony/Component/Notifier/Bridge/RocketChat/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/RocketChat/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\RocketChat\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Sendberry/composer.json b/src/Symfony/Component/Notifier/Bridge/Sendberry/composer.json index 56a9e2163023e..2dcbd77c51b2b 100644 --- a/src/Symfony/Component/Notifier/Bridge/Sendberry/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Sendberry/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Sendberry\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Sevenio/composer.json b/src/Symfony/Component/Notifier/Bridge/Sevenio/composer.json index c2b6d0b5264c7..2c489b47fb50b 100644 --- a/src/Symfony/Component/Notifier/Bridge/Sevenio/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Sevenio/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Sevenio\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/SimpleTextin/composer.json b/src/Symfony/Component/Notifier/Bridge/SimpleTextin/composer.json index f27e41c7b090a..8e1e6799135bb 100644 --- a/src/Symfony/Component/Notifier/Bridge/SimpleTextin/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/SimpleTextin/composer.json @@ -20,11 +20,11 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "require-dev": { - "symfony/event-dispatcher": "^6.4|^7.0" + "symfony/event-dispatcher": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\SimpleTextin\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Sinch/composer.json b/src/Symfony/Component/Notifier/Bridge/Sinch/composer.json index 296393553b02d..8128c5bfa780d 100644 --- a/src/Symfony/Component/Notifier/Bridge/Sinch/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Sinch/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Sinch\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Sipgate/composer.json b/src/Symfony/Component/Notifier/Bridge/Sipgate/composer.json index bba4c1bb1b652..12ffb1f792d82 100644 --- a/src/Symfony/Component/Notifier/Bridge/Sipgate/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Sipgate/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { diff --git a/src/Symfony/Component/Notifier/Bridge/Slack/Block/SlackActionsBlock.php b/src/Symfony/Component/Notifier/Bridge/Slack/Block/SlackActionsBlock.php index 25da853677415..848b9bfd98f83 100644 --- a/src/Symfony/Component/Notifier/Bridge/Slack/Block/SlackActionsBlock.php +++ b/src/Symfony/Component/Notifier/Bridge/Slack/Block/SlackActionsBlock.php @@ -24,16 +24,26 @@ public function __construct() /** * @return $this */ - public function button(string $text, string $url, ?string $style = null): static + public function button(string $text, ?string $url = null, ?string $style = null, ?string $value = null): static { if (25 === \count($this->options['elements'] ?? [])) { throw new \LogicException('Maximum number of buttons should not exceed 25.'); } - $element = new SlackButtonBlockElement($text, $url, $style); + $element = new SlackButtonBlockElement($text, $url, $style, $value); $this->options['elements'][] = $element->toArray(); return $this; } + + /** + * @return $this + */ + public function id(string $id): static + { + $this->options['block_id'] = $id; + + return $this; + } } diff --git a/src/Symfony/Component/Notifier/Bridge/Slack/Block/SlackButtonBlockElement.php b/src/Symfony/Component/Notifier/Bridge/Slack/Block/SlackButtonBlockElement.php index ff83bb9d870a5..8b1eed19472cb 100644 --- a/src/Symfony/Component/Notifier/Bridge/Slack/Block/SlackButtonBlockElement.php +++ b/src/Symfony/Component/Notifier/Bridge/Slack/Block/SlackButtonBlockElement.php @@ -16,7 +16,7 @@ */ final class SlackButtonBlockElement extends AbstractSlackBlockElement { - public function __construct(string $text, string $url, ?string $style = null) + public function __construct(string $text, ?string $url = null, ?string $style = null, ?string $value = null) { $this->options = [ 'type' => 'button', @@ -24,12 +24,19 @@ public function __construct(string $text, string $url, ?string $style = null) 'type' => 'plain_text', 'text' => $text, ], - 'url' => $url, ]; + if ($url) { + $this->options['url'] = $url; + } + if ($style) { // primary or danger $this->options['style'] = $style; } + + if ($value) { + $this->options['value'] = $value; + } } } diff --git a/src/Symfony/Component/Notifier/Bridge/Slack/Tests/Block/SlackActionsBlockTest.php b/src/Symfony/Component/Notifier/Bridge/Slack/Tests/Block/SlackActionsBlockTest.php index 2a21a39133c1f..682a895bdffc0 100644 --- a/src/Symfony/Component/Notifier/Bridge/Slack/Tests/Block/SlackActionsBlockTest.php +++ b/src/Symfony/Component/Notifier/Bridge/Slack/Tests/Block/SlackActionsBlockTest.php @@ -19,8 +19,9 @@ final class SlackActionsBlockTest extends TestCase public function testCanBeInstantiated() { $actions = new SlackActionsBlock(); - $actions->button('first button text', 'https://example.org') + $actions->button('first button text', 'https://example.org', null, 'test-value') ->button('second button text', 'https://example.org/slack', 'danger') + ->button('third button text', null, null, 'test-value-3') ; $this->assertSame([ @@ -33,6 +34,7 @@ public function testCanBeInstantiated() 'text' => 'first button text', ], 'url' => 'https://example.org', + 'value' => 'test-value' ], [ 'type' => 'button', @@ -43,6 +45,14 @@ public function testCanBeInstantiated() 'url' => 'https://example.org/slack', 'style' => 'danger', ], + [ + 'type' => 'button', + 'text' => [ + 'type' => 'plain_text', + 'text' => 'third button text', + ], + 'value' => 'test-value-3', + ] ], ], $actions->toArray()); } diff --git a/src/Symfony/Component/Notifier/Bridge/Slack/composer.json b/src/Symfony/Component/Notifier/Bridge/Slack/composer.json index 8507a4d041254..bb6752dd37080 100644 --- a/src/Symfony/Component/Notifier/Bridge/Slack/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Slack/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Slack\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Sms77/composer.json b/src/Symfony/Component/Notifier/Bridge/Sms77/composer.json index 8dd642e151321..25def742454a1 100644 --- a/src/Symfony/Component/Notifier/Bridge/Sms77/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Sms77/composer.json @@ -18,8 +18,8 @@ "require": { "php": ">=8.2", "symfony/deprecation-contracts": "^2.5|^3", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Sms77\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/SmsBiuras/composer.json b/src/Symfony/Component/Notifier/Bridge/SmsBiuras/composer.json index cbba623e99aa4..feff4ced7eede 100644 --- a/src/Symfony/Component/Notifier/Bridge/SmsBiuras/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/SmsBiuras/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.3" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.3|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\SmsBiuras\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/SmsFactor/composer.json b/src/Symfony/Component/Notifier/Bridge/SmsFactor/composer.json index b530771b49dce..5496b1185c5eb 100644 --- a/src/Symfony/Component/Notifier/Bridge/SmsFactor/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/SmsFactor/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\SmsFactor\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/SmsSluzba/composer.json b/src/Symfony/Component/Notifier/Bridge/SmsSluzba/composer.json index c4256019769a0..fd419bf91fcf7 100644 --- a/src/Symfony/Component/Notifier/Bridge/SmsSluzba/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/SmsSluzba/composer.json @@ -16,10 +16,10 @@ } ], "require": { - "php": ">=8.1", - "symfony/http-client": "^6.4|^7.1", - "symfony/notifier": "^7.2", - "symfony/serializer": "^6.4|^7.1" + "php": ">=8.2", + "symfony/http-client": "^6.4|^7.1|^8.0", + "symfony/notifier": "^7.2|^8.0", + "symfony/serializer": "^6.4|^7.1|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\SmsSluzba\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Smsapi/composer.json b/src/Symfony/Component/Notifier/Bridge/Smsapi/composer.json index 40e2710c4dff7..481ac4538c99f 100644 --- a/src/Symfony/Component/Notifier/Bridge/Smsapi/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Smsapi/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.3" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.3|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Smsapi\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Smsbox/composer.json b/src/Symfony/Component/Notifier/Bridge/Smsbox/composer.json index 0b1907fb71f15..2c6d8e9cc0242 100644 --- a/src/Symfony/Component/Notifier/Bridge/Smsbox/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Smsbox/composer.json @@ -25,13 +25,13 @@ ], "require": { "php": ">=8.2", - "symfony/clock": "^6.4|^7.0", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2", + "symfony/clock": "^6.4|^7.0|^8.0", + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0", "symfony/polyfill-php83": "^1.28" }, "require-dev": { - "symfony/webhook": "^6.4|^7.0" + "symfony/webhook": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { diff --git a/src/Symfony/Component/Notifier/Bridge/Smsc/composer.json b/src/Symfony/Component/Notifier/Bridge/Smsc/composer.json index 2a5bded5aea9b..f057349e0e65a 100644 --- a/src/Symfony/Component/Notifier/Bridge/Smsc/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Smsc/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Smsc\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Smsense/composer.json b/src/Symfony/Component/Notifier/Bridge/Smsense/composer.json index 4002648bd504b..f80bd05867d3c 100644 --- a/src/Symfony/Component/Notifier/Bridge/Smsense/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Smsense/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Smsense\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Smsmode/composer.json b/src/Symfony/Component/Notifier/Bridge/Smsmode/composer.json index a9131f75ed3ad..f975c19833ccd 100644 --- a/src/Symfony/Component/Notifier/Bridge/Smsmode/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Smsmode/composer.json @@ -20,11 +20,11 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "require-dev": { - "symfony/event-dispatcher": "^6.4|^7.0" + "symfony/event-dispatcher": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Smsmode\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/SpotHit/composer.json b/src/Symfony/Component/Notifier/Bridge/SpotHit/composer.json index a9b66ba3636b4..491df32dedded 100644 --- a/src/Symfony/Component/Notifier/Bridge/SpotHit/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/SpotHit/composer.json @@ -21,8 +21,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\SpotHit\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Sweego/composer.json b/src/Symfony/Component/Notifier/Bridge/Sweego/composer.json index 006d739b86151..f9c3dc1d26f18 100644 --- a/src/Symfony/Component/Notifier/Bridge/Sweego/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Sweego/composer.json @@ -17,11 +17,11 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "require-dev": { - "symfony/webhook": "^6.4|^7.0" + "symfony/webhook": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/http-foundation": "<7.1" diff --git a/src/Symfony/Component/Notifier/Bridge/Telegram/composer.json b/src/Symfony/Component/Notifier/Bridge/Telegram/composer.json index 435641839410a..e046bcfd320e5 100644 --- a/src/Symfony/Component/Notifier/Bridge/Telegram/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Telegram/composer.json @@ -17,9 +17,9 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/mime": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/mime": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Telegram\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Telnyx/composer.json b/src/Symfony/Component/Notifier/Bridge/Telnyx/composer.json index 3b53e750bd395..860c0f7f9efd2 100644 --- a/src/Symfony/Component/Notifier/Bridge/Telnyx/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Telnyx/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Telnyx\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Termii/composer.json b/src/Symfony/Component/Notifier/Bridge/Termii/composer.json index 31ed79a368071..57d397d206c9b 100644 --- a/src/Symfony/Component/Notifier/Bridge/Termii/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Termii/composer.json @@ -20,11 +20,11 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "require-dev": { - "symfony/event-dispatcher": "^6.4|^7.0" + "symfony/event-dispatcher": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Termii\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/TurboSms/composer.json b/src/Symfony/Component/Notifier/Bridge/TurboSms/composer.json index 36c6def23ae2d..d90400dad8aca 100644 --- a/src/Symfony/Component/Notifier/Bridge/TurboSms/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/TurboSms/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2", + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0", "symfony/polyfill-mbstring": "^1.0" }, "autoload": { diff --git a/src/Symfony/Component/Notifier/Bridge/Twilio/composer.json b/src/Symfony/Component/Notifier/Bridge/Twilio/composer.json index ee1872491bdfb..f2ae0c75429ca 100644 --- a/src/Symfony/Component/Notifier/Bridge/Twilio/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Twilio/composer.json @@ -17,11 +17,11 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "require-dev": { - "symfony/webhook": "^6.4|^7.0" + "symfony/webhook": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/http-foundation": "<6.4" diff --git a/src/Symfony/Component/Notifier/Bridge/Twitter/composer.json b/src/Symfony/Component/Notifier/Bridge/Twitter/composer.json index f50531a1448ed..2f96a28349f40 100644 --- a/src/Symfony/Component/Notifier/Bridge/Twitter/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Twitter/composer.json @@ -17,11 +17,11 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "require-dev": { - "symfony/mime": "^6.4|^7.0" + "symfony/mime": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/mime": "<6.4" diff --git a/src/Symfony/Component/Notifier/Bridge/Unifonic/composer.json b/src/Symfony/Component/Notifier/Bridge/Unifonic/composer.json index 48fbbdf2db84b..30cad613f85af 100644 --- a/src/Symfony/Component/Notifier/Bridge/Unifonic/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Unifonic/composer.json @@ -21,8 +21,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Unifonic\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Vonage/composer.json b/src/Symfony/Component/Notifier/Bridge/Vonage/composer.json index 243f0903155fe..a8939fb564e88 100644 --- a/src/Symfony/Component/Notifier/Bridge/Vonage/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Vonage/composer.json @@ -17,11 +17,11 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "require-dev": { - "symfony/webhook": "^6.4|^7.0" + "symfony/webhook": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Vonage\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Yunpian/composer.json b/src/Symfony/Component/Notifier/Bridge/Yunpian/composer.json index 58366edc8eb74..4bf05c1afc0cd 100644 --- a/src/Symfony/Component/Notifier/Bridge/Yunpian/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Yunpian/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Yunpian\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Zendesk/composer.json b/src/Symfony/Component/Notifier/Bridge/Zendesk/composer.json index 87044d4d4829e..66eea8847150d 100644 --- a/src/Symfony/Component/Notifier/Bridge/Zendesk/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Zendesk/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Zendesk\\": "" }, diff --git a/src/Symfony/Component/Notifier/Bridge/Zulip/composer.json b/src/Symfony/Component/Notifier/Bridge/Zulip/composer.json index f124c18e7e58b..8fb05ff6b2817 100644 --- a/src/Symfony/Component/Notifier/Bridge/Zulip/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/Zulip/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/notifier": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/notifier": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Zulip\\": "" }, diff --git a/src/Symfony/Component/Notifier/composer.json b/src/Symfony/Component/Notifier/composer.json index 3cb8fe7d28073..9cc0495f4d396 100644 --- a/src/Symfony/Component/Notifier/composer.json +++ b/src/Symfony/Component/Notifier/composer.json @@ -22,8 +22,8 @@ "require-dev": { "symfony/event-dispatcher-contracts": "^2.5|^3", "symfony/http-client-contracts": "^2.5|^3", - "symfony/http-foundation": "^6.4|^7.0", - "symfony/messenger": "^6.4|^7.0" + "symfony/http-foundation": "^6.4|^7.0|^8.0", + "symfony/messenger": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/event-dispatcher": "<6.4", diff --git a/src/Symfony/Component/ObjectMapper/composer.json b/src/Symfony/Component/ObjectMapper/composer.json index eb89582d8aad6..1ae9f2740fea2 100644 --- a/src/Symfony/Component/ObjectMapper/composer.json +++ b/src/Symfony/Component/ObjectMapper/composer.json @@ -20,7 +20,7 @@ "psr/container": "^2.0" }, "require-dev": { - "symfony/property-access": "^7.2" + "symfony/property-access": "^7.2|^8.0" }, "autoload": { "psr-4": { @@ -32,5 +32,6 @@ }, "conflict": { "symfony/property-access": "<7.2" - } + }, + "minimum-stability": "dev" } diff --git a/src/Symfony/Component/PasswordHasher/composer.json b/src/Symfony/Component/PasswordHasher/composer.json index ebcb51b4b9599..1eb6681722c02 100644 --- a/src/Symfony/Component/PasswordHasher/composer.json +++ b/src/Symfony/Component/PasswordHasher/composer.json @@ -19,8 +19,8 @@ "php": ">=8.2" }, "require-dev": { - "symfony/security-core": "^6.4|^7.0", - "symfony/console": "^6.4|^7.0" + "symfony/security-core": "^6.4|^7.0|^8.0", + "symfony/console": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/security-core": "<6.4" diff --git a/src/Symfony/Component/Process/PhpProcess.php b/src/Symfony/Component/Process/PhpProcess.php index 0e7ff84647fb8..930f591f0d399 100644 --- a/src/Symfony/Component/Process/PhpProcess.php +++ b/src/Symfony/Component/Process/PhpProcess.php @@ -55,6 +55,9 @@ public static function fromShellCommandline(string $command, ?string $cwd = null throw new LogicException(\sprintf('The "%s()" method cannot be called when using "%s".', __METHOD__, self::class)); } + /** + * @param (callable('out'|'err', string):void)|null $callback + */ public function start(?callable $callback = null, array $env = []): void { if (null === $this->getCommandLine()) { diff --git a/src/Symfony/Component/Process/PhpSubprocess.php b/src/Symfony/Component/Process/PhpSubprocess.php index bdd4173c2a053..8282f93cd47ea 100644 --- a/src/Symfony/Component/Process/PhpSubprocess.php +++ b/src/Symfony/Component/Process/PhpSubprocess.php @@ -78,6 +78,9 @@ public static function fromShellCommandline(string $command, ?string $cwd = null throw new LogicException(\sprintf('The "%s()" method cannot be called when using "%s".', __METHOD__, self::class)); } + /** + * @param (callable('out'|'err', string):void)|null $callback + */ public function start(?callable $callback = null, array $env = []): void { if (null === $this->getCommandLine()) { diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index a8beb93d44988..d52db23ac6afb 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -51,6 +51,9 @@ class Process implements \IteratorAggregate public const ITER_SKIP_OUT = 4; // Use this flag to skip STDOUT while iterating public const ITER_SKIP_ERR = 8; // Use this flag to skip STDERR while iterating + /** + * @var \Closure('out'|'err', string)|null + */ private ?\Closure $callback = null; private array|string $commandline; private ?string $cwd; @@ -231,8 +234,8 @@ public function __clone() * The STDOUT and STDERR are also available after the process is finished * via the getOutput() and getErrorOutput() methods. * - * @param callable|null $callback A PHP callback to run whenever there is some - * output available on STDOUT or STDERR + * @param (callable('out'|'err', string):void)|null $callback A PHP callback to run whenever there is some + * output available on STDOUT or STDERR * * @return int The exit status code * @@ -257,6 +260,9 @@ public function run(?callable $callback = null, array $env = []): int * This is identical to run() except that an exception is thrown if the process * exits with a non-zero exit code. * + * @param (callable('out'|'err', string):void)|null $callback A PHP callback to run whenever there is some + * output available on STDOUT or STDERR + * * @return $this * * @throws ProcessFailedException if the process didn't terminate successfully @@ -284,8 +290,8 @@ public function mustRun(?callable $callback = null, array $env = []): static * the output in real-time while writing the standard input to the process. * It allows to have feedback from the independent process during execution. * - * @param callable|null $callback A PHP callback to run whenever there is some - * output available on STDOUT or STDERR + * @param (callable('out'|'err', string):void)|null $callback A PHP callback to run whenever there is some + * output available on STDOUT or STDERR * * @throws ProcessStartFailedException When process can't be launched * @throws RuntimeException When process is already running @@ -395,8 +401,8 @@ public function start(?callable $callback = null, array $env = []): void * * Be warned that the process is cloned before being started. * - * @param callable|null $callback A PHP callback to run whenever there is some - * output available on STDOUT or STDERR + * @param (callable('out'|'err', string):void)|null $callback A PHP callback to run whenever there is some + * output available on STDOUT or STDERR * * @throws ProcessStartFailedException When process can't be launched * @throws RuntimeException When process is already running @@ -424,7 +430,8 @@ public function restart(?callable $callback = null, array $env = []): static * from the output in real-time while writing the standard input to the process. * It allows to have feedback from the independent process during execution. * - * @param callable|null $callback A valid PHP callback + * @param (callable('out'|'err', string):void)|null $callback A PHP callback to run whenever there is some + * output available on STDOUT or STDERR * * @return int The exitcode of the process * @@ -471,6 +478,9 @@ public function wait(?callable $callback = null): int * from the output in real-time while writing the standard input to the process. * It allows to have feedback from the independent process during execution. * + * @param (callable('out'|'err', string):bool)|null $callback A PHP callback to run whenever there is some + * output available on STDOUT or STDERR + * * @throws RuntimeException When process timed out * @throws LogicException When process is not yet started * @throws ProcessTimedOutException In case the timeout was reached @@ -1291,7 +1301,9 @@ private function getDescriptors(bool $hasCallback): array * The callbacks adds all occurred output to the specific buffer and calls * the user callback (if present) with the received output. * - * @param callable|null $callback The user defined PHP callback + * @param callable('out'|'err', string)|null $callback + * + * @return \Closure('out'|'err', string):bool */ protected function buildCallback(?callable $callback = null): \Closure { @@ -1299,14 +1311,11 @@ protected function buildCallback(?callable $callback = null): \Closure return fn ($type, $data): bool => null !== $callback && $callback($type, $data); } - $out = self::OUT; - - return function ($type, $data) use ($callback, $out): bool { - if ($out == $type) { - $this->addOutput($data); - } else { - $this->addErrorOutput($data); - } + return function ($type, $data) use ($callback): bool { + match ($type) { + self::OUT => $this->addOutput($data), + self::ERR => $this->addErrorOutput($data), + }; return null !== $callback && $callback($type, $data); }; diff --git a/src/Symfony/Component/PropertyAccess/composer.json b/src/Symfony/Component/PropertyAccess/composer.json index 376ee7e1afd0d..906e432b03f99 100644 --- a/src/Symfony/Component/PropertyAccess/composer.json +++ b/src/Symfony/Component/PropertyAccess/composer.json @@ -17,10 +17,11 @@ ], "require": { "php": ">=8.2", - "symfony/property-info": "^6.4|^7.0" + "symfony/property-info": "^6.4|^7.0|^8.0" }, "require-dev": { - "symfony/cache": "^6.4|^7.0" + "symfony/cache": "^6.4|^7.0|^8.0", + "symfony/var-exporter": "^6.4.1|^7.0.1|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\PropertyAccess\\": "" }, diff --git a/src/Symfony/Component/PropertyInfo/composer.json b/src/Symfony/Component/PropertyInfo/composer.json index f8ae018a40b7f..89c2c6ad01cce 100644 --- a/src/Symfony/Component/PropertyInfo/composer.json +++ b/src/Symfony/Component/PropertyInfo/composer.json @@ -25,13 +25,13 @@ "require": { "php": ">=8.2", "symfony/deprecation-contracts": "^2.5|^3", - "symfony/string": "^6.4|^7.0", - "symfony/type-info": "~7.1.9|^7.2.2" + "symfony/string": "^6.4|^7.0|^8.0", + "symfony/type-info": "~7.1.9|^7.2.2|^8.0" }, "require-dev": { - "symfony/serializer": "^6.4|^7.0", - "symfony/cache": "^6.4|^7.0", - "symfony/dependency-injection": "^6.4|^7.0", + "symfony/serializer": "^6.4|^7.0|^8.0", + "symfony/cache": "^6.4|^7.0|^8.0", + "symfony/dependency-injection": "^6.4|^7.0|^8.0", "phpdocumentor/reflection-docblock": "^5.2", "phpstan/phpdoc-parser": "^1.0|^2.0" }, diff --git a/src/Symfony/Component/RateLimiter/composer.json b/src/Symfony/Component/RateLimiter/composer.json index fdf0e01c4979b..428ce3480e53f 100644 --- a/src/Symfony/Component/RateLimiter/composer.json +++ b/src/Symfony/Component/RateLimiter/composer.json @@ -17,11 +17,11 @@ ], "require": { "php": ">=8.2", - "symfony/options-resolver": "^7.3" + "symfony/options-resolver": "^7.3|^8.0" }, "require-dev": { "psr/cache": "^1.0|^2.0|^3.0", - "symfony/lock": "^6.4|^7.0" + "symfony/lock": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\RateLimiter\\": "" }, diff --git a/src/Symfony/Component/RemoteEvent/composer.json b/src/Symfony/Component/RemoteEvent/composer.json index 292110b3424f5..83b82a71727e7 100644 --- a/src/Symfony/Component/RemoteEvent/composer.json +++ b/src/Symfony/Component/RemoteEvent/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": ">=8.2", - "symfony/messenger": "^6.4|^7.0" + "symfony/messenger": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\RemoteEvent\\": "" }, diff --git a/src/Symfony/Component/Routing/CHANGELOG.md b/src/Symfony/Component/Routing/CHANGELOG.md index d21e550f9b57f..4ef96d53232fe 100644 --- a/src/Symfony/Component/Routing/CHANGELOG.md +++ b/src/Symfony/Component/Routing/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +7.4 +--- + + * Allow query-specific parameters in `UrlGenerator` using `_query` + 7.3 --- diff --git a/src/Symfony/Component/Routing/Generator/UrlGenerator.php b/src/Symfony/Component/Routing/Generator/UrlGenerator.php index 216b0d5479ac4..d82b91898194a 100644 --- a/src/Symfony/Component/Routing/Generator/UrlGenerator.php +++ b/src/Symfony/Component/Routing/Generator/UrlGenerator.php @@ -142,6 +142,18 @@ public function generate(string $name, array $parameters = [], int $referenceTyp */ protected function doGenerate(array $variables, array $defaults, array $requirements, array $tokens, array $parameters, string $name, int $referenceType, array $hostTokens, array $requiredSchemes = []): string { + $queryParameters = []; + + if (isset($parameters['_query'])) { + if (\is_array($parameters['_query'])) { + $queryParameters = $parameters['_query']; + unset($parameters['_query']); + } else { + trigger_deprecation('symfony/routing', '7.4', 'Parameter "_query" is reserved for passing an array of query parameters. Passing a scalar value is deprecated and will throw an exception in Symfony 8.0.'); + // throw new InvalidParameterException('Parameter "_query" must be an array of query parameters.'); + } + } + $variables = array_flip($variables); $mergedParams = array_replace($defaults, $this->context->getParameters(), $parameters); @@ -260,6 +272,7 @@ protected function doGenerate(array $variables, array $defaults, array $requirem // add a query string if needed $extra = array_udiff_assoc(array_diff_key($parameters, $variables), $defaults, fn ($a, $b) => $a == $b ? 0 : 1); + $extra = array_merge($extra, $queryParameters); array_walk_recursive($extra, $caster = static function (&$v) use (&$caster) { if (\is_object($v)) { diff --git a/src/Symfony/Component/Routing/Route.php b/src/Symfony/Component/Routing/Route.php index 1ed484f71237b..621a4239fcf7a 100644 --- a/src/Symfony/Component/Routing/Route.php +++ b/src/Symfony/Component/Routing/Route.php @@ -420,7 +420,7 @@ private function extractInlineDefaultsAndRequirements(string $pattern): string $pattern = preg_replace_callback('#\{(!?)([\w\x80-\xFF]++)(:([\w\x80-\xFF]++)(\.[\w\x80-\xFF]++)?)?(<.*?>)?(\?[^\}]*+)?\}#', function ($m) use (&$mapping) { if (isset($m[7][0])) { - $this->setDefault($m[2], '?' !== $m[6] ? substr($m[7], 1) : null); + $this->setDefault($m[2], '?' !== $m[7] ? substr($m[7], 1) : null); } if (isset($m[6][0])) { $this->setRequirement($m[2], substr($m[6], 1, -1)); diff --git a/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php b/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php index 25a4c67460c82..27af767947e16 100644 --- a/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php +++ b/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php @@ -1054,6 +1054,80 @@ public function testUtf8VarName() $this->assertSame('/app.php/foo/baz', $this->getGenerator($routes)->generate('test', ['bär' => 'baz'])); } + public function testQueryParameters() + { + $routes = $this->getRoutes('user', new Route('/user/{username}')); + $url = $this->getGenerator($routes)->generate('user', [ + 'username' => 'john', + 'a' => 'foo', + 'b' => 'bar', + 'c' => 'baz', + '_query' => [ + 'a' => '123', + 'd' => '789', + ], + ]); + $this->assertSame('/app.php/user/john?a=123&b=bar&c=baz&d=789', $url); + } + + public function testRouteHostParameterAndQueryParameterWithSameName() + { + $routes = $this->getRoutes('admin_stats', new Route('/admin/stats', requirements: ['domain' => '.+'], host: '{siteCode}.{domain}')); + $url = $this->getGenerator($routes)->generate('admin_stats', [ + 'siteCode' => 'fr', + 'domain' => 'example.com', + '_query' => [ + 'siteCode' => 'us', + ], + ], UrlGeneratorInterface::NETWORK_PATH); + $this->assertSame('//fr.example.com/app.php/admin/stats?siteCode=us', $url); + } + + public function testRoutePathParameterAndQueryParameterWithSameName() + { + $routes = $this->getRoutes('user', new Route('/user/{id}')); + $url = $this->getGenerator($routes)->generate('user', [ + 'id' => '123', + '_query' => [ + 'id' => '456', + ], + ]); + $this->assertSame('/app.php/user/123?id=456', $url); + } + + public function testQueryParameterCannotSubstituteRouteParameter() + { + $routes = $this->getRoutes('user', new Route('/user/{id}')); + + $this->expectException(MissingMandatoryParametersException::class); + $this->expectExceptionMessage('Some mandatory parameters are missing ("id") to generate a URL for route "user".'); + + $this->getGenerator($routes)->generate('user', [ + '_query' => [ + 'id' => '456', + ], + ]); + } + + /** + * @group legacy + */ + public function testQueryParametersWithScalarValue() + { + $routes = $this->getRoutes('user', new Route('/user/{id}')); + + $this->expectDeprecation( + 'Since symfony/routing 7.4: Parameter "_query" is reserved for passing an array of query parameters. ' . + 'Passing a scalar value is deprecated and will throw an exception in Symfony 8.0.', + ); + + $url = $this->getGenerator($routes)->generate('user', [ + 'id' => '123', + '_query' => 'foo', + ]); + $this->assertSame('/app.php/user/123?_query=foo', $url); + } + protected function getGenerator(RouteCollection $routes, array $parameters = [], $logger = null, ?string $defaultLocale = null) { $context = new RequestContext('/app.php'); diff --git a/src/Symfony/Component/Routing/Tests/RouteTest.php b/src/Symfony/Component/Routing/Tests/RouteTest.php index b58358a3ef31b..3472804249f57 100644 --- a/src/Symfony/Component/Routing/Tests/RouteTest.php +++ b/src/Symfony/Component/Routing/Tests/RouteTest.php @@ -226,37 +226,48 @@ public function testSerialize() $this->assertNotSame($route, $unserialized); } - public function testInlineDefaultAndRequirement() + /** + * @dataProvider provideInlineDefaultAndRequirementCases + */ + public function testInlineDefaultAndRequirement(Route $route, string $expectedPath, string $expectedHost, array $expectedDefaults, array $expectedRequirements) + { + self::assertSame($expectedPath, $route->getPath()); + self::assertSame($expectedHost, $route->getHost()); + self::assertSame($expectedDefaults, $route->getDefaults()); + self::assertSame($expectedRequirements, $route->getRequirements()); + } + + public static function provideInlineDefaultAndRequirementCases(): iterable { - $this->assertEquals((new Route('/foo/{bar}'))->setDefault('bar', null), new Route('/foo/{bar?}')); - $this->assertEquals((new Route('/foo/{bar}'))->setDefault('bar', 'baz'), new Route('/foo/{bar?baz}')); - $this->assertEquals((new Route('/foo/{bar}'))->setDefault('bar', 'baz'), new Route('/foo/{bar?baz}')); - $this->assertEquals((new Route('/foo/{!bar}'))->setDefault('bar', 'baz'), new Route('/foo/{!bar?baz}')); - $this->assertEquals((new Route('/foo/{bar}'))->setDefault('bar', 'baz'), new Route('/foo/{bar?}', ['bar' => 'baz'])); - - $this->assertEquals((new Route('/foo/{bar}'))->setRequirement('bar', '.*'), new Route('/foo/{bar<.*>}')); - $this->assertEquals((new Route('/foo/{bar}'))->setRequirement('bar', '>'), new Route('/foo/{bar<>>}')); - $this->assertEquals((new Route('/foo/{bar}'))->setRequirement('bar', '\d+'), new Route('/foo/{bar<.*>}', [], ['bar' => '\d+'])); - $this->assertEquals((new Route('/foo/{bar}'))->setRequirement('bar', '[a-z]{2}'), new Route('/foo/{bar<[a-z]{2}>}')); - $this->assertEquals((new Route('/foo/{!bar}'))->setRequirement('bar', '\d+'), new Route('/foo/{!bar<\d+>}')); - - $this->assertEquals((new Route('/foo/{bar}'))->setDefault('bar', null)->setRequirement('bar', '.*'), new Route('/foo/{bar<.*>?}')); - $this->assertEquals((new Route('/foo/{bar}'))->setDefault('bar', '<>')->setRequirement('bar', '>'), new Route('/foo/{bar<>>?<>}')); - - $this->assertEquals((new Route('/{foo}/{!bar}'))->setDefaults(['bar' => '<>', 'foo' => '\\'])->setRequirements(['bar' => '\\', 'foo' => '.']), new Route('/{foo<.>?\}/{!bar<\>?<>}')); - - $this->assertEquals((new Route('/'))->setHost('{bar}')->setDefault('bar', null), (new Route('/'))->setHost('{bar?}')); - $this->assertEquals((new Route('/'))->setHost('{bar}')->setDefault('bar', 'baz'), (new Route('/'))->setHost('{bar?baz}')); - $this->assertEquals((new Route('/'))->setHost('{bar}')->setDefault('bar', 'baz'), (new Route('/'))->setHost('{bar?baz}')); - $this->assertEquals((new Route('/'))->setHost('{bar}')->setDefault('bar', null), (new Route('/', ['bar' => 'baz']))->setHost('{bar?}')); - - $this->assertEquals((new Route('/'))->setHost('{bar}')->setRequirement('bar', '.*'), (new Route('/'))->setHost('{bar<.*>}')); - $this->assertEquals((new Route('/'))->setHost('{bar}')->setRequirement('bar', '>'), (new Route('/'))->setHost('{bar<>>}')); - $this->assertEquals((new Route('/'))->setHost('{bar}')->setRequirement('bar', '.*'), (new Route('/', [], ['bar' => '\d+']))->setHost('{bar<.*>}')); - $this->assertEquals((new Route('/'))->setHost('{bar}')->setRequirement('bar', '[a-z]{2}'), (new Route('/'))->setHost('{bar<[a-z]{2}>}')); - - $this->assertEquals((new Route('/'))->setHost('{bar}')->setDefault('bar', null)->setRequirement('bar', '.*'), (new Route('/'))->setHost('{bar<.*>?}')); - $this->assertEquals((new Route('/'))->setHost('{bar}')->setDefault('bar', '<>')->setRequirement('bar', '>'), (new Route('/'))->setHost('{bar<>>?<>}')); + yield [new Route('/foo/{bar?}'), '/foo/{bar}', '', ['bar' => null], []]; + yield [new Route('/foo/{bar?baz}'), '/foo/{bar}', '', ['bar' => 'baz'], []]; + yield [new Route('/foo/{bar?baz}'), '/foo/{bar}', '', ['bar' => 'baz'], []]; + yield [new Route('/foo/{!bar?baz}'), '/foo/{!bar}', '', ['bar' => 'baz'], []]; + yield [new Route('/foo/{bar?}', ['bar' => 'baz']), '/foo/{bar}', '', ['bar' => 'baz'], []]; + + yield [new Route('/foo/{bar<.*>}'), '/foo/{bar}', '', [], ['bar' => '.*']]; + yield [new Route('/foo/{bar<>>}'), '/foo/{bar}', '', [], ['bar' => '>']]; + yield [new Route('/foo/{bar<.*>}', [], ['bar' => '\d+']), '/foo/{bar}', '', [], ['bar' => '\d+']]; + yield [new Route('/foo/{bar<[a-z]{2}>}'), '/foo/{bar}', '', [], ['bar' => '[a-z]{2}']]; + yield [new Route('/foo/{!bar<\d+>}'), '/foo/{!bar}', '', [], ['bar' => '\d+']]; + + yield [new Route('/foo/{bar<.*>?}'), '/foo/{bar}', '', ['bar' => null], ['bar' => '.*']]; + yield [new Route('/foo/{bar<>>?<>}'), '/foo/{bar}', '', ['bar' => '<>'], ['bar' => '>']]; + + yield [new Route('/{foo<.>?\}/{!bar<\>?<>}'), '/{foo}/{!bar}', '', ['foo' => '\\', 'bar' => '<>'], ['foo' => '.', 'bar' => '\\']]; + + yield [new Route('/', host: '{bar?}'), '/', '{bar}', ['bar' => null], []]; + yield [new Route('/', host: '{bar?baz}'), '/', '{bar}', ['bar' => 'baz'], []]; + yield [new Route('/', host: '{bar?baz}'), '/', '{bar}', ['bar' => 'baz'], []]; + yield [new Route('/', ['bar' => 'baz'], host: '{bar?}'), '/', '{bar}', ['bar' => null], []]; + + yield [new Route('/', host: '{bar<.*>}'), '/', '{bar}', [], ['bar' => '.*']]; + yield [new Route('/', host: '{bar<>>}'), '/', '{bar}', [], ['bar' => '>']]; + yield [new Route('/', [], ['bar' => '\d+'], host: '{bar<.*>}'), '/', '{bar}', [], ['bar' => '.*']]; + yield [new Route('/', host: '{bar<[a-z]{2}>}'), '/', '{bar}', [], ['bar' => '[a-z]{2}']]; + + yield [new Route('/', host: '{bar<.*>?}'), '/', '{bar}', ['bar' => null], ['bar' => '.*']]; + yield [new Route('/', host: '{bar<>>?<>}'), '/', '{bar}', ['bar' => '<>'], ['bar' => '>']]; } /** diff --git a/src/Symfony/Component/Routing/composer.json b/src/Symfony/Component/Routing/composer.json index 59e30bef69611..1fcc24b61606c 100644 --- a/src/Symfony/Component/Routing/composer.json +++ b/src/Symfony/Component/Routing/composer.json @@ -20,11 +20,11 @@ "symfony/deprecation-contracts": "^2.5|^3" }, "require-dev": { - "symfony/config": "^6.4|^7.0", - "symfony/http-foundation": "^6.4|^7.0", - "symfony/yaml": "^6.4|^7.0", - "symfony/expression-language": "^6.4|^7.0", - "symfony/dependency-injection": "^6.4|^7.0", + "symfony/config": "^6.4|^7.0|^8.0", + "symfony/http-foundation": "^6.4|^7.0|^8.0", + "symfony/yaml": "^6.4|^7.0|^8.0", + "symfony/expression-language": "^6.4|^7.0|^8.0", + "symfony/dependency-injection": "^6.4|^7.0|^8.0", "psr/log": "^1|^2|^3" }, "conflict": { diff --git a/src/Symfony/Component/Runtime/composer.json b/src/Symfony/Component/Runtime/composer.json index fa9c2cb3f58d0..624f90541d30f 100644 --- a/src/Symfony/Component/Runtime/composer.json +++ b/src/Symfony/Component/Runtime/composer.json @@ -21,10 +21,10 @@ }, "require-dev": { "composer/composer": "^2.6", - "symfony/console": "^6.4|^7.0", - "symfony/dotenv": "^6.4|^7.0", - "symfony/http-foundation": "^6.4|^7.0", - "symfony/http-kernel": "^6.4|^7.0" + "symfony/console": "^6.4|^7.0|^8.0", + "symfony/dotenv": "^6.4|^7.0|^8.0", + "symfony/http-foundation": "^6.4|^7.0|^8.0", + "symfony/http-kernel": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/dotenv": "<6.4" diff --git a/src/Symfony/Component/Scheduler/CHANGELOG.md b/src/Symfony/Component/Scheduler/CHANGELOG.md index 67512476a7a8e..26067e3589104 100644 --- a/src/Symfony/Component/Scheduler/CHANGELOG.md +++ b/src/Symfony/Component/Scheduler/CHANGELOG.md @@ -5,6 +5,7 @@ CHANGELOG --- * Add `TriggerNormalizer` + * Throw exception when multiple schedule provider services are registered under the same scheduler name 7.2 --- diff --git a/src/Symfony/Component/Scheduler/DependencyInjection/AddScheduleMessengerPass.php b/src/Symfony/Component/Scheduler/DependencyInjection/AddScheduleMessengerPass.php index 696422e0d28da..64880149244e1 100644 --- a/src/Symfony/Component/Scheduler/DependencyInjection/AddScheduleMessengerPass.php +++ b/src/Symfony/Component/Scheduler/DependencyInjection/AddScheduleMessengerPass.php @@ -46,6 +46,11 @@ public function process(ContainerBuilder $container): void $scheduleProviderIds = []; foreach ($container->findTaggedServiceIds('scheduler.schedule_provider') as $serviceId => $tags) { $name = $tags[0]['name']; + + if (isset($scheduleProviderIds[$name])) { + throw new InvalidArgumentException(\sprintf('Schedule provider service "%s" can not replace already registered service "%s" for schedule "%s". Make sure to register only one provider per schedule name.', $serviceId, $scheduleProviderIds[$name], $name), 1); + } + $scheduleProviderIds[$name] = $serviceId; } diff --git a/src/Symfony/Component/Scheduler/Tests/DependencyInjection/RegisterProviderTest.php b/src/Symfony/Component/Scheduler/Tests/DependencyInjection/RegisterProviderTest.php new file mode 100644 index 0000000000000..8bbfe41f71be4 --- /dev/null +++ b/src/Symfony/Component/Scheduler/Tests/DependencyInjection/RegisterProviderTest.php @@ -0,0 +1,34 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Scheduler\Tests\DependencyInjection; + +use PHPUnit\Framework\TestCase; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; +use Symfony\Component\Scheduler\DependencyInjection\AddScheduleMessengerPass; +use Symfony\Component\Scheduler\Tests\Fixtures\SomeScheduleProvider; + +class RegisterProviderTest extends TestCase +{ + public function testErrorOnMultipleProvidersForTheSameSchedule() + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionCode(1); + + $container = new ContainerBuilder(); + + $container->register('provider_a', SomeScheduleProvider::class)->addTag('scheduler.schedule_provider', ['name' => 'default']); + $container->register('provider_b', SomeScheduleProvider::class)->addTag('scheduler.schedule_provider', ['name' => 'default']); + + (new AddScheduleMessengerPass())->process($container); + } +} diff --git a/src/Symfony/Component/Scheduler/composer.json b/src/Symfony/Component/Scheduler/composer.json index e907a79d55dcb..8a5cc60506212 100644 --- a/src/Symfony/Component/Scheduler/composer.json +++ b/src/Symfony/Component/Scheduler/composer.json @@ -21,17 +21,17 @@ ], "require": { "php": ">=8.2", - "symfony/clock": "^6.4|^7.0" + "symfony/clock": "^6.4|^7.0|^8.0" }, "require-dev": { "dragonmantank/cron-expression": "^3.1", - "symfony/cache": "^6.4|^7.0", - "symfony/console": "^6.4|^7.0", - "symfony/dependency-injection": "^6.4|^7.0", - "symfony/event-dispatcher": "^6.4|^7.0", - "symfony/lock": "^6.4|^7.0", - "symfony/messenger": "^6.4|^7.0", - "symfony/serializer": "^6.4|^7.1" + "symfony/cache": "^6.4|^7.0|^8.0", + "symfony/console": "^6.4|^7.0|^8.0", + "symfony/dependency-injection": "^6.4|^7.0|^8.0", + "symfony/event-dispatcher": "^6.4|^7.0|^8.0", + "symfony/lock": "^6.4|^7.0|^8.0", + "symfony/messenger": "^6.4|^7.0|^8.0", + "symfony/serializer": "^6.4|^7.1|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Scheduler\\": "" }, diff --git a/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php b/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php index b2e18a29efe51..683e46d4e0eb8 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php +++ b/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php @@ -32,16 +32,12 @@ abstract class AbstractToken implements TokenInterface, \Serializable */ public function __construct(array $roles = []) { - $this->roleNames = []; - - foreach ($roles as $role) { - $this->roleNames[] = (string) $role; - } + $this->roleNames = $roles; } public function getRoleNames(): array { - return $this->roleNames ??= self::__construct($this->user->getRoles()) ?? $this->roleNames; + return $this->roleNames ??= $this->user?->getRoles() ?? []; } public function getUserIdentifier(): string @@ -90,13 +86,7 @@ public function eraseCredentials(): void */ public function __serialize(): array { - $data = [$this->user, true, null, $this->attributes]; - - if (!$this->user instanceof EquatableInterface) { - $data[] = $this->roleNames; - } - - return $data; + return [$this->user, true, null, $this->attributes, $this->getRoleNames()]; } /** @@ -160,12 +150,7 @@ public function __toString(): string $class = static::class; $class = substr($class, strrpos($class, '\\') + 1); - $roles = []; - foreach ($this->roleNames as $role) { - $roles[] = $role; - } - - return \sprintf('%s(user="%s", roles="%s")', $class, $this->getUserIdentifier(), implode(', ', $roles)); + return \sprintf('%s(user="%s", roles="%s")', $class, $this->getUserIdentifier(), implode(', ', $this->getRoleNames())); } /** diff --git a/src/Symfony/Component/Security/Core/Authorization/Voter/AuthenticatedVoter.php b/src/Symfony/Component/Security/Core/Authorization/Voter/AuthenticatedVoter.php index 1403aaaaf0b15..3ab6b92c1d956 100644 --- a/src/Symfony/Component/Security/Core/Authorization/Voter/AuthenticatedVoter.php +++ b/src/Symfony/Component/Security/Core/Authorization/Voter/AuthenticatedVoter.php @@ -45,11 +45,10 @@ public function __construct( */ public function vote(TokenInterface $token, mixed $subject, array $attributes/* , ?Vote $vote = null */): int { - $vote = 3 < \func_num_args() ? func_get_arg(3) : new Vote(); - $vote ??= new Vote(); + $vote = 3 < \func_num_args() ? func_get_arg(3) : null; if ($attributes === [self::PUBLIC_ACCESS]) { - $vote->reasons[] = 'Access is public.'; + $vote?->addReason('Access is public.'); return VoterInterface::ACCESS_GRANTED; } @@ -73,7 +72,7 @@ public function vote(TokenInterface $token, mixed $subject, array $attributes/* if ((self::IS_AUTHENTICATED_FULLY === $attribute || self::IS_AUTHENTICATED_REMEMBERED === $attribute) && $this->authenticationTrustResolver->isFullFledged($token) ) { - $vote->reasons[] = 'The user is fully authenticated.'; + $vote?->addReason('The user is fully authenticated.'); return VoterInterface::ACCESS_GRANTED; } @@ -81,32 +80,32 @@ public function vote(TokenInterface $token, mixed $subject, array $attributes/* if (self::IS_AUTHENTICATED_REMEMBERED === $attribute && $this->authenticationTrustResolver->isRememberMe($token) ) { - $vote->reasons[] = 'The user is remembered.'; + $vote?->addReason('The user is remembered.'); return VoterInterface::ACCESS_GRANTED; } if (self::IS_AUTHENTICATED === $attribute && $this->authenticationTrustResolver->isAuthenticated($token)) { - $vote->reasons[] = 'The user is authenticated.'; + $vote?->addReason('The user is authenticated.'); return VoterInterface::ACCESS_GRANTED; } if (self::IS_REMEMBERED === $attribute && $this->authenticationTrustResolver->isRememberMe($token)) { - $vote->reasons[] = 'The user is remembered.'; + $vote?->addReason('The user is remembered.'); return VoterInterface::ACCESS_GRANTED; } if (self::IS_IMPERSONATOR === $attribute && $token instanceof SwitchUserToken) { - $vote->reasons[] = 'The user is impersonating another user.'; + $vote?->addReason('The user is impersonating another user.'); return VoterInterface::ACCESS_GRANTED; } } if (VoterInterface::ACCESS_DENIED === $result) { - $vote->reasons[] = 'The user is not appropriately authenticated.'; + $vote?->addReason('The user is not appropriately authenticated.'); } return $result; diff --git a/src/Symfony/Component/Security/Core/Authorization/Voter/ClosureVoter.php b/src/Symfony/Component/Security/Core/Authorization/Voter/ClosureVoter.php index 03a9f7571a571..4fb5502fd91c5 100644 --- a/src/Symfony/Component/Security/Core/Authorization/Voter/ClosureVoter.php +++ b/src/Symfony/Component/Security/Core/Authorization/Voter/ClosureVoter.php @@ -42,7 +42,6 @@ public function supportsType(string $subjectType): bool public function vote(TokenInterface $token, mixed $subject, array $attributes, ?Vote $vote = null): int { - $vote ??= new Vote(); $context = new IsGrantedContext($token, $token->getUser(), $this->authorizationChecker); $failingClosures = []; $result = VoterInterface::ACCESS_ABSTAIN; @@ -54,7 +53,7 @@ public function vote(TokenInterface $token, mixed $subject, array $attributes, ? $name = (new \ReflectionFunction($attribute))->name; $result = VoterInterface::ACCESS_DENIED; if ($attribute($context, $subject)) { - $vote->reasons[] = \sprintf('Closure %s returned true.', $name); + $vote?->addReason(\sprintf('Closure %s returned true.', $name)); return VoterInterface::ACCESS_GRANTED; } @@ -63,7 +62,7 @@ public function vote(TokenInterface $token, mixed $subject, array $attributes, ? } if ($failingClosures) { - $vote->reasons[] = \sprintf('Closure%s %s returned false.', 1 < \count($failingClosures) ? 's' : '', implode(', ', $failingClosures)); + $vote?->addReason(\sprintf('Closure%s %s returned false.', 1 < \count($failingClosures) ? 's' : '', implode(', ', $failingClosures))); } return $result; diff --git a/src/Symfony/Component/Security/Core/Authorization/Voter/ExpressionVoter.php b/src/Symfony/Component/Security/Core/Authorization/Voter/ExpressionVoter.php index 35d727a8eb15e..719aae7d46872 100644 --- a/src/Symfony/Component/Security/Core/Authorization/Voter/ExpressionVoter.php +++ b/src/Symfony/Component/Security/Core/Authorization/Voter/ExpressionVoter.php @@ -49,8 +49,7 @@ public function supportsType(string $subjectType): bool */ public function vote(TokenInterface $token, mixed $subject, array $attributes/* , ?Vote $vote = null */): int { - $vote = 3 < \func_num_args() ? func_get_arg(3) : new Vote(); - $vote ??= new Vote(); + $vote = 3 < \func_num_args() ? func_get_arg(3) : null; $result = VoterInterface::ACCESS_ABSTAIN; $variables = null; $failingExpressions = []; @@ -64,7 +63,7 @@ public function vote(TokenInterface $token, mixed $subject, array $attributes/* $result = VoterInterface::ACCESS_DENIED; if ($this->expressionLanguage->evaluate($attribute, $variables)) { - $vote->reasons[] = \sprintf('Expression (%s) is true.', $attribute); + $vote?->addReason(\sprintf('Expression (%s) is true.', $attribute)); return VoterInterface::ACCESS_GRANTED; } @@ -73,7 +72,7 @@ public function vote(TokenInterface $token, mixed $subject, array $attributes/* } if ($failingExpressions) { - $vote->reasons[] = \sprintf('Expression (%s) is false.', implode(') || (', $failingExpressions)); + $vote?->addReason(\sprintf('Expression (%s) is false.', implode(') || (', $failingExpressions))); } return $result; diff --git a/src/Symfony/Component/Security/Core/Authorization/Voter/RoleVoter.php b/src/Symfony/Component/Security/Core/Authorization/Voter/RoleVoter.php index 46c08d15b48ed..2225e8d4d4c41 100644 --- a/src/Symfony/Component/Security/Core/Authorization/Voter/RoleVoter.php +++ b/src/Symfony/Component/Security/Core/Authorization/Voter/RoleVoter.php @@ -30,8 +30,7 @@ public function __construct( */ public function vote(TokenInterface $token, mixed $subject, array $attributes/* , ?Vote $vote = null */): int { - $vote = 3 < \func_num_args() ? func_get_arg(3) : new Vote(); - $vote ??= new Vote(); + $vote = 3 < \func_num_args() ? func_get_arg(3) : null; $result = VoterInterface::ACCESS_ABSTAIN; $roles = $this->extractRoles($token); $missingRoles = []; @@ -44,7 +43,7 @@ public function vote(TokenInterface $token, mixed $subject, array $attributes/* $result = VoterInterface::ACCESS_DENIED; if (\in_array($attribute, $roles, true)) { - $vote->reasons[] = \sprintf('The user has %s.', $attribute); + $vote?->addReason(\sprintf('The user has %s.', $attribute)); return VoterInterface::ACCESS_GRANTED; } @@ -53,7 +52,7 @@ public function vote(TokenInterface $token, mixed $subject, array $attributes/* } if (VoterInterface::ACCESS_DENIED === $result) { - $vote->reasons[] = \sprintf('The user doesn\'t have%s %s.', 1 < \count($missingRoles) ? ' any of' : '', implode(', ', $missingRoles)); + $vote?->addReason(\sprintf('The user doesn\'t have%s %s.', 1 < \count($missingRoles) ? ' any of' : '', implode(', ', $missingRoles))); } return $result; diff --git a/src/Symfony/Component/Security/Core/Authorization/Voter/TraceableVoter.php b/src/Symfony/Component/Security/Core/Authorization/Voter/TraceableVoter.php index 47572797ee906..ec92606359859 100644 --- a/src/Symfony/Component/Security/Core/Authorization/Voter/TraceableVoter.php +++ b/src/Symfony/Component/Security/Core/Authorization/Voter/TraceableVoter.php @@ -32,9 +32,9 @@ public function __construct( public function vote(TokenInterface $token, mixed $subject, array $attributes, ?Vote $vote = null): int { - $result = $this->voter->vote($token, $subject, $attributes, $vote ??= new Vote()); + $result = $this->voter->vote($token, $subject, $attributes, $vote); - $this->eventDispatcher->dispatch(new VoteEvent($this->voter, $subject, $attributes, $result, $vote->reasons), 'debug.security.authorization.vote'); + $this->eventDispatcher->dispatch(new VoteEvent($this->voter, $subject, $attributes, $result, $vote->reasons ?? []), 'debug.security.authorization.vote'); return $result; } diff --git a/src/Symfony/Component/Security/Core/Authorization/Voter/Voter.php b/src/Symfony/Component/Security/Core/Authorization/Voter/Voter.php index 3d7fd9e2d7a1f..55930def8fda9 100644 --- a/src/Symfony/Component/Security/Core/Authorization/Voter/Voter.php +++ b/src/Symfony/Component/Security/Core/Authorization/Voter/Voter.php @@ -29,10 +29,9 @@ abstract class Voter implements VoterInterface, CacheableVoterInterface */ public function vote(TokenInterface $token, mixed $subject, array $attributes/* , ?Vote $vote = null */): int { - $vote = 3 < \func_num_args() ? func_get_arg(3) : new Vote(); - $vote ??= new Vote(); + $vote = 3 < \func_num_args() ? func_get_arg(3) : null; // abstain vote by default in case none of the attributes are supported - $vote->result = self::ACCESS_ABSTAIN; + $voteResult = self::ACCESS_ABSTAIN; foreach ($attributes as $attribute) { try { @@ -48,15 +47,27 @@ public function vote(TokenInterface $token, mixed $subject, array $attributes/* } // as soon as at least one attribute is supported, default is to deny access - $vote->result = self::ACCESS_DENIED; + $voteResult = self::ACCESS_DENIED; + + if (null !== $vote) { + $vote->result = $voteResult; + } if ($this->voteOnAttribute($attribute, $subject, $token, $vote)) { // grant access as soon as at least one attribute returns a positive response - return $vote->result = self::ACCESS_GRANTED; + if (null !== $vote) { + $vote->result = self::ACCESS_GRANTED; + } + + return self::ACCESS_GRANTED; } } - return $vote->result; + if (null !== $vote) { + $vote->result = $voteResult; + } + + return $voteResult; } /** diff --git a/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/VoterTest.php b/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/VoterTest.php index a8f87e09da7e6..eaada3061dbfe 100644 --- a/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/VoterTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/VoterTest.php @@ -33,35 +33,51 @@ public static function getTests(): array return [ [$voter, ['EDIT'], VoterInterface::ACCESS_GRANTED, new \stdClass(), 'ACCESS_GRANTED if attribute and class are supported and attribute grants access'], + [$voter, ['EDIT'], VoterInterface::ACCESS_GRANTED, new \stdClass(), 'ACCESS_GRANTED if attribute and class are supported and attribute grants access', new Vote()], [$voter, ['CREATE'], VoterInterface::ACCESS_DENIED, new \stdClass(), 'ACCESS_DENIED if attribute and class are supported and attribute does not grant access'], + [$voter, ['CREATE'], VoterInterface::ACCESS_DENIED, new \stdClass(), 'ACCESS_DENIED if attribute and class are supported and attribute does not grant access', new Vote()], [$voter, ['DELETE', 'EDIT'], VoterInterface::ACCESS_GRANTED, new \stdClass(), 'ACCESS_GRANTED if one attribute is supported and grants access'], + [$voter, ['DELETE', 'EDIT'], VoterInterface::ACCESS_GRANTED, new \stdClass(), 'ACCESS_GRANTED if one attribute is supported and grants access', new Vote()], [$voter, ['DELETE', 'CREATE'], VoterInterface::ACCESS_DENIED, new \stdClass(), 'ACCESS_DENIED if one attribute is supported and denies access'], + [$voter, ['DELETE', 'CREATE'], VoterInterface::ACCESS_DENIED, new \stdClass(), 'ACCESS_DENIED if one attribute is supported and denies access', new Vote()], [$voter, ['CREATE', 'EDIT'], VoterInterface::ACCESS_GRANTED, new \stdClass(), 'ACCESS_GRANTED if one attribute grants access'], + [$voter, ['CREATE', 'EDIT'], VoterInterface::ACCESS_GRANTED, new \stdClass(), 'ACCESS_GRANTED if one attribute grants access', new Vote()], [$voter, ['DELETE'], VoterInterface::ACCESS_ABSTAIN, new \stdClass(), 'ACCESS_ABSTAIN if no attribute is supported'], + [$voter, ['DELETE'], VoterInterface::ACCESS_ABSTAIN, new \stdClass(), 'ACCESS_ABSTAIN if no attribute is supported', new Vote()], [$voter, ['EDIT'], VoterInterface::ACCESS_ABSTAIN, new class {}, 'ACCESS_ABSTAIN if class is not supported'], + [$voter, ['EDIT'], VoterInterface::ACCESS_ABSTAIN, new class {}, 'ACCESS_ABSTAIN if class is not supported', new Vote()], [$voter, ['EDIT'], VoterInterface::ACCESS_ABSTAIN, null, 'ACCESS_ABSTAIN if object is null'], + [$voter, ['EDIT'], VoterInterface::ACCESS_ABSTAIN, null, 'ACCESS_ABSTAIN if object is null', new Vote()], [$voter, [], VoterInterface::ACCESS_ABSTAIN, new \stdClass(), 'ACCESS_ABSTAIN if no attributes were provided'], + [$voter, [], VoterInterface::ACCESS_ABSTAIN, new \stdClass(), 'ACCESS_ABSTAIN if no attributes were provided', new Vote()], [$voter, [new StringableAttribute()], VoterInterface::ACCESS_GRANTED, new \stdClass(), 'ACCESS_GRANTED if attribute and class are supported and attribute grants access'], + [$voter, [new StringableAttribute()], VoterInterface::ACCESS_GRANTED, new \stdClass(), 'ACCESS_GRANTED if attribute and class are supported and attribute grants access', new Vote()], [$voter, [new \stdClass()], VoterInterface::ACCESS_ABSTAIN, new \stdClass(), 'ACCESS_ABSTAIN if attributes were not strings'], + [$voter, [new \stdClass()], VoterInterface::ACCESS_ABSTAIN, new \stdClass(), 'ACCESS_ABSTAIN if attributes were not strings', new Vote()], [$integerVoter, [42], VoterInterface::ACCESS_GRANTED, new \stdClass(), 'ACCESS_GRANTED if attribute is an integer'], + [$integerVoter, [42], VoterInterface::ACCESS_GRANTED, new \stdClass(), 'ACCESS_GRANTED if attribute is an integer', new Vote()], ]; } /** * @dataProvider getTests */ - public function testVote(VoterInterface $voter, array $attributes, $expectedVote, $object, $message) + public function testVote(VoterInterface $voter, array $attributes, $expectedVote, $object, $message, ?Vote $vote = null) { - $this->assertEquals($expectedVote, $voter->vote($this->token, $object, $attributes), $message); + $this->assertSame($expectedVote, $voter->vote($this->token, $object, $attributes, $vote), $message); + + if (null !== $vote) { + self::assertSame($expectedVote, $vote->result); + } } public function testVoteWithTypeError() diff --git a/src/Symfony/Component/Security/Core/User/UserInterface.php b/src/Symfony/Component/Security/Core/User/UserInterface.php index 120521211b326..24c0581f83cbd 100644 --- a/src/Symfony/Component/Security/Core/User/UserInterface.php +++ b/src/Symfony/Component/Security/Core/User/UserInterface.php @@ -15,9 +15,7 @@ * Represents the interface that all user classes must implement. * * This interface is useful because the authentication layer can deal with - * the object through its lifecycle, using the object to get the hashed - * password (for checking against a submitted password), assigning roles - * and so on. + * the object through its lifecycle, assigning roles and so on. * * Regardless of how your users are loaded or where they come from (a database, * configuration, web service, etc.), you will have a class that implements diff --git a/src/Symfony/Component/Security/Core/composer.json b/src/Symfony/Component/Security/Core/composer.json index 0aaff1e3645bf..9d662f7e9eeda 100644 --- a/src/Symfony/Component/Security/Core/composer.json +++ b/src/Symfony/Component/Security/Core/composer.json @@ -20,20 +20,20 @@ "symfony/deprecation-contracts": "^2.5|^3", "symfony/event-dispatcher-contracts": "^2.5|^3", "symfony/service-contracts": "^2.5|^3", - "symfony/password-hasher": "^6.4|^7.0" + "symfony/password-hasher": "^6.4|^7.0|^8.0" }, "require-dev": { "psr/container": "^1.1|^2.0", "psr/cache": "^1.0|^2.0|^3.0", - "symfony/cache": "^6.4|^7.0", - "symfony/dependency-injection": "^6.4|^7.0", - "symfony/event-dispatcher": "^6.4|^7.0", - "symfony/expression-language": "^6.4|^7.0", - "symfony/http-foundation": "^6.4|^7.0", - "symfony/ldap": "^6.4|^7.0", - "symfony/string": "^6.4|^7.0", - "symfony/translation": "^6.4.3|^7.0.3", - "symfony/validator": "^6.4|^7.0", + "symfony/cache": "^6.4|^7.0|^8.0", + "symfony/dependency-injection": "^6.4|^7.0|^8.0", + "symfony/event-dispatcher": "^6.4|^7.0|^8.0", + "symfony/expression-language": "^6.4|^7.0|^8.0", + "symfony/http-foundation": "^6.4|^7.0|^8.0", + "symfony/ldap": "^6.4|^7.0|^8.0", + "symfony/string": "^6.4|^7.0|^8.0", + "symfony/translation": "^6.4.3|^7.0.3|^8.0", + "symfony/validator": "^6.4|^7.0|^8.0", "psr/log": "^1|^2|^3" }, "conflict": { diff --git a/src/Symfony/Component/Security/Csrf/composer.json b/src/Symfony/Component/Security/Csrf/composer.json index c2bfed1de3d7e..6129d76ce8e1b 100644 --- a/src/Symfony/Component/Security/Csrf/composer.json +++ b/src/Symfony/Component/Security/Csrf/composer.json @@ -17,12 +17,12 @@ ], "require": { "php": ">=8.2", - "symfony/security-core": "^6.4|^7.0" + "symfony/security-core": "^6.4|^7.0|^8.0" }, "require-dev": { "psr/log": "^1|^2|^3", - "symfony/http-foundation": "^6.4|^7.0", - "symfony/http-kernel": "^6.4|^7.0" + "symfony/http-foundation": "^6.4|^7.0|^8.0", + "symfony/http-kernel": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/http-foundation": "<6.4" diff --git a/src/Symfony/Component/Security/Http/Tests/EventListener/IsGrantedAttributeListenerTest.php b/src/Symfony/Component/Security/Http/Tests/EventListener/IsGrantedAttributeListenerTest.php index 73494f405468c..d34b31f2bdeb8 100644 --- a/src/Symfony/Component/Security/Http/Tests/EventListener/IsGrantedAttributeListenerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/EventListener/IsGrantedAttributeListenerTest.php @@ -232,7 +232,7 @@ protected function supports(string $attribute, mixed $subject): bool protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token, ?Vote $vote = null): bool { - $vote->reasons[] = 'Because I can 😈.'; + $vote?->addReason('Because I can 😈.'); return false; } diff --git a/src/Symfony/Component/Security/Http/composer.json b/src/Symfony/Component/Security/Http/composer.json index 77f6af87395ec..a6c2626da5873 100644 --- a/src/Symfony/Component/Security/Http/composer.json +++ b/src/Symfony/Component/Security/Http/composer.json @@ -18,23 +18,24 @@ "require": { "php": ">=8.2", "symfony/deprecation-contracts": "^2.5|^3", - "symfony/http-foundation": "^6.4|^7.0", - "symfony/http-kernel": "^6.4|^7.0", + "symfony/event-dispatcher": "^6.4|^7.0", + "symfony/http-foundation": "^6.4|^7.0|^8.0", + "symfony/http-kernel": "^6.4|^7.0|^8.0", "symfony/polyfill-mbstring": "~1.0", - "symfony/property-access": "^6.4|^7.0", - "symfony/security-core": "^7.3", + "symfony/property-access": "^6.4|^7.0|^8.0", + "symfony/security-core": "^7.3|^8.0", "symfony/service-contracts": "^2.5|^3" }, "require-dev": { - "symfony/cache": "^6.4|^7.0", - "symfony/clock": "^6.4|^7.0", - "symfony/expression-language": "^6.4|^7.0", - "symfony/http-client": "^6.4|^7.0", + "symfony/cache": "^6.4|^7.0|^8.0", + "symfony/clock": "^6.4|^7.0|^8.0", + "symfony/expression-language": "^6.4|^7.0|^8.0", + "symfony/http-client": "^6.4|^7.0|^8.0", "symfony/http-client-contracts": "^3.0", - "symfony/rate-limiter": "^6.4|^7.0", - "symfony/routing": "^6.4|^7.0", - "symfony/security-csrf": "^6.4|^7.0", - "symfony/translation": "^6.4|^7.0", + "symfony/rate-limiter": "^6.4|^7.0|^8.0", + "symfony/routing": "^6.4|^7.0|^8.0", + "symfony/security-csrf": "^6.4|^7.0|^8.0", + "symfony/translation": "^6.4|^7.0|^8.0", "psr/log": "^1|^2|^3", "web-token/jwt-library": "^3.3.2|^4.0" }, diff --git a/src/Symfony/Component/Serializer/composer.json b/src/Symfony/Component/Serializer/composer.json index d8809fa079ef9..1a58ba7ee133b 100644 --- a/src/Symfony/Component/Serializer/composer.json +++ b/src/Symfony/Component/Serializer/composer.json @@ -24,26 +24,26 @@ "phpdocumentor/reflection-docblock": "^3.2|^4.0|^5.0", "phpstan/phpdoc-parser": "^1.0|^2.0", "seld/jsonlint": "^1.10", - "symfony/cache": "^6.4|^7.0", - "symfony/config": "^6.4|^7.0", - "symfony/console": "^6.4|^7.0", - "symfony/dependency-injection": "^7.2", - "symfony/error-handler": "^6.4|^7.0", - "symfony/filesystem": "^6.4|^7.0", - "symfony/form": "^6.4|^7.0", - "symfony/http-foundation": "^6.4|^7.0", - "symfony/http-kernel": "^6.4|^7.0", - "symfony/messenger": "^6.4|^7.0", - "symfony/mime": "^6.4|^7.0", - "symfony/property-access": "^6.4|^7.0", - "symfony/property-info": "^6.4|^7.0", + "symfony/cache": "^6.4|^7.0|^8.0", + "symfony/config": "^6.4|^7.0|^8.0", + "symfony/console": "^6.4|^7.0|^8.0", + "symfony/dependency-injection": "^7.2|^8.0", + "symfony/error-handler": "^6.4|^7.0|^8.0", + "symfony/filesystem": "^6.4|^7.0|^8.0", + "symfony/form": "^6.4|^7.0|^8.0", + "symfony/http-foundation": "^6.4|^7.0|^8.0", + "symfony/http-kernel": "^6.4|^7.0|^8.0", + "symfony/messenger": "^6.4|^7.0|^8.0", + "symfony/mime": "^6.4|^7.0|^8.0", + "symfony/property-access": "^6.4|^7.0|^8.0", + "symfony/property-info": "^6.4|^7.0|^8.0", "symfony/translation-contracts": "^2.5|^3", - "symfony/type-info": "^7.1", - "symfony/uid": "^6.4|^7.0", - "symfony/validator": "^6.4|^7.0", - "symfony/var-dumper": "^6.4|^7.0", - "symfony/var-exporter": "^6.4|^7.0", - "symfony/yaml": "^6.4|^7.0" + "symfony/type-info": "^7.1|^8.0", + "symfony/uid": "^6.4|^7.0|^8.0", + "symfony/validator": "^6.4|^7.0|^8.0", + "symfony/var-dumper": "^6.4|^7.0|^8.0", + "symfony/var-exporter": "^6.4|^7.0|^8.0", + "symfony/yaml": "^6.4|^7.0|^8.0" }, "conflict": { "phpdocumentor/reflection-docblock": "<3.2.2", diff --git a/src/Symfony/Component/String/composer.json b/src/Symfony/Component/String/composer.json index 10d0ee620e4da..e2f31fdb14525 100644 --- a/src/Symfony/Component/String/composer.json +++ b/src/Symfony/Component/String/composer.json @@ -23,12 +23,12 @@ "symfony/polyfill-mbstring": "~1.0" }, "require-dev": { - "symfony/error-handler": "^6.4|^7.0", - "symfony/emoji": "^7.1", - "symfony/http-client": "^6.4|^7.0", - "symfony/intl": "^6.4|^7.0", + "symfony/error-handler": "^6.4|^7.0|^8.0", + "symfony/emoji": "^7.1|^8.0", + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/intl": "^6.4|^7.0|^8.0", "symfony/translation-contracts": "^2.5|^3.0", - "symfony/var-exporter": "^6.4|^7.0" + "symfony/var-exporter": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/translation-contracts": "<2.5" diff --git a/src/Symfony/Component/Translation/Bridge/Crowdin/composer.json b/src/Symfony/Component/Translation/Bridge/Crowdin/composer.json index d2f60819d6b9b..700733a7d8c6a 100644 --- a/src/Symfony/Component/Translation/Bridge/Crowdin/composer.json +++ b/src/Symfony/Component/Translation/Bridge/Crowdin/composer.json @@ -21,9 +21,9 @@ ], "require": { "php": ">=8.2", - "symfony/config": "^6.4|^7.0", - "symfony/http-client": "^6.4|^7.0", - "symfony/translation": "^7.2" + "symfony/config": "^6.4|^7.0|^8.0", + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/translation": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Translation\\Bridge\\Crowdin\\": "" }, diff --git a/src/Symfony/Component/Translation/Bridge/Loco/composer.json b/src/Symfony/Component/Translation/Bridge/Loco/composer.json index 40eb6f753d363..a98c6f91595b8 100644 --- a/src/Symfony/Component/Translation/Bridge/Loco/composer.json +++ b/src/Symfony/Component/Translation/Bridge/Loco/composer.json @@ -17,9 +17,9 @@ ], "require": { "php": ">=8.2", - "symfony/http-client": "^6.4|^7.0", - "symfony/config": "^6.4|^7.0", - "symfony/translation": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/config": "^6.4|^7.0|^8.0", + "symfony/translation": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Translation\\Bridge\\Loco\\": "" }, diff --git a/src/Symfony/Component/Translation/Bridge/Lokalise/composer.json b/src/Symfony/Component/Translation/Bridge/Lokalise/composer.json index 78be5ea3c89cc..6f9a8c915e20b 100644 --- a/src/Symfony/Component/Translation/Bridge/Lokalise/composer.json +++ b/src/Symfony/Component/Translation/Bridge/Lokalise/composer.json @@ -17,9 +17,9 @@ ], "require": { "php": ">=8.2", - "symfony/config": "^6.4|^7.0", - "symfony/http-client": "^6.4|^7.0", - "symfony/translation": "^7.2" + "symfony/config": "^6.4|^7.0|^8.0", + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/translation": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Translation\\Bridge\\Lokalise\\": "" }, diff --git a/src/Symfony/Component/Translation/Bridge/Phrase/composer.json b/src/Symfony/Component/Translation/Bridge/Phrase/composer.json index 2d3105037f7c6..3cd63db74b5a9 100644 --- a/src/Symfony/Component/Translation/Bridge/Phrase/composer.json +++ b/src/Symfony/Component/Translation/Bridge/Phrase/composer.json @@ -18,9 +18,9 @@ "require": { "php": ">=8.2", "psr/cache": "^3.0", - "symfony/http-client": "^6.4|^7.0", - "symfony/mime": "^6.4|^7.0", - "symfony/translation": "^7.2" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/mime": "^6.4|^7.0|^8.0", + "symfony/translation": "^7.2|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Translation\\Bridge\\Phrase\\": "" }, diff --git a/src/Symfony/Component/Translation/MessageCatalogue.php b/src/Symfony/Component/Translation/MessageCatalogue.php index 2d229f2dd1839..eac50bb1f9b9e 100644 --- a/src/Symfony/Component/Translation/MessageCatalogue.php +++ b/src/Symfony/Component/Translation/MessageCatalogue.php @@ -217,6 +217,16 @@ public function getMetadata(string $key = '', string $domain = 'messages'): mixe return $this->metadata; } + if (isset($this->metadata[$domain.self::INTL_DOMAIN_SUFFIX])) { + if ('' === $key) { + return $this->metadata[$domain.self::INTL_DOMAIN_SUFFIX]; + } + + if (isset($this->metadata[$domain.self::INTL_DOMAIN_SUFFIX][$key])) { + return $this->metadata[$domain.self::INTL_DOMAIN_SUFFIX][$key]; + } + } + if (isset($this->metadata[$domain])) { if ('' == $key) { return $this->metadata[$domain]; diff --git a/src/Symfony/Component/Translation/Tests/Catalogue/MessageCatalogueTest.php b/src/Symfony/Component/Translation/Tests/Catalogue/MessageCatalogueTest.php new file mode 100644 index 0000000000000..1ac61673999b2 --- /dev/null +++ b/src/Symfony/Component/Translation/Tests/Catalogue/MessageCatalogueTest.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests\Catalogue; + +use PHPUnit\Framework\TestCase; +use Symfony\Component\Translation\MessageCatalogue; + +class MessageCatalogueTest extends TestCase +{ + public function testIcuMetadataKept() + { + $mc = new MessageCatalogue('en', ['messages' => ['a' => 'new_a']]); + $metadata = ['metadata' => 'value']; + $mc->setMetadata('a', $metadata, 'messages+intl-icu'); + $this->assertEquals($metadata, $mc->getMetadata('a', 'messages')); + $this->assertEquals($metadata, $mc->getMetadata('a', 'messages+intl-icu')); + } +} diff --git a/src/Symfony/Component/Translation/composer.json b/src/Symfony/Component/Translation/composer.json index ce9a7bf48c61b..69a2998af9390 100644 --- a/src/Symfony/Component/Translation/composer.json +++ b/src/Symfony/Component/Translation/composer.json @@ -23,17 +23,17 @@ }, "require-dev": { "nikic/php-parser": "^5.0", - "symfony/config": "^6.4|^7.0", - "symfony/console": "^6.4|^7.0", - "symfony/dependency-injection": "^6.4|^7.0", + "symfony/config": "^6.4|^7.0|^8.0", + "symfony/console": "^6.4|^7.0|^8.0", + "symfony/dependency-injection": "^6.4|^7.0|^8.0", "symfony/http-client-contracts": "^2.5|^3.0", - "symfony/http-kernel": "^6.4|^7.0", - "symfony/intl": "^6.4|^7.0", + "symfony/http-kernel": "^6.4|^7.0|^8.0", + "symfony/intl": "^6.4|^7.0|^8.0", "symfony/polyfill-intl-icu": "^1.21", - "symfony/routing": "^6.4|^7.0", + "symfony/routing": "^6.4|^7.0|^8.0", "symfony/service-contracts": "^2.5|^3", - "symfony/yaml": "^6.4|^7.0", - "symfony/finder": "^6.4|^7.0", + "symfony/yaml": "^6.4|^7.0|^8.0", + "symfony/finder": "^6.4|^7.0|^8.0", "psr/log": "^1|^2|^3" }, "conflict": { diff --git a/src/Symfony/Component/TypeInfo/Tests/Fixtures/DummyWithTypeAliases.php b/src/Symfony/Component/TypeInfo/Tests/Fixtures/DummyWithTypeAliases.php index 0b65137e4cdda..7f73190df1549 100644 --- a/src/Symfony/Component/TypeInfo/Tests/Fixtures/DummyWithTypeAliases.php +++ b/src/Symfony/Component/TypeInfo/Tests/Fixtures/DummyWithTypeAliases.php @@ -12,11 +12,15 @@ namespace Symfony\Component\TypeInfo\Tests\Fixtures; /** + * @phpstan-type CustomArray = array{0: CustomInt, 1: CustomString, 2: bool} * @phpstan-type CustomString = string + * * @phpstan-import-type CustomInt from DummyWithPhpDoc * @phpstan-import-type CustomInt from DummyWithPhpDoc as AliasedCustomInt * + * @psalm-type PsalmCustomArray = array{0: PsalmCustomInt, 1: PsalmCustomString, 2: bool} * @psalm-type PsalmCustomString = string + * * @psalm-import-type PsalmCustomInt from DummyWithPhpDoc * @psalm-import-type PsalmCustomInt from DummyWithPhpDoc as PsalmAliasedCustomInt */ @@ -53,9 +57,31 @@ final class DummyWithTypeAliases public mixed $psalmOtherAliasedExternalAlias; } +/** + * @phpstan-type Foo = array{0: Bar} + * @phpstan-type Bar = array{0: Foo} + */ +final class DummyWithRecursiveTypeAliases +{ +} + +/** + * @phpstan-type Invalid = SomethingInvalid + */ +final class DummyWithInvalidTypeAlias +{ +} + /** * @phpstan-import-type Invalid from DummyWithTypeAliases */ final class DummyWithInvalidTypeAliasImport { } + +/** + * @phpstan-import-type Invalid from int + */ +final class DummyWithTypeAliasImportedFromInvalidClassName +{ +} diff --git a/src/Symfony/Component/TypeInfo/Tests/TypeContext/TypeContextFactoryTest.php b/src/Symfony/Component/TypeInfo/Tests/TypeContext/TypeContextFactoryTest.php index e7794e4f114b6..7d6725ed26743 100644 --- a/src/Symfony/Component/TypeInfo/Tests/TypeContext/TypeContextFactoryTest.php +++ b/src/Symfony/Component/TypeInfo/Tests/TypeContext/TypeContextFactoryTest.php @@ -15,9 +15,12 @@ use Symfony\Component\TypeInfo\Exception\LogicException; use Symfony\Component\TypeInfo\Tests\Fixtures\AbstractDummy; use Symfony\Component\TypeInfo\Tests\Fixtures\Dummy; +use Symfony\Component\TypeInfo\Tests\Fixtures\DummyWithInvalidTypeAlias; use Symfony\Component\TypeInfo\Tests\Fixtures\DummyWithInvalidTypeAliasImport; +use Symfony\Component\TypeInfo\Tests\Fixtures\DummyWithRecursiveTypeAliases; use Symfony\Component\TypeInfo\Tests\Fixtures\DummyWithTemplates; use Symfony\Component\TypeInfo\Tests\Fixtures\DummyWithTypeAliases; +use Symfony\Component\TypeInfo\Tests\Fixtures\DummyWithTypeAliasImportedFromInvalidClassName; use Symfony\Component\TypeInfo\Tests\Fixtures\DummyWithUses; use Symfony\Component\TypeInfo\Type; use Symfony\Component\TypeInfo\TypeContext\TypeContextFactory; @@ -128,27 +131,33 @@ public function testCollectTypeAliases() $this->assertEquals([ 'CustomString' => Type::string(), 'CustomInt' => Type::int(), + 'CustomArray' => Type::arrayShape([0 => Type::int(), 1 => Type::string(), 2 => Type::bool()]), 'AliasedCustomInt' => Type::int(), 'PsalmCustomString' => Type::string(), 'PsalmCustomInt' => Type::int(), + 'PsalmCustomArray' => Type::arrayShape([0 => Type::int(), 1 => Type::string(), 2 => Type::bool()]), 'PsalmAliasedCustomInt' => Type::int(), ], $this->typeContextFactory->createFromClassName(DummyWithTypeAliases::class)->typeAliases); $this->assertEquals([ 'CustomString' => Type::string(), 'CustomInt' => Type::int(), + 'CustomArray' => Type::arrayShape([0 => Type::int(), 1 => Type::string(), 2 => Type::bool()]), 'AliasedCustomInt' => Type::int(), 'PsalmCustomString' => Type::string(), 'PsalmCustomInt' => Type::int(), + 'PsalmCustomArray' => Type::arrayShape([0 => Type::int(), 1 => Type::string(), 2 => Type::bool()]), 'PsalmAliasedCustomInt' => Type::int(), ], $this->typeContextFactory->createFromReflection(new \ReflectionClass(DummyWithTypeAliases::class))->typeAliases); $this->assertEquals([ 'CustomString' => Type::string(), 'CustomInt' => Type::int(), + 'CustomArray' => Type::arrayShape([0 => Type::int(), 1 => Type::string(), 2 => Type::bool()]), 'AliasedCustomInt' => Type::int(), 'PsalmCustomString' => Type::string(), 'PsalmCustomInt' => Type::int(), + 'PsalmCustomArray' => Type::arrayShape([0 => Type::int(), 1 => Type::string(), 2 => Type::bool()]), 'PsalmAliasedCustomInt' => Type::int(), ], $this->typeContextFactory->createFromReflection(new \ReflectionProperty(DummyWithTypeAliases::class, 'localAlias'))->typeAliases); } @@ -167,4 +176,28 @@ public function testThrowWhenImportingInvalidAlias() $this->typeContextFactory->createFromClassName(DummyWithInvalidTypeAliasImport::class); } + + public function testThrowWhenCannotResolveTypeAlias() + { + $this->expectException(LogicException::class); + $this->expectExceptionMessage('Cannot resolve "Invalid" type alias.'); + + $this->typeContextFactory->createFromClassName(DummyWithInvalidTypeAlias::class); + } + + public function testThrowWhenTypeAliasNotImportedFromValidClassName() + { + $this->expectException(LogicException::class); + $this->expectExceptionMessage('Type alias "Invalid" is not imported from a valid class name.'); + + $this->typeContextFactory->createFromClassName(DummyWithTypeAliasImportedFromInvalidClassName::class); + } + + public function testThrowWhenImportingRecursiveTypeAliases() + { + $this->expectException(LogicException::class); + $this->expectExceptionMessage('Cannot resolve "Bar" type alias.'); + + $this->typeContextFactory->createFromClassName(DummyWithRecursiveTypeAliases::class)->typeAliases; + } } diff --git a/src/Symfony/Component/TypeInfo/Tests/TypeResolver/StringTypeResolverTest.php b/src/Symfony/Component/TypeInfo/Tests/TypeResolver/StringTypeResolverTest.php index fcfe909cecf6e..9cdd9e1f196e9 100644 --- a/src/Symfony/Component/TypeInfo/Tests/TypeResolver/StringTypeResolverTest.php +++ b/src/Symfony/Component/TypeInfo/Tests/TypeResolver/StringTypeResolverTest.php @@ -79,6 +79,7 @@ public static function resolveDataProvider(): iterable yield [Type::arrayShape(['foo' => Type::bool()], sealed: false), 'array{foo: bool, ...}']; yield [Type::arrayShape(['foo' => Type::bool()], extraKeyType: Type::int(), extraValueType: Type::string()), 'array{foo: bool, ...}']; yield [Type::arrayShape(['foo' => Type::bool()], extraValueType: Type::int()), 'array{foo: bool, ...}']; + yield [Type::arrayShape(['foo' => Type::union(Type::bool(), Type::float(), Type::int(), Type::null(), Type::string()), 'bar' => Type::string()]), 'array{foo: scalar|null, bar: string}']; // object shape yield [Type::object(), 'object{foo: true, bar: false}']; @@ -157,6 +158,9 @@ public static function resolveDataProvider(): iterable yield [Type::generic(Type::object(\DateTime::class), Type::string(), Type::bool()), \DateTime::class.'']; yield [Type::generic(Type::object(\DateTime::class), Type::generic(Type::object(\Stringable::class), Type::bool())), \sprintf('%s<%s>', \DateTime::class, \Stringable::class)]; yield [Type::int(), 'int<0, 100>']; + yield [Type::string(), \sprintf('value-of<%s>', DummyBackedEnum::class)]; + yield [Type::int(), 'key-of>']; + yield [Type::bool(), 'value-of>']; // union yield [Type::union(Type::int(), Type::string()), 'int|string']; @@ -216,9 +220,21 @@ public function testCannotResolveParentWithoutTypeContext() $this->resolver->resolve('parent'); } - public function testCannotUnknownIdentifier() + public function testCannotResolveUnknownIdentifier() { $this->expectException(UnsupportedException::class); $this->resolver->resolve('unknown'); } + + public function testCannotResolveKeyOfInvalidType() + { + $this->expectException(UnsupportedException::class); + $this->resolver->resolve('key-of'); + } + + public function testCannotResolveValueOfInvalidType() + { + $this->expectException(UnsupportedException::class); + $this->resolver->resolve('value-of'); + } } diff --git a/src/Symfony/Component/TypeInfo/Type/CollectionType.php b/src/Symfony/Component/TypeInfo/Type/CollectionType.php index 80fbbdba6c3fa..a801f2b51f8d0 100644 --- a/src/Symfony/Component/TypeInfo/Type/CollectionType.php +++ b/src/Symfony/Component/TypeInfo/Type/CollectionType.php @@ -65,25 +65,27 @@ public static function mergeCollectionValueTypes(array $types): Type $boolTypes = []; $objectTypes = []; - foreach ($types as $t) { - // cannot create an union with a standalone type - if ($t->isIdentifiedBy(TypeIdentifier::MIXED)) { - return Type::mixed(); - } + foreach ($types as $type) { + foreach (($type instanceof UnionType ? $type->getTypes() : [$type]) as $t) { + // cannot create an union with a standalone type + if ($t->isIdentifiedBy(TypeIdentifier::MIXED)) { + return Type::mixed(); + } - if ($t->isIdentifiedBy(TypeIdentifier::TRUE, TypeIdentifier::FALSE, TypeIdentifier::BOOL)) { - $boolTypes[] = $t; + if ($t->isIdentifiedBy(TypeIdentifier::TRUE, TypeIdentifier::FALSE, TypeIdentifier::BOOL)) { + $boolTypes[] = $t; - continue; - } + continue; + } - if ($t->isIdentifiedBy(TypeIdentifier::OBJECT)) { - $objectTypes[] = $t; + if ($t->isIdentifiedBy(TypeIdentifier::OBJECT)) { + $objectTypes[] = $t; - continue; - } + continue; + } - $normalizedTypes[] = $t; + $normalizedTypes[] = $t; + } } $boolTypes = array_unique($boolTypes); diff --git a/src/Symfony/Component/TypeInfo/TypeContext/TypeContextFactory.php b/src/Symfony/Component/TypeInfo/TypeContext/TypeContextFactory.php index d268c85fe49b0..a149a52249ba7 100644 --- a/src/Symfony/Component/TypeInfo/TypeContext/TypeContextFactory.php +++ b/src/Symfony/Component/TypeInfo/TypeContext/TypeContextFactory.php @@ -199,32 +199,85 @@ private function collectTypeAliases(\ReflectionClass $reflection, TypeContext $t } $aliases = []; - foreach ($this->getPhpDocNode($rawDocNode)->getTagsByName('@psalm-type') + $this->getPhpDocNode($rawDocNode)->getTagsByName('@phpstan-type') as $tag) { - if (!$tag->value instanceof TypeAliasTagValueNode) { + $resolvedAliases = []; + + foreach ($this->getPhpDocNode($rawDocNode)->getTagsByName('@psalm-import-type') + $this->getPhpDocNode($rawDocNode)->getTagsByName('@phpstan-import-type') as $tag) { + if (!$tag->value instanceof TypeAliasImportTagValueNode) { continue; } - $aliases[$tag->value->alias] = $this->stringTypeResolver->resolve((string) $tag->value->type, $typeContext); + $importedFromType = $this->stringTypeResolver->resolve((string) $tag->value->importedFrom, $typeContext); + if (!$importedFromType instanceof ObjectType) { + throw new LogicException(\sprintf('Type alias "%s" is not imported from a valid class name.', $tag->value->importedAlias)); + } + + $importedFromContext = $this->createFromClassName($importedFromType->getClassName()); + + $typeAlias = $importedFromContext->typeAliases[$tag->value->importedAlias] ?? null; + if (!$typeAlias) { + throw new LogicException(\sprintf('Cannot find any "%s" type alias in "%s".', $tag->value->importedAlias, $importedFromType->getClassName())); + } + + $resolvedAliases[$tag->value->importedAs ?? $tag->value->importedAlias] = $typeAlias; } - foreach ($this->getPhpDocNode($rawDocNode)->getTagsByName('@psalm-import-type') + $this->getPhpDocNode($rawDocNode)->getTagsByName('@phpstan-import-type') as $tag) { - if (!$tag->value instanceof TypeAliasImportTagValueNode) { + foreach ($this->getPhpDocNode($rawDocNode)->getTagsByName('@psalm-type') + $this->getPhpDocNode($rawDocNode)->getTagsByName('@phpstan-type') as $tag) { + if (!$tag->value instanceof TypeAliasTagValueNode) { continue; } - /** @var ObjectType $importedType */ - $importedType = $this->stringTypeResolver->resolve((string) $tag->value->importedFrom, $typeContext); - $importedTypeContext = $this->createFromClassName($importedType->getClassName()); + $aliases[$tag->value->alias] = (string) $tag->value->type; + } - $typeAlias = $importedTypeContext->typeAliases[$tag->value->importedAlias] ?? null; - if (!$typeAlias) { - throw new LogicException(\sprintf('Cannot find any "%s" type alias in "%s".', $tag->value->importedAlias, $importedType->getClassName())); + return $this->resolveTypeAliases($aliases, $resolvedAliases, $typeContext); + } + + /** + * @param array $toResolve + * @param array $resolved + * + * @return array + */ + private function resolveTypeAliases(array $toResolve, array $resolved, TypeContext $typeContext): array + { + if (!$toResolve) { + return []; + } + + $typeContext = new TypeContext( + $typeContext->calledClassName, + $typeContext->declaringClassName, + $typeContext->namespace, + $typeContext->uses, + $typeContext->templates, + $typeContext->typeAliases + $resolved, + ); + + $succeeded = false; + $lastFailure = null; + $lastFailingAlias = null; + + foreach ($toResolve as $alias => $type) { + try { + $resolved[$alias] = $this->stringTypeResolver->resolve($type, $typeContext); + unset($toResolve[$alias]); + $succeeded = true; + } catch (UnsupportedException $lastFailure) { + $lastFailingAlias = $alias; } + } + + // nothing has succeeded, the result won't be different from the + // previous one, we can stop here. + if (!$succeeded) { + throw new LogicException(\sprintf('Cannot resolve "%s" type alias.', $lastFailingAlias), 0, $lastFailure); + } - $aliases[$tag->value->importedAs ?? $tag->value->importedAlias] = $typeAlias; + if ($toResolve) { + return $this->resolveTypeAliases($toResolve, $resolved, $typeContext); } - return $aliases; + return $resolved; } private function getPhpDocNode(string $rawDocNode): PhpDocNode diff --git a/src/Symfony/Component/TypeInfo/TypeResolver/StringTypeResolver.php b/src/Symfony/Component/TypeInfo/TypeResolver/StringTypeResolver.php index 475e0212490d7..43457c9314fca 100644 --- a/src/Symfony/Component/TypeInfo/TypeResolver/StringTypeResolver.php +++ b/src/Symfony/Component/TypeInfo/TypeResolver/StringTypeResolver.php @@ -38,6 +38,7 @@ use Symfony\Component\TypeInfo\Exception\InvalidArgumentException; use Symfony\Component\TypeInfo\Exception\UnsupportedException; use Symfony\Component\TypeInfo\Type; +use Symfony\Component\TypeInfo\Type\BackedEnumType; use Symfony\Component\TypeInfo\Type\BuiltinType; use Symfony\Component\TypeInfo\Type\CollectionType; use Symfony\Component\TypeInfo\Type\GenericType; @@ -195,6 +196,28 @@ private function getTypeFromNode(TypeNode $node, ?TypeContext $typeContext): Typ } if ($node instanceof GenericTypeNode) { + if ($node->type instanceof IdentifierTypeNode && 'value-of' === $node->type->name) { + $type = $this->getTypeFromNode($node->genericTypes[0], $typeContext); + if ($type instanceof BackedEnumType) { + return $type->getBackingType(); + } + + if ($type instanceof CollectionType) { + return $type->getCollectionValueType(); + } + + throw new \DomainException(\sprintf('"%s" is not a valid type for "value-of".', $node->genericTypes[0])); + } + + if ($node->type instanceof IdentifierTypeNode && 'key-of' === $node->type->name) { + $type = $this->getTypeFromNode($node->genericTypes[0], $typeContext); + if ($type instanceof CollectionType) { + return $type->getCollectionKeyType(); + } + + throw new \DomainException(\sprintf('"%s" is not a valid type for "key-of".', $node->genericTypes[0])); + } + $type = $this->getTypeFromNode($node->type, $typeContext); // handle integer ranges as simple integers diff --git a/src/Symfony/Component/Uid/Exception/InvalidUlidException.php b/src/Symfony/Component/Uid/Exception/InvalidUlidException.php deleted file mode 100644 index cfb42ac5867a7..0000000000000 --- a/src/Symfony/Component/Uid/Exception/InvalidUlidException.php +++ /dev/null @@ -1,20 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Uid\Exception; - -class InvalidUlidException extends InvalidArgumentException -{ - public function __construct(string $value) - { - parent::__construct(\sprintf('Invalid ULID: "%s".', $value)); - } -} diff --git a/src/Symfony/Component/Uid/Exception/InvalidUuidException.php b/src/Symfony/Component/Uid/Exception/InvalidUuidException.php deleted file mode 100644 index 97009412b9c63..0000000000000 --- a/src/Symfony/Component/Uid/Exception/InvalidUuidException.php +++ /dev/null @@ -1,22 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Uid\Exception; - -class InvalidUuidException extends InvalidArgumentException -{ - public function __construct( - public readonly int $type, - string $value, - ) { - parent::__construct(\sprintf('Invalid UUID%s: "%s".', $type ? 'v'.$type : '', $value)); - } -} diff --git a/src/Symfony/Component/Uid/Tests/UlidTest.php b/src/Symfony/Component/Uid/Tests/UlidTest.php index fe1e15b4cedde..f34660fbfd393 100644 --- a/src/Symfony/Component/Uid/Tests/UlidTest.php +++ b/src/Symfony/Component/Uid/Tests/UlidTest.php @@ -13,7 +13,6 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Uid\Exception\InvalidArgumentException; -use Symfony\Component\Uid\Exception\InvalidUlidException; use Symfony\Component\Uid\MaxUlid; use Symfony\Component\Uid\NilUlid; use Symfony\Component\Uid\Tests\Fixtures\CustomUlid; @@ -43,7 +42,7 @@ public function testGenerate() public function testWithInvalidUlid() { - $this->expectException(InvalidUlidException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Invalid ULID: "this is not a ulid".'); new Ulid('this is not a ulid'); diff --git a/src/Symfony/Component/Uid/Ulid.php b/src/Symfony/Component/Uid/Ulid.php index 9170d429b0eb7..5ea3b84051880 100644 --- a/src/Symfony/Component/Uid/Ulid.php +++ b/src/Symfony/Component/Uid/Ulid.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Uid; use Symfony\Component\Uid\Exception\InvalidArgumentException; -use Symfony\Component\Uid\Exception\InvalidUlidException; /** * A ULID is lexicographically sortable and contains a 48-bit timestamp and 80-bit of crypto-random entropy. @@ -39,7 +38,7 @@ public function __construct(?string $ulid = null) $this->uid = $ulid; } else { if (!self::isValid($ulid)) { - throw new InvalidUlidException($ulid); + throw new InvalidArgumentException(\sprintf('Invalid ULID: "%s".', $ulid)); } $this->uid = strtoupper($ulid); diff --git a/src/Symfony/Component/Uid/Uuid.php b/src/Symfony/Component/Uid/Uuid.php index 66717f2ca1d2e..e1c9735ee85fe 100644 --- a/src/Symfony/Component/Uid/Uuid.php +++ b/src/Symfony/Component/Uid/Uuid.php @@ -11,7 +11,7 @@ namespace Symfony\Component\Uid; -use Symfony\Component\Uid\Exception\InvalidUuidException; +use Symfony\Component\Uid\Exception\InvalidArgumentException; /** * @author Grégoire Pineau @@ -41,13 +41,13 @@ public function __construct(string $uuid, bool $checkVariant = false) $type = preg_match('{^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$}Di', $uuid) ? (int) $uuid[14] : false; if (false === $type || (static::TYPE ?: $type) !== $type) { - throw new InvalidUuidException(static::TYPE, $uuid); + throw new InvalidArgumentException(\sprintf('Invalid UUID%s: "%s".', static::TYPE ? 'v'.static::TYPE : '', $uuid)); } $this->uid = strtolower($uuid); if ($checkVariant && !\in_array($this->uid[19], ['8', '9', 'a', 'b'], true)) { - throw new InvalidUuidException(static::TYPE, $uuid); + throw new InvalidArgumentException(\sprintf('Invalid UUID%s: "%s".', static::TYPE ? 'v'.static::TYPE : '', $uuid)); } } diff --git a/src/Symfony/Component/Uid/composer.json b/src/Symfony/Component/Uid/composer.json index 9843341c6d174..a3dd9f4401c94 100644 --- a/src/Symfony/Component/Uid/composer.json +++ b/src/Symfony/Component/Uid/composer.json @@ -24,7 +24,7 @@ "symfony/polyfill-uuid": "^1.15" }, "require-dev": { - "symfony/console": "^6.4|^7.0" + "symfony/console": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Uid\\": "" }, diff --git a/src/Symfony/Component/Validator/CHANGELOG.md b/src/Symfony/Component/Validator/CHANGELOG.md index a7363d7f59c19..e8146d2a50683 100644 --- a/src/Symfony/Component/Validator/CHANGELOG.md +++ b/src/Symfony/Component/Validator/CHANGELOG.md @@ -6,7 +6,55 @@ CHANGELOG * Add the `filenameCharset` and `filenameCountUnit` options to the `File` constraint * Deprecate defining custom constraints not supporting named arguments + + Before: + + ```php + use Symfony\Component\Validator\Constraint; + + class CustomConstraint extends Constraint + { + public function __construct(array $options) + { + // ... + } + } + ``` + + After: + + ```php + use Symfony\Component\Validator\Attribute\HasNamedArguments; + use Symfony\Component\Validator\Constraint; + + class CustomConstraint extends Constraint + { + #[HasNamedArguments] + public function __construct($option1, $option2, $groups, $payload) + { + // ... + } + } + ``` * Deprecate passing an array of options to the constructors of the constraint classes, pass each option as a dedicated argument instead + + Before: + + ```php + new NotNull([ + 'groups' => ['foo', 'bar'], + 'message' => 'a custom constraint violation message', + ]) + ``` + + After: + + ```php + new NotNull( + groups: ['foo', 'bar'], + message: 'a custom constraint violation message', + ) + ``` * Add support for ratio checks for SVG files to the `Image` constraint * Add support for the `otherwise` option in the `When` constraint * Add support for multiple fields containing nested constraints in `Composite` constraints diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.cs.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.cs.xlf index 2a2e559b95238..d5f48f0ae7ff2 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.cs.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.cs.xlf @@ -468,7 +468,7 @@ This value is not a valid Twig template. - Tato hodnota není platná šablona Twig. + Tato hodnota není platná Twig šablona. diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.nl.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.nl.xlf index 0e0de772720c4..1781b1f29ec64 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.nl.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.nl.xlf @@ -468,7 +468,7 @@ This value is not a valid Twig template. - Deze waarde is geen geldige Twig-template. + Deze waarde is geen geldige Twig-template. diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.pt_BR.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.pt_BR.xlf index a6be16580c6bd..0acf6dbf23a6c 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.pt_BR.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.pt_BR.xlf @@ -468,7 +468,7 @@ This value is not a valid Twig template. - Este valor não é um modelo Twig válido. + Este valor não é um modelo Twig válido. diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.ru.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.ru.xlf index e4179779d6c27..727ae0aefdf86 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.ru.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.ru.xlf @@ -468,7 +468,7 @@ This value is not a valid Twig template. - Это значение не является допустимым шаблоном Twig. + Это значение не является корректным шаблоном Twig. diff --git a/src/Symfony/Component/Validator/Tests/Constraints/MacAddressValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/MacAddressValidatorTest.php index d755df486e140..5abb7487ba328 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/MacAddressValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/MacAddressValidatorTest.php @@ -63,6 +63,19 @@ public function testValidMac($mac) $this->assertNoViolation(); } + /** + * @dataProvider getNotValidMacs + */ + public function testNotValidMac($mac) + { + $this->validator->validate($mac, new MacAddress()); + + $this->buildViolation('This value is not a valid MAC address.') + ->setParameter('{{ value }}', '"'.$mac.'"') + ->setCode(MacAddress::INVALID_MAC_ERROR) + ->assertRaised(); + } + public static function getValidMacs(): array { return [ @@ -76,6 +89,17 @@ public static function getValidMacs(): array ]; } + public static function getNotValidMacs(): array + { + return [ + ['00:00:00:00:00'], + ['00:00:00:00:00:0G'], + ['GG:GG:GG:GG:GG:GG'], + ['GG-GG-GG-GG-GG-GG'], + ['GGGG.GGGG.GGGG'], + ]; + } + public static function getValidLocalUnicastMacs(): array { return [ diff --git a/src/Symfony/Component/Validator/composer.json b/src/Symfony/Component/Validator/composer.json index 0eaac5f6bf735..899808727470e 100644 --- a/src/Symfony/Component/Validator/composer.json +++ b/src/Symfony/Component/Validator/composer.json @@ -24,23 +24,23 @@ "symfony/translation-contracts": "^2.5|^3" }, "require-dev": { - "symfony/console": "^6.4|^7.0", - "symfony/finder": "^6.4|^7.0", - "symfony/http-client": "^6.4|^7.0", - "symfony/http-foundation": "^6.4|^7.0", - "symfony/http-kernel": "^6.4|^7.0", - "symfony/intl": "^6.4|^7.0", - "symfony/yaml": "^6.4|^7.0", - "symfony/config": "^6.4|^7.0", - "symfony/dependency-injection": "^6.4|^7.0", - "symfony/expression-language": "^6.4|^7.0", - "symfony/cache": "^6.4|^7.0", - "symfony/mime": "^6.4|^7.0", - "symfony/property-access": "^6.4|^7.0", - "symfony/property-info": "^6.4|^7.0", - "symfony/string": "^6.4|^7.0", - "symfony/translation": "^6.4.3|^7.0.3", - "symfony/type-info": "^7.1", + "symfony/console": "^6.4|^7.0|^8.0", + "symfony/finder": "^6.4|^7.0|^8.0", + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/http-foundation": "^6.4|^7.0|^8.0", + "symfony/http-kernel": "^6.4|^7.0|^8.0", + "symfony/intl": "^6.4|^7.0|^8.0", + "symfony/yaml": "^6.4|^7.0|^8.0", + "symfony/config": "^6.4|^7.0|^8.0", + "symfony/dependency-injection": "^6.4|^7.0|^8.0", + "symfony/expression-language": "^6.4|^7.0|^8.0", + "symfony/cache": "^6.4|^7.0|^8.0", + "symfony/mime": "^6.4|^7.0|^8.0", + "symfony/property-access": "^6.4|^7.0|^8.0", + "symfony/property-info": "^6.4|^7.0|^8.0", + "symfony/string": "^6.4|^7.0|^8.0", + "symfony/translation": "^6.4.3|^7.0.3|^8.0", + "symfony/type-info": "^7.1|^8.0", "egulias/email-validator": "^2.1.10|^3|^4" }, "conflict": { diff --git a/src/Symfony/Component/VarDumper/Caster/SymfonyCaster.php b/src/Symfony/Component/VarDumper/Caster/SymfonyCaster.php index 42dc901a5f293..0921f62543a5a 100644 --- a/src/Symfony/Component/VarDumper/Caster/SymfonyCaster.php +++ b/src/Symfony/Component/VarDumper/Caster/SymfonyCaster.php @@ -80,12 +80,14 @@ public static function castLazyObjectState($state, array $a, Stub $stub, bool $i $instance = $a['realInstance'] ?? null; - $a = ['status' => new ConstStub(match ($a['status']) { - LazyObjectState::STATUS_INITIALIZED_FULL => 'INITIALIZED_FULL', - LazyObjectState::STATUS_INITIALIZED_PARTIAL => 'INITIALIZED_PARTIAL', - LazyObjectState::STATUS_UNINITIALIZED_FULL => 'UNINITIALIZED_FULL', - LazyObjectState::STATUS_UNINITIALIZED_PARTIAL => 'UNINITIALIZED_PARTIAL', - }, $a['status'])]; + if (isset($a['status'])) { // forward-compat with Symfony 8 + $a = ['status' => new ConstStub(match ($a['status']) { + LazyObjectState::STATUS_INITIALIZED_FULL => 'INITIALIZED_FULL', + LazyObjectState::STATUS_INITIALIZED_PARTIAL => 'INITIALIZED_PARTIAL', + LazyObjectState::STATUS_UNINITIALIZED_FULL => 'UNINITIALIZED_FULL', + LazyObjectState::STATUS_UNINITIALIZED_PARTIAL => 'UNINITIALIZED_PARTIAL', + }, $a['status'])]; + } if ($instance) { $a['realInstance'] = $instance; diff --git a/src/Symfony/Component/VarDumper/Test/VarDumperTestTrait.php b/src/Symfony/Component/VarDumper/Test/VarDumperTestTrait.php index e29121a306cde..f50adb13fc679 100644 --- a/src/Symfony/Component/VarDumper/Test/VarDumperTestTrait.php +++ b/src/Symfony/Component/VarDumper/Test/VarDumperTestTrait.php @@ -45,11 +45,17 @@ protected function tearDownVarDumper(): void $this->varDumperConfig['flags'] = null; } + /** + * @return void + */ public function assertDumpEquals(mixed $expected, mixed $data, int $filter = 0, string $message = '') { $this->assertSame($this->prepareExpectation($expected, $filter), $this->getDump($data, null, $filter), $message); } + /** + * @return void + */ public function assertDumpMatchesFormat(mixed $expected, mixed $data, int $filter = 0, string $message = '') { $this->assertStringMatchesFormat($this->prepareExpectation($expected, $filter), $this->getDump($data, null, $filter), $message); diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/ResourceCasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/ResourceCasterTest.php index 029f7fb0d6876..946db1dd828a6 100644 --- a/src/Symfony/Component/VarDumper/Tests/Caster/ResourceCasterTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Caster/ResourceCasterTest.php @@ -69,14 +69,11 @@ public function testCastDbaPriorToPhp84() } /** - * @requires PHP 8.4 + * @requires PHP 8.4.2 + * @requires extension dba */ public function testCastDba() { - if (\PHP_VERSION_ID < 80402) { - $this->markTestSkipped('The test cannot be run on PHP 8.4.0 and PHP 8.4.1, see https://github.com/php/php-src/issues/16990'); - } - $dba = dba_open(sys_get_temp_dir().'/test.db', 'c'); $this->assertDumpMatchesFormat( @@ -89,6 +86,7 @@ public function testCastDba() /** * @requires PHP 8.4 + * @requires extension dba */ public function testCastDbaOnBuggyPhp84() { diff --git a/src/Symfony/Component/VarDumper/composer.json b/src/Symfony/Component/VarDumper/composer.json index ed312c5288b88..23c982098d053 100644 --- a/src/Symfony/Component/VarDumper/composer.json +++ b/src/Symfony/Component/VarDumper/composer.json @@ -22,10 +22,10 @@ }, "require-dev": { "ext-iconv": "*", - "symfony/console": "^6.4|^7.0", - "symfony/http-kernel": "^6.4|^7.0", - "symfony/process": "^6.4|^7.0", - "symfony/uid": "^6.4|^7.0", + "symfony/console": "^6.4|^7.0|^8.0", + "symfony/http-kernel": "^6.4|^7.0|^8.0", + "symfony/process": "^6.4|^7.0|^8.0", + "symfony/uid": "^6.4|^7.0|^8.0", "twig/twig": "^3.12" }, "conflict": { diff --git a/src/Symfony/Component/VarExporter/composer.json b/src/Symfony/Component/VarExporter/composer.json index 215d3ee56a836..36f1b422ff267 100644 --- a/src/Symfony/Component/VarExporter/composer.json +++ b/src/Symfony/Component/VarExporter/composer.json @@ -20,9 +20,9 @@ "symfony/deprecation-contracts": "^2.5|^3" }, "require-dev": { - "symfony/property-access": "^6.4|^7.0", - "symfony/serializer": "^6.4|^7.0", - "symfony/var-dumper": "^6.4|^7.0" + "symfony/property-access": "^6.4|^7.0|^8.0", + "symfony/serializer": "^6.4|^7.0|^8.0", + "symfony/var-dumper": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\VarExporter\\": "" }, diff --git a/src/Symfony/Component/WebLink/CHANGELOG.md b/src/Symfony/Component/WebLink/CHANGELOG.md index 28dad5abdd749..6da8115f91fcc 100644 --- a/src/Symfony/Component/WebLink/CHANGELOG.md +++ b/src/Symfony/Component/WebLink/CHANGELOG.md @@ -1,6 +1,12 @@ CHANGELOG ========= +7.4 +--- + + * Add `HttpHeaderParser` to read `Link` headers from HTTP responses + * Make `HttpHeaderSerializer` non-final + 4.4.0 ----- diff --git a/src/Symfony/Component/WebLink/HttpHeaderParser.php b/src/Symfony/Component/WebLink/HttpHeaderParser.php new file mode 100644 index 0000000000000..15fc91cde2522 --- /dev/null +++ b/src/Symfony/Component/WebLink/HttpHeaderParser.php @@ -0,0 +1,87 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\WebLink; + +use Psr\Link\EvolvableLinkProviderInterface; + +/** + * Parse a list of HTTP Link headers into a list of Link instances. + * + * @see https://tools.ietf.org/html/rfc5988 + * + * @author Jérôme Tamarelle + */ +class HttpHeaderParser +{ + // Regex to match each link entry: <...>; param1=...; param2=... + private const LINK_PATTERN = '/<([^>]*)>\s*((?:\s*;\s*[a-zA-Z0-9\-_]+(?:\s*=\s*(?:"(?:[^"\\\\]|\\\\.)*"|[^";,\s]+))?)*)/'; + + // Regex to match parameters: ; key[=value] + private const PARAM_PATTERN = '/;\s*([a-zA-Z0-9\-_]+)(?:\s*=\s*(?:"((?:[^"\\\\]|\\\\.)*)"|([^";,\s]+)))?/'; + + /** + * @param string|string[] $headers Value of the "Link" HTTP header + */ + public function parse(string|array $headers): EvolvableLinkProviderInterface + { + if (is_array($headers)) { + $headers = implode(', ', $headers); + } + $links = new GenericLinkProvider(); + + if (!preg_match_all(self::LINK_PATTERN, $headers, $matches, \PREG_SET_ORDER)) { + return $links; + } + + foreach ($matches as $match) { + $href = $match[1]; + $attributesString = $match[2]; + + $attributes = []; + if (preg_match_all(self::PARAM_PATTERN, $attributesString, $attributeMatches, \PREG_SET_ORDER)) { + $rels = null; + foreach ($attributeMatches as $pm) { + $key = $pm[1]; + $value = match (true) { + // Quoted value, unescape quotes + ($pm[2] ?? '') !== '' => stripcslashes($pm[2]), + ($pm[3] ?? '') !== '' => $pm[3], + // No value + default => true, + }; + + if ($key === 'rel') { + // Only the first occurrence of the "rel" attribute is read + $rels ??= $value === true ? [] : preg_split('/\s+/', $value, 0, \PREG_SPLIT_NO_EMPTY); + } elseif (is_array($attributes[$key] ?? null)) { + $attributes[$key][] = $value; + } elseif (isset($attributes[$key])) { + $attributes[$key] = [$attributes[$key], $value]; + } else { + $attributes[$key] = $value; + } + } + } + + $link = new Link(null, $href); + foreach ($rels ?? [] as $rel) { + $link = $link->withRel($rel); + } + foreach ($attributes as $k => $v) { + $link = $link->withAttribute($k, $v); + } + $links = $links->withLink($link); + } + + return $links; + } +} diff --git a/src/Symfony/Component/WebLink/HttpHeaderSerializer.php b/src/Symfony/Component/WebLink/HttpHeaderSerializer.php index 4d537c96f9cb8..d3b686add0baa 100644 --- a/src/Symfony/Component/WebLink/HttpHeaderSerializer.php +++ b/src/Symfony/Component/WebLink/HttpHeaderSerializer.php @@ -20,7 +20,7 @@ * * @author Kévin Dunglas */ -final class HttpHeaderSerializer +class HttpHeaderSerializer { /** * Builds the value of the "Link" HTTP header. diff --git a/src/Symfony/Component/WebLink/Link.php b/src/Symfony/Component/WebLink/Link.php index 1f5fbbdf9c6b5..519194c675206 100644 --- a/src/Symfony/Component/WebLink/Link.php +++ b/src/Symfony/Component/WebLink/Link.php @@ -153,7 +153,7 @@ class Link implements EvolvableLinkInterface private array $rel = []; /** - * @var array + * @var array> */ private array $attributes = []; @@ -181,6 +181,11 @@ public function getRels(): array return array_values($this->rel); } + /** + * Returns a list of attributes that describe the target URI. + * + * @return array> + */ public function getAttributes(): array { return $this->attributes; @@ -210,6 +215,14 @@ public function withoutRel(string $rel): static return $that; } + /** + * Returns an instance with the specified attribute added. + * + * If the specified attribute is already present, it will be overwritten + * with the new value. + * + * @param scalar|\Stringable|list $value + */ public function withAttribute(string $attribute, string|\Stringable|int|float|bool|array $value): static { $that = clone $this; diff --git a/src/Symfony/Component/WebLink/Tests/HttpHeaderParserTest.php b/src/Symfony/Component/WebLink/Tests/HttpHeaderParserTest.php new file mode 100644 index 0000000000000..b2ccc3e89163a --- /dev/null +++ b/src/Symfony/Component/WebLink/Tests/HttpHeaderParserTest.php @@ -0,0 +1,112 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\WebLink\Tests; + +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\TestCase; +use Symfony\Component\WebLink\HttpHeaderParser; + +class HttpHeaderParserTest extends TestCase +{ + public function testParse() + { + $parser = new HttpHeaderParser(); + + $header = [ + '; rel="prerender",; rel="dns-prefetch"; pr="0.7",; rel="preload"; as="script"', + '; rel="preload"; as="image"; nopush,; rel="alternate next"; hreflang="fr"; hreflang="de"; title="Hello"' + ]; + $provider = $parser->parse($header); + $links = $provider->getLinks(); + + self::assertCount(5, $links); + + self::assertSame(['prerender'], $links[0]->getRels()); + self::assertSame('/1', $links[0]->getHref()); + self::assertSame([], $links[0]->getAttributes()); + + self::assertSame(['dns-prefetch'], $links[1]->getRels()); + self::assertSame('/2', $links[1]->getHref()); + self::assertSame(['pr' => '0.7'], $links[1]->getAttributes()); + + self::assertSame(['preload'], $links[2]->getRels()); + self::assertSame('/3', $links[2]->getHref()); + self::assertSame(['as' => 'script'], $links[2]->getAttributes()); + + self::assertSame(['preload'], $links[3]->getRels()); + self::assertSame('/4', $links[3]->getHref()); + self::assertSame(['as' => 'image', 'nopush' => true], $links[3]->getAttributes()); + + self::assertSame(['alternate', 'next'], $links[4]->getRels()); + self::assertSame('/5', $links[4]->getHref()); + self::assertSame(['hreflang' => ['fr', 'de'], 'title' => 'Hello'], $links[4]->getAttributes()); + } + + public function testParseEmpty() + { + $parser = new HttpHeaderParser(); + $provider = $parser->parse(''); + self::assertCount(0, $provider->getLinks()); + } + + /** @dataProvider provideHeaderParsingCases */ + #[DataProvider('provideHeaderParsingCases')] + public function testParseVariousAttributes(string $header, array $expectedRels, array $expectedAttributes) + { + $parser = new HttpHeaderParser(); + $links = $parser->parse($header)->getLinks(); + + self::assertCount(1, $links); + self::assertSame('/foo', $links[0]->getHref()); + self::assertSame($expectedRels, $links[0]->getRels()); + self::assertSame($expectedAttributes, $links[0]->getAttributes()); + } + + public static function provideHeaderParsingCases() + { + yield 'double_quotes_in_attribute_value' => [ + '; rel="alternate"; title="\"escape me\" \"already escaped\" \"\"\""', + ['alternate'], + ['title' => '"escape me" "already escaped" """'], + ]; + + yield 'unquoted_attribute_value' => [ + '; rel=alternate; type=text/html', + ['alternate'], + ['type' => 'text/html'], + ]; + + yield 'attribute_with_punctuation' => [ + '; rel="alternate"; title=">; hello, world; test:case"', + ['alternate'], + ['title' => '>; hello, world; test:case'], + ]; + + yield 'no_rel' => [ + '; type=text/html', + [], + ['type' => 'text/html'], + ]; + + yield 'empty_rel' => [ + '; rel', + [], + [], + ]; + + yield 'multiple_rel_attributes_get_first' => [ + '; rel="alternate" rel="next"', + ['alternate'], + [], + ]; + } +} diff --git a/src/Symfony/Component/WebLink/Tests/LinkTest.php b/src/Symfony/Component/WebLink/Tests/LinkTest.php index 226bc3af11620..07946af9b0d01 100644 --- a/src/Symfony/Component/WebLink/Tests/LinkTest.php +++ b/src/Symfony/Component/WebLink/Tests/LinkTest.php @@ -27,10 +27,10 @@ public function testCanSetAndRetrieveValues() ->withAttribute('me', 'you') ; - $this->assertEquals('http://www.google.com', $link->getHref()); + $this->assertSame('http://www.google.com', $link->getHref()); $this->assertContains('next', $link->getRels()); $this->assertArrayHasKey('me', $link->getAttributes()); - $this->assertEquals('you', $link->getAttributes()['me']); + $this->assertSame('you', $link->getAttributes()['me']); } public function testCanRemoveValues() @@ -44,7 +44,7 @@ public function testCanRemoveValues() $link = $link->withoutAttribute('me') ->withoutRel('next'); - $this->assertEquals('http://www.google.com', $link->getHref()); + $this->assertSame('http://www.google.com', $link->getHref()); $this->assertFalse(\in_array('next', $link->getRels(), true)); $this->assertArrayNotHasKey('me', $link->getAttributes()); } @@ -65,7 +65,7 @@ public function testConstructor() { $link = new Link('next', 'http://www.google.com'); - $this->assertEquals('http://www.google.com', $link->getHref()); + $this->assertSame('http://www.google.com', $link->getHref()); $this->assertContains('next', $link->getRels()); } diff --git a/src/Symfony/Component/WebLink/composer.json b/src/Symfony/Component/WebLink/composer.json index 3203f6fa83163..0d7ca7857629a 100644 --- a/src/Symfony/Component/WebLink/composer.json +++ b/src/Symfony/Component/WebLink/composer.json @@ -23,7 +23,7 @@ "psr/link": "^1.1|^2.0" }, "require-dev": { - "symfony/http-kernel": "^6.4|^7.0" + "symfony/http-kernel": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/http-kernel": "<6.4" diff --git a/src/Symfony/Component/Webhook/composer.json b/src/Symfony/Component/Webhook/composer.json index 46ce35b5d90cb..035817b066383 100644 --- a/src/Symfony/Component/Webhook/composer.json +++ b/src/Symfony/Component/Webhook/composer.json @@ -17,14 +17,14 @@ ], "require": { "php": ">=8.2", - "symfony/http-foundation": "^6.4|^7.0", - "symfony/http-kernel": "^6.4|^7.0", - "symfony/messenger": "^6.4|^7.0", - "symfony/remote-event": "^6.4|^7.0" + "symfony/http-foundation": "^6.4|^7.0|^8.0", + "symfony/http-kernel": "^6.4|^7.0|^8.0", + "symfony/messenger": "^6.4|^7.0|^8.0", + "symfony/remote-event": "^6.4|^7.0|^8.0" }, "require-dev": { - "symfony/http-client": "^6.4|^7.0", - "symfony/serializer": "^6.4|^7.0" + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/serializer": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Webhook\\": "" }, diff --git a/src/Symfony/Component/Workflow/composer.json b/src/Symfony/Component/Workflow/composer.json index 3e2c50a38cffd..ff8561caa1c88 100644 --- a/src/Symfony/Component/Workflow/composer.json +++ b/src/Symfony/Component/Workflow/composer.json @@ -25,15 +25,15 @@ }, "require-dev": { "psr/log": "^1|^2|^3", - "symfony/config": "^6.4|^7.0", - "symfony/dependency-injection": "^6.4|^7.0", - "symfony/error-handler": "^6.4|^7.0", - "symfony/event-dispatcher": "^6.4|^7.0", - "symfony/expression-language": "^6.4|^7.0", - "symfony/http-kernel": "^6.4|^7.0", - "symfony/security-core": "^6.4|^7.0", - "symfony/stopwatch": "^6.4|^7.0", - "symfony/validator": "^6.4|^7.0" + "symfony/config": "^6.4|^7.0|^8.0", + "symfony/dependency-injection": "^6.4|^7.0|^8.0", + "symfony/error-handler": "^6.4|^7.0|^8.0", + "symfony/event-dispatcher": "^6.4|^7.0|^8.0", + "symfony/expression-language": "^6.4|^7.0|^8.0", + "symfony/http-kernel": "^6.4|^7.0|^8.0", + "symfony/security-core": "^6.4|^7.0|^8.0", + "symfony/stopwatch": "^6.4|^7.0|^8.0", + "symfony/validator": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/event-dispatcher": "<6.4" diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index bfa910c745b1c..3a0889a5090b3 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -750,7 +750,7 @@ private static function evaluateScalar(string $scalar, int $flags, array &$refer if (false !== $scalar = $time->getTimestamp()) { return $scalar; } - } catch (\ValueError) { + } catch (\DateRangeError|\ValueError) { // no-op } diff --git a/src/Symfony/Component/Yaml/composer.json b/src/Symfony/Component/Yaml/composer.json index 2ceac94665037..8f31f2e4de031 100644 --- a/src/Symfony/Component/Yaml/composer.json +++ b/src/Symfony/Component/Yaml/composer.json @@ -21,7 +21,7 @@ "symfony/polyfill-ctype": "^1.8" }, "require-dev": { - "symfony/console": "^6.4|^7.0" + "symfony/console": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/console": "<6.4"