H
H
hitakiri2016-02-27 23:48:14
symfony
hitakiri, 2016-02-27 23:48:14

What is the correct way to pass a service parameter in Symfony?

Symfony 3.0.2 When I run the bundle, I get an error:

ContextErrorException in GitkiExtension.php line 30: Catchable Fatal Error: Argument 1 passed to Dontdrinkandroot\GitkiBundle\Twig\GitkiExtension::__construct() must be an instance of Symfony\Component\Security\Core\Security, instance of Symfony\Component\Security\Core\Authorization\AuthorizationChecker given, called in /var/www/teralit.local/var/cache/dev/appDevDebugProjectContainer.php on line 856 and defined

Actually GitkiExtension.php itself:
use Dontdrinkandroot\GitkiBundle\Service\ExtensionRegistry\ExtensionRegistryInterface;
use Dontdrinkandroot\GitkiBundle\Service\Role\RoleServiceInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Core\Authorization\AuthorizationChecker;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
class GitkiExtension extends \Twig_Extension
{

    /**
     * @var Security
     */
    private $securityContext;

    /**
     * @var ExtensionRegistryInterface
     */
    private $extensionRegistry;

    /**
     * @var RoleServiceInterface
     */
    private $roleService;

    public function __construct(
            Security $securityContext,
            RoleServiceInterface $roleService,
            ExtensionRegistryInterface $extensionRegistry
            ){
        $this->securityContext = $securityContext;
        $this->roleService = $roleService;
        $this->extensionRegistry = $extensionRegistry;
    }

services.yml :
ddr.gitki.twig.gitki_extension:
        class: Dontdrinkandroot\GitkiBundle\Twig\GitkiExtension
        arguments:
            - '@security.authorization_checker'
            - '@ddr.gitki.service.role'
            - '@ddr.gitki.registry.extension'
        tags:
            - { name: twig.extension }

Upd
Solution:
public function __construct(
            AuthorizationCheckerInterface $securityContext,
            RoleServiceInterface $roleService,
            ExtensionRegistryInterface $extensionRegistry
            ){
        $this->securityContext = $securityContext;
        $this->roleService = $roleService;
        $this->extensionRegistry = $extensionRegistry;
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan, 2016-02-28
@0neS

https://symfony.com/blog/new-in-symfony-2-6-securi...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question