Skip to content

[HttpKernel] Do not ignore enum in controller arguments when it has an #[Autowire] attribute #60165

New issue

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

Merged
merged 1 commit into from
Apr 7, 2025

Conversation

ruudk
Copy link
Contributor

@ruudk ruudk commented Apr 7, 2025

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues
License MIT

When moving services injected from the constructor to the controller arguments, I noticed a bug.

We were auto wiring an env var to a backed enum like this:

class Foo
{
    public function __construct(
        #[Autowire(env: 'enum:App\Enum:SOME_ENV_KEY')]
        private \App\Enum $someEnum,
    ) {}

    public function __invoke() {}
}

This works fine with normal Symfony Dependency Injection.

But when we switch to controller arguments like this:

class Foo
{
    public function __invoke(
        #[Autowire(env: 'enum:App\Enum:SOME_ENV_KEY')]
        \App\Enum $someEnum,
    ) {}
}

This stops working.

The issue is that BackedEnum's are excluded. But this should only be excluded when there is no Autowire attribute.

@nicolas-grekas

This comment was marked as outdated.

…entLocatorsPass

When moving services injected from the constructor to the controller arguments, I noticed a bug.

We were auto wiring an env var to a backed enum like this:

```php
class Foo
{
    public function __construct(
        #[Autowire(env: 'enum:App\Enum:SOME_ENV_KEY')]
        private \App\Enum $someEnum,
    ) {}

    public function __invoke() {}
}
```

This works fine with normal Symfony Dependency Injection.

But when we switch to controller arguments like this:
```php
class Foo
{
    public function __invoke(
        #[Autowire(env: 'enum:App\Enum:SOME_ENV_KEY')]
        \App\Enum $someEnum,
    ) {}
}
```

This stops working.

The issue is that BackedEnum's are excluded. But this should only be excluded when there is no Autowire attribute.
@ruudk ruudk force-pushed the 6.4-fix-autowire-on-unit-enum branch from fa93de7 to 5d6a211 Compare April 7, 2025 09:51
@ruudk

This comment was marked as outdated.

@nicolas-grekas nicolas-grekas changed the title [HttpKernel] Do not ignore enum in controller arguments when it has an #Autowire] attribute [HttpKernel] Do not ignore enum in controller arguments when it has an #[Autowire] attribute Apr 7, 2025
@symfony symfony deleted a comment from carsonbot Apr 7, 2025
@nicolas-grekas
Copy link
Member

Thank you @ruudk.

@nicolas-grekas nicolas-grekas merged commit ea60073 into symfony:6.4 Apr 7, 2025
8 of 11 checks passed
This was referenced May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants