Skip to content

ServiceSubscriberInterface, voters and private services issue #89

Open
@vandroids

Description

@vandroids

Support question

Hello!
I'm trying to use ServiceSubscriberInterface after reading this article https://symfonycasts.com/screencast/symfony-doctrine/service-subscriber

They suggest to use service locator pattern for the sake of performance in voters.
And the problem is this:

namespace App\Voters;

use Psr\Container\ContainerInterface;
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Contracts\Service\ServiceSubscriberInterface;

class MyVoter extends Voter implements ServiceSubscriberInterface
{
    /**
     * @var ContainerInterface
     */
    private $container;

    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }

    protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
    {
        $this->container->get(AccessDecisionManagerInterface::class)->decide...
    }

    public static function getSubscribedServices()
    {
        return [
            AccessDecisionManagerInterface::class
        ];
    }
}

Phpstan tells me that Service "Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface" is private.
But my code actually works without any problems.

Can you please help me to find out what to do in this situation?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions