diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index e6333054fe172..58caff2209f37 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,6 +1,6 @@ | Q | A | ------------- | --- -| Branch? | 6.1 for features / 4.4, 5.4 or 6.0 for bug fixes +| Branch? | 6.2 for features / 4.4, 5.4, 6.0 or 6.1 for bug fixes | Bug fix? | yes/no | New feature? | yes/no | Deprecations? | yes/no diff --git a/CHANGELOG-6.1.md b/CHANGELOG-6.1.md index 88b3cc9960d82..861bc8ed110f7 100644 --- a/CHANGELOG-6.1.md +++ b/CHANGELOG-6.1.md @@ -7,6 +7,38 @@ in 6.1 minor versions. To get the diff for a specific change, go to https://github.com/symfony/symfony/commit/XXX where XXX is the change hash To get the diff between two versions, go to https://github.com/symfony/symfony/compare/v6.1.0...v6.1.1 +* 6.1.0 (2022-05-27) + + * bug #46453 [PropertyInfo] Fix resolution of partially docblock covered constructors (ostrolucky) + * bug #46454 [ExpressionLanguage] Fix null-safe chaining (HypeMC) + * bug #46386 [Console]  Fix missing negative variation of negatable options in shell completion (GromNaN) + * bug #46387 [Console] Complete negatable options (Fish) (GromNaN) + * bug #46448 [DependencyInjection] Fix "proxy" tag: resolve its parameters and pass it to child definitions (nicolas-grekas) + * bug #46442 [FrameworkBundle] Revert "bug #46125 Always add CacheCollectorPass (fancyweb)" (chalasr) + * bug #46443 [DoctrineBridge] Don't reinit managers when they are proxied as ghost objects (nicolas-grekas) + * bug #46427 [FrameworkBundle] fix wiring of annotations.cached_reader (nicolas-grekas) + * bug #46425 [DependencyInjection] Ignore unused bindings defined by attribute (nicolas-grekas) + * bug #46434 [FrameworkBundle] Fix BC break in abstract config commands (yceruto) + * bug #46424 [Form] do not accept array input when a form is not multiple (xabbuh) + * bug #46367 [Mime] Throw exception when body in Email attach method is not ok (alamirault) + * bug #46421 [VarDumper][VarExporter] Deal with DatePeriod->include_end_date on PHP 8.2 (nicolas-grekas) + * bug #46401 [Cache] Throw when "redis_sentinel" is used with a non-Predis "class" option (buffcode) + * bug #46414 Bootstrap 4 fieldset for row errors (konradkozaczenko) + * bug #46412 [FrameworkBundle] Fix dumping extension config without bundle (yceruto) + * bug #46385 [HttpKernel] New bundle path convention when `AbstractBundle` is used (yceruto) + * bug #46382 [HttpClient] Honor "max_duration" when replacing requests with async decorators (nicolas-grekas) + * bug #46407 [Filesystem] Safeguard (sym)link calls (derrabus) + * bug #46098 [Form] Fix same choice loader with different choice values (HeahDude) + * bug #46380 [HttpClient] Add missing HttpOptions::setMaxDuration() (nicolas-grekas) + * bug #46377 [HttpKernel] Fix missing null type in `ErrorListener::__construct()` (chalasr) + * bug #46249 [HttpFoundation] [Session] Regenerate invalid session id (peter17) + * bug #46373 [HtmlSanitizer] Fix default config service definition (wouterj) + * bug #46328 [Config] Allow scalar configuration in PHP Configuration (jderusse, HypeMC) + * bug #46366 [Mime] Add null check for EmailHeaderSame (magikid) + * bug #46361 [PropertyInfo] Ignore empty doc-block for promoted properties in PhpStanExtractor (BoShurik) + * bug #46364 [Config] Fix looking for single files in phars with GlobResource (nicolas-grekas) + * bug #46365 [HttpKernel] Revert "bug #46327 Allow ErrorHandler ^5.0 to be used" (nicolas-grekas) + * 6.1.0-RC1 (2022-05-14) * feature #46335 [Form][FrameworkBundle][TwigBundle] Add Twig filter, form-type extension and improve service definitions for HtmlSanitizer (nicolas-grekas) diff --git a/src/Symfony/Bridge/Doctrine/Form/DataTransformer/CollectionToArrayTransformer.php b/src/Symfony/Bridge/Doctrine/Form/DataTransformer/CollectionToArrayTransformer.php index 3c1141c54860d..d5dc1a23b72a6 100644 --- a/src/Symfony/Bridge/Doctrine/Form/DataTransformer/CollectionToArrayTransformer.php +++ b/src/Symfony/Bridge/Doctrine/Form/DataTransformer/CollectionToArrayTransformer.php @@ -46,9 +46,7 @@ public function transform(mixed $collection): mixed } /** - * Transforms choice keys into entities. - * - * @param mixed $array An array of entities + * Transforms an array into a collection. */ public function reverseTransform(mixed $array): Collection { diff --git a/src/Symfony/Bridge/Doctrine/ManagerRegistry.php b/src/Symfony/Bridge/Doctrine/ManagerRegistry.php index 7be0473590231..5e958d1865300 100644 --- a/src/Symfony/Bridge/Doctrine/ManagerRegistry.php +++ b/src/Symfony/Bridge/Doctrine/ManagerRegistry.php @@ -12,6 +12,7 @@ namespace Symfony\Bridge\Doctrine; use Doctrine\Persistence\AbstractManagerRegistry; +use ProxyManager\Proxy\GhostObjectInterface; use ProxyManager\Proxy\LazyLoadingInterface; use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator; use Symfony\Component\DependencyInjection\Container; @@ -19,7 +20,7 @@ /** * References Doctrine connections and entity/document managers. * - * @author Lukas Kahwe Smith + * @author Lukas Kahwe Smith */ abstract class ManagerRegistry extends AbstractManagerRegistry { @@ -49,6 +50,9 @@ protected function resetService($name): void if (!$manager instanceof LazyLoadingInterface) { throw new \LogicException('Resetting a non-lazy manager service is not supported. '.(interface_exists(LazyLoadingInterface::class) && class_exists(RuntimeInstantiator::class) ? sprintf('Declare the "%s" service as lazy.', $name) : 'Try running "composer require symfony/proxy-manager-bridge".')); } + if ($manager instanceof GhostObjectInterface) { + throw new \LogicException('Resetting a lazy-ghost-object manager service is not supported.'); + } $manager->setProxyInitializer(\Closure::bind( function (&$wrappedInstance, LazyLoadingInterface $manager) use ($name) { if (isset($this->aliases[$name])) { diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/DoctrineChoiceLoaderTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/DoctrineChoiceLoaderTest.php index 98b3c96d9b3a7..bd3f834f63ace 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/DoctrineChoiceLoaderTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/DoctrineChoiceLoaderTest.php @@ -153,8 +153,7 @@ public function testLoadChoiceListUsesObjectLoaderIfAvailable() $this->assertEquals($choiceList, $loaded = $loader->loadChoiceList()); // no further loads on subsequent calls - - $this->assertSame($loaded, $loader->loadChoiceList()); + $this->assertEquals($loaded, $loader->loadChoiceList()); } public function testLoadValuesForChoices() diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php index fd167bbe764ae..18f918dd3b522 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php @@ -1776,4 +1776,32 @@ public function testSubmitNullMultipleUsesDefaultEmptyData() $this->assertEquals($collection, $form->getNormData()); $this->assertEquals($collection, $form->getData()); } + + public function testWithSameLoaderAndDifferentChoiceValueCallbacks() + { + $entity1 = new SingleIntIdEntity(1, 'Foo'); + $entity2 = new SingleIntIdEntity(2, 'Bar'); + $this->persist([$entity1, $entity2]); + + $view = $this->factory->create(FormTypeTest::TESTED_TYPE) + ->add('entity_one', self::TESTED_TYPE, [ + 'em' => 'default', + 'class' => self::SINGLE_IDENT_CLASS, + ]) + ->add('entity_two', self::TESTED_TYPE, [ + 'em' => 'default', + 'class' => self::SINGLE_IDENT_CLASS, + 'choice_value' => function ($choice) { + return $choice ? $choice->name : ''; + }, + ]) + ->createView() + ; + + $this->assertSame('1', $view['entity_one']->vars['choices'][1]->value); + $this->assertSame('2', $view['entity_one']->vars['choices'][2]->value); + + $this->assertSame('Foo', $view['entity_two']->vars['choices']['Foo']->value); + $this->assertSame('Bar', $view['entity_two']->vars['choices']['Bar']->value); + } } diff --git a/src/Symfony/Bridge/Doctrine/composer.json b/src/Symfony/Bridge/Doctrine/composer.json index 20cb58ddb931f..8de4371499e8d 100644 --- a/src/Symfony/Bridge/Doctrine/composer.json +++ b/src/Symfony/Bridge/Doctrine/composer.json @@ -29,7 +29,7 @@ "symfony/cache": "^5.4|^6.0", "symfony/config": "^5.4|^6.0", "symfony/dependency-injection": "^5.4|^6.0", - "symfony/form": "^5.4|^6.0", + "symfony/form": "^5.4.9|^6.0.9", "symfony/http-kernel": "^5.4|^6.0", "symfony/messenger": "^5.4|^6.0", "symfony/doctrine-messenger": "^5.4|^6.0", diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_horizontal_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_horizontal_layout.html.twig index a75e364187743..990b324cb0d17 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_horizontal_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_horizontal_layout.html.twig @@ -49,6 +49,7 @@ col-sm-2
{{- form_widget(form, widget_attr) -}} {{- form_help(form) -}} + {{- form_errors(form) -}}
{##} diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php index 41d3eddd9964e..5f79d95bf036d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php @@ -90,20 +90,20 @@ protected function findExtension(string $name): ExtensionInterface $guess = $bundle->getName(); $minScore = $distance; } + } - $extension = $bundle->getContainerExtension(); + $container = $this->getContainerBuilder($kernel); - if ($extension) { - if ($name === $extension->getAlias()) { - return $extension; - } + if ($container->hasExtension($name)) { + return $container->getExtension($name); + } - $distance = levenshtein($name, $extension->getAlias()); + foreach ($container->getExtensions() as $extension) { + $distance = levenshtein($name, $extension->getAlias()); - if ($distance < $minScore) { - $guess = $extension->getAlias(); - $minScore = $distance; - } + if ($distance < $minScore) { + $guess = $extension->getAlias(); + $minScore = $distance; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddAnnotationsCachedReaderPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddAnnotationsCachedReaderPass.php index a0581ff21fb6f..d7db6ebf050a4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddAnnotationsCachedReaderPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddAnnotationsCachedReaderPass.php @@ -29,7 +29,6 @@ public function process(ContainerBuilder $container) // "annotation_reader" at build time don't get any cache foreach ($container->findTaggedServiceIds('annotations.cached_reader') as $id => $tags) { $reader = $container->getDefinition($id); - $reader->setPublic(false); $properties = $reader->getProperties(); if (isset($properties['cacheProviderBackup'])) { diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php index c1d18f91f7dff..32b578ee7b64a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php @@ -31,6 +31,7 @@ class UnusedTagsPass implements CompilerPassInterface 'chatter.transport_factory', 'config_cache.resource_checker', 'console.command', + 'container.do_not_inline', 'container.env_var_loader', 'container.env_var_processor', 'container.hot_path', diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 07f15e9b28b52..3770d337850a4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -27,7 +27,6 @@ use Symfony\Bridge\Twig\Extension\CsrfExtension; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Routing\AnnotatedRouteControllerLoader; -use Symfony\Bundle\FrameworkBundle\Routing\Attribute\AsRoutingConditionService; use Symfony\Bundle\FrameworkBundle\Routing\RouteLoaderInterface; use Symfony\Bundle\FullStack; use Symfony\Bundle\MercureBundle\MercureBundle; @@ -676,6 +675,8 @@ public function load(array $configs, ContainerBuilder $container) ->addTag('routing.route_loader'); $container->setParameter('container.behavior_describing_tags', [ + 'annotations.cached_reader', + 'container.do_not_inline', 'container.service_locator', 'container.service_subscriber', 'kernel.event_subscriber', @@ -683,10 +684,6 @@ public function load(array $configs, ContainerBuilder $container) 'kernel.locale_aware', 'kernel.reset', ]); - - $container->registerAttributeForAutoconfiguration(AsRoutingConditionService::class, static function (ChildDefinition $definition, AsRoutingConditionService $attribute): void { - $definition->addTag('routing.condition_service', (array) $attribute); - }); } /** @@ -1662,11 +1659,9 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde $container ->getDefinition('annotations.cached_reader') - ->setPublic(true) // set to false in AddAnnotationsCachedReaderPass ->replaceArgument(2, $config['debug']) // reference the cache provider without using it until AddAnnotationsCachedReaderPass runs ->addArgument(new ServiceClosureArgument(new Reference($cacheService))) - ->addTag('annotations.cached_reader') ; $container->setAlias('annotation_reader', 'annotations.cached_reader'); diff --git a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php index 0e060cf6240fa..3b86ea1344fcf 100644 --- a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php +++ b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php @@ -163,12 +163,12 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new RegisterReverseContainerPass(true)); $container->addCompilerPass(new RegisterReverseContainerPass(false), PassConfig::TYPE_AFTER_REMOVING); $container->addCompilerPass(new RemoveUnusedSessionMarshallingHandlerPass()); - $container->addCompilerPass(new CacheCollectorPass(), PassConfig::TYPE_BEFORE_REMOVING); if ($container->getParameter('kernel.debug')) { $container->addCompilerPass(new AddDebugLogProcessorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 2); $container->addCompilerPass(new UnusedTagsPass(), PassConfig::TYPE_AFTER_REMOVING); $container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_BEFORE_REMOVING, -255); + $container->addCompilerPass(new CacheCollectorPass(), PassConfig::TYPE_BEFORE_REMOVING); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.php index fd25a3ab2fb2e..1b178f16a95d3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.php @@ -37,6 +37,8 @@ inline_service(ArrayAdapter::class), abstract_arg('Debug-Flag'), ]) + ->tag('annotations.cached_reader') + ->tag('container.do_not_inline') ->set('annotations.filesystem_cache_adapter', FilesystemAdapter::class) ->args([ diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/html_sanitizer.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/html_sanitizer.php index ba87eda1a3357..19e1a2175cdb1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/html_sanitizer.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/html_sanitizer.php @@ -21,7 +21,7 @@ ->call('allowSafeElements') ->set('html_sanitizer.sanitizer.default', HtmlSanitizer::class) - ->args([service('html_sanitizer.config')]) + ->args([service('html_sanitizer.config.default')]) ->tag('html_sanitizer', ['name' => 'default']) ->alias('html_sanitizer', 'html_sanitizer.sanitizer.default') diff --git a/src/Symfony/Bundle/FrameworkBundle/Routing/Attribute/AsRoutingConditionService.php b/src/Symfony/Bundle/FrameworkBundle/Routing/Attribute/AsRoutingConditionService.php index 7467913e21c05..d1f1a5f34a654 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Routing/Attribute/AsRoutingConditionService.php +++ b/src/Symfony/Bundle/FrameworkBundle/Routing/Attribute/AsRoutingConditionService.php @@ -11,6 +11,8 @@ namespace Symfony\Bundle\FrameworkBundle\Routing\Attribute; +use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag; + /** * Service tag to autoconfigure routing condition services. * @@ -37,11 +39,12 @@ * } */ #[\Attribute(\Attribute::TARGET_CLASS)] -class AsRoutingConditionService +class AsRoutingConditionService extends AutoconfigureTag { public function __construct( - public ?string $alias = null, - public int $priority = 0, + string $alias = null, + int $priority = 0, ) { + parent::__construct('routing.condition_service', ['alias' => $alias, 'priority' => $priority]); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 447f817598caa..51cb4346eb2d2 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -1947,6 +1947,8 @@ public function testRegisterParameterCollectingBehaviorDescribingTags() $this->assertTrue($container->hasParameter('container.behavior_describing_tags')); $this->assertEquals([ + 'annotations.cached_reader', + 'container.do_not_inline', 'container.service_locator', 'container.service_subscriber', 'kernel.event_subscriber', diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDebugCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDebugCommandTest.php index 8135f4dcfe419..463318af39f47 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDebugCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDebugCommandTest.php @@ -70,6 +70,15 @@ public function testDefaultParameterValueIsResolvedIfConfigIsExisting() $this->assertStringContainsString(sprintf("dsn: 'file:%s/profiler'", $kernelCacheDir), $tester->getDisplay()); } + public function testDumpExtensionConfigWithoutBundle() + { + $tester = $this->createCommandTester(); + $ret = $tester->execute(['name' => 'test_dump']); + + $this->assertSame(0, $ret, 'Returns 0 in case of success'); + $this->assertStringContainsString('enabled: true', $tester->getDisplay()); + } + public function testDumpUndefinedBundleOption() { $tester = $this->createCommandTester(); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDumpReferenceCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDumpReferenceCommandTest.php index e86a7ff790ef7..4747b785f8149 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDumpReferenceCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDumpReferenceCommandTest.php @@ -50,6 +50,15 @@ public function testDumpBundleName() $this->assertStringContainsString(' custom:', $tester->getDisplay()); } + public function testDumpExtensionConfigWithoutBundle() + { + $tester = $this->createCommandTester(); + $ret = $tester->execute(['name' => 'test_dump']); + + $this->assertSame(0, $ret, 'Returns 0 in case of success'); + $this->assertStringContainsString('enabled: true', $tester->getDisplay()); + } + public function testDumpAtPath() { $tester = $this->createCommandTester(); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Extension/TestDumpExtension.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Extension/TestDumpExtension.php new file mode 100644 index 0000000000000..d8cef92850992 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Extension/TestDumpExtension.php @@ -0,0 +1,41 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Extension; + +use Symfony\Component\Config\Definition\Builder\TreeBuilder; +use Symfony\Component\Config\Definition\ConfigurationInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Extension\Extension; + +class TestDumpExtension extends Extension implements ConfigurationInterface +{ + public function getConfigTreeBuilder(): TreeBuilder + { + $treeBuilder = new TreeBuilder('test_dump'); + $treeBuilder->getRootNode() + ->children() + ->booleanNode('enabled')->defaultTrue()->end() + ->end() + ; + + return $treeBuilder; + } + + public function load(array $configs, ContainerBuilder $container): void + { + } + + public function getConfiguration(array $config, ContainerBuilder $container): ConfigurationInterface + { + return $this; + } +} diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php index 31fcc742fd05b..b182e902d7392 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php @@ -12,6 +12,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\app; use Psr\Log\NullLogger; +use Symfony\Bundle\FrameworkBundle\Tests\Functional\Extension\TestDumpExtension; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\Config\Loader\LoaderInterface; @@ -80,6 +81,7 @@ public function registerContainerConfiguration(LoaderInterface $loader) protected function build(ContainerBuilder $container) { $container->register('logger', NullLogger::class); + $container->registerExtension(new TestDumpExtension()); } public function __sleep(): array diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index 5c7ed9028f7eb..1a301287d043d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -20,11 +20,11 @@ "composer-runtime-api": ">=2.1", "ext-xml": "*", "symfony/cache": "^5.4|^6.0", - "symfony/config": "^5.4|^6.0", - "symfony/dependency-injection": "^5.4.5|^6.0.5", + "symfony/config": "^6.1", + "symfony/dependency-injection": "^6.1", "symfony/deprecation-contracts": "^2.1|^3", + "symfony/error-handler": "^6.1", "symfony/event-dispatcher": "^5.4|^6.0", - "symfony/error-handler": "^5.4|^6.0", "symfony/http-foundation": "^5.4|^6.0", "symfony/http-kernel": "^6.1", "symfony/polyfill-mbstring": "~1.0", @@ -55,7 +55,7 @@ "symfony/rate-limiter": "^5.4|^6.0", "symfony/security-bundle": "^5.4|^6.0", "symfony/semaphore": "^5.4|^6.0", - "symfony/serializer": "^5.4|^6.0", + "symfony/serializer": "^6.1", "symfony/stopwatch": "^5.4|^6.0", "symfony/string": "^5.4|^6.0", "symfony/translation": "^5.4|^6.0", diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/LdapFactoryTrait.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/LdapFactoryTrait.php index 8af8e4424b270..deccbb3975469 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/LdapFactoryTrait.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/LdapFactoryTrait.php @@ -35,10 +35,6 @@ public function getKey(): string public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): string { $key = str_replace('-', '_', $this->getKey()); - if (!class_exists(LdapAuthenticator::class)) { - throw new \LogicException(sprintf('The "%s" authenticator requires the "symfony/ldap" package version "5.1" or higher.', $key)); - } - $authenticatorId = parent::createAuthenticator($container, $firewallName, $config, $userProviderId); $container->setDefinition('security.listener.'.$key.'.'.$firewallName, new Definition(CheckLdapCredentialsListener::class)) diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/LoginLinkFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/LoginLinkFactory.php index 88e34192abf14..29b588631bc0a 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/LoginLinkFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/LoginLinkFactory.php @@ -20,7 +20,6 @@ use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface; use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface; -use Symfony\Component\Security\Http\LoginLink\LoginLinkHandler; /** * @internal @@ -88,10 +87,6 @@ public function getKey(): string public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): string { - if (!class_exists(LoginLinkHandler::class)) { - throw new \LogicException('Login login link requires symfony/security-http:^5.2.'); - } - if (!$container->hasDefinition('security.authenticator.login_link')) { $loader = new PhpFileLoader($container, new FileLocator(\dirname(__DIR__).'/../../Resources/config')); $loader->load('security_authenticator_login_link.php'); diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/LoginThrottlingFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/LoginThrottlingFactory.php index 5b5c1a55bce0a..5b2cfe781f490 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/LoginThrottlingFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/LoginThrottlingFactory.php @@ -19,7 +19,6 @@ use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\HttpFoundation\RateLimiter\RequestRateLimiterInterface; use Symfony\Component\RateLimiter\RateLimiterFactory; -use Symfony\Component\Security\Http\EventListener\LoginThrottlingListener; use Symfony\Component\Security\Http\RateLimiter\DefaultLoginRateLimiter; /** @@ -56,10 +55,6 @@ public function addConfiguration(NodeDefinition $builder) public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): array { - if (!class_exists(LoginThrottlingListener::class)) { - throw new \LogicException('Login throttling requires symfony/security-http:^5.2.'); - } - if (!class_exists(RateLimiterFactory::class)) { throw new \LogicException('Login throttling requires the Rate Limiter component. Try running "composer require symfony/rate-limiter".'); } diff --git a/src/Symfony/Component/Cache/Tests/Adapter/RedisAdapterSentinelTest.php b/src/Symfony/Component/Cache/Tests/Adapter/RedisAdapterSentinelTest.php index 881630c062d6c..efdcf57875959 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/RedisAdapterSentinelTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/RedisAdapterSentinelTest.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\SkippedTestSuiteError; use Symfony\Component\Cache\Adapter\AbstractAdapter; use Symfony\Component\Cache\Adapter\RedisAdapter; +use Symfony\Component\Cache\Exception\CacheException; use Symfony\Component\Cache\Exception\InvalidArgumentException; /** diff --git a/src/Symfony/Component/Cache/Traits/RedisTrait.php b/src/Symfony/Component/Cache/Traits/RedisTrait.php index f7dd039a5b963..f563eab2b2117 100644 --- a/src/Symfony/Component/Cache/Traits/RedisTrait.php +++ b/src/Symfony/Component/Cache/Traits/RedisTrait.php @@ -177,6 +177,10 @@ public static function createConnection(string $dsn, array $options = []): \Redi $class = $params['redis_cluster'] ? \RedisCluster::class : (1 < \count($hosts) ? \RedisArray::class : \Redis::class); } else { $class = $params['class'] ?? \Predis\Client::class; + + if (isset($params['redis_sentinel']) && !is_a($class, \Predis\Client::class, true) && !class_exists(\RedisSentinel::class)) { + throw new CacheException(sprintf('Cannot use Redis Sentinel: class "%s" does not extend "Predis\Client" and ext-redis >= 5.2 not found: "%s".', $class, $dsn)); + } } if (is_a($class, \Redis::class, true)) { diff --git a/src/Symfony/Component/Config/Builder/ClassBuilder.php b/src/Symfony/Component/Config/Builder/ClassBuilder.php index 8c1dbec78b013..8194a1526ace5 100644 --- a/src/Symfony/Component/Config/Builder/ClassBuilder.php +++ b/src/Symfony/Component/Config/Builder/ClassBuilder.php @@ -65,7 +65,7 @@ public function build(): string } $require .= sprintf('require_once __DIR__.\DIRECTORY_SEPARATOR.\'%s\';', implode('\'.\DIRECTORY_SEPARATOR.\'', $path))."\n"; } - $use = ''; + $use = $require ? "\n" : ''; foreach (array_keys($this->use) as $statement) { $use .= sprintf('use %s;', $statement)."\n"; } @@ -78,7 +78,7 @@ public function build(): string foreach ($this->methods as $method) { $lines = explode("\n", $method->getContent()); foreach ($lines as $line) { - $body .= ' '.$line."\n"; + $body .= ($line ? ' '.$line : '')."\n"; } } @@ -86,9 +86,7 @@ public function build(): string namespace NAMESPACE; -REQUIRE -USE - +REQUIREUSE /** * This class is automatically generated to help in creating a config. */ diff --git a/src/Symfony/Component/Config/Builder/ConfigBuilderGenerator.php b/src/Symfony/Component/Config/Builder/ConfigBuilderGenerator.php index eff9043a00041..1b45062164d10 100644 --- a/src/Symfony/Component/Config/Builder/ConfigBuilderGenerator.php +++ b/src/Symfony/Component/Config/Builder/ConfigBuilderGenerator.php @@ -130,23 +130,49 @@ private function buildNode(NodeInterface $node, ClassBuilder $class, string $nam private function handleArrayNode(ArrayNode $node, ClassBuilder $class, string $namespace): void { - if ('' !== $comment = $this->getComment($node)) { - $comment = "/**\n$comment*/\n"; - } - $childClass = new ClassBuilder($namespace, $node->getName()); $childClass->setAllowExtraKeys($node->shouldIgnoreExtraKeys()); $class->addRequire($childClass); $this->classes[] = $childClass; - $property = $class->addProperty($node->getName(), $childClass->getFqcn()); - $body = ' + $hasNormalizationClosures = $this->hasNormalizationClosures($node); + $comment = $this->getComment($node); + if ($hasNormalizationClosures) { + $comment .= sprintf(' * @return %s|$this'."\n ", $childClass->getFqcn()); + } + if ('' !== $comment) { + $comment = "/**\n$comment*/\n"; + } + + $property = $class->addProperty( + $node->getName(), + $this->getType($childClass->getFqcn(), $hasNormalizationClosures) + ); + $body = $hasNormalizationClosures ? ' +COMMENTpublic function NAME(mixed $value = []): CLASS|static +{ + if (!\is_array($value)) { + $this->_usedProperties[\'PROPERTY\'] = true; + $this->PROPERTY = $value; + + return $this; + } + + if (!$this->PROPERTY instanceof CLASS) { + $this->_usedProperties[\'PROPERTY\'] = true; + $this->PROPERTY = new CLASS($value); + } elseif (0 < \func_num_args()) { + throw new InvalidConfigurationException(\'The node created by "NAME()" has already been initialized. You cannot pass values the second time you call NAME().\'); + } + + return $this->PROPERTY; +}' : ' COMMENTpublic function NAME(array $value = []): CLASS { if (null === $this->PROPERTY) { $this->_usedProperties[\'PROPERTY\'] = true; $this->PROPERTY = new CLASS($value); - } elseif ([] !== $value) { + } elseif (0 < \func_num_args()) { throw new InvalidConfigurationException(\'The node created by "NAME()" has already been initialized. You cannot pass values the second time you call NAME().\'); } @@ -176,7 +202,11 @@ public function NAME(mixed $valueDEFAULT): static return $this; }'; - $class->addMethod($node->getName(), $body, ['PROPERTY' => $property->getName(), 'COMMENT' => $comment, 'DEFAULT' => $node->hasDefaultValue() ? ' = '.var_export($node->getDefaultValue(), true) : '']); + $class->addMethod($node->getName(), $body, [ + 'PROPERTY' => $property->getName(), + 'COMMENT' => $comment, + 'DEFAULT' => $node->hasDefaultValue() ? ' = '.var_export($node->getDefaultValue(), true) : '', + ]); } private function handlePrototypedArrayNode(PrototypedArrayNode $node, ClassBuilder $class, string $namespace): void @@ -184,6 +214,7 @@ private function handlePrototypedArrayNode(PrototypedArrayNode $node, ClassBuild $name = $this->getSingularName($node); $prototype = $node->getPrototype(); $methodName = $name; + $hasNormalizationClosures = $this->hasNormalizationClosures($node) || $this->hasNormalizationClosures($prototype); $parameterType = $this->getParameterType($prototype); if (null !== $parameterType || $prototype instanceof ScalarNode) { @@ -193,11 +224,11 @@ private function handlePrototypedArrayNode(PrototypedArrayNode $node, ClassBuild // This is an array of values; don't use singular name $body = ' /** - * @param ParamConfigurator|list $value + * @param PHPDOC_TYPE $value * * @return $this */ -public function NAME(ParamConfigurator|array $value): static +public function NAME(TYPE $value): static { $this->_usedProperties[\'PROPERTY\'] = true; $this->PROPERTY = $value; @@ -205,7 +236,11 @@ public function NAME(ParamConfigurator|array $value): static return $this; }'; - $class->addMethod($node->getName(), $body, ['PROPERTY' => $property->getName(), 'TYPE' => '' === $parameterType ? 'mixed' : $parameterType]); + $class->addMethod($node->getName(), $body, [ + 'PROPERTY' => $property->getName(), + 'TYPE' => $hasNormalizationClosures ? 'mixed' : 'ParamConfigurator|array', + 'PHPDOC_TYPE' => $hasNormalizationClosures ? 'mixed' : sprintf('ParamConfigurator|list', '' === $parameterType ? 'mixed' : $parameterType), + ]); } else { $body = ' /** @@ -219,7 +254,12 @@ public function NAME(string $VAR, TYPE $VALUE): static return $this; }'; - $class->addMethod($methodName, $body, ['PROPERTY' => $property->getName(), 'TYPE' => '' === $parameterType ? 'mixed' : 'ParamConfigurator|'.$parameterType, 'VAR' => '' === $key ? 'key' : $key, 'VALUE' => 'value' === $key ? 'data' : 'value']); + $class->addMethod($methodName, $body, [ + 'PROPERTY' => $property->getName(), + 'TYPE' => $hasNormalizationClosures || '' === $parameterType ? 'mixed' : 'ParamConfigurator|'.$parameterType, + 'VAR' => '' === $key ? 'key' : $key, + 'VALUE' => 'value' === $key ? 'data' : 'value', + ]); } return; @@ -231,14 +271,33 @@ public function NAME(string $VAR, TYPE $VALUE): static } $class->addRequire($childClass); $this->classes[] = $childClass; - $property = $class->addProperty($node->getName(), $childClass->getFqcn().'[]'); - if ('' !== $comment = $this->getComment($node)) { + $property = $class->addProperty( + $node->getName(), + $this->getType($childClass->getFqcn().'[]', $hasNormalizationClosures) + ); + + $comment = $this->getComment($node); + if ($hasNormalizationClosures) { + $comment .= sprintf(' * @return %s|$this'."\n ", $childClass->getFqcn()); + } + if ('' !== $comment) { $comment = "/**\n$comment*/\n"; } if (null === $key = $node->getKeyAttribute()) { - $body = ' + $body = $hasNormalizationClosures ? ' +COMMENTpublic function NAME(mixed $value = []): CLASS|static +{ + $this->_usedProperties[\'PROPERTY\'] = true; + if (!\is_array($value)) { + $this->PROPERTY[] = $value; + + return $this; + } + + return $this->PROPERTY[] = new CLASS($value); +}' : ' COMMENTpublic function NAME(array $value = []): CLASS { $this->_usedProperties[\'PROPERTY\'] = true; @@ -247,22 +306,43 @@ public function NAME(string $VAR, TYPE $VALUE): static }'; $class->addMethod($methodName, $body, ['COMMENT' => $comment, 'PROPERTY' => $property->getName(), 'CLASS' => $childClass->getFqcn()]); } else { - $body = ' -COMMENTpublic function NAME(string $VAR, array $VALUE = []): CLASS + $body = $hasNormalizationClosures ? ' +COMMENTpublic function NAME(string $VAR, mixed $VALUE = []): CLASS|static { - if (!isset($this->PROPERTY[$VAR])) { + if (!\is_array($VALUE)) { $this->_usedProperties[\'PROPERTY\'] = true; + $this->PROPERTY[$VAR] = $VALUE; - return $this->PROPERTY[$VAR] = new CLASS($VALUE); + return $this; } - if ([] === $VALUE) { - return $this->PROPERTY[$VAR]; + + if (!isset($this->PROPERTY[$VAR]) || !$this->PROPERTY[$VAR] instanceof CLASS) { + $this->_usedProperties[\'PROPERTY\'] = true; + $this->PROPERTY[$VAR] = new CLASS($VALUE); + } elseif (1 < \func_num_args()) { + throw new InvalidConfigurationException(\'The node created by "NAME()" has already been initialized. You cannot pass values the second time you call NAME().\'); } - throw new InvalidConfigurationException(\'The node created by "NAME()" has already been initialized. You cannot pass values the second time you call NAME().\'); + return $this->PROPERTY[$VAR]; +}' : ' +COMMENTpublic function NAME(string $VAR, array $VALUE = []): CLASS +{ + if (!isset($this->PROPERTY[$VAR])) { + $this->_usedProperties[\'PROPERTY\'] = true; + $this->PROPERTY[$VAR] = new CLASS($VALUE); + } elseif (1 < \func_num_args()) { + throw new InvalidConfigurationException(\'The node created by "NAME()" has already been initialized. You cannot pass values the second time you call NAME().\'); + } + + return $this->PROPERTY[$VAR]; }'; $class->addUse(InvalidConfigurationException::class); - $class->addMethod($methodName, $body, ['COMMENT' => $comment, 'PROPERTY' => $property->getName(), 'CLASS' => $childClass->getFqcn(), 'VAR' => '' === $key ? 'key' : $key, 'VALUE' => 'value' === $key ? 'data' : 'value']); + $class->addMethod($methodName, $body, [ + 'COMMENT' => $comment, 'PROPERTY' => $property->getName(), + 'CLASS' => $childClass->getFqcn(), + 'VAR' => '' === $key ? 'key' : $key, + 'VALUE' => 'value' === $key ? 'data' : 'value', + ]); } $this->buildNode($prototype, $childClass, $namespace.'\\'.$childClass->getName()); @@ -393,16 +473,22 @@ private function buildToArray(ClassBuilder $class): void $code = '$this->PROPERTY'; if (null !== $p->getType()) { if ($p->isArray()) { - $code = 'array_map(function ($v) { return $v->toArray(); }, $this->PROPERTY)'; + $code = $p->areScalarsAllowed() + ? 'array_map(function ($v) { return $v instanceof CLASS ? $v->toArray() : $v; }, $this->PROPERTY)' + : 'array_map(function ($v) { return $v->toArray(); }, $this->PROPERTY)' + ; } else { - $code = '$this->PROPERTY->toArray()'; + $code = $p->areScalarsAllowed() + ? '$this->PROPERTY instanceof CLASS ? $this->PROPERTY->toArray() : $this->PROPERTY' + : '$this->PROPERTY->toArray()' + ; } } $body .= strtr(' if (isset($this->_usedProperties[\'PROPERTY\'])) { $output[\'ORG_NAME\'] = '.$code.'; - }', ['PROPERTY' => $p->getName(), 'ORG_NAME' => $p->getOriginalName()]); + }', ['PROPERTY' => $p->getName(), 'ORG_NAME' => $p->getOriginalName(), 'CLASS' => $p->getType()]); } $extraKeys = $class->shouldAllowExtraKeys() ? ' + $this->_extraKeys' : ''; @@ -423,9 +509,15 @@ private function buildConstructor(ClassBuilder $class): void $code = '$value[\'ORG_NAME\']'; if (null !== $p->getType()) { if ($p->isArray()) { - $code = 'array_map(function ($v) { return new '.$p->getType().'($v); }, $value[\'ORG_NAME\'])'; + $code = $p->areScalarsAllowed() + ? 'array_map(function ($v) { return \is_array($v) ? new '.$p->getType().'($v) : $v; }, $value[\'ORG_NAME\'])' + : 'array_map(function ($v) { return new '.$p->getType().'($v); }, $value[\'ORG_NAME\'])' + ; } else { - $code = 'new '.$p->getType().'($value[\'ORG_NAME\'])'; + $code = $p->areScalarsAllowed() + ? '\is_array($value[\'ORG_NAME\']) ? new '.$p->getType().'($value[\'ORG_NAME\']) : $value[\'ORG_NAME\']' + : 'new '.$p->getType().'($value[\'ORG_NAME\'])' + ; } } @@ -453,8 +545,7 @@ private function buildConstructor(ClassBuilder $class): void $class->addMethod('__construct', ' public function __construct(array $value = []) -{ -'.$body.' +{'.$body.' }'); } @@ -486,4 +577,21 @@ private function getSubNamespace(ClassBuilder $rootClass): string { return sprintf('%s\\%s', $rootClass->getNamespace(), substr($rootClass->getName(), 0, -6)); } + + private function hasNormalizationClosures(NodeInterface $node): bool + { + try { + $r = new \ReflectionProperty($node, 'normalizationClosures'); + } catch (\ReflectionException) { + return false; + } + $r->setAccessible(true); + + return [] !== $r->getValue($node); + } + + private function getType(string $classType, bool $hasNormalizationClosures): string + { + return $classType.($hasNormalizationClosures ? '|scalar' : ''); + } } diff --git a/src/Symfony/Component/Config/Builder/Property.php b/src/Symfony/Component/Config/Builder/Property.php index 714a29549edcd..cf2f8d549ed4b 100644 --- a/src/Symfony/Component/Config/Builder/Property.php +++ b/src/Symfony/Component/Config/Builder/Property.php @@ -23,6 +23,7 @@ class Property private string $name; private string $originalName; private bool $array = false; + private bool $scalarsAllowed = false; private ?string $type = null; private ?string $content = null; @@ -47,6 +48,11 @@ public function setType(string $type): void $this->array = false; $this->type = $type; + if (str_ends_with($type, '|scalar')) { + $this->scalarsAllowed = true; + $this->type = $type = substr($type, 0, -7); + } + if (str_ends_with($type, '[]')) { $this->array = true; $this->type = substr($type, 0, -2); @@ -72,4 +78,9 @@ public function isArray(): bool { return $this->array; } + + public function areScalarsAllowed(): bool + { + return $this->scalarsAllowed; + } } diff --git a/src/Symfony/Component/Config/Resource/GlobResource.php b/src/Symfony/Component/Config/Resource/GlobResource.php index 964066cde69eb..96699c8d9d45e 100644 --- a/src/Symfony/Component/Config/Resource/GlobResource.php +++ b/src/Symfony/Component/Config/Resource/GlobResource.php @@ -106,7 +106,9 @@ public function getIterator(): \Traversable $prefix = str_replace('\\', '/', $this->prefix); $paths = null; - if (!str_starts_with($this->prefix, 'phar://') && !str_contains($this->pattern, '/**/')) { + if ('' === $this->pattern && is_file($prefix)) { + $paths = [$this->prefix]; + } elseif (!str_starts_with($this->prefix, 'phar://') && !str_contains($this->pattern, '/**/')) { if ($this->globBrace || !str_contains($this->pattern, '{')) { $paths = glob($this->prefix.$this->pattern, \GLOB_NOSORT | $this->globBrace); } elseif (!str_contains($this->pattern, '\\') || !preg_match('/\\\\[,{}]/', $this->pattern)) { @@ -167,12 +169,19 @@ function (\SplFileInfo $file, $path) { throw new \LogicException(sprintf('Extended glob pattern "%s" cannot be used as the Finder component is not installed.', $this->pattern)); } - $regex = Glob::toRegex($this->pattern); + if (is_file($prefix = $this->prefix)) { + $prefix = \dirname($prefix); + $pattern = basename($prefix).$this->pattern; + } else { + $pattern = $this->pattern; + } + + $regex = Glob::toRegex($pattern); if ($this->recursive) { $regex = substr_replace($regex, '(/|$)', -2, 1); } - $prefixLen = \strlen($this->prefix); + $prefixLen = \strlen($prefix); yield from (new Finder()) ->followLinks() @@ -190,7 +199,7 @@ function (\SplFileInfo $file, $path) { } }) ->sortByName() - ->in($this->prefix) + ->in($prefix) ; } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList.config.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList.config.php index 5bb32b89be990..4dc2d3e87ab53 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList.config.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList.config.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + use Symfony\Config\AddToListConfig; return static function (AddToListConfig $config) { diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList.output.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList.output.php index 6efdb83839604..1949f59c24963 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList.output.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList.output.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + return [ 'translator' => [ 'fallbacks' => ['sv', 'fr', 'es'], diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList.php index fcc2109ad4b86..d5f24e4adb6b0 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList.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\Config\Tests\Builder\Fixtures; use Symfony\Component\Config\Definition\Builder\TreeBuilder; diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/Messenger/ReceivingConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/Messenger/ReceivingConfig.php index 5a00750db92e9..76f065bf2097c 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/Messenger/ReceivingConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/Messenger/ReceivingConfig.php @@ -2,11 +2,9 @@ namespace Symfony\Config\AddToList\Messenger; - use Symfony\Component\Config\Loader\ParamConfigurator; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; - /** * This class is automatically generated to help in creating a config. */ @@ -15,7 +13,7 @@ class ReceivingConfig private $priority; private $color; private $_usedProperties = []; - + /** * @default null * @param ParamConfigurator|int $value @@ -25,10 +23,10 @@ public function priority($value): static { $this->_usedProperties['priority'] = true; $this->priority = $value; - + return $this; } - + /** * @default null * @param ParamConfigurator|mixed $value @@ -38,30 +36,29 @@ public function color($value): static { $this->_usedProperties['color'] = true; $this->color = $value; - + return $this; } - + public function __construct(array $value = []) { - if (array_key_exists('priority', $value)) { $this->_usedProperties['priority'] = true; $this->priority = $value['priority']; unset($value['priority']); } - + if (array_key_exists('color', $value)) { $this->_usedProperties['color'] = true; $this->color = $value['color']; unset($value['color']); } - + if ([] !== $value) { throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); } } - + public function toArray(): array { $output = []; @@ -71,7 +68,7 @@ public function toArray(): array if (isset($this->_usedProperties['color'])) { $output['color'] = $this->color; } - + return $output; } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/Messenger/RoutingConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/Messenger/RoutingConfig.php index 6c68b355e1592..0d24a76392b0e 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/Messenger/RoutingConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/Messenger/RoutingConfig.php @@ -2,11 +2,9 @@ namespace Symfony\Config\AddToList\Messenger; - use Symfony\Component\Config\Loader\ParamConfigurator; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; - /** * This class is automatically generated to help in creating a config. */ @@ -14,7 +12,7 @@ class RoutingConfig { private $senders; private $_usedProperties = []; - + /** * @param ParamConfigurator|list $value * @@ -24,31 +22,30 @@ public function senders(ParamConfigurator|array $value): static { $this->_usedProperties['senders'] = true; $this->senders = $value; - + return $this; } - + public function __construct(array $value = []) { - if (array_key_exists('senders', $value)) { $this->_usedProperties['senders'] = true; $this->senders = $value['senders']; unset($value['senders']); } - + if ([] !== $value) { throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); } } - + public function toArray(): array { $output = []; if (isset($this->_usedProperties['senders'])) { $output['senders'] = $this->senders; } - + return $output; } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/MessengerConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/MessengerConfig.php index 85b593a1b05f1..bc8625d9fb0c1 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/MessengerConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/MessengerConfig.php @@ -7,7 +7,6 @@ use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; - /** * This class is automatically generated to help in creating a config. */ @@ -16,48 +15,45 @@ class MessengerConfig private $routing; private $receiving; private $_usedProperties = []; - + public function routing(string $message_class, array $value = []): \Symfony\Config\AddToList\Messenger\RoutingConfig { if (!isset($this->routing[$message_class])) { $this->_usedProperties['routing'] = true; - - return $this->routing[$message_class] = new \Symfony\Config\AddToList\Messenger\RoutingConfig($value); - } - if ([] === $value) { - return $this->routing[$message_class]; + $this->routing[$message_class] = new \Symfony\Config\AddToList\Messenger\RoutingConfig($value); + } elseif (1 < \func_num_args()) { + throw new InvalidConfigurationException('The node created by "routing()" has already been initialized. You cannot pass values the second time you call routing().'); } - - throw new InvalidConfigurationException('The node created by "routing()" has already been initialized. You cannot pass values the second time you call routing().'); + + return $this->routing[$message_class]; } - + public function receiving(array $value = []): \Symfony\Config\AddToList\Messenger\ReceivingConfig { $this->_usedProperties['receiving'] = true; - + return $this->receiving[] = new \Symfony\Config\AddToList\Messenger\ReceivingConfig($value); } - + public function __construct(array $value = []) { - if (array_key_exists('routing', $value)) { $this->_usedProperties['routing'] = true; $this->routing = array_map(function ($v) { return new \Symfony\Config\AddToList\Messenger\RoutingConfig($v); }, $value['routing']); unset($value['routing']); } - + if (array_key_exists('receiving', $value)) { $this->_usedProperties['receiving'] = true; $this->receiving = array_map(function ($v) { return new \Symfony\Config\AddToList\Messenger\ReceivingConfig($v); }, $value['receiving']); unset($value['receiving']); } - + if ([] !== $value) { throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); } } - + public function toArray(): array { $output = []; @@ -67,7 +63,7 @@ public function toArray(): array if (isset($this->_usedProperties['receiving'])) { $output['receiving'] = array_map(function ($v) { return $v->toArray(); }, $this->receiving); } - + return $output; } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/Translator/Books/PageConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/Translator/Books/PageConfig.php index e69f63f87e270..b17f032dc98b0 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/Translator/Books/PageConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/Translator/Books/PageConfig.php @@ -2,11 +2,9 @@ namespace Symfony\Config\AddToList\Translator\Books; - use Symfony\Component\Config\Loader\ParamConfigurator; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; - /** * This class is automatically generated to help in creating a config. */ @@ -15,7 +13,7 @@ class PageConfig private $number; private $content; private $_usedProperties = []; - + /** * @default null * @param ParamConfigurator|int $value @@ -25,10 +23,10 @@ public function number($value): static { $this->_usedProperties['number'] = true; $this->number = $value; - + return $this; } - + /** * @default null * @param ParamConfigurator|mixed $value @@ -38,30 +36,29 @@ public function content($value): static { $this->_usedProperties['content'] = true; $this->content = $value; - + return $this; } - + public function __construct(array $value = []) { - if (array_key_exists('number', $value)) { $this->_usedProperties['number'] = true; $this->number = $value['number']; unset($value['number']); } - + if (array_key_exists('content', $value)) { $this->_usedProperties['content'] = true; $this->content = $value['content']; unset($value['content']); } - + if ([] !== $value) { throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); } } - + public function toArray(): array { $output = []; @@ -71,7 +68,7 @@ public function toArray(): array if (isset($this->_usedProperties['content'])) { $output['content'] = $this->content; } - + return $output; } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/Translator/BooksConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/Translator/BooksConfig.php index cb8c874537fa4..2207ef41f8c57 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/Translator/BooksConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/Translator/BooksConfig.php @@ -6,7 +6,6 @@ use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; - /** * This class is automatically generated to help in creating a config. */ @@ -14,7 +13,7 @@ class BooksConfig { private $page; private $_usedProperties = []; - + /** * @example "page 1" * @default {"number":1,"content":""} @@ -22,31 +21,30 @@ class BooksConfig public function page(array $value = []): \Symfony\Config\AddToList\Translator\Books\PageConfig { $this->_usedProperties['page'] = true; - + return $this->page[] = new \Symfony\Config\AddToList\Translator\Books\PageConfig($value); } - + public function __construct(array $value = []) { - if (array_key_exists('page', $value)) { $this->_usedProperties['page'] = true; $this->page = array_map(function ($v) { return new \Symfony\Config\AddToList\Translator\Books\PageConfig($v); }, $value['page']); unset($value['page']); } - + if ([] !== $value) { throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); } } - + public function toArray(): array { $output = []; if (isset($this->_usedProperties['page'])) { $output['page'] = array_map(function ($v) { return $v->toArray(); }, $this->page); } - + return $output; } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/TranslatorConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/TranslatorConfig.php index 60488a0758394..00622f162ad0e 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/TranslatorConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/TranslatorConfig.php @@ -7,7 +7,6 @@ use Symfony\Component\Config\Loader\ParamConfigurator; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; - /** * This class is automatically generated to help in creating a config. */ @@ -17,7 +16,7 @@ class TranslatorConfig private $sources; private $books; private $_usedProperties = []; - + /** * @param ParamConfigurator|list $value * @@ -27,10 +26,10 @@ public function fallbacks(ParamConfigurator|array $value): static { $this->_usedProperties['fallbacks'] = true; $this->fallbacks = $value; - + return $this; } - + /** * @return $this */ @@ -38,10 +37,10 @@ public function source(string $source_class, mixed $value): static { $this->_usedProperties['sources'] = true; $this->sources[$source_class] = $value; - + return $this; } - + /** * looks for translation in old fashion way * @deprecated The child node "books" at path "translator" is deprecated. @@ -51,39 +50,38 @@ public function books(array $value = []): \Symfony\Config\AddToList\Translator\B if (null === $this->books) { $this->_usedProperties['books'] = true; $this->books = new \Symfony\Config\AddToList\Translator\BooksConfig($value); - } elseif ([] !== $value) { + } elseif (0 < \func_num_args()) { throw new InvalidConfigurationException('The node created by "books()" has already been initialized. You cannot pass values the second time you call books().'); } - + return $this->books; } - + public function __construct(array $value = []) { - if (array_key_exists('fallbacks', $value)) { $this->_usedProperties['fallbacks'] = true; $this->fallbacks = $value['fallbacks']; unset($value['fallbacks']); } - + if (array_key_exists('sources', $value)) { $this->_usedProperties['sources'] = true; $this->sources = $value['sources']; unset($value['sources']); } - + if (array_key_exists('books', $value)) { $this->_usedProperties['books'] = true; $this->books = new \Symfony\Config\AddToList\Translator\BooksConfig($value['books']); unset($value['books']); } - + if ([] !== $value) { throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); } } - + public function toArray(): array { $output = []; @@ -96,7 +94,7 @@ public function toArray(): array if (isset($this->_usedProperties['books'])) { $output['books'] = $this->books->toArray(); } - + return $output; } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToListConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToListConfig.php index e6f0c262b88db..a8b0adb28b5f2 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToListConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToListConfig.php @@ -7,7 +7,6 @@ use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; - /** * This class is automatically generated to help in creating a config. */ @@ -16,56 +15,55 @@ class AddToListConfig implements \Symfony\Component\Config\Builder\ConfigBuilder private $translator; private $messenger; private $_usedProperties = []; - + public function translator(array $value = []): \Symfony\Config\AddToList\TranslatorConfig { if (null === $this->translator) { $this->_usedProperties['translator'] = true; $this->translator = new \Symfony\Config\AddToList\TranslatorConfig($value); - } elseif ([] !== $value) { + } elseif (0 < \func_num_args()) { throw new InvalidConfigurationException('The node created by "translator()" has already been initialized. You cannot pass values the second time you call translator().'); } - + return $this->translator; } - + public function messenger(array $value = []): \Symfony\Config\AddToList\MessengerConfig { if (null === $this->messenger) { $this->_usedProperties['messenger'] = true; $this->messenger = new \Symfony\Config\AddToList\MessengerConfig($value); - } elseif ([] !== $value) { + } elseif (0 < \func_num_args()) { throw new InvalidConfigurationException('The node created by "messenger()" has already been initialized. You cannot pass values the second time you call messenger().'); } - + return $this->messenger; } - + public function getExtensionAlias(): string { return 'add_to_list'; } - + public function __construct(array $value = []) { - if (array_key_exists('translator', $value)) { $this->_usedProperties['translator'] = true; $this->translator = new \Symfony\Config\AddToList\TranslatorConfig($value['translator']); unset($value['translator']); } - + if (array_key_exists('messenger', $value)) { $this->_usedProperties['messenger'] = true; $this->messenger = new \Symfony\Config\AddToList\MessengerConfig($value['messenger']); unset($value['messenger']); } - + if ([] !== $value) { throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); } } - + public function toArray(): array { $output = []; @@ -75,7 +73,7 @@ public function toArray(): array if (isset($this->_usedProperties['messenger'])) { $output['messenger'] = $this->messenger->toArray(); } - + return $output; } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys.config.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys.config.php index 45069e7490c22..598255fec6bf6 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys.config.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys.config.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + use Symfony\Config\ArrayExtraKeysConfig; return static function (ArrayExtraKeysConfig $config) { diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys.output.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys.output.php index d2fdc1ef5c8e4..ff0bdbd686cb7 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys.output.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys.output.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + return [ 'foo' => [ 'baz' => 'foo_baz', diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys.php index 751fe5c2934cc..96c515e55b46d 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys.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\Config\Tests\Builder\Fixtures; use Symfony\Component\Config\Definition\Builder\TreeBuilder; diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeys/BarConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeys/BarConfig.php index 5e5c5c02da7f2..3b44d838ff81e 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeys/BarConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeys/BarConfig.php @@ -2,10 +2,8 @@ namespace Symfony\Config\ArrayExtraKeys; - use Symfony\Component\Config\Loader\ParamConfigurator; - /** * This class is automatically generated to help in creating a config. */ @@ -15,7 +13,7 @@ class BarConfig private $grault; private $_usedProperties = []; private $_extraKeys; - + /** * @default null * @param ParamConfigurator|mixed $value @@ -25,10 +23,10 @@ public function corge($value): static { $this->_usedProperties['corge'] = true; $this->corge = $value; - + return $this; } - + /** * @default null * @param ParamConfigurator|mixed $value @@ -38,29 +36,28 @@ public function grault($value): static { $this->_usedProperties['grault'] = true; $this->grault = $value; - + return $this; } - + public function __construct(array $value = []) { - if (array_key_exists('corge', $value)) { $this->_usedProperties['corge'] = true; $this->corge = $value['corge']; unset($value['corge']); } - + if (array_key_exists('grault', $value)) { $this->_usedProperties['grault'] = true; $this->grault = $value['grault']; unset($value['grault']); } - + $this->_extraKeys = $value; - + } - + public function toArray(): array { $output = []; @@ -70,10 +67,10 @@ public function toArray(): array if (isset($this->_usedProperties['grault'])) { $output['grault'] = $this->grault; } - + return $output + $this->_extraKeys; } - + /** * @param ParamConfigurator|mixed $value * @@ -82,7 +79,7 @@ public function toArray(): array public function set(string $key, mixed $value): static { $this->_extraKeys[$key] = $value; - + return $this; } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeys/BazConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeys/BazConfig.php index 5500fa3a71737..236e751dd997f 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeys/BazConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeys/BazConfig.php @@ -2,31 +2,28 @@ namespace Symfony\Config\ArrayExtraKeys; - use Symfony\Component\Config\Loader\ParamConfigurator; - /** * This class is automatically generated to help in creating a config. */ class BazConfig { private $_extraKeys; - + public function __construct(array $value = []) { - $this->_extraKeys = $value; - + } - + public function toArray(): array { $output = []; - + return $output + $this->_extraKeys; } - + /** * @param ParamConfigurator|mixed $value * @@ -35,7 +32,7 @@ public function toArray(): array public function set(string $key, mixed $value): static { $this->_extraKeys[$key] = $value; - + return $this; } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeys/FooConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeys/FooConfig.php index 073de94368bb4..77754d0c02c9f 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeys/FooConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeys/FooConfig.php @@ -2,10 +2,8 @@ namespace Symfony\Config\ArrayExtraKeys; - use Symfony\Component\Config\Loader\ParamConfigurator; - /** * This class is automatically generated to help in creating a config. */ @@ -15,7 +13,7 @@ class FooConfig private $qux; private $_usedProperties = []; private $_extraKeys; - + /** * @default null * @param ParamConfigurator|mixed $value @@ -25,10 +23,10 @@ public function baz($value): static { $this->_usedProperties['baz'] = true; $this->baz = $value; - + return $this; } - + /** * @default null * @param ParamConfigurator|mixed $value @@ -38,29 +36,28 @@ public function qux($value): static { $this->_usedProperties['qux'] = true; $this->qux = $value; - + return $this; } - + public function __construct(array $value = []) { - if (array_key_exists('baz', $value)) { $this->_usedProperties['baz'] = true; $this->baz = $value['baz']; unset($value['baz']); } - + if (array_key_exists('qux', $value)) { $this->_usedProperties['qux'] = true; $this->qux = $value['qux']; unset($value['qux']); } - + $this->_extraKeys = $value; - + } - + public function toArray(): array { $output = []; @@ -70,10 +67,10 @@ public function toArray(): array if (isset($this->_usedProperties['qux'])) { $output['qux'] = $this->qux; } - + return $output + $this->_extraKeys; } - + /** * @param ParamConfigurator|mixed $value * @@ -82,7 +79,7 @@ public function toArray(): array public function set(string $key, mixed $value): static { $this->_extraKeys[$key] = $value; - + return $this; } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeysConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeysConfig.php index 3d8adb7095b33..2d7628f038736 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeysConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeysConfig.php @@ -8,7 +8,6 @@ use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; - /** * This class is automatically generated to help in creating a config. */ @@ -18,69 +17,68 @@ class ArrayExtraKeysConfig implements \Symfony\Component\Config\Builder\ConfigBu private $bar; private $baz; private $_usedProperties = []; - + public function foo(array $value = []): \Symfony\Config\ArrayExtraKeys\FooConfig { if (null === $this->foo) { $this->_usedProperties['foo'] = true; $this->foo = new \Symfony\Config\ArrayExtraKeys\FooConfig($value); - } elseif ([] !== $value) { + } elseif (0 < \func_num_args()) { throw new InvalidConfigurationException('The node created by "foo()" has already been initialized. You cannot pass values the second time you call foo().'); } - + return $this->foo; } - + public function bar(array $value = []): \Symfony\Config\ArrayExtraKeys\BarConfig { $this->_usedProperties['bar'] = true; - + return $this->bar[] = new \Symfony\Config\ArrayExtraKeys\BarConfig($value); } - + public function baz(array $value = []): \Symfony\Config\ArrayExtraKeys\BazConfig { if (null === $this->baz) { $this->_usedProperties['baz'] = true; $this->baz = new \Symfony\Config\ArrayExtraKeys\BazConfig($value); - } elseif ([] !== $value) { + } elseif (0 < \func_num_args()) { throw new InvalidConfigurationException('The node created by "baz()" has already been initialized. You cannot pass values the second time you call baz().'); } - + return $this->baz; } - + public function getExtensionAlias(): string { return 'array_extra_keys'; } - + public function __construct(array $value = []) { - if (array_key_exists('foo', $value)) { $this->_usedProperties['foo'] = true; $this->foo = new \Symfony\Config\ArrayExtraKeys\FooConfig($value['foo']); unset($value['foo']); } - + if (array_key_exists('bar', $value)) { $this->_usedProperties['bar'] = true; $this->bar = array_map(function ($v) { return new \Symfony\Config\ArrayExtraKeys\BarConfig($v); }, $value['bar']); unset($value['bar']); } - + if (array_key_exists('baz', $value)) { $this->_usedProperties['baz'] = true; $this->baz = new \Symfony\Config\ArrayExtraKeys\BazConfig($value['baz']); unset($value['baz']); } - + if ([] !== $value) { throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); } } - + public function toArray(): array { $output = []; @@ -93,7 +91,7 @@ public function toArray(): array if (isset($this->_usedProperties['baz'])) { $output['baz'] = $this->baz->toArray(); } - + return $output; } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.config.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.config.php index 4b86755c91a5b..430258ac382fa 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.config.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.config.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + use Symfony\Config\NodeInitialValuesConfig; return static function (NodeInitialValuesConfig $config) { diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.output.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.output.php index 7fe70f9645b9e..c4ad8affe2144 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.output.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.output.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + return [ 'some_clever_name' => [ 'first' => 'bar', diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.php index c290cf9730670..153af57be9b5b 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.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\Config\Tests\Builder\Fixtures; use Symfony\Component\Config\Definition\Builder\TreeBuilder; diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValues/Messenger/TransportsConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValues/Messenger/TransportsConfig.php index 501a8c0703cc8..b9d8b48db3556 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValues/Messenger/TransportsConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValues/Messenger/TransportsConfig.php @@ -2,11 +2,9 @@ namespace Symfony\Config\NodeInitialValues\Messenger; - use Symfony\Component\Config\Loader\ParamConfigurator; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; - /** * This class is automatically generated to help in creating a config. */ @@ -16,7 +14,7 @@ class TransportsConfig private $serializer; private $options; private $_usedProperties = []; - + /** * @default null * @param ParamConfigurator|mixed $value @@ -26,10 +24,10 @@ public function dsn($value): static { $this->_usedProperties['dsn'] = true; $this->dsn = $value; - + return $this; } - + /** * @default null * @param ParamConfigurator|mixed $value @@ -39,10 +37,10 @@ public function serializer($value): static { $this->_usedProperties['serializer'] = true; $this->serializer = $value; - + return $this; } - + /** * @param ParamConfigurator|list $value * @@ -52,36 +50,35 @@ public function options(ParamConfigurator|array $value): static { $this->_usedProperties['options'] = true; $this->options = $value; - + return $this; } - + public function __construct(array $value = []) { - if (array_key_exists('dsn', $value)) { $this->_usedProperties['dsn'] = true; $this->dsn = $value['dsn']; unset($value['dsn']); } - + if (array_key_exists('serializer', $value)) { $this->_usedProperties['serializer'] = true; $this->serializer = $value['serializer']; unset($value['serializer']); } - + if (array_key_exists('options', $value)) { $this->_usedProperties['options'] = true; $this->options = $value['options']; unset($value['options']); } - + if ([] !== $value) { throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); } } - + public function toArray(): array { $output = []; @@ -94,7 +91,7 @@ public function toArray(): array if (isset($this->_usedProperties['options'])) { $output['options'] = $this->options; } - + return $output; } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValues/MessengerConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValues/MessengerConfig.php index 12ff61109cae7..d174c8932b4f8 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValues/MessengerConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValues/MessengerConfig.php @@ -6,7 +6,6 @@ use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; - /** * This class is automatically generated to help in creating a config. */ @@ -14,42 +13,39 @@ class MessengerConfig { private $transports; private $_usedProperties = []; - + public function transports(string $name, array $value = []): \Symfony\Config\NodeInitialValues\Messenger\TransportsConfig { if (!isset($this->transports[$name])) { $this->_usedProperties['transports'] = true; - - return $this->transports[$name] = new \Symfony\Config\NodeInitialValues\Messenger\TransportsConfig($value); + $this->transports[$name] = new \Symfony\Config\NodeInitialValues\Messenger\TransportsConfig($value); + } elseif (1 < \func_num_args()) { + throw new InvalidConfigurationException('The node created by "transports()" has already been initialized. You cannot pass values the second time you call transports().'); } - if ([] === $value) { - return $this->transports[$name]; - } - - throw new InvalidConfigurationException('The node created by "transports()" has already been initialized. You cannot pass values the second time you call transports().'); + + return $this->transports[$name]; } - + public function __construct(array $value = []) { - if (array_key_exists('transports', $value)) { $this->_usedProperties['transports'] = true; $this->transports = array_map(function ($v) { return new \Symfony\Config\NodeInitialValues\Messenger\TransportsConfig($v); }, $value['transports']); unset($value['transports']); } - + if ([] !== $value) { throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); } } - + public function toArray(): array { $output = []; if (isset($this->_usedProperties['transports'])) { $output['transports'] = array_map(function ($v) { return $v->toArray(); }, $this->transports); } - + return $output; } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValues/SomeCleverNameConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValues/SomeCleverNameConfig.php index 2ec96d285bdaf..ec9c8cbf1a255 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValues/SomeCleverNameConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValues/SomeCleverNameConfig.php @@ -2,11 +2,9 @@ namespace Symfony\Config\NodeInitialValues; - use Symfony\Component\Config\Loader\ParamConfigurator; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; - /** * This class is automatically generated to help in creating a config. */ @@ -16,7 +14,7 @@ class SomeCleverNameConfig private $second; private $third; private $_usedProperties = []; - + /** * @default null * @param ParamConfigurator|mixed $value @@ -26,10 +24,10 @@ public function first($value): static { $this->_usedProperties['first'] = true; $this->first = $value; - + return $this; } - + /** * @default null * @param ParamConfigurator|mixed $value @@ -39,10 +37,10 @@ public function second($value): static { $this->_usedProperties['second'] = true; $this->second = $value; - + return $this; } - + /** * @default null * @param ParamConfigurator|mixed $value @@ -52,36 +50,35 @@ public function third($value): static { $this->_usedProperties['third'] = true; $this->third = $value; - + return $this; } - + public function __construct(array $value = []) { - if (array_key_exists('first', $value)) { $this->_usedProperties['first'] = true; $this->first = $value['first']; unset($value['first']); } - + if (array_key_exists('second', $value)) { $this->_usedProperties['second'] = true; $this->second = $value['second']; unset($value['second']); } - + if (array_key_exists('third', $value)) { $this->_usedProperties['third'] = true; $this->third = $value['third']; unset($value['third']); } - + if ([] !== $value) { throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); } } - + public function toArray(): array { $output = []; @@ -94,7 +91,7 @@ public function toArray(): array if (isset($this->_usedProperties['third'])) { $output['third'] = $this->third; } - + return $output; } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValuesConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValuesConfig.php index 1ba307fb491eb..d019ecf81bb76 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValuesConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValuesConfig.php @@ -7,7 +7,6 @@ use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; - /** * This class is automatically generated to help in creating a config. */ @@ -16,56 +15,55 @@ class NodeInitialValuesConfig implements \Symfony\Component\Config\Builder\Confi private $someCleverName; private $messenger; private $_usedProperties = []; - + public function someCleverName(array $value = []): \Symfony\Config\NodeInitialValues\SomeCleverNameConfig { if (null === $this->someCleverName) { $this->_usedProperties['someCleverName'] = true; $this->someCleverName = new \Symfony\Config\NodeInitialValues\SomeCleverNameConfig($value); - } elseif ([] !== $value) { + } elseif (0 < \func_num_args()) { throw new InvalidConfigurationException('The node created by "someCleverName()" has already been initialized. You cannot pass values the second time you call someCleverName().'); } - + return $this->someCleverName; } - + public function messenger(array $value = []): \Symfony\Config\NodeInitialValues\MessengerConfig { if (null === $this->messenger) { $this->_usedProperties['messenger'] = true; $this->messenger = new \Symfony\Config\NodeInitialValues\MessengerConfig($value); - } elseif ([] !== $value) { + } elseif (0 < \func_num_args()) { throw new InvalidConfigurationException('The node created by "messenger()" has already been initialized. You cannot pass values the second time you call messenger().'); } - + return $this->messenger; } - + public function getExtensionAlias(): string { return 'node_initial_values'; } - + public function __construct(array $value = []) { - if (array_key_exists('some_clever_name', $value)) { $this->_usedProperties['someCleverName'] = true; $this->someCleverName = new \Symfony\Config\NodeInitialValues\SomeCleverNameConfig($value['some_clever_name']); unset($value['some_clever_name']); } - + if (array_key_exists('messenger', $value)) { $this->_usedProperties['messenger'] = true; $this->messenger = new \Symfony\Config\NodeInitialValues\MessengerConfig($value['messenger']); unset($value['messenger']); } - + if ([] !== $value) { throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); } } - + public function toArray(): array { $output = []; @@ -75,7 +73,7 @@ public function toArray(): array if (isset($this->_usedProperties['messenger'])) { $output['messenger'] = $this->messenger->toArray(); } - + return $output; } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders.config.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders.config.php index 089252f32f341..8e6b5ae3f90d0 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders.config.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders.config.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\DependencyInjection\Loader\Configurator; use Symfony\Config\PlaceholdersConfig; diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders.output.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders.output.php index ca27298c368e9..56a5af670807a 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders.output.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders.output.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + return [ 'enabled' => '%env(bool:FOO_ENABLED)%', 'favorite_float' => '%eulers_number%', diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders.php index 6735b5e955675..5d9c680daaced 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders.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\Config\Tests\Builder\Fixtures; use Symfony\Component\Config\Definition\Builder\TreeBuilder; diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders/Symfony/Config/PlaceholdersConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders/Symfony/Config/PlaceholdersConfig.php index 427f883513093..eb23423fffe3b 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders/Symfony/Config/PlaceholdersConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders/Symfony/Config/PlaceholdersConfig.php @@ -2,11 +2,9 @@ namespace Symfony\Config; - use Symfony\Component\Config\Loader\ParamConfigurator; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; - /** * This class is automatically generated to help in creating a config. */ @@ -16,7 +14,7 @@ class PlaceholdersConfig implements \Symfony\Component\Config\Builder\ConfigBuil private $favoriteFloat; private $goodIntegers; private $_usedProperties = []; - + /** * @default false * @param ParamConfigurator|bool $value @@ -26,10 +24,10 @@ public function enabled($value): static { $this->_usedProperties['enabled'] = true; $this->enabled = $value; - + return $this; } - + /** * @default null * @param ParamConfigurator|float $value @@ -39,10 +37,10 @@ public function favoriteFloat($value): static { $this->_usedProperties['favoriteFloat'] = true; $this->favoriteFloat = $value; - + return $this; } - + /** * @param ParamConfigurator|list $value * @@ -52,41 +50,40 @@ public function goodIntegers(ParamConfigurator|array $value): static { $this->_usedProperties['goodIntegers'] = true; $this->goodIntegers = $value; - + return $this; } - + public function getExtensionAlias(): string { return 'placeholders'; } - + public function __construct(array $value = []) { - if (array_key_exists('enabled', $value)) { $this->_usedProperties['enabled'] = true; $this->enabled = $value['enabled']; unset($value['enabled']); } - + if (array_key_exists('favorite_float', $value)) { $this->_usedProperties['favoriteFloat'] = true; $this->favoriteFloat = $value['favorite_float']; unset($value['favorite_float']); } - + if (array_key_exists('good_integers', $value)) { $this->_usedProperties['goodIntegers'] = true; $this->goodIntegers = $value['good_integers']; unset($value['good_integers']); } - + if ([] !== $value) { throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); } } - + public function toArray(): array { $output = []; @@ -99,7 +96,7 @@ public function toArray(): array if (isset($this->_usedProperties['goodIntegers'])) { $output['good_integers'] = $this->goodIntegers; } - + return $output; } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.config.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.config.php index b4498957057c4..fd4c0ce5f2cfa 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.config.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.config.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + use Symfony\Config\PrimitiveTypesConfig; return static function (PrimitiveTypesConfig $config) { diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.output.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.output.php index 366fd5c19f4cb..867e387dbf3c2 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.output.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.output.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + return [ 'boolean_node' => true, 'enum_node' => 'foo', diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.php index 3d36f72bff2db..6ffcf5a4ef533 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.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\Config\Tests\Builder\Fixtures; use Symfony\Component\Config\Definition\Builder\TreeBuilder; diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes/Symfony/Config/PrimitiveTypesConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes/Symfony/Config/PrimitiveTypesConfig.php index 16ebd3bf18211..6701d472cec04 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes/Symfony/Config/PrimitiveTypesConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes/Symfony/Config/PrimitiveTypesConfig.php @@ -2,11 +2,9 @@ namespace Symfony\Config; - use Symfony\Component\Config\Loader\ParamConfigurator; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; - /** * This class is automatically generated to help in creating a config. */ @@ -19,7 +17,7 @@ class PrimitiveTypesConfig implements \Symfony\Component\Config\Builder\ConfigBu private $scalarNode; private $scalarNodeWithDefault; private $_usedProperties = []; - + /** * @default null * @param ParamConfigurator|bool $value @@ -29,10 +27,10 @@ public function booleanNode($value): static { $this->_usedProperties['booleanNode'] = true; $this->booleanNode = $value; - + return $this; } - + /** * @default null * @param ParamConfigurator|'foo'|'bar'|'baz' $value @@ -42,10 +40,10 @@ public function enumNode($value): static { $this->_usedProperties['enumNode'] = true; $this->enumNode = $value; - + return $this; } - + /** * @default null * @param ParamConfigurator|float $value @@ -55,10 +53,10 @@ public function floatNode($value): static { $this->_usedProperties['floatNode'] = true; $this->floatNode = $value; - + return $this; } - + /** * @default null * @param ParamConfigurator|int $value @@ -68,10 +66,10 @@ public function integerNode($value): static { $this->_usedProperties['integerNode'] = true; $this->integerNode = $value; - + return $this; } - + /** * @default null * @param ParamConfigurator|mixed $value @@ -81,10 +79,10 @@ public function scalarNode($value): static { $this->_usedProperties['scalarNode'] = true; $this->scalarNode = $value; - + return $this; } - + /** * @default true * @param ParamConfigurator|mixed $value @@ -94,59 +92,58 @@ public function scalarNodeWithDefault($value): static { $this->_usedProperties['scalarNodeWithDefault'] = true; $this->scalarNodeWithDefault = $value; - + return $this; } - + public function getExtensionAlias(): string { return 'primitive_types'; } - + public function __construct(array $value = []) { - if (array_key_exists('boolean_node', $value)) { $this->_usedProperties['booleanNode'] = true; $this->booleanNode = $value['boolean_node']; unset($value['boolean_node']); } - + if (array_key_exists('enum_node', $value)) { $this->_usedProperties['enumNode'] = true; $this->enumNode = $value['enum_node']; unset($value['enum_node']); } - + if (array_key_exists('float_node', $value)) { $this->_usedProperties['floatNode'] = true; $this->floatNode = $value['float_node']; unset($value['float_node']); } - + if (array_key_exists('integer_node', $value)) { $this->_usedProperties['integerNode'] = true; $this->integerNode = $value['integer_node']; unset($value['integer_node']); } - + if (array_key_exists('scalar_node', $value)) { $this->_usedProperties['scalarNode'] = true; $this->scalarNode = $value['scalar_node']; unset($value['scalar_node']); } - + if (array_key_exists('scalar_node_with_default', $value)) { $this->_usedProperties['scalarNodeWithDefault'] = true; $this->scalarNodeWithDefault = $value['scalar_node_with_default']; unset($value['scalar_node_with_default']); } - + if ([] !== $value) { throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); } } - + public function toArray(): array { $output = []; @@ -168,7 +165,7 @@ public function toArray(): array if (isset($this->_usedProperties['scalarNodeWithDefault'])) { $output['scalar_node_with_default'] = $this->scalarNodeWithDefault; } - + return $output; } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.config.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.config.php new file mode 100644 index 0000000000000..d0c6d320709c2 --- /dev/null +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.config.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Symfony\Config\ScalarNormalizedTypesConfig; + +return static function (ScalarNormalizedTypesConfig $config) { + $config + ->simpleArray('foo') + ->keyedArray('key', 'value') + ->object(true) + ->listObject('bar') + ->listObject('baz') + ->listObject()->name('qux'); + + $config + ->keyedListObject('Foo\\Bar', true) + ->keyedListObject('Foo\\Baz')->settings(['one', 'two']); + + $config->nested([ + 'nested_object' => true, + 'nested_list_object' => ['one', 'two'], + ]); +}; diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.output.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.output.php new file mode 100644 index 0000000000000..9dcf3a9f3d335 --- /dev/null +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.output.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +return [ + 'simple_array' => 'foo', + 'keyed_array' => [ + 'key' => 'value', + ], + 'object' => true, + 'list_object' => [ + 'bar', + 'baz', + ['name' => 'qux'], + ], + 'keyed_list_object' => [ + 'Foo\\Bar' => true, + 'Foo\\Baz' => [ + 'settings' => ['one', 'two'], + ], + ], + 'nested' => [ + 'nested_object' => true, + 'nested_list_object' => ['one', 'two'], + ], +]; diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.php new file mode 100644 index 0000000000000..2c33797427eed --- /dev/null +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.php @@ -0,0 +1,144 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Config\Tests\Builder\Fixtures; + +use Symfony\Component\Config\Definition\Builder\TreeBuilder; +use Symfony\Component\Config\Definition\ConfigurationInterface; + +class ScalarNormalizedTypes implements ConfigurationInterface +{ + public function getConfigTreeBuilder(): TreeBuilder + { + $tb = new TreeBuilder('scalar_normalized_types'); + $rootNode = $tb->getRootNode(); + $rootNode + ->children() + ->arrayNode('simple_array') + ->beforeNormalization()->ifString()->then(function ($v) { return [$v]; })->end() + ->prototype('scalar')->end() + ->end() + ->arrayNode('keyed_array') + ->useAttributeAsKey('name') + ->prototype('array') + ->beforeNormalization() + ->ifString()->then(function ($v) { return [$v]; }) + ->end() + ->prototype('scalar')->end() + ->end() + ->end() + ->arrayNode('object') + ->addDefaultsIfNotSet() + ->beforeNormalization() + ->ifTrue(function ($v) { return !\is_array($v); }) + ->then(function ($v) { return ['enabled' => $v]; }) + ->end() + ->children() + ->booleanNode('enabled')->defaultNull()->end() + ->scalarNode('date_format')->end() + ->booleanNode('remove_used_context_fields')->end() + ->end() + ->end() + ->arrayNode('list_object') + ->beforeNormalization() + ->always() + ->then(function ($values) { + // inspired by Workflow places + if (isset($values[0]) && \is_string($values[0])) { + return array_map(function (string $value) { + return ['name' => $value]; + }, $values); + } + + if (isset($values[0]) && \is_array($values[0])) { + return $values; + } + + foreach ($values as $name => $value) { + if (\is_array($value) && \array_key_exists('name', $value)) { + continue; + } + $value['name'] = $name; + $values[$name] = $value; + } + + return array_values($values); + }) + ->end() + ->isRequired() + ->requiresAtLeastOneElement() + ->prototype('array') + ->children() + ->scalarNode('name') + ->isRequired() + ->cannotBeEmpty() + ->end() + ->arrayNode('data') + ->normalizeKeys(false) + ->defaultValue([]) + ->prototype('variable')->end() + ->end() + ->end() + ->end() + ->end() + ->arrayNode('keyed_list_object') + ->useAttributeAsKey('class') + ->prototype('array') + ->beforeNormalization() + ->ifTrue(function ($v) { return !\is_array($v); }) + ->then(function ($v) { return ['enabled' => $v]; }) + ->end() + ->children() + ->booleanNode('enabled')->defaultTrue()->end() + ->arrayNode('settings') + ->prototype('scalar')->end() + ->end() + ->end() + ->end() + ->end() + ->arrayNode('nested') + ->children() + ->arrayNode('nested_object') + ->addDefaultsIfNotSet() + ->beforeNormalization() + ->ifTrue(function ($v) { return !\is_array($v); }) + ->then(function ($v) { return ['enabled' => $v]; }) + ->end() + ->children() + ->booleanNode('enabled')->defaultNull()->end() + ->end() + ->end() + ->arrayNode('nested_list_object') + ->beforeNormalization() + ->ifTrue(function ($v) { return isset($v[0]) && \is_string($v[0]); }) + ->then(function ($values) { + return array_map(function (string $value) { + return ['name' => $value]; + }, $values); + }) + ->end() + ->prototype('array') + ->children() + ->scalarNode('name') + ->isRequired() + ->cannotBeEmpty() + ->end() + ->end() + ->end() + ->end() + ->end() + ->end() + ->end() + ; + + return $tb; + } +} diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/KeyedListObjectConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/KeyedListObjectConfig.php new file mode 100644 index 0000000000000..4ca54c31574d0 --- /dev/null +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/KeyedListObjectConfig.php @@ -0,0 +1,75 @@ +_usedProperties['enabled'] = true; + $this->enabled = $value; + + return $this; + } + + /** + * @param ParamConfigurator|list $value + * + * @return $this + */ + public function settings(ParamConfigurator|array $value): static + { + $this->_usedProperties['settings'] = true; + $this->settings = $value; + + return $this; + } + + public function __construct(array $value = []) + { + if (array_key_exists('enabled', $value)) { + $this->_usedProperties['enabled'] = true; + $this->enabled = $value['enabled']; + unset($value['enabled']); + } + + if (array_key_exists('settings', $value)) { + $this->_usedProperties['settings'] = true; + $this->settings = $value['settings']; + unset($value['settings']); + } + + if ([] !== $value) { + throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); + } + } + + public function toArray(): array + { + $output = []; + if (isset($this->_usedProperties['enabled'])) { + $output['enabled'] = $this->enabled; + } + if (isset($this->_usedProperties['settings'])) { + $output['settings'] = $this->settings; + } + + return $output; + } + +} diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/ListObjectConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/ListObjectConfig.php new file mode 100644 index 0000000000000..47217f41418bb --- /dev/null +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/ListObjectConfig.php @@ -0,0 +1,75 @@ +_usedProperties['name'] = true; + $this->name = $value; + + return $this; + } + + /** + * @param ParamConfigurator|list $value + * + * @return $this + */ + public function data(ParamConfigurator|array $value): static + { + $this->_usedProperties['data'] = true; + $this->data = $value; + + return $this; + } + + public function __construct(array $value = []) + { + if (array_key_exists('name', $value)) { + $this->_usedProperties['name'] = true; + $this->name = $value['name']; + unset($value['name']); + } + + if (array_key_exists('data', $value)) { + $this->_usedProperties['data'] = true; + $this->data = $value['data']; + unset($value['data']); + } + + if ([] !== $value) { + throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); + } + } + + public function toArray(): array + { + $output = []; + if (isset($this->_usedProperties['name'])) { + $output['name'] = $this->name; + } + if (isset($this->_usedProperties['data'])) { + $output['data'] = $this->data; + } + + return $output; + } + +} diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/Nested/NestedListObjectConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/Nested/NestedListObjectConfig.php new file mode 100644 index 0000000000000..52ebc9b09700a --- /dev/null +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/Nested/NestedListObjectConfig.php @@ -0,0 +1,52 @@ +_usedProperties['name'] = true; + $this->name = $value; + + return $this; + } + + public function __construct(array $value = []) + { + if (array_key_exists('name', $value)) { + $this->_usedProperties['name'] = true; + $this->name = $value['name']; + unset($value['name']); + } + + if ([] !== $value) { + throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); + } + } + + public function toArray(): array + { + $output = []; + if (isset($this->_usedProperties['name'])) { + $output['name'] = $this->name; + } + + return $output; + } + +} diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/Nested/NestedObjectConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/Nested/NestedObjectConfig.php new file mode 100644 index 0000000000000..00d4d72620b3e --- /dev/null +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/Nested/NestedObjectConfig.php @@ -0,0 +1,52 @@ +_usedProperties['enabled'] = true; + $this->enabled = $value; + + return $this; + } + + public function __construct(array $value = []) + { + if (array_key_exists('enabled', $value)) { + $this->_usedProperties['enabled'] = true; + $this->enabled = $value['enabled']; + unset($value['enabled']); + } + + if ([] !== $value) { + throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); + } + } + + public function toArray(): array + { + $output = []; + if (isset($this->_usedProperties['enabled'])) { + $output['enabled'] = $this->enabled; + } + + return $output; + } + +} diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/NestedConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/NestedConfig.php new file mode 100644 index 0000000000000..08540ced245d0 --- /dev/null +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/NestedConfig.php @@ -0,0 +1,89 @@ +_usedProperties['nestedObject'] = true; + $this->nestedObject = $value; + + return $this; + } + + if (!$this->nestedObject instanceof \Symfony\Config\ScalarNormalizedTypes\Nested\NestedObjectConfig) { + $this->_usedProperties['nestedObject'] = true; + $this->nestedObject = new \Symfony\Config\ScalarNormalizedTypes\Nested\NestedObjectConfig($value); + } elseif (0 < \func_num_args()) { + throw new InvalidConfigurationException('The node created by "nestedObject()" has already been initialized. You cannot pass values the second time you call nestedObject().'); + } + + return $this->nestedObject; + } + + /** + * @return \Symfony\Config\ScalarNormalizedTypes\Nested\NestedListObjectConfig|$this + */ + public function nestedListObject(mixed $value = []): \Symfony\Config\ScalarNormalizedTypes\Nested\NestedListObjectConfig|static + { + $this->_usedProperties['nestedListObject'] = true; + if (!\is_array($value)) { + $this->nestedListObject[] = $value; + + return $this; + } + + return $this->nestedListObject[] = new \Symfony\Config\ScalarNormalizedTypes\Nested\NestedListObjectConfig($value); + } + + public function __construct(array $value = []) + { + if (array_key_exists('nested_object', $value)) { + $this->_usedProperties['nestedObject'] = true; + $this->nestedObject = \is_array($value['nested_object']) ? new \Symfony\Config\ScalarNormalizedTypes\Nested\NestedObjectConfig($value['nested_object']) : $value['nested_object']; + unset($value['nested_object']); + } + + if (array_key_exists('nested_list_object', $value)) { + $this->_usedProperties['nestedListObject'] = true; + $this->nestedListObject = array_map(function ($v) { return \is_array($v) ? new \Symfony\Config\ScalarNormalizedTypes\Nested\NestedListObjectConfig($v) : $v; }, $value['nested_list_object']); + unset($value['nested_list_object']); + } + + if ([] !== $value) { + throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); + } + } + + public function toArray(): array + { + $output = []; + if (isset($this->_usedProperties['nestedObject'])) { + $output['nested_object'] = $this->nestedObject instanceof \Symfony\Config\ScalarNormalizedTypes\Nested\NestedObjectConfig ? $this->nestedObject->toArray() : $this->nestedObject; + } + if (isset($this->_usedProperties['nestedListObject'])) { + $output['nested_list_object'] = array_map(function ($v) { return $v instanceof \Symfony\Config\ScalarNormalizedTypes\Nested\NestedListObjectConfig ? $v->toArray() : $v; }, $this->nestedListObject); + } + + return $output; + } + +} diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/ObjectConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/ObjectConfig.php new file mode 100644 index 0000000000000..00d1a573a9369 --- /dev/null +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/ObjectConfig.php @@ -0,0 +1,98 @@ +_usedProperties['enabled'] = true; + $this->enabled = $value; + + return $this; + } + + /** + * @default null + * @param ParamConfigurator|mixed $value + * @return $this + */ + public function dateFormat($value): static + { + $this->_usedProperties['dateFormat'] = true; + $this->dateFormat = $value; + + return $this; + } + + /** + * @default null + * @param ParamConfigurator|bool $value + * @return $this + */ + public function removeUsedContextFields($value): static + { + $this->_usedProperties['removeUsedContextFields'] = true; + $this->removeUsedContextFields = $value; + + return $this; + } + + public function __construct(array $value = []) + { + if (array_key_exists('enabled', $value)) { + $this->_usedProperties['enabled'] = true; + $this->enabled = $value['enabled']; + unset($value['enabled']); + } + + if (array_key_exists('date_format', $value)) { + $this->_usedProperties['dateFormat'] = true; + $this->dateFormat = $value['date_format']; + unset($value['date_format']); + } + + if (array_key_exists('remove_used_context_fields', $value)) { + $this->_usedProperties['removeUsedContextFields'] = true; + $this->removeUsedContextFields = $value['remove_used_context_fields']; + unset($value['remove_used_context_fields']); + } + + if ([] !== $value) { + throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); + } + } + + public function toArray(): array + { + $output = []; + if (isset($this->_usedProperties['enabled'])) { + $output['enabled'] = $this->enabled; + } + if (isset($this->_usedProperties['dateFormat'])) { + $output['date_format'] = $this->dateFormat; + } + if (isset($this->_usedProperties['removeUsedContextFields'])) { + $output['remove_used_context_fields'] = $this->removeUsedContextFields; + } + + return $output; + } + +} diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypesConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypesConfig.php new file mode 100644 index 0000000000000..244c0405a1d31 --- /dev/null +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypesConfig.php @@ -0,0 +1,195 @@ +_usedProperties['simpleArray'] = true; + $this->simpleArray = $value; + + return $this; + } + + /** + * @return $this + */ + public function keyedArray(string $name, mixed $value): static + { + $this->_usedProperties['keyedArray'] = true; + $this->keyedArray[$name] = $value; + + return $this; + } + + /** + * @default {"enabled":null} + * @return \Symfony\Config\ScalarNormalizedTypes\ObjectConfig|$this + */ + public function object(mixed $value = []): \Symfony\Config\ScalarNormalizedTypes\ObjectConfig|static + { + if (!\is_array($value)) { + $this->_usedProperties['object'] = true; + $this->object = $value; + + return $this; + } + + if (!$this->object instanceof \Symfony\Config\ScalarNormalizedTypes\ObjectConfig) { + $this->_usedProperties['object'] = true; + $this->object = new \Symfony\Config\ScalarNormalizedTypes\ObjectConfig($value); + } elseif (0 < \func_num_args()) { + throw new InvalidConfigurationException('The node created by "object()" has already been initialized. You cannot pass values the second time you call object().'); + } + + return $this->object; + } + + /** + * @return \Symfony\Config\ScalarNormalizedTypes\ListObjectConfig|$this + */ + public function listObject(mixed $value = []): \Symfony\Config\ScalarNormalizedTypes\ListObjectConfig|static + { + $this->_usedProperties['listObject'] = true; + if (!\is_array($value)) { + $this->listObject[] = $value; + + return $this; + } + + return $this->listObject[] = new \Symfony\Config\ScalarNormalizedTypes\ListObjectConfig($value); + } + + /** + * @return \Symfony\Config\ScalarNormalizedTypes\KeyedListObjectConfig|$this + */ + public function keyedListObject(string $class, mixed $value = []): \Symfony\Config\ScalarNormalizedTypes\KeyedListObjectConfig|static + { + if (!\is_array($value)) { + $this->_usedProperties['keyedListObject'] = true; + $this->keyedListObject[$class] = $value; + + return $this; + } + + if (!isset($this->keyedListObject[$class]) || !$this->keyedListObject[$class] instanceof \Symfony\Config\ScalarNormalizedTypes\KeyedListObjectConfig) { + $this->_usedProperties['keyedListObject'] = true; + $this->keyedListObject[$class] = new \Symfony\Config\ScalarNormalizedTypes\KeyedListObjectConfig($value); + } elseif (1 < \func_num_args()) { + throw new InvalidConfigurationException('The node created by "keyedListObject()" has already been initialized. You cannot pass values the second time you call keyedListObject().'); + } + + return $this->keyedListObject[$class]; + } + + public function nested(array $value = []): \Symfony\Config\ScalarNormalizedTypes\NestedConfig + { + if (null === $this->nested) { + $this->_usedProperties['nested'] = true; + $this->nested = new \Symfony\Config\ScalarNormalizedTypes\NestedConfig($value); + } elseif (0 < \func_num_args()) { + throw new InvalidConfigurationException('The node created by "nested()" has already been initialized. You cannot pass values the second time you call nested().'); + } + + return $this->nested; + } + + public function getExtensionAlias(): string + { + return 'scalar_normalized_types'; + } + + public function __construct(array $value = []) + { + if (array_key_exists('simple_array', $value)) { + $this->_usedProperties['simpleArray'] = true; + $this->simpleArray = $value['simple_array']; + unset($value['simple_array']); + } + + if (array_key_exists('keyed_array', $value)) { + $this->_usedProperties['keyedArray'] = true; + $this->keyedArray = $value['keyed_array']; + unset($value['keyed_array']); + } + + if (array_key_exists('object', $value)) { + $this->_usedProperties['object'] = true; + $this->object = \is_array($value['object']) ? new \Symfony\Config\ScalarNormalizedTypes\ObjectConfig($value['object']) : $value['object']; + unset($value['object']); + } + + if (array_key_exists('list_object', $value)) { + $this->_usedProperties['listObject'] = true; + $this->listObject = array_map(function ($v) { return \is_array($v) ? new \Symfony\Config\ScalarNormalizedTypes\ListObjectConfig($v) : $v; }, $value['list_object']); + unset($value['list_object']); + } + + if (array_key_exists('keyed_list_object', $value)) { + $this->_usedProperties['keyedListObject'] = true; + $this->keyedListObject = array_map(function ($v) { return \is_array($v) ? new \Symfony\Config\ScalarNormalizedTypes\KeyedListObjectConfig($v) : $v; }, $value['keyed_list_object']); + unset($value['keyed_list_object']); + } + + if (array_key_exists('nested', $value)) { + $this->_usedProperties['nested'] = true; + $this->nested = new \Symfony\Config\ScalarNormalizedTypes\NestedConfig($value['nested']); + unset($value['nested']); + } + + if ([] !== $value) { + throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); + } + } + + public function toArray(): array + { + $output = []; + if (isset($this->_usedProperties['simpleArray'])) { + $output['simple_array'] = $this->simpleArray; + } + if (isset($this->_usedProperties['keyedArray'])) { + $output['keyed_array'] = $this->keyedArray; + } + if (isset($this->_usedProperties['object'])) { + $output['object'] = $this->object instanceof \Symfony\Config\ScalarNormalizedTypes\ObjectConfig ? $this->object->toArray() : $this->object; + } + if (isset($this->_usedProperties['listObject'])) { + $output['list_object'] = array_map(function ($v) { return $v instanceof \Symfony\Config\ScalarNormalizedTypes\ListObjectConfig ? $v->toArray() : $v; }, $this->listObject); + } + if (isset($this->_usedProperties['keyedListObject'])) { + $output['keyed_list_object'] = array_map(function ($v) { return $v instanceof \Symfony\Config\ScalarNormalizedTypes\KeyedListObjectConfig ? $v->toArray() : $v; }, $this->keyedListObject); + } + if (isset($this->_usedProperties['nested'])) { + $output['nested'] = $this->nested->toArray(); + } + + return $output; + } + +} diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType.config.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType.config.php index 10b70bf6d26f9..ed65c1f2c36cb 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType.config.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType.config.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + use Symfony\Config\VariableTypeConfig; return static function (VariableTypeConfig $config) { diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType.output.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType.output.php index 87c38a584a28a..71ef3f426a98a 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType.output.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType.output.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + return [ 'any_value' => 'foobar', ]; diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType.php index c3fa62cfd9e49..11a8bea6f8674 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType.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\Config\Tests\Builder\Fixtures; use Symfony\Component\Config\Definition\Builder\TreeBuilder; diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType/Symfony/Config/VariableTypeConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType/Symfony/Config/VariableTypeConfig.php index 12ce07dca1709..6cfd617932c82 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType/Symfony/Config/VariableTypeConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType/Symfony/Config/VariableTypeConfig.php @@ -2,11 +2,9 @@ namespace Symfony\Config; - use Symfony\Component\Config\Loader\ParamConfigurator; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; - /** * This class is automatically generated to help in creating a config. */ @@ -14,7 +12,7 @@ class VariableTypeConfig implements \Symfony\Component\Config\Builder\ConfigBuil { private $anyValue; private $_usedProperties = []; - + /** * @default null * @param ParamConfigurator|mixed $value @@ -25,36 +23,35 @@ public function anyValue(mixed $value): static { $this->_usedProperties['anyValue'] = true; $this->anyValue = $value; - + return $this; } - + public function getExtensionAlias(): string { return 'variable_type'; } - + public function __construct(array $value = []) { - if (array_key_exists('any_value', $value)) { $this->_usedProperties['anyValue'] = true; $this->anyValue = $value['any_value']; unset($value['any_value']); } - + if ([] !== $value) { throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); } } - + public function toArray(): array { $output = []; if (isset($this->_usedProperties['anyValue'])) { $output['any_value'] = $this->anyValue; } - + return $output; } diff --git a/src/Symfony/Component/Config/Tests/Builder/GeneratedConfigTest.php b/src/Symfony/Component/Config/Tests/Builder/GeneratedConfigTest.php index 0c80f15ec8e71..e6ef8973765c4 100644 --- a/src/Symfony/Component/Config/Tests/Builder/GeneratedConfigTest.php +++ b/src/Symfony/Component/Config/Tests/Builder/GeneratedConfigTest.php @@ -56,6 +56,7 @@ protected function tearDown(): void public function fixtureNames() { $array = [ + 'ScalarNormalizedTypes' => 'scalar_normalized_types', 'PrimitiveTypes' => 'primitive_types', 'VariableType' => 'variable_type', 'AddToList' => 'add_to_list', diff --git a/src/Symfony/Component/Config/Tests/Fixtures/some.phar b/src/Symfony/Component/Config/Tests/Fixtures/some.phar new file mode 100644 index 0000000000000..93d4e87c0b89b Binary files /dev/null and b/src/Symfony/Component/Config/Tests/Fixtures/some.phar differ diff --git a/src/Symfony/Component/Config/Tests/Resource/GlobResourceTest.php b/src/Symfony/Component/Config/Tests/Resource/GlobResourceTest.php index ed823584d7564..06fefcd6113dd 100644 --- a/src/Symfony/Component/Config/Tests/Resource/GlobResourceTest.php +++ b/src/Symfony/Component/Config/Tests/Resource/GlobResourceTest.php @@ -205,4 +205,29 @@ public function testSerializeUnserialize() $this->assertEquals($p->getValue($resource), $p->getValue($newResource)); } + + public function testPhar() + { + $s = \DIRECTORY_SEPARATOR; + $cwd = getcwd(); + chdir(\dirname(__DIR__).'/Fixtures'); + try { + $resource = new GlobResource('phar://some.phar', '*', true); + $files = array_keys(iterator_to_array($resource)); + $this->assertSame(["phar://some.phar{$s}ProjectWithXsdExtensionInPhar.php", "phar://some.phar{$s}schema{$s}project-1.0.xsd"], $files); + + $resource = new GlobResource("phar://some.phar{$s}ProjectWithXsdExtensionInPhar.php", '', true); + $files = array_keys(iterator_to_array($resource)); + $this->assertSame(["phar://some.phar{$s}ProjectWithXsdExtensionInPhar.php"], $files); + } finally { + chdir($cwd); + } + } + + public function testFilePrefix() + { + $resource = new GlobResource(__FILE__, '/**/', true); + $files = array_keys(iterator_to_array($resource)); + $this->assertSame([], $files); + } } diff --git a/src/Symfony/Component/Console/Completion/Output/BashCompletionOutput.php b/src/Symfony/Component/Console/Completion/Output/BashCompletionOutput.php index 8d5ffa6b67d4b..c6f76eb8fbd40 100644 --- a/src/Symfony/Component/Console/Completion/Output/BashCompletionOutput.php +++ b/src/Symfony/Component/Console/Completion/Output/BashCompletionOutput.php @@ -24,6 +24,9 @@ public function write(CompletionSuggestions $suggestions, OutputInterface $outpu $values = $suggestions->getValueSuggestions(); foreach ($suggestions->getOptionSuggestions() as $option) { $values[] = '--'.$option->getName(); + if ($option->isNegatable()) { + $values[] = '--no-'.$option->getName(); + } } $output->writeln(implode("\n", $values)); } diff --git a/src/Symfony/Component/Console/Completion/Output/FishCompletionOutput.php b/src/Symfony/Component/Console/Completion/Output/FishCompletionOutput.php index 9b02f09aa8250..d2c414e487511 100644 --- a/src/Symfony/Component/Console/Completion/Output/FishCompletionOutput.php +++ b/src/Symfony/Component/Console/Completion/Output/FishCompletionOutput.php @@ -24,6 +24,9 @@ public function write(CompletionSuggestions $suggestions, OutputInterface $outpu $values = $suggestions->getValueSuggestions(); foreach ($suggestions->getOptionSuggestions() as $option) { $values[] = '--'.$option->getName(); + if ($option->isNegatable()) { + $values[] = '--no-'.$option->getName(); + } } $output->write(implode("\n", $values)); } diff --git a/src/Symfony/Component/Console/Tests/Command/CompleteCommandTest.php b/src/Symfony/Component/Console/Tests/Command/CompleteCommandTest.php index 102f490a4ff05..87c64504b499f 100644 --- a/src/Symfony/Component/Console/Tests/Command/CompleteCommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/CompleteCommandTest.php @@ -119,9 +119,9 @@ public function testCompleteCommandInputDefinition(array $input, array $suggesti public function provideCompleteCommandInputDefinitionInputs() { - yield 'definition' => [['bin/console', 'hello', '-'], ['--help', '--quiet', '--verbose', '--version', '--ansi', '--no-interaction']]; + yield 'definition' => [['bin/console', 'hello', '-'], ['--help', '--quiet', '--verbose', '--version', '--ansi', '--no-ansi', '--no-interaction']]; yield 'custom' => [['bin/console', 'hello'], ['Fabien', 'Robin', 'Wouter']]; - yield 'definition-aliased' => [['bin/console', 'ahoy', '-'], ['--help', '--quiet', '--verbose', '--version', '--ansi', '--no-interaction']]; + yield 'definition-aliased' => [['bin/console', 'ahoy', '-'], ['--help', '--quiet', '--verbose', '--version', '--ansi', '--no-ansi', '--no-interaction']]; yield 'custom-aliased' => [['bin/console', 'ahoy'], ['Fabien', 'Robin', 'Wouter']]; } diff --git a/src/Symfony/Component/Console/Tests/Completion/Output/BashCompletionOutputTest.php b/src/Symfony/Component/Console/Tests/Completion/Output/BashCompletionOutputTest.php new file mode 100644 index 0000000000000..84ec56accbbfd --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Completion/Output/BashCompletionOutputTest.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Tests\Completion\Output; + +use Symfony\Component\Console\Completion\Output\BashCompletionOutput; +use Symfony\Component\Console\Completion\Output\CompletionOutputInterface; + +class BashCompletionOutputTest extends CompletionOutputTestCase +{ + public function getCompletionOutput(): CompletionOutputInterface + { + return new BashCompletionOutput(); + } + + public function getExpectedOptionsOutput(): string + { + return "--option1\n--negatable\n--no-negatable".\PHP_EOL; + } + + public function getExpectedValuesOutput(): string + { + return "Green\nRed\nYellow".\PHP_EOL; + } +} diff --git a/src/Symfony/Component/Console/Tests/Completion/Output/CompletionOutputTestCase.php b/src/Symfony/Component/Console/Tests/Completion/Output/CompletionOutputTestCase.php new file mode 100644 index 0000000000000..c4551e5b67b70 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Completion/Output/CompletionOutputTestCase.php @@ -0,0 +1,51 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Tests\Completion\Output; + +use PHPUnit\Framework\TestCase; +use Symfony\Component\Console\Completion\CompletionSuggestions; +use Symfony\Component\Console\Completion\Output\CompletionOutputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\StreamOutput; + +abstract class CompletionOutputTestCase extends TestCase +{ + abstract public function getCompletionOutput(): CompletionOutputInterface; + + abstract public function getExpectedOptionsOutput(): string; + + abstract public function getExpectedValuesOutput(): string; + + public function testOptionsOutput() + { + $options = [ + new InputOption('option1', 'o', InputOption::VALUE_NONE), + new InputOption('negatable', null, InputOption::VALUE_NEGATABLE), + ]; + $suggestions = new CompletionSuggestions(); + $suggestions->suggestOptions($options); + $stream = fopen('php://memory', 'rw+'); + $this->getCompletionOutput()->write($suggestions, new StreamOutput($stream)); + fseek($stream, 0); + $this->assertEquals($this->getExpectedOptionsOutput(), stream_get_contents($stream)); + } + + public function testValuesOutput() + { + $suggestions = new CompletionSuggestions(); + $suggestions->suggestValues(['Green', 'Red', 'Yellow']); + $stream = fopen('php://memory', 'rw+'); + $this->getCompletionOutput()->write($suggestions, new StreamOutput($stream)); + fseek($stream, 0); + $this->assertEquals($this->getExpectedValuesOutput(), stream_get_contents($stream)); + } +} diff --git a/src/Symfony/Component/Console/Tests/Completion/Output/FishCompletionOutputTest.php b/src/Symfony/Component/Console/Tests/Completion/Output/FishCompletionOutputTest.php new file mode 100644 index 0000000000000..2e615d04016ee --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Completion/Output/FishCompletionOutputTest.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Tests\Completion\Output; + +use Symfony\Component\Console\Completion\Output\CompletionOutputInterface; +use Symfony\Component\Console\Completion\Output\FishCompletionOutput; + +class FishCompletionOutputTest extends CompletionOutputTestCase +{ + public function getCompletionOutput(): CompletionOutputInterface + { + return new FishCompletionOutput(); + } + + public function getExpectedOptionsOutput(): string + { + return "--option1\n--negatable\n--no-negatable"; + } + + public function getExpectedValuesOutput(): string + { + return "Green\nRed\nYellow"; + } +} diff --git a/src/Symfony/Component/DependencyInjection/Compiler/DecoratorServicePass.php b/src/Symfony/Component/DependencyInjection/Compiler/DecoratorServicePass.php index a0c45d1cf1a89..ac3ca8b29bab5 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/DecoratorServicePass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/DecoratorServicePass.php @@ -40,6 +40,10 @@ public function process(ContainerBuilder $container) } $decoratingDefinitions = []; + $tagsToKeep = $container->hasParameter('container.behavior_describing_tags') + ? $container->getParameter('container.behavior_describing_tags') + : ['container.do_not_inline', 'container.service_locator', 'container.service_subscriber']; + foreach ($definitions as [$id, $definition]) { $decoratedService = $definition->getDecoratedService(); [$inner, $renamedId] = $decoratedService; @@ -90,8 +94,8 @@ public function process(ContainerBuilder $container) $decoratingTags = $decoratingDefinition->getTags(); $resetTags = []; - // container.service_locator and container.service_subscriber have special logic and they must not be transferred out to decorators - foreach (['container.service_locator', 'container.service_subscriber'] as $containerTag) { + // Behavior-describing tags must not be transferred out to decorators + foreach ($tagsToKeep as $containerTag) { if (isset($decoratingTags[$containerTag])) { $resetTags[$containerTag] = $decoratingTags[$containerTag]; unset($decoratingTags[$containerTag]); diff --git a/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php index b65f56a17be4e..9ccf834664e32 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php @@ -163,7 +163,7 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed */ private function isInlineableDefinition(string $id, Definition $definition): bool { - if ($definition->hasErrors() || $definition->isDeprecated() || $definition->isLazy() || $definition->isSynthetic()) { + if ($definition->hasErrors() || $definition->isDeprecated() || $definition->isLazy() || $definition->isSynthetic() || $definition->hasTag('container.do_not_inline')) { return false; } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/RegisterAutoconfigureAttributesPass.php b/src/Symfony/Component/DependencyInjection/Compiler/RegisterAutoconfigureAttributesPass.php index de18b501f15c0..6c9c180448fb5 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/RegisterAutoconfigureAttributesPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/RegisterAutoconfigureAttributesPass.php @@ -77,7 +77,8 @@ private static function registerForAutoconfiguration(ContainerBuilder $container ], ], ], - $class->getFileName() + $class->getFileName(), + false ); }; diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveChildDefinitionsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveChildDefinitionsPass.php index 46a2e04fd6b65..934132bd9af77 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveChildDefinitionsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveChildDefinitionsPass.php @@ -188,6 +188,12 @@ private function doResolveDefinition(ChildDefinition $definition): Definition // and it's not legal on an instanceof $def->setAutoconfigured($definition->isAutoconfigured()); + if (!$def->hasTag('proxy')) { + foreach ($parentDef->getTag('proxy') as $v) { + $def->addTag('proxy', $v); + } + } + return $def; } } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveParameterPlaceHoldersPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveParameterPlaceHoldersPass.php index 6b381913d11d2..07631de6ec622 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveParameterPlaceHoldersPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveParameterPlaceHoldersPass.php @@ -84,6 +84,11 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed if (isset($changes['file'])) { $value->setFile($this->bag->resolveValue($value->getFile())); } + $tags = $value->getTags(); + if (isset($tags['proxy'])) { + $tags['proxy'] = $this->bag->resolveValue($tags['proxy']); + $value->setTags($tags); + } } $value = parent::processValue($value, $isRoot); diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index 9b480a3810580..c47db72c1d79b 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -220,7 +220,7 @@ private function parseImports(array $content, string $file) } } - private function parseDefinitions(array $content, string $file) + private function parseDefinitions(array $content, string $file, bool $trackBindings = true) { if (!isset($content['services'])) { return; @@ -246,14 +246,14 @@ private function parseDefinitions(array $content, string $file) if (\is_string($service) && str_starts_with($service, '@')) { throw new InvalidArgumentException(sprintf('Type definition "%s" cannot be an alias within "_instanceof" in "%s". Check your YAML syntax.', $id, $file)); } - $this->parseDefinition($id, $service, $file, []); + $this->parseDefinition($id, $service, $file, [], false, $trackBindings); } } $this->isLoadingInstanceof = false; $defaults = $this->parseDefaults($content, $file); foreach ($content['services'] as $id => $service) { - $this->parseDefinition($id, $service, $file, $defaults); + $this->parseDefinition($id, $service, $file, $defaults, false, $trackBindings); } } @@ -338,7 +338,7 @@ private function isUsingShortSyntax(array $service): bool /** * @throws InvalidArgumentException When tags are invalid */ - private function parseDefinition(string $id, array|string|null $service, string $file, array $defaults, bool $return = false) + private function parseDefinition(string $id, array|string|null $service, string $file, array $defaults, bool $return = false, bool $trackBindings = true) { if (preg_match('/^_[a-zA-Z0-9_]*$/', $id)) { throw new InvalidArgumentException(sprintf('Service names that start with an underscore are reserved. Rename the "%s" service or define it in XML instead.', $id)); @@ -662,7 +662,7 @@ private function parseDefinition(string $id, array|string|null $service, string $bindingType = $this->isLoadingInstanceof ? BoundArgument::INSTANCEOF_BINDING : BoundArgument::SERVICE_BINDING; foreach ($bindings as $argument => $value) { if (!$value instanceof BoundArgument) { - $bindings[$argument] = new BoundArgument($value, true, $bindingType, $file); + $bindings[$argument] = new BoundArgument($value, $trackBindings, $bindingType, $file); } } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php index 2fb01ad78d741..5064c1f75fe1e 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php @@ -323,6 +323,34 @@ public function testProcessDoesNotSetLazyArgumentValuesAfterInlining() $this->assertSame('inline', (string) $values[0]); } + public function testDoNotInline() + { + $container = new ContainerBuilder(); + $container->register('decorated1', 'decorated1')->addTag('container.do_not_inline'); + $container->register('decorated2', 'decorated2')->addTag('container.do_not_inline'); + $container->setAlias('alias2', 'decorated2'); + + $container + ->register('s1', 's1') + ->setDecoratedService('decorated1') + ->setPublic(true) + ->setProperties(['inner' => new Reference('s1.inner')]); + + $container + ->register('s2', 's2') + ->setDecoratedService('alias2') + ->setPublic(true) + ->setProperties(['inner' => new Reference('s2.inner')]); + + $container->compile(); + + $this->assertFalse($container->hasAlias('alias2')); + $this->assertEquals(new Reference('decorated2'), $container->getDefinition('s2')->getProperties()['inner']); + $this->assertEquals(new Reference('s1.inner'), $container->getDefinition('s1')->getProperties()['inner']); + $this->assertSame('decorated2', $container->getDefinition('decorated2')->getClass()); + $this->assertSame('decorated1', $container->getDefinition('s1.inner')->getClass()); + } + protected function process(ContainerBuilder $container) { (new InlineServiceDefinitionsPass(new AnalyzeServiceReferencesPass()))->process($container); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterAutoconfigureAttributesPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterAutoconfigureAttributesPassTest.php index 18db622baf64c..deaa2fbac3935 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterAutoconfigureAttributesPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterAutoconfigureAttributesPassTest.php @@ -31,7 +31,7 @@ public function testProcess() (new RegisterAutoconfigureAttributesPass())->process($container); - $argument = new BoundArgument(1, true, BoundArgument::INSTANCEOF_BINDING, realpath(__DIR__.'/../Fixtures/AutoconfigureAttributed.php')); + $argument = new BoundArgument(1, false, BoundArgument::INSTANCEOF_BINDING, realpath(__DIR__.'/../Fixtures/AutoconfigureAttributed.php')); $values = $argument->getValues(); --$values[1]; $argument->setValues($values); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveChildDefinitionsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveChildDefinitionsPassTest.php index 4be6f803cd936..d6b1013c31af3 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveChildDefinitionsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveChildDefinitionsPassTest.php @@ -118,6 +118,31 @@ public function testProcessDoesNotCopyTags() $this->assertEquals([], $def->getTags()); } + public function testProcessCopiesTagsProxy() + { + $container = new ContainerBuilder(); + + $container + ->register('parent') + ->addTag('proxy', ['a' => 'b']) + ; + + $container + ->setDefinition('child1', new ChildDefinition('parent')) + ; + $container + ->setDefinition('child2', (new ChildDefinition('parent'))->addTag('proxy', ['c' => 'd'])) + ; + + $this->process($container); + + $def = $container->getDefinition('child1'); + $this->assertSame(['proxy' => [['a' => 'b']]], $def->getTags()); + + $def = $container->getDefinition('child2'); + $this->assertSame(['proxy' => [['c' => 'd']]], $def->getTags()); + } + public function testProcessDoesNotCopyDecoratedService() { $container = new ContainerBuilder(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php index c586e72c2acbc..96c45205459df 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php @@ -97,6 +97,20 @@ public function testParameterNotFoundExceptionsIsNotThrown() $this->assertCount(1, $definition->getErrors()); } + public function testOnlyProxyTagIsResolved() + { + $containerBuilder = new ContainerBuilder(); + $containerBuilder->setParameter('a_param', 'here_you_go'); + $definition = $containerBuilder->register('def'); + $definition->addTag('foo', ['bar' => '%a_param%']); + $definition->addTag('proxy', ['interface' => '%a_param%']); + + $pass = new ResolveParameterPlaceHoldersPass(true, false); + $pass->process($containerBuilder); + + $this->assertSame(['foo' => [['bar' => '%a_param%']], 'proxy' => [['interface' => 'here_you_go']]], $definition->getTags()); + } + private function createContainerBuilder(): ContainerBuilder { $containerBuilder = new ContainerBuilder(); diff --git a/src/Symfony/Component/ErrorHandler/Internal/TentativeTypes.php b/src/Symfony/Component/ErrorHandler/Internal/TentativeTypes.php index ee403b3d1b078..2168a1c075816 100644 --- a/src/Symfony/Component/ErrorHandler/Internal/TentativeTypes.php +++ b/src/Symfony/Component/ErrorHandler/Internal/TentativeTypes.php @@ -37,7 +37,7 @@ class TentativeTypes 'DateTime' => [ '__wakeup' => 'void', '__set_state' => 'DateTime', - 'createFromImmutable' => 'DateTime', + 'createFromImmutable' => 'static', 'createFromFormat' => 'DateTime|false', 'getLastErrors' => 'array|false', 'format' => 'string', @@ -72,7 +72,7 @@ class TentativeTypes 'setDate' => 'DateTimeImmutable', 'setISODate' => 'DateTimeImmutable', 'setTimestamp' => 'DateTimeImmutable', - 'createFromMutable' => 'DateTimeImmutable', + 'createFromMutable' => 'static', ], 'DateTimeZone' => [ 'getName' => 'string', @@ -1150,8 +1150,8 @@ class TentativeTypes 'getFlags' => 'int', 'setMaxLineLen' => 'void', 'getMaxLineLen' => 'int', - 'hasChildren' => 'bool', - 'getChildren' => '?RecursiveIterator', + 'hasChildren' => 'false', + 'getChildren' => 'null', 'seek' => 'void', 'getCurrentLine' => 'string', ], @@ -1240,7 +1240,7 @@ class TentativeTypes 'current' => 'never', 'next' => 'void', 'key' => 'never', - 'valid' => 'bool', + 'valid' => 'false', 'rewind' => 'void', ], 'CallbackFilterIterator' => [ diff --git a/src/Symfony/Component/ExpressionLanguage/Node/GetAttrNode.php b/src/Symfony/Component/ExpressionLanguage/Node/GetAttrNode.php index edcec01374749..f5a14879528df 100644 --- a/src/Symfony/Component/ExpressionLanguage/Node/GetAttrNode.php +++ b/src/Symfony/Component/ExpressionLanguage/Node/GetAttrNode.php @@ -24,6 +24,8 @@ class GetAttrNode extends Node public const METHOD_CALL = 2; public const ARRAY_CALL = 3; + private bool $isShortCircuited = false; + public function __construct(Node $node, Node $attribute, ArrayNode $arguments, int $type) { parent::__construct( @@ -70,9 +72,16 @@ public function evaluate(array $functions, array $values) switch ($this->attributes['type']) { case self::PROPERTY_CALL: $obj = $this->nodes['node']->evaluate($functions, $values); + if (null === $obj && $this->nodes['attribute']->isNullSafe) { + $this->isShortCircuited = true; + + return null; + } + if (null === $obj && $this->isShortCircuited()) { return null; } + if (!\is_object($obj)) { throw new \RuntimeException(sprintf('Unable to get property "%s" of non-object "%s".', $this->nodes['attribute']->dump(), $this->nodes['node']->dump())); } @@ -83,9 +92,16 @@ public function evaluate(array $functions, array $values) case self::METHOD_CALL: $obj = $this->nodes['node']->evaluate($functions, $values); + if (null === $obj && $this->nodes['attribute']->isNullSafe) { + $this->isShortCircuited = true; + + return null; + } + if (null === $obj && $this->isShortCircuited()) { return null; } + if (!\is_object($obj)) { throw new \RuntimeException(sprintf('Unable to call method "%s" of non-object "%s".', $this->nodes['attribute']->dump(), $this->nodes['node']->dump())); } @@ -97,6 +113,11 @@ public function evaluate(array $functions, array $values) case self::ARRAY_CALL: $array = $this->nodes['node']->evaluate($functions, $values); + + if (null === $array && $this->isShortCircuited()) { + return null; + } + if (!\is_array($array) && !$array instanceof \ArrayAccess) { throw new \RuntimeException(sprintf('Unable to get an item of non-array "%s".', $this->nodes['node']->dump())); } @@ -105,6 +126,13 @@ public function evaluate(array $functions, array $values) } } + private function isShortCircuited(): bool + { + return $this->isShortCircuited + || ($this->nodes['node'] instanceof self && $this->nodes['node']->isShortCircuited()) + ; + } + public function toArray() { switch ($this->attributes['type']) { diff --git a/src/Symfony/Component/ExpressionLanguage/Tests/ExpressionLanguageTest.php b/src/Symfony/Component/ExpressionLanguage/Tests/ExpressionLanguageTest.php index 1f9770972f5e6..2c66d52927e58 100644 --- a/src/Symfony/Component/ExpressionLanguage/Tests/ExpressionLanguageTest.php +++ b/src/Symfony/Component/ExpressionLanguage/Tests/ExpressionLanguageTest.php @@ -249,13 +249,13 @@ public function testNullSafeEvaluate($expression, $foo) /** * @dataProvider provideNullSafe */ - public function testNullsafeCompile($expression, $foo) + public function testNullSafeCompile($expression, $foo) { $expressionLanguage = new ExpressionLanguage(); $this->assertNull(eval(sprintf('return %s;', $expressionLanguage->compile($expression, ['foo' => 'foo'])))); } - public function provideNullsafe() + public function provideNullSafe() { $foo = new class() extends \stdClass { public function bar() @@ -272,6 +272,47 @@ public function bar() yield ['foo["bar"]?.baz()', ['bar' => null]]; yield ['foo.bar()?.baz', $foo]; yield ['foo.bar()?.baz()', $foo]; + + yield ['foo?.bar.baz', null]; + yield ['foo?.bar["baz"]', null]; + yield ['foo?.bar["baz"]["qux"]', null]; + yield ['foo?.bar["baz"]["qux"].quux', null]; + yield ['foo?.bar["baz"]["qux"].quux()', null]; + yield ['foo?.bar().baz', null]; + yield ['foo?.bar()["baz"]', null]; + yield ['foo?.bar()["baz"]["qux"]', null]; + yield ['foo?.bar()["baz"]["qux"].quux', null]; + yield ['foo?.bar()["baz"]["qux"].quux()', null]; + } + + /** + * @dataProvider provideInvalidNullSafe + */ + public function testNullSafeEvaluateFails($expression, $foo, $message) + { + $expressionLanguage = new ExpressionLanguage(); + + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage($message); + $expressionLanguage->evaluate($expression, ['foo' => $foo]); + } + + /** + * @dataProvider provideInvalidNullSafe + */ + public function testNullSafeCompileFails($expression, $foo) + { + $expressionLanguage = new ExpressionLanguage(); + + $this->expectWarning(); + eval(sprintf('return %s;', $expressionLanguage->compile($expression, ['foo' => 'foo']))); + } + + public function provideInvalidNullSafe() + { + yield ['foo?.bar.baz', (object) ['bar' => null], 'Unable to get property "baz" of non-object "foo.bar".']; + yield ['foo?.bar["baz"]', (object) ['bar' => null], 'Unable to get an item of non-array "foo.bar".']; + yield ['foo?.bar["baz"].qux.quux', (object) ['bar' => ['baz' => null]], 'Unable to get property "qux" of non-object "foo.bar["baz"]".']; } /** diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index 2103146473c9a..7f04f6dee7ba9 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -317,6 +317,8 @@ private function isReadable(string $filename): bool */ public function symlink(string $originDir, string $targetDir, bool $copyOnWindows = false) { + self::assertFunctionExists('symlink'); + if ('\\' === \DIRECTORY_SEPARATOR) { $originDir = strtr($originDir, '/', '\\'); $targetDir = strtr($targetDir, '/', '\\'); @@ -352,6 +354,8 @@ public function symlink(string $originDir, string $targetDir, bool $copyOnWindow */ public function hardlink(string $originFile, string|iterable $targetFiles) { + self::assertFunctionExists('link'); + if (!$this->exists($originFile)) { throw new FileNotFoundException(null, 0, null, $originFile); } @@ -703,8 +707,17 @@ private function getSchemeAndHierarchy(string $filename): array return 2 === \count($components) ? [$components[0], $components[1]] : [null, $components[0]]; } - private static function box(callable $func, mixed ...$args): mixed + private static function assertFunctionExists(string $func): void { + if (!\function_exists($func)) { + throw new IOException(sprintf('Unable to perform filesystem operation because the "%s()" function has been disabled.', $func)); + } + } + + private static function box(string $func, mixed ...$args): mixed + { + self::assertFunctionExists($func); + self::$lastError = null; set_error_handler(__CLASS__.'::handleError'); try { diff --git a/src/Symfony/Component/Form/ChoiceList/Loader/AbstractChoiceLoader.php b/src/Symfony/Component/Form/ChoiceList/Loader/AbstractChoiceLoader.php index def29c80ded33..6aa2267a039b0 100644 --- a/src/Symfony/Component/Form/ChoiceList/Loader/AbstractChoiceLoader.php +++ b/src/Symfony/Component/Form/ChoiceList/Loader/AbstractChoiceLoader.php @@ -19,10 +19,7 @@ */ abstract class AbstractChoiceLoader implements ChoiceLoaderInterface { - /** - * The loaded choice list. - */ - private ArrayChoiceList $choiceList; + private ?iterable $choices; /** * @final @@ -31,7 +28,7 @@ abstract class AbstractChoiceLoader implements ChoiceLoaderInterface */ public function loadChoiceList(callable $value = null): ChoiceListInterface { - return $this->choiceList ?? ($this->choiceList = new ArrayChoiceList($this->loadChoices(), $value)); + return new ArrayChoiceList($this->choices ??= $this->loadChoices(), $value); } /** @@ -43,10 +40,6 @@ public function loadChoicesForValues(array $values, callable $value = null): arr return []; } - if (isset($this->choiceList)) { - return $this->choiceList->getChoicesForValues($values); - } - return $this->doLoadChoicesForValues($values, $value); } @@ -64,10 +57,6 @@ public function loadValuesForChoices(array $choices, callable $value = null): ar return array_map($value, $choices); } - if (isset($this->choiceList)) { - return $this->choiceList->getValuesForChoices($choices); - } - return $this->doLoadValuesForChoices($choices); } diff --git a/src/Symfony/Component/Form/Form.php b/src/Symfony/Component/Form/Form.php index fc2b3fdb66f04..83e3aede28ed5 100644 --- a/src/Symfony/Component/Form/Form.php +++ b/src/Symfony/Component/Form/Form.php @@ -507,7 +507,7 @@ public function submit(mixed $submittedData, bool $clearMissing = true): static $submittedData = null; $this->transformationFailure = new TransformationFailedException('Submitted data was expected to be text or number, file upload given.'); } - } elseif (\is_array($submittedData) && !$this->config->getCompound() && !$this->config->hasOption('multiple')) { + } elseif (\is_array($submittedData) && !$this->config->getCompound() && !$this->config->getOption('multiple', false)) { $submittedData = null; $this->transformationFailure = new TransformationFailedException('Submitted data was expected to be text or number, array given.'); } diff --git a/src/Symfony/Component/Form/Tests/ChoiceList/LazyChoiceListTest.php b/src/Symfony/Component/Form/Tests/ChoiceList/LazyChoiceListTest.php index 6f30d0896e1ba..94d41cf9e740f 100644 --- a/src/Symfony/Component/Form/Tests/ChoiceList/LazyChoiceListTest.php +++ b/src/Symfony/Component/Form/Tests/ChoiceList/LazyChoiceListTest.php @@ -32,7 +32,7 @@ public function testGetChoiceLoadersLoadsLoadedListOnFirstCall() $this->assertSame(['RESULT'], $list->getChoices()); $this->assertSame(['RESULT'], $list->getChoices()); - $this->assertSame(1, $calls); + $this->assertSame(2, $calls); } public function testGetValuesLoadsLoadedListOnFirstCall() @@ -46,7 +46,7 @@ public function testGetValuesLoadsLoadedListOnFirstCall() $this->assertSame(['RESULT'], $list->getValues()); $this->assertSame(['RESULT'], $list->getValues()); - $this->assertSame(1, $calls); + $this->assertSame(2, $calls); } public function testGetStructuredValuesLoadsLoadedListOnFirstCall() @@ -60,7 +60,7 @@ public function testGetStructuredValuesLoadsLoadedListOnFirstCall() $this->assertSame(['RESULT'], $list->getStructuredValues()); $this->assertSame(['RESULT'], $list->getStructuredValues()); - $this->assertSame(1, $calls); + $this->assertSame(2, $calls); } public function testGetOriginalKeysLoadsLoadedListOnFirstCall() @@ -79,7 +79,7 @@ public function testGetOriginalKeysLoadsLoadedListOnFirstCall() $this->assertSame(['foo' => 'a', 'bar' => 'b', 'baz' => 'c'], $list->getOriginalKeys()); $this->assertSame(['foo' => 'a', 'bar' => 'b', 'baz' => 'c'], $list->getOriginalKeys()); - $this->assertSame(3, $calls); + $this->assertSame(6, $calls); } public function testGetChoicesForValuesForwardsCallIfListNotLoaded() @@ -98,7 +98,7 @@ public function testGetChoicesForValuesForwardsCallIfListNotLoaded() $this->assertSame(['foo', 'bar'], $list->getChoicesForValues(['a', 'b'])); $this->assertSame(['foo', 'bar'], $list->getChoicesForValues(['a', 'b'])); - $this->assertSame(3, $calls); + $this->assertSame(6, $calls); } public function testGetChoicesForValuesUsesLoadedList() diff --git a/src/Symfony/Component/Form/Tests/ChoiceList/Loader/CallbackChoiceLoaderTest.php b/src/Symfony/Component/Form/Tests/ChoiceList/Loader/CallbackChoiceLoaderTest.php index 52dd5f8af580f..69eb787a23dfa 100644 --- a/src/Symfony/Component/Form/Tests/ChoiceList/Loader/CallbackChoiceLoaderTest.php +++ b/src/Symfony/Component/Form/Tests/ChoiceList/Loader/CallbackChoiceLoaderTest.php @@ -67,11 +67,18 @@ public function testLoadChoiceList() $this->assertInstanceOf(ChoiceListInterface::class, self::$loader->loadChoiceList(self::$value)); } - public function testLoadChoiceListOnlyOnce() + public function testLoadChoicesOnlyOnce() { - $loadedChoiceList = self::$loader->loadChoiceList(self::$value); + $calls = 0; + $loader = new CallbackChoiceLoader(function () use (&$calls) { + ++$calls; - $this->assertSame($loadedChoiceList, self::$loader->loadChoiceList(self::$value)); + return [1]; + }); + $loadedChoiceList = $loader->loadChoiceList(); + + $this->assertNotSame($loadedChoiceList, $loader->loadChoiceList()); + $this->assertSame(1, $calls); } public function testLoadChoicesForValuesLoadsChoiceListOnFirstCall() diff --git a/src/Symfony/Component/Form/Tests/ChoiceList/Loader/IntlCallbackChoiceLoaderTest.php b/src/Symfony/Component/Form/Tests/ChoiceList/Loader/IntlCallbackChoiceLoaderTest.php index a5fc262dcd3a1..e2827b0d913be 100644 --- a/src/Symfony/Component/Form/Tests/ChoiceList/Loader/IntlCallbackChoiceLoaderTest.php +++ b/src/Symfony/Component/Form/Tests/ChoiceList/Loader/IntlCallbackChoiceLoaderTest.php @@ -68,11 +68,19 @@ public function testLoadChoiceList() $this->assertInstanceOf(ChoiceListInterface::class, self::$loader->loadChoiceList(self::$value)); } - public function testLoadChoiceListOnlyOnce() + public function testLoadChoicesOnlyOnce() { - $loadedChoiceList = self::$loader->loadChoiceList(self::$value); + $calls = 0; + $loader = new IntlCallbackChoiceLoader(function () use (&$calls) { + ++$calls; - $this->assertSame($loadedChoiceList, self::$loader->loadChoiceList(self::$value)); + return self::$choices; + }); + + $loadedChoiceList = $loader->loadChoiceList(self::$value); + + $this->assertNotSame($loadedChoiceList, $loader->loadChoiceList(self::$value)); + $this->assertSame(1, $calls); } public function testLoadChoicesForValuesLoadsChoiceListOnFirstCall() diff --git a/src/Symfony/Component/Form/Tests/CompoundFormTest.php b/src/Symfony/Component/Form/Tests/CompoundFormTest.php index 4fdb085a446d9..fcc55a56385de 100644 --- a/src/Symfony/Component/Form/Tests/CompoundFormTest.php +++ b/src/Symfony/Component/Form/Tests/CompoundFormTest.php @@ -1057,7 +1057,8 @@ public function testArrayTransformationFailureOnSubmit() $this->assertNull($this->form->get('foo')->getData()); $this->assertSame('Submitted data was expected to be text or number, array given.', $this->form->get('foo')->getTransformationFailure()->getMessage()); - $this->assertSame(['bar'], $this->form->get('bar')->getData()); + $this->assertNull($this->form->get('bar')->getData()); + $this->assertSame('Submitted data was expected to be text or number, array given.', $this->form->get('bar')->getTransformationFailure()->getMessage()); } public function testFileUpload() diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php index b7d9329849e96..8109a9c60079d 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php @@ -14,6 +14,7 @@ use Symfony\Component\Form\ChoiceList\Loader\CallbackChoiceLoader; use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView; use Symfony\Component\Form\ChoiceList\View\ChoiceView; +use Symfony\Component\Form\Exception\TransformationFailedException; use Symfony\Component\Form\FormInterface; use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException; @@ -1949,7 +1950,12 @@ public function testSubmitInvalidNestedValue($multiple, $expanded, $submissionDa $form->submit($submissionData); $this->assertFalse($form->isSynchronized()); - $this->assertEquals('All choices submitted must be NULL, strings or ints.', $form->getTransformationFailure()->getMessage()); + $this->assertInstanceOf(TransformationFailedException::class, $form->getTransformationFailure()); + if (!$multiple && !$expanded) { + $this->assertEquals('Submitted data was expected to be text or number, array given.', $form->getTransformationFailure()->getMessage()); + } else { + $this->assertEquals('All choices submitted must be NULL, strings or ints.', $form->getTransformationFailure()->getMessage()); + } } public function invalidNestedValueTestMatrix() @@ -2247,4 +2253,32 @@ public function testFilteredChoiceLoader() new ChoiceView('c', 'c', 'Kris'), ], $form->createView()->vars['choices']); } + + public function testWithSameLoaderAndDifferentChoiceValueCallbacks() + { + $choiceLoader = new CallbackChoiceLoader(function () { + return [1, 2, 3]; + }); + + $view = $this->factory->create(FormTypeTest::TESTED_TYPE) + ->add('choice_one', self::TESTED_TYPE, [ + 'choice_loader' => $choiceLoader, + ]) + ->add('choice_two', self::TESTED_TYPE, [ + 'choice_loader' => $choiceLoader, + 'choice_value' => function ($choice) { + return $choice ? (string) $choice * 10 : ''; + }, + ]) + ->createView() + ; + + $this->assertSame('1', $view['choice_one']->vars['choices'][0]->value); + $this->assertSame('2', $view['choice_one']->vars['choices'][1]->value); + $this->assertSame('3', $view['choice_one']->vars['choices'][2]->value); + + $this->assertSame('10', $view['choice_two']->vars['choices'][0]->value); + $this->assertSame('20', $view['choice_two']->vars['choices'][1]->value); + $this->assertSame('30', $view['choice_two']->vars['choices'][2]->value); + } } diff --git a/src/Symfony/Component/HttpClient/HttpOptions.php b/src/Symfony/Component/HttpClient/HttpOptions.php index 4167b78b4fa06..d71b11926d4aa 100644 --- a/src/Symfony/Component/HttpClient/HttpOptions.php +++ b/src/Symfony/Component/HttpClient/HttpOptions.php @@ -195,6 +195,16 @@ public function setTimeout(float $timeout): static return $this; } + /** + * @return $this + */ + public function setMaxDuration(float $maxDuration): static + { + $this->options['max_duration'] = $maxDuration; + + return $this; + } + /** * @return $this */ diff --git a/src/Symfony/Component/HttpClient/Response/AmpResponse.php b/src/Symfony/Component/HttpClient/Response/AmpResponse.php index 7ab4ec5c11c90..f5d0095ec97c6 100644 --- a/src/Symfony/Component/HttpClient/Response/AmpResponse.php +++ b/src/Symfony/Component/HttpClient/Response/AmpResponse.php @@ -87,6 +87,7 @@ public function __construct(AmpClientState $multi, Request $request, array $opti $info['upload_content_length'] = -1.0; $info['download_content_length'] = -1.0; $info['user_data'] = $options['user_data']; + $info['max_duration'] = $options['max_duration']; $info['debug'] = ''; $onProgress = $options['on_progress'] ?? static function () {}; diff --git a/src/Symfony/Component/HttpClient/Response/AsyncContext.php b/src/Symfony/Component/HttpClient/Response/AsyncContext.php index a762d4352b2e0..9aacc70e512e4 100644 --- a/src/Symfony/Component/HttpClient/Response/AsyncContext.php +++ b/src/Symfony/Component/HttpClient/Response/AsyncContext.php @@ -13,6 +13,7 @@ use Symfony\Component\HttpClient\Chunk\DataChunk; use Symfony\Component\HttpClient\Chunk\LastChunk; +use Symfony\Component\HttpClient\Exception\TransportException; use Symfony\Contracts\HttpClient\ChunkInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\HttpClient\ResponseInterface; @@ -155,13 +156,18 @@ public function getResponse(): ResponseInterface */ public function replaceRequest(string $method, string $url, array $options = []): ResponseInterface { - $this->info['previous_info'][] = $this->response->getInfo(); + $this->info['previous_info'][] = $info = $this->response->getInfo(); if (null !== $onProgress = $options['on_progress'] ?? null) { $thisInfo = &$this->info; $options['on_progress'] = static function (int $dlNow, int $dlSize, array $info) use (&$thisInfo, $onProgress) { $onProgress($dlNow, $dlSize, $thisInfo + $info); }; } + if (0 < ($info['max_duration'] ?? 0) && 0 < ($info['total_time'] ?? 0)) { + if (0 >= $options['max_duration'] = $info['max_duration'] - $info['total_time']) { + throw new TransportException(sprintf('Max duration was reached for "%s".', $info['url'])); + } + } return $this->response = $this->client->request($method, $url, ['buffer' => false] + $options); } diff --git a/src/Symfony/Component/HttpClient/Response/AsyncResponse.php b/src/Symfony/Component/HttpClient/Response/AsyncResponse.php index c65e8478f5249..63337a9e94362 100644 --- a/src/Symfony/Component/HttpClient/Response/AsyncResponse.php +++ b/src/Symfony/Component/HttpClient/Response/AsyncResponse.php @@ -85,6 +85,9 @@ public function __construct(HttpClientInterface $client, string $method, string if (\array_key_exists('user_data', $options)) { $this->info['user_data'] = $options['user_data']; } + if (\array_key_exists('max_duration', $options)) { + $this->info['max_duration'] = $options['max_duration']; + } } public function getStatusCode(): int diff --git a/src/Symfony/Component/HttpClient/Response/CurlResponse.php b/src/Symfony/Component/HttpClient/Response/CurlResponse.php index cf698f6cb0695..9a8abca522025 100644 --- a/src/Symfony/Component/HttpClient/Response/CurlResponse.php +++ b/src/Symfony/Component/HttpClient/Response/CurlResponse.php @@ -67,6 +67,7 @@ public function __construct(CurlClientState $multi, \CurlHandle|string $ch, arra $this->timeout = $options['timeout'] ?? null; $this->info['http_method'] = $method; $this->info['user_data'] = $options['user_data'] ?? null; + $this->info['max_duration'] = $options['max_duration'] ?? null; $this->info['start_time'] = $this->info['start_time'] ?? microtime(true); $info = &$this->info; $headers = &$this->headers; diff --git a/src/Symfony/Component/HttpClient/Response/MockResponse.php b/src/Symfony/Component/HttpClient/Response/MockResponse.php index 9b80f310e8f13..fe89cd18edbb5 100644 --- a/src/Symfony/Component/HttpClient/Response/MockResponse.php +++ b/src/Symfony/Component/HttpClient/Response/MockResponse.php @@ -140,6 +140,7 @@ public static function fromRequest(string $method, string $url, array $options, $response->info['http_method'] = $method; $response->info['http_code'] = 0; $response->info['user_data'] = $options['user_data'] ?? null; + $response->info['max_duration'] = $options['max_duration'] ?? null; $response->info['url'] = $url; if ($mock instanceof self) { @@ -285,6 +286,7 @@ private static function readResponse(self $response, array $options, ResponseInt $response->info = [ 'start_time' => $response->info['start_time'], 'user_data' => $response->info['user_data'], + 'max_duration' => $response->info['max_duration'], 'http_code' => $response->info['http_code'], ] + $info + $response->info; diff --git a/src/Symfony/Component/HttpClient/Response/NativeResponse.php b/src/Symfony/Component/HttpClient/Response/NativeResponse.php index b79d3cc03a54a..077d8f9a8ddcc 100644 --- a/src/Symfony/Component/HttpClient/Response/NativeResponse.php +++ b/src/Symfony/Component/HttpClient/Response/NativeResponse.php @@ -67,6 +67,7 @@ public function __construct(NativeClientState $multi, $context, string $url, arr $this->buffer = fopen('php://temp', 'w+'); $info['user_data'] = $options['user_data']; + $info['max_duration'] = $options['max_duration']; ++$multi->responseCount; $this->initializer = static function (self $response) { diff --git a/src/Symfony/Component/HttpClient/Tests/AsyncDecoratorTraitTest.php b/src/Symfony/Component/HttpClient/Tests/AsyncDecoratorTraitTest.php index 820efde4d9211..892c3e4d2ce96 100644 --- a/src/Symfony/Component/HttpClient/Tests/AsyncDecoratorTraitTest.php +++ b/src/Symfony/Component/HttpClient/Tests/AsyncDecoratorTraitTest.php @@ -13,6 +13,7 @@ use Symfony\Component\HttpClient\AsyncDecoratorTrait; use Symfony\Component\HttpClient\DecoratorTrait; +use Symfony\Component\HttpClient\Exception\TransportException; use Symfony\Component\HttpClient\HttpClient; use Symfony\Component\HttpClient\Response\AsyncContext; use Symfony\Component\HttpClient\Response\AsyncResponse; @@ -339,4 +340,28 @@ public function request(string $method, string $url, array $options = []): Respo $this->expectExceptionMessage('Instance of "Symfony\Component\HttpClient\Response\NativeResponse" is already consumed and cannot be managed by "Symfony\Component\HttpClient\Response\AsyncResponse". A decorated client should not call any of the response\'s methods in its "request()" method.'); $response->getStatusCode(); } + + public function testMaxDuration() + { + $sawFirst = false; + $client = $this->getHttpClient(__FUNCTION__, function (ChunkInterface $chunk, AsyncContext $context) use (&$sawFirst) { + try { + if (!$chunk->isFirst() || !$sawFirst) { + $sawFirst = $sawFirst || $chunk->isFirst(); + yield $chunk; + } + } catch (TransportExceptionInterface $e) { + $context->getResponse()->cancel(); + $context->replaceRequest('GET', 'http://localhost:8057/timeout-body', ['timeout' => 0.4]); + } + }); + + $response = $client->request('GET', 'http://localhost:8057/timeout-body', ['max_duration' => 0.75, 'timeout' => 0.4]); + + $this->assertSame(0.75, $response->getInfo('max_duration')); + + $this->expectException(TransportException::class); + $this->expectExceptionMessage('Max duration was reached for "http://localhost:8057/timeout-body".'); + $response->getContent(); + } } diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php index 09b33d5b18fa7..50668bb136b30 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php @@ -135,6 +135,12 @@ public function start(): bool throw new \RuntimeException(sprintf('Failed to start the session because headers have already been sent by "%s" at line %d.', $file, $line)); } + $sessionId = $_COOKIE[session_name()] ?? null; + if ($sessionId && !preg_match('/^[a-zA-Z0-9,-]{22,}$/', $sessionId)) { + // the session ID in the header is invalid, create a new one + session_id(session_create_id()); + } + // ok to try and start the session if (!session_start()) { throw new \RuntimeException('Failed to start the session.'); diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php index 5c131f229ffd5..a771d2e010095 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php @@ -283,4 +283,13 @@ public function testGetBagsOnceSessionStartedIsIgnored() $this->assertEquals($storage->getBag('flashes'), $bag); } + + public function testRegenerateInvalidSessionId() + { + $_COOKIE[session_name()] = '&~['; + $started = (new NativeSessionStorage())->start(); + + $this->assertTrue($started); + $this->assertMatchesRegularExpression('/^[a-zA-Z0-9,-]{22,}$/', session_id()); + } } diff --git a/src/Symfony/Component/HttpKernel/Bundle/AbstractBundle.php b/src/Symfony/Component/HttpKernel/Bundle/AbstractBundle.php index 3e6029f8c2510..244f3ec32b0b2 100644 --- a/src/Symfony/Component/HttpKernel/Bundle/AbstractBundle.php +++ b/src/Symfony/Component/HttpKernel/Bundle/AbstractBundle.php @@ -47,4 +47,18 @@ public function getContainerExtension(): ?ExtensionInterface return $this->extension ??= new BundleExtension($this, $this->extensionAlias); } + + /** + * {@inheritdoc} + */ + public function getPath(): string + { + if (null === $this->path) { + $reflected = new \ReflectionObject($this); + // assume the modern directory structure by default + $this->path = \dirname($reflected->getFileName(), 2); + } + + return $this->path; + } } diff --git a/src/Symfony/Component/HttpKernel/CHANGELOG.md b/src/Symfony/Component/HttpKernel/CHANGELOG.md index 6c40b7da3a66a..bb26bd4145017 100644 --- a/src/Symfony/Component/HttpKernel/CHANGELOG.md +++ b/src/Symfony/Component/HttpKernel/CHANGELOG.md @@ -10,6 +10,7 @@ CHANGELOG * Add `Profiler::isEnabled()` so collaborating collector services may elect to omit themselves * Add the `UidValueResolver` argument value resolver * Add `AbstractBundle` class for DI configuration/definition on a single file + * Update the path of a bundle placed in the `src/` directory to the parent directory when `AbstractBundle` is used 6.0 --- diff --git a/src/Symfony/Component/HttpKernel/EventListener/ErrorListener.php b/src/Symfony/Component/HttpKernel/EventListener/ErrorListener.php index 770773712906b..8a0d18d8fa4ed 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/ErrorListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/ErrorListener.php @@ -35,7 +35,7 @@ class ErrorListener implements EventSubscriberInterface protected $debug; protected $exceptionsMapping; - public function __construct(string|object|array $controller, LoggerInterface $logger = null, bool $debug = false, array $exceptionsMapping = []) + public function __construct(string|object|array|null $controller, LoggerInterface $logger = null, bool $debug = false, array $exceptionsMapping = []) { $this->controller = $controller; $this->logger = $logger; diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 603365b81c3b5..37a758c7cfaf1 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -78,12 +78,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl */ private static array $freshCache = []; - public const VERSION = '6.1.0-RC1'; + public const VERSION = '6.1.0'; public const VERSION_ID = 60100; public const MAJOR_VERSION = 6; public const MINOR_VERSION = 1; public const RELEASE_VERSION = 0; - public const EXTRA_VERSION = 'RC1'; + public const EXTRA_VERSION = ''; public const END_OF_MAINTENANCE = '01/2023'; public const END_OF_LIFE = '01/2023'; diff --git a/src/Symfony/Component/Mime/Email.php b/src/Symfony/Component/Mime/Email.php index bfc7c37f1b043..8516acb380086 100644 --- a/src/Symfony/Component/Mime/Email.php +++ b/src/Symfony/Component/Mime/Email.php @@ -257,12 +257,16 @@ public function getPriority(): int } /** - * @param resource|string $body + * @param resource|string|null $body * * @return $this */ public function text($body, string $charset = 'utf-8'): static { + if (null !== $body && !\is_string($body) && !\is_resource($body)) { + throw new \TypeError(sprintf('The body must be a string, a resource or null (got "%s").', get_debug_type($body))); + } + $this->text = $body; $this->textCharset = $charset; @@ -289,6 +293,10 @@ public function getTextCharset(): ?string */ public function html($body, string $charset = 'utf-8'): static { + if (null !== $body && !\is_string($body) && !\is_resource($body)) { + throw new \TypeError(sprintf('The body must be a string, a resource or null (got "%s").', get_debug_type($body))); + } + $this->html = $body; $this->htmlCharset = $charset; @@ -315,6 +323,10 @@ public function getHtmlCharset(): ?string */ public function attach($body, string $name = null, string $contentType = null): static { + if (!\is_string($body) && !\is_resource($body)) { + throw new \TypeError(sprintf('The body must be a string or a resource (got "%s").', get_debug_type($body))); + } + $this->attachments[] = ['body' => $body, 'name' => $name, 'content-type' => $contentType, 'inline' => false]; return $this; @@ -337,6 +349,10 @@ public function attachFromPath(string $path, string $name = null, string $conten */ public function embed($body, string $name = null, string $contentType = null): static { + if (!\is_string($body) && !\is_resource($body)) { + throw new \TypeError(sprintf('The body must be a string or a resource (got "%s").', get_debug_type($body))); + } + $this->attachments[] = ['body' => $body, 'name' => $name, 'content-type' => $contentType, 'inline' => true]; return $this; @@ -457,7 +473,7 @@ private function prepareParts(): ?array $names = []; $htmlPart = null; $html = $this->html; - if (null !== $this->html) { + if (null !== $html) { $htmlPart = new TextPart($html, $this->htmlCharset, 'html'); $html = $htmlPart->getBody(); diff --git a/src/Symfony/Component/Mime/Test/Constraint/EmailHeaderSame.php b/src/Symfony/Component/Mime/Test/Constraint/EmailHeaderSame.php index 45cf2253cc82d..bb0cba6984a3a 100644 --- a/src/Symfony/Component/Mime/Test/Constraint/EmailHeaderSame.php +++ b/src/Symfony/Component/Mime/Test/Constraint/EmailHeaderSame.php @@ -55,12 +55,14 @@ protected function matches($message): bool */ protected function failureDescription($message): string { - return sprintf('the Email %s (value is %s)', $this->toString(), $this->getHeaderValue($message)); + return sprintf('the Email %s (value is %s)', $this->toString(), $this->getHeaderValue($message) ?? 'null'); } - private function getHeaderValue($message): string + private function getHeaderValue($message): ?string { - $header = $message->getHeaders()->get($this->headerName); + if (null === $header = $message->getHeaders()->get($this->headerName)) { + return null; + } return $header instanceof UnstructuredHeader ? $header->getValue() : $header->getBodyAsString(); } diff --git a/src/Symfony/Component/Mime/Tests/EmailTest.php b/src/Symfony/Component/Mime/Tests/EmailTest.php index ea06c7f6c12f5..76d8e2f9723d2 100644 --- a/src/Symfony/Component/Mime/Tests/EmailTest.php +++ b/src/Symfony/Component/Mime/Tests/EmailTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Mime\Tests; +use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; use Symfony\Component\Mime\Address; use Symfony\Component\Mime\Email; @@ -19,6 +20,7 @@ use Symfony\Component\Mime\Part\Multipart\MixedPart; use Symfony\Component\Mime\Part\Multipart\RelatedPart; use Symfony\Component\Mime\Part\TextPart; +use Symfony\Component\Mime\Test\Constraint\EmailHeaderSame; use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor; use Symfony\Component\Serializer\Encoder\JsonEncoder; use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer; @@ -466,4 +468,76 @@ public function testSymfonySerialize() $this->assertEquals($expected->getHeaders(), $n->getHeaders()); $this->assertEquals($expected->getBody(), $n->getBody()); } + + public function testMissingHeaderDoesNotThrowError() + { + $this->expectException(ExpectationFailedException::class); + $this->expectExceptionMessage('Failed asserting that the Email has header "foo" with value "bar" (value is null).'); + + $e = new Email(); + $emailHeaderSame = new EmailHeaderSame('foo', 'bar'); + $emailHeaderSame->evaluate($e); + } + + public function testAttachBodyExpectStringOrResource() + { + $this->expectException(\TypeError::class); + $this->expectExceptionMessage('The body must be a string or a resource (got "bool").'); + + (new Email())->attach(false); + } + + public function testEmbedBodyExpectStringOrResource() + { + $this->expectException(\TypeError::class); + $this->expectExceptionMessage('The body must be a string or a resource (got "bool").'); + + (new Email())->embed(false); + } + + public function testHtmlBodyExpectStringOrResourceOrNull() + { + $this->expectException(\TypeError::class); + $this->expectExceptionMessage('The body must be a string, a resource or null (got "bool").'); + + (new Email())->html(false); + } + + public function testHtmlBodyAcceptedTypes() + { + $email = new Email(); + + $email->html('foo'); + $this->assertSame('foo', $email->getHtmlBody()); + + $email->html(null); + $this->assertNull($email->getHtmlBody()); + + $contents = file_get_contents(__DIR__.'/Fixtures/mimetypes/test', 'r'); + $email->html($contents); + $this->assertSame($contents, $email->getHtmlBody()); + } + + public function testTextBodyExpectStringOrResourceOrNull() + { + $this->expectException(\TypeError::class); + $this->expectExceptionMessage('The body must be a string, a resource or null (got "bool").'); + + (new Email())->text(false); + } + + public function testTextBodyAcceptedTypes() + { + $email = new Email(); + + $email->text('foo'); + $this->assertSame('foo', $email->getTextBody()); + + $email->text(null); + $this->assertNull($email->getTextBody()); + + $contents = file_get_contents(__DIR__.'/Fixtures/mimetypes/test', 'r'); + $email->text($contents); + $this->assertSame($contents, $email->getTextBody()); + } } diff --git a/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php b/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php index db25e14f44736..52a4a78f2537f 100644 --- a/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php +++ b/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php @@ -227,7 +227,11 @@ private function getDocBlockFromProperty(string $class, string $property): ?arra $constructor = new \ReflectionMethod($class, '__construct'); $rawDocNode = $constructor->getDocComment(); $source = self::MUTATOR; - } elseif (null === $rawDocNode = $reflectionProperty->getDocComment() ?: null) { + } else { + $rawDocNode = $reflectionProperty->getDocComment(); + } + + if (!$rawDocNode) { return null; } @@ -235,6 +239,10 @@ private function getDocBlockFromProperty(string $class, string $property): ?arra $phpDocNode = $this->phpDocParser->parse($tokens); $tokens->consumeTokenType(Lexer::TOKEN_END); + if (self::MUTATOR === $source && !$this->filterDocBlockParams($phpDocNode, $property)) { + return null; + } + return [$phpDocNode, $source, $reflectionProperty->class]; } diff --git a/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php b/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTestDoc.php similarity index 97% rename from src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php rename to src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTestDoc.php index 0cf346fce03c1..f57721ca31bdb 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTestDoc.php @@ -18,6 +18,7 @@ use Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy; use Symfony\Component\PropertyInfo\Tests\Fixtures\ParentDummy; use Symfony\Component\PropertyInfo\Tests\Fixtures\Php80Dummy; +use Symfony\Component\PropertyInfo\Tests\Fixtures\Php80PromotedDummy; use Symfony\Component\PropertyInfo\Tests\Fixtures\RootDummy\RootDummyItem; use Symfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage\DummyUsedInTrait; use Symfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage\DummyUsingTrait; @@ -439,15 +440,17 @@ public function testDummyNamespaceWithProperty() /** * @dataProvider php80TypesProvider */ - public function testExtractPhp80Type($property, array $type = null) + public function testExtractPhp80Type(string $class, $property, array $type = null) { - $this->assertEquals($type, $this->extractor->getTypes(Php80Dummy::class, $property, [])); + $this->assertEquals($type, $this->extractor->getTypes($class, $property, [])); } public function php80TypesProvider() { return [ - ['promotedAndMutated', [new Type(Type::BUILTIN_TYPE_STRING)]], + [Php80Dummy::class, 'promotedAndMutated', [new Type(Type::BUILTIN_TYPE_STRING)]], + [Php80Dummy::class, 'promoted', null], + [Php80PromotedDummy::class, 'promoted', null], ]; } } diff --git a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/ConstructorDummy.php b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/ConstructorDummy.php index 23ef5cceaef75..1c50c67e73ed6 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/ConstructorDummy.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/ConstructorDummy.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\PropertyInfo\Tests\Fixtures; /** diff --git a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/DockBlockFallback.php b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/DockBlockFallback.php index 89136280da56b..ac4d4b6583d62 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/DockBlockFallback.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/DockBlockFallback.php @@ -1,7 +1,5 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace A { class Property { diff --git a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/NoProperties.php b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/NoProperties.php index 177bbe4df0f03..e0cd0c7e21b35 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/NoProperties.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/NoProperties.php @@ -1,7 +1,5 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\PropertyInfo\Tests\Fixtures; class Php80Dummy diff --git a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php80PromotedDummy.php b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php80PromotedDummy.php new file mode 100644 index 0000000000000..f612df99e2ba4 --- /dev/null +++ b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php80PromotedDummy.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\PropertyInfo\Tests\Fixtures; + +class Php80PromotedDummy +{ + public function __construct(private string $promoted) + { + } + + public function getPromoted(): string + { + return $this->promoted; + } +} diff --git a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php81Dummy.php b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php81Dummy.php index 1300c3e695f1f..842f59fbfd47b 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php81Dummy.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php81Dummy.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\PropertyInfo\Tests\Fixtures; class Php81Dummy diff --git a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/PseudoTypeDummy.php b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/PseudoTypeDummy.php index 71756044fafc9..d2efecef9dcf4 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/PseudoTypeDummy.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/PseudoTypeDummy.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\PropertyInfo\Tests\Fixtures; class PseudoTypeDummy diff --git a/src/Symfony/Component/VarDumper/Caster/DateCaster.php b/src/Symfony/Component/VarDumper/Caster/DateCaster.php index 99f53849b8695..18641fbc1d348 100644 --- a/src/Symfony/Component/VarDumper/Caster/DateCaster.php +++ b/src/Symfony/Component/VarDumper/Caster/DateCaster.php @@ -103,11 +103,11 @@ public static function castPeriod(\DatePeriod $p, array $a, Stub $stub, bool $is } $period = sprintf( - 'every %s, from %s (%s) %s', + 'every %s, from %s%s %s', self::formatInterval($p->getDateInterval()), + $p->include_start_date ? '[' : ']', self::formatDateTime($p->getStartDate()), - $p->include_start_date ? 'included' : 'excluded', - ($end = $p->getEndDate()) ? 'to '.self::formatDateTime($end) : 'recurring '.$p->recurrences.' time/s' + ($end = $p->getEndDate()) ? 'to '.self::formatDateTime($end).(\PHP_VERSION_ID >= 80200 && $p->include_end_date ? ']' : '[') : 'recurring '.$p->recurrences.' time/s' ); $p = [Caster::PREFIX_VIRTUAL.'period' => new ConstStub($period, implode("\n", $dates))]; diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/DateCasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/DateCasterTest.php index c1cc61504c902..335aa7dda4b1c 100644 --- a/src/Symfony/Component/VarDumper/Tests/Caster/DateCasterTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Caster/DateCasterTest.php @@ -373,26 +373,26 @@ public function testCastPeriod($start, $interval, $end, $options, $xPeriod, $xDa public function providePeriods() { $periods = [ - ['2017-01-01', 'P1D', '2017-01-03', 0, 'every + 1d, from 2017-01-01 00:00:00.0 (included) to 2017-01-03 00:00:00.0', '1) 2017-01-01%a2) 2017-01-02'], - ['2017-01-01', 'P1D', 1, 0, 'every + 1d, from 2017-01-01 00:00:00.0 (included) recurring 2 time/s', '1) 2017-01-01%a2) 2017-01-02'], + ['2017-01-01', 'P1D', '2017-01-03', 0, 'every + 1d, from [2017-01-01 00:00:00.0 to 2017-01-03 00:00:00.0[', '1) 2017-01-01%a2) 2017-01-02'], + ['2017-01-01', 'P1D', 1, 0, 'every + 1d, from [2017-01-01 00:00:00.0 recurring 2 time/s', '1) 2017-01-01%a2) 2017-01-02'], - ['2017-01-01', 'P1D', '2017-01-04', 0, 'every + 1d, from 2017-01-01 00:00:00.0 (included) to 2017-01-04 00:00:00.0', '1) 2017-01-01%a2) 2017-01-02%a3) 2017-01-03'], - ['2017-01-01', 'P1D', 2, 0, 'every + 1d, from 2017-01-01 00:00:00.0 (included) recurring 3 time/s', '1) 2017-01-01%a2) 2017-01-02%a3) 2017-01-03'], + ['2017-01-01', 'P1D', '2017-01-04', 0, 'every + 1d, from [2017-01-01 00:00:00.0 to 2017-01-04 00:00:00.0[', '1) 2017-01-01%a2) 2017-01-02%a3) 2017-01-03'], + ['2017-01-01', 'P1D', 2, 0, 'every + 1d, from [2017-01-01 00:00:00.0 recurring 3 time/s', '1) 2017-01-01%a2) 2017-01-02%a3) 2017-01-03'], - ['2017-01-01', 'P1D', '2017-01-05', 0, 'every + 1d, from 2017-01-01 00:00:00.0 (included) to 2017-01-05 00:00:00.0', '1) 2017-01-01%a2) 2017-01-02%a1 more'], - ['2017-01-01', 'P1D', 3, 0, 'every + 1d, from 2017-01-01 00:00:00.0 (included) recurring 4 time/s', '1) 2017-01-01%a2) 2017-01-02%a3) 2017-01-03%a1 more'], + ['2017-01-01', 'P1D', '2017-01-05', 0, 'every + 1d, from [2017-01-01 00:00:00.0 to 2017-01-05 00:00:00.0[', '1) 2017-01-01%a2) 2017-01-02%a1 more'], + ['2017-01-01', 'P1D', 3, 0, 'every + 1d, from [2017-01-01 00:00:00.0 recurring 4 time/s', '1) 2017-01-01%a2) 2017-01-02%a3) 2017-01-03%a1 more'], - ['2017-01-01', 'P1D', '2017-01-21', 0, 'every + 1d, from 2017-01-01 00:00:00.0 (included) to 2017-01-21 00:00:00.0', '1) 2017-01-01%a17 more'], - ['2017-01-01', 'P1D', 19, 0, 'every + 1d, from 2017-01-01 00:00:00.0 (included) recurring 20 time/s', '1) 2017-01-01%a17 more'], + ['2017-01-01', 'P1D', '2017-01-21', 0, 'every + 1d, from [2017-01-01 00:00:00.0 to 2017-01-21 00:00:00.0[', '1) 2017-01-01%a17 more'], + ['2017-01-01', 'P1D', 19, 0, 'every + 1d, from [2017-01-01 00:00:00.0 recurring 20 time/s', '1) 2017-01-01%a17 more'], - ['2017-01-01 01:00:00', 'P1D', '2017-01-03 01:00:00', 0, 'every + 1d, from 2017-01-01 01:00:00.0 (included) to 2017-01-03 01:00:00.0', '1) 2017-01-01 01:00:00.0%a2) 2017-01-02 01:00:00.0'], - ['2017-01-01 01:00:00', 'P1D', 1, 0, 'every + 1d, from 2017-01-01 01:00:00.0 (included) recurring 2 time/s', '1) 2017-01-01 01:00:00.0%a2) 2017-01-02 01:00:00.0'], + ['2017-01-01 01:00:00', 'P1D', '2017-01-03 01:00:00', 0, 'every + 1d, from [2017-01-01 01:00:00.0 to 2017-01-03 01:00:00.0[', '1) 2017-01-01 01:00:00.0%a2) 2017-01-02 01:00:00.0'], + ['2017-01-01 01:00:00', 'P1D', 1, 0, 'every + 1d, from [2017-01-01 01:00:00.0 recurring 2 time/s', '1) 2017-01-01 01:00:00.0%a2) 2017-01-02 01:00:00.0'], - ['2017-01-01', 'P1DT1H', '2017-01-03', 0, 'every + 1d 01:00:00.0, from 2017-01-01 00:00:00.0 (included) to 2017-01-03 00:00:00.0', '1) 2017-01-01 00:00:00.0%a2) 2017-01-02 01:00:00.0'], - ['2017-01-01', 'P1DT1H', 1, 0, 'every + 1d 01:00:00.0, from 2017-01-01 00:00:00.0 (included) recurring 2 time/s', '1) 2017-01-01 00:00:00.0%a2) 2017-01-02 01:00:00.0'], + ['2017-01-01', 'P1DT1H', '2017-01-03', 0, 'every + 1d 01:00:00.0, from [2017-01-01 00:00:00.0 to 2017-01-03 00:00:00.0[', '1) 2017-01-01 00:00:00.0%a2) 2017-01-02 01:00:00.0'], + ['2017-01-01', 'P1DT1H', 1, 0, 'every + 1d 01:00:00.0, from [2017-01-01 00:00:00.0 recurring 2 time/s', '1) 2017-01-01 00:00:00.0%a2) 2017-01-02 01:00:00.0'], - ['2017-01-01', 'P1D', '2017-01-04', \DatePeriod::EXCLUDE_START_DATE, 'every + 1d, from 2017-01-01 00:00:00.0 (excluded) to 2017-01-04 00:00:00.0', '1) 2017-01-02%a2) 2017-01-03'], - ['2017-01-01', 'P1D', 2, \DatePeriod::EXCLUDE_START_DATE, 'every + 1d, from 2017-01-01 00:00:00.0 (excluded) recurring 2 time/s', '1) 2017-01-02%a2) 2017-01-03'], + ['2017-01-01', 'P1D', '2017-01-04', \DatePeriod::EXCLUDE_START_DATE, 'every + 1d, from ]2017-01-01 00:00:00.0 to 2017-01-04 00:00:00.0[', '1) 2017-01-02%a2) 2017-01-03'], + ['2017-01-01', 'P1D', 2, \DatePeriod::EXCLUDE_START_DATE, 'every + 1d, from ]2017-01-01 00:00:00.0 recurring 2 time/s', '1) 2017-01-02%a2) 2017-01-03'], ]; return $periods; diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php index 2d0bab03edae3..de0915a3f3612 100644 --- a/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php @@ -39,7 +39,7 @@ public function testReflectionCaster() +name: "ReflectionClass" %Aimplements: array:%d [ %A] - constants: array:3 [ + constants: array:%d [ 0 => ReflectionClassConstant { +name: "IS_IMPLICIT_ABSTRACT" +class: "ReflectionClass" @@ -58,7 +58,7 @@ public function testReflectionCaster() modifiers: "public" value: %d } - ] +%A] properties: array:%d [ "name" => ReflectionProperty { %A +name: "name" diff --git a/src/Symfony/Component/VarExporter/Tests/Fixtures/datetime.php b/src/Symfony/Component/VarExporter/Tests/Fixtures/datetime.php index 6429f10efe9f1..7078ef2525674 100644 --- a/src/Symfony/Component/VarExporter/Tests/Fixtures/datetime.php +++ b/src/Symfony/Component/VarExporter/Tests/Fixtures/datetime.php @@ -70,6 +70,7 @@ 'interval' => $o[6], 'recurrences' => 5, 'include_start_date' => true, + 'include_end_date' => false, ], ] );