Skip to content

ServiceSubscriberInterface, voters and private services issue #89

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

Open
vandroids opened this issue Jul 17, 2020 · 3 comments
Open

ServiceSubscriberInterface, voters and private services issue #89

vandroids opened this issue Jul 17, 2020 · 3 comments

Comments

@vandroids
Copy link

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?

@ondrejmirtes ondrejmirtes transferred this issue from phpstan/phpstan Jul 17, 2020
@malarzm
Copy link
Contributor

malarzm commented Jun 16, 2021

Just bumped into same issue, seems that c340de8 wasn't a full fix

@specdrum-agc
Copy link

@malarzm there is old deprecated interface Symfony\Component\DependencyInjection\ServiceSubscriberInterface in the commit c340de8 . It has been removed in symfony 4, AFAIR. For now it is Symfony\Contracts\Service\ServiceSubscriberInterface

@malarzm
Copy link
Contributor

malarzm commented Jan 5, 2023

@specdrum-agc thanks for the ping! From what I can see we were originally using the correct interface (god bless GitHub showing links in issues from my private repositories). But also nowadays we no longer have the error in our baseline so I reckon this was fixed somewhen in the past by the way :)

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

3 participants