Skip to content

Conversation

@soyuka
Copy link
Member

@soyuka soyuka commented Sep 9, 2025

#[Get(
    uriTemplate: '/link_parameter_provider_resources/{id}',
    uriVariables: [
        'id' => new Link(
            provider: ReadLinkParameterProvider::class,
            fromClass: Dummy::class
        ),
    ],
    provider: [self::class, 'provide']
)]
class LinkParameterProviderResource
{
    public string $id;
    public Dummy $dummy;
    public Dummy $dummyFromOperation;

    /**
     * @param HttpOperation $operation
     */
    public static function provide(Operation $operation, array $uriVariables = [])
    {
        $d = new self();
        $d->id = '1';
        $d->dummyFromOperation = $operation->getUriVariables()['id']->getValue();
        $d->dummy = $uriVariables['id'];

        return $d;
    }
}

@soyuka soyuka force-pushed the parameter-provider-uri-variable branch 4 times, most recently from c5547d8 to 3fcd7b3 Compare September 9, 2025 12:59
@soyuka soyuka force-pushed the parameter-provider-uri-variable branch from 3fcd7b3 to b527657 Compare September 9, 2025 14:15
@soyuka soyuka merged commit c9692b5 into api-platform:4.2 Sep 9, 2025
100 of 112 checks passed
@stephanvierkant
Copy link
Contributor

I've got this:

#[Get(routePrefix: '/foobar', provider: FooBarStatus::class . '::getCase'),]
enum FooBarStatus : string
{
    /** @param array<string, mixed> $uriVariables */
    public static function getCase(Operation $operation, array $uriVariables) : static
    {
        $name = $uriVariables['id'] ?? null;

        $reflectionClass = new ReflectionEnum($operation->getClass());

        if ($reflectionClass->getBackingType()->getName() === 'int') {
            $name = (int) $name;
        }

        return self::tryFrom($name);
    }
}

This doesn't work anymore. Can someone explain what should be changed?

@soyuka
Copy link
Member Author

soyuka commented Sep 19, 2025

I don't understand why it looks like this should work fine. It's definitely not linked to this PR please open a new issue.

@stephanvierkant
Copy link
Contributor

You're right, this PR isn't the cause. I'll try to find out what caused it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants