Skip to content
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

ParameterBagInterface::get() with ServiceSubscriberInterface #338

Open
hlecorche opened this issue Feb 21, 2023 · 1 comment
Open

ParameterBagInterface::get() with ServiceSubscriberInterface #338

hlecorche opened this issue Feb 21, 2023 · 1 comment

Comments

@hlecorche
Copy link

Hello,

Since #192 (fix #191), the return type for ParameterBagInterface::get() works with dependency injection but not with ServiceSubscriberInterface :

namespace App\Issue;

use Psr\Container\ContainerInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Contracts\Service\ServiceSubscriberInterface;

class Issue implements ServiceSubscriberInterface
{
    public function __construct(protected ContainerInterface $container, protected ParameterBagInterface $parameterBag)
    {
    }

    public function test(): void
    {
        $parameterBagFromConstructor = $this->parameterBag;
        // Expected: Dumped type: Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface
        // Observed: Dumped type: Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface
        \PHPStan\dumpType($parameterBagFromConstructor);

        $parameterBagFromContainer = $this->container->get(ParameterBagInterface::class);
        // Expected: Dumped type: Symfony\Component\DependencyInjection\ParameterBag\ContainerBag
        // Observed: Dumped type: Symfony\Component\DependencyInjection\ParameterBag\ContainerBag
        \PHPStan\dumpType($parameterBagFromContainer);

        $parameterFromConstructor = $parameterBagFromConstructor->get('kernel.project_dir');
        // Expected: Dumped type: string
        // Observed: Dumped type: string
        \PHPStan\dumpType($parameterFromConstructor);

        $parameterFromContainer = $parameterBagFromContainer->get('kernel.project_dir');
        // Expected: Dumped type: string
        // Observed: Dumped type: array|bool|float|int|string|UnitEnum|null
        \PHPStan\dumpType($parameterFromContainer);
    }

    public static function getSubscribedServices(): array
    {
        return [
            ParameterBagInterface::class,
        ];
    }
}

Is there a solution for add the support of ParameterBagInterface::get() with ServiceSubscriberInterface ?

Thanks

@pscheit
Copy link

pscheit commented Dec 4, 2023

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

No branches or pull requests

2 participants