Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
5.4.23
Although Symfony 5.4 allows set an enum as an argument in DI Definition, it is not possible set the enum as the argument in Configurator.
Works:
protected function build(ContainerBuilder $container) { $container->register(MyService::class) ->setPublic(true) ->setArgument('$myEnum', MyEnum::First) ; }
Not works:
return static function (ContainerConfigurator $configurator): void { $configurator->services()->set(MyService::class) ->public() ->arg('$myEnum', MyEnum::First) ; };
Throws: Cannot use values of type "App\Service\MyEnum" in service configuration files.
config/services.php
$configurator->services()->set(MyService::class) ->arg('$myEnum', MyEnum::First) ;
src/Service/MyEnum.php
<?php namespace App\Service; enum MyEnum: string { case First = 'first'; case Second = 'second'; }
src/Service/MyService.php
<?php namespace App\Service; class MyService { public function __construct(MyEnum $myEnum) { } }
Symfony\Component\DependencyInjection\Loader\Configurator\AbstractConfigurator::processValue
Line 102
Replace
case null === $value: case \is_scalar($value): return $value;
by
case null === $value: case \is_scalar($value): case $value instanceof \UnitEnum: return $value;
No response
The text was updated successfully, but these errors were encountered:
This change makes sense. Can you submit a PR with the fix (and a test preventing regressions) ?
Sorry, something went wrong.
This works on 6.2 since #48045
I wrote some relevant arguments why this fix/feature should be merged to 5.4 LTS.
features are never merged into patch versions.
No branches or pull requests
Symfony version(s) affected
5.4.23
Description
Although Symfony 5.4 allows set an enum as an argument in DI Definition, it is not possible set the enum as the argument in Configurator.
Works:
Not works:
Throws: Cannot use values of type "App\Service\MyEnum" in service configuration files.
How to reproduce
config/services.php
src/Service/MyEnum.php
src/Service/MyService.php
Possible Solution
Symfony\Component\DependencyInjection\Loader\Configurator\AbstractConfigurator::processValue
Line 102
Replace
by
Additional Context
No response
The text was updated successfully, but these errors were encountered: