From 0e5dea3dc24198456440044c26e6721840e5e4b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sun, 10 Nov 2024 22:26:41 +0100 Subject: [PATCH 1/4] Remove deprecated methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Luís Cobucci --- src/Builder.php | 16 ---------------- src/ContainerBuilder.php | 25 ------------------------- test/ContainerBuilderTest.php | 13 ------------- 3 files changed, 54 deletions(-) diff --git a/src/Builder.php b/src/Builder.php index 0393805b..32128143 100644 --- a/src/Builder.php +++ b/src/Builder.php @@ -15,13 +15,6 @@ interface Builder { public const DEFAULT_PRIORITY = 0; - /** - * Changes the generator to handle the files - * - * @deprecated This is deprecated in favour of using the correct naming constructor. - */ - public function setGenerator(Generator $generator): Builder; - /** * Add a file to be loaded */ @@ -58,15 +51,6 @@ public function addPackage(string $className, array $constructArguments = []): B */ public function setProfileName(string $profileName): Builder; - /** - * Mark the container to be used as development mode - * - * @deprecated this method will be removed in favour of a more explicit name. - * - * @see enableDebugging - */ - public function useDevelopmentMode(): Builder; - /** * Configure the container to track file updates */ diff --git a/src/ContainerBuilder.php b/src/ContainerBuilder.php index 9aa752e9..e6a425fd 100644 --- a/src/ContainerBuilder.php +++ b/src/ContainerBuilder.php @@ -25,19 +25,6 @@ public function __construct( $this->setDefaultConfiguration(); } - /** - * @deprecated Use the named constructor according to the generator - * - * @see ContainerBuilder::xml() - * @see ContainerBuilder::yaml() - * @see ContainerBuilder::php() - * @see ContainerBuilder::delegating() - */ - public static function default(string $configurationFile, string $namespace): self - { - return self::xml($configurationFile, $namespace); - } - /** @param class-string $builderClass */ public static function xml( string $configurationFile, @@ -100,13 +87,6 @@ private function setDefaultConfiguration(): void $this->config->addPass($this->parameterBag); } - public function setGenerator(Generator $generator): Builder - { - $this->generator = $generator; - - return $this; - } - public function addFile(string $file): Builder { $this->config->addFile($file); @@ -151,11 +131,6 @@ public function setProfileName(string $profileName): Builder return $this; } - public function useDevelopmentMode(): Builder - { - return $this->enableDebugging(); - } - public function enableDebugging(): Builder { $this->parameterBag->set('app.devmode', true); diff --git a/test/ContainerBuilderTest.php b/test/ContainerBuilderTest.php index d61f4bb7..19900330 100644 --- a/test/ContainerBuilderTest.php +++ b/test/ContainerBuilderTest.php @@ -59,7 +59,6 @@ public function namedConstructorsShouldSimplifyTheObjectCreation( /** @return iterable}> */ public static function supportedFormats(): iterable { - yield 'default' => ['default', new Generators\Xml(__FILE__)]; yield 'xml' => ['xml', new Generators\Xml(__FILE__)]; yield 'yaml' => ['yaml', new Generators\Yaml(__FILE__)]; yield 'php' => ['php', new Generators\Php(__FILE__)]; @@ -99,18 +98,6 @@ public function constructShouldReceiveTheDependenciesAsArguments(): void self::assertFalse($this->parameterBag->get('app.devmode')); } - #[PHPUnit\Test] - public function setGeneratorShouldChangeTheAttributeAndReturnSelf(): void - { - $builder = new ContainerBuilder($this->config, $this->generator, $this->parameterBag); - $generator = $this->createMock(Generator::class); - $expected = new ContainerBuilder($this->config, $generator, $this->parameterBag); - - // @phpstan-ignore-next-line method is deprecated and will be removed in the next major version - self::assertSame($builder, $builder->setGenerator($generator)); - self::assertEquals($expected, $builder); - } - #[PHPUnit\Test] public function addFileShouldAppendANewFileOnTheListAndReturnSelf(): void { From 7b2427b1513413fe3e39fbf3b51566725a4b7099 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sun, 10 Nov 2024 22:29:39 +0100 Subject: [PATCH 2/4] Make some classes read-only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Luís Cobucci --- src/Compiler.php | 2 +- src/Compiler/DumpXmlContainer.php | 2 +- src/ContainerBuilder.php | 2 +- src/Generator.php | 6 +++--- src/Generators/Delegating.php | 2 +- src/Generators/Php.php | 2 +- src/Generators/Xml.php | 2 +- src/Generators/Yaml.php | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Compiler.php b/src/Compiler.php index 95209cf0..dfd5496c 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -18,7 +18,7 @@ use function is_array; use function is_string; -final class Compiler +final readonly class Compiler { private const DEFAULT_PASS_CONFIG = [null, PassConfig::TYPE_BEFORE_OPTIMIZATION, 0]; diff --git a/src/Compiler/DumpXmlContainer.php b/src/Compiler/DumpXmlContainer.php index 3fdb61a6..d15f5b78 100644 --- a/src/Compiler/DumpXmlContainer.php +++ b/src/Compiler/DumpXmlContainer.php @@ -8,7 +8,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Dumper\XmlDumper; -final class DumpXmlContainer implements CompilerPassInterface +final readonly class DumpXmlContainer implements CompilerPassInterface { public function __construct(private ConfigCacheInterface $configCache) { diff --git a/src/ContainerBuilder.php b/src/ContainerBuilder.php index e6a425fd..5015b8bb 100644 --- a/src/ContainerBuilder.php +++ b/src/ContainerBuilder.php @@ -15,7 +15,7 @@ use function assert; use function is_bool; -final class ContainerBuilder implements Builder +final readonly class ContainerBuilder implements Builder { public function __construct( private ContainerConfiguration $config, diff --git a/src/Generator.php b/src/Generator.php index 3c81d4e3..a190692a 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -13,14 +13,14 @@ use function assert; use function is_a; -abstract class Generator +abstract readonly class Generator { private Compiler $compiler; /** @param class-string $builderClass */ public function __construct( - private readonly string $configurationFile, - private readonly string $builderClass = SymfonyBuilder::class, + private string $configurationFile, + private string $builderClass = SymfonyBuilder::class, ) { $this->compiler = new Compiler(); } diff --git a/src/Generators/Delegating.php b/src/Generators/Delegating.php index 4e0eb481..c4b7ba03 100644 --- a/src/Generators/Delegating.php +++ b/src/Generators/Delegating.php @@ -16,7 +16,7 @@ /** * The dependency injection generator that allows XML, YAML and PHP files */ -final class Delegating extends Generator +final readonly class Delegating extends Generator { /** @inheritDoc */ public function getLoader(SymfonyBuilder $container, array $paths, ?string $profileName = null): LoaderInterface diff --git a/src/Generators/Php.php b/src/Generators/Php.php index 85c34b00..53a5ed6d 100644 --- a/src/Generators/Php.php +++ b/src/Generators/Php.php @@ -12,7 +12,7 @@ /** * The dependency injection generator for PHP files */ -final class Php extends Generator +final readonly class Php extends Generator { /** @inheritDoc */ public function getLoader(SymfonyBuilder $container, array $paths, ?string $profileName = null): LoaderInterface diff --git a/src/Generators/Xml.php b/src/Generators/Xml.php index dba92122..8a32a868 100644 --- a/src/Generators/Xml.php +++ b/src/Generators/Xml.php @@ -12,7 +12,7 @@ /** * The dependency injection generator for XML files */ -final class Xml extends Generator +final readonly class Xml extends Generator { /** @inheritDoc */ public function getLoader(SymfonyBuilder $container, array $paths, ?string $profileName = null): LoaderInterface diff --git a/src/Generators/Yaml.php b/src/Generators/Yaml.php index 668057ba..84d5a17e 100644 --- a/src/Generators/Yaml.php +++ b/src/Generators/Yaml.php @@ -12,7 +12,7 @@ /** * The dependency injection generator for YAML files */ -final class Yaml extends Generator +final readonly class Yaml extends Generator { /** @inheritDoc */ public function getLoader(SymfonyBuilder $container, array $paths, ?string $profileName = null): LoaderInterface From 3f5a497538032e30c3ea185e70b591f7a6f3649a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sun, 10 Nov 2024 22:33:01 +0100 Subject: [PATCH 3/4] Only resolve value once MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Luís Cobucci --- src/Compiler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compiler.php b/src/Compiler.php index dfd5496c..143edcfc 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -82,7 +82,7 @@ private function getContainerContent( $options['as_files'] = true; $options['inline_factories'] = $options['debug'] === false; - $options['inline_class_loader'] = $options['debug'] === false; + $options['inline_class_loader'] = $options['inline_factories']; $content = (new PhpDumper($container))->dump($options); assert(is_array($content)); From 2ffdcc7cfe6ce1756a6237724e853229c2fa31b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sun, 10 Nov 2024 22:33:30 +0100 Subject: [PATCH 4/4] Clarify which classes are under BC-guarantees MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Luís Cobucci --- src/Compiler.php | 1 + src/Compiler/ParameterBag.php | 2 ++ src/Config/ContainerConfiguration.php | 1 + src/Generator.php | 1 + src/Generators/Delegating.php | 2 ++ src/Generators/Php.php | 2 ++ src/Generators/Xml.php | 2 ++ src/Generators/Yaml.php | 2 ++ src/Testing/MakeServicesPublic.php | 1 + 9 files changed, 14 insertions(+) diff --git a/src/Compiler.php b/src/Compiler.php index 143edcfc..81e0f7e7 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -18,6 +18,7 @@ use function is_array; use function is_string; +/** @internal */ final readonly class Compiler { private const DEFAULT_PASS_CONFIG = [null, PassConfig::TYPE_BEFORE_OPTIMIZATION, 0]; diff --git a/src/Compiler/ParameterBag.php b/src/Compiler/ParameterBag.php index 36b057a0..2e36f70b 100644 --- a/src/Compiler/ParameterBag.php +++ b/src/Compiler/ParameterBag.php @@ -10,6 +10,8 @@ * Injects parameters into the container * * You should use this to define dynamic parameters using PHP + * + * @internal */ final class ParameterBag implements CompilerPassInterface { diff --git a/src/Config/ContainerConfiguration.php b/src/Config/ContainerConfiguration.php index c64378d9..bc83186d 100644 --- a/src/Config/ContainerConfiguration.php +++ b/src/Config/ContainerConfiguration.php @@ -20,6 +20,7 @@ use const DIRECTORY_SEPARATOR; +/** @internal */ final class ContainerConfiguration { public const CLASS_NAME = 'AppContainer'; diff --git a/src/Generator.php b/src/Generator.php index a190692a..67ce764f 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -13,6 +13,7 @@ use function assert; use function is_a; +/** @internal */ abstract readonly class Generator { private Compiler $compiler; diff --git a/src/Generators/Delegating.php b/src/Generators/Delegating.php index c4b7ba03..ed9f3739 100644 --- a/src/Generators/Delegating.php +++ b/src/Generators/Delegating.php @@ -15,6 +15,8 @@ /** * The dependency injection generator that allows XML, YAML and PHP files + * + * @internal */ final readonly class Delegating extends Generator { diff --git a/src/Generators/Php.php b/src/Generators/Php.php index 53a5ed6d..b15ed9fc 100644 --- a/src/Generators/Php.php +++ b/src/Generators/Php.php @@ -11,6 +11,8 @@ /** * The dependency injection generator for PHP files + * + * @internal */ final readonly class Php extends Generator { diff --git a/src/Generators/Xml.php b/src/Generators/Xml.php index 8a32a868..3b1242c9 100644 --- a/src/Generators/Xml.php +++ b/src/Generators/Xml.php @@ -11,6 +11,8 @@ /** * The dependency injection generator for XML files + * + * @internal */ final readonly class Xml extends Generator { diff --git a/src/Generators/Yaml.php b/src/Generators/Yaml.php index 84d5a17e..e33222f2 100644 --- a/src/Generators/Yaml.php +++ b/src/Generators/Yaml.php @@ -11,6 +11,8 @@ /** * The dependency injection generator for YAML files + * + * @internal */ final readonly class Yaml extends Generator { diff --git a/src/Testing/MakeServicesPublic.php b/src/Testing/MakeServicesPublic.php index 1f2fbc45..a4ee234f 100644 --- a/src/Testing/MakeServicesPublic.php +++ b/src/Testing/MakeServicesPublic.php @@ -6,6 +6,7 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; +/** @internal */ final class MakeServicesPublic implements CompilerPassInterface { /**