Symfony\Component\Security\Core\SecurityContext::__construct PHP Method

__construct() public method

For backwards compatibility, the signature of sf <2.6 still works.
public __construct ( Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface | Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface $tokenStorage, Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface | Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface $authorizationChecker, boolean $alwaysAuthenticate = false )
$tokenStorage Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface | Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface
$authorizationChecker Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface | Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface
$alwaysAuthenticate boolean only applicable with old signature
    public function __construct($tokenStorage, $authorizationChecker, $alwaysAuthenticate = false)
    {
        $oldSignature = $tokenStorage instanceof AuthenticationManagerInterface && $authorizationChecker instanceof AccessDecisionManagerInterface;
        $newSignature = $tokenStorage instanceof TokenStorageInterface && $authorizationChecker instanceof AuthorizationCheckerInterface;
        // confirm possible signatures
        if (!$oldSignature && !$newSignature) {
            throw new \BadMethodCallException('Unable to construct SecurityContext, please provide the correct arguments');
        }
        if ($oldSignature) {
            // renamed for clarity
            $authenticationManager = $tokenStorage;
            $accessDecisionManager = $authorizationChecker;
            $tokenStorage = new TokenStorage();
            $authorizationChecker = new AuthorizationChecker($tokenStorage, $authenticationManager, $accessDecisionManager, $alwaysAuthenticate);
        }
        $this->tokenStorage = $tokenStorage;
        $this->authorizationChecker = $authorizationChecker;
    }

Usage Example

 /**
  * @param $security_config
  * @param $encoderFactory
  * @param $doctrine
  */
 public function __construct($security_config, $encoderFactory, $doctrine)
 {
     $this->security_config = $security_config;
     $this->encoderFactory = $encoderFactory;
     $this->doctrine = $doctrine;
     parent::__construct($this->getAuthenticationManager(), $this->getAccessDecisionManager());
 }
All Usage Examples Of Symfony\Component\Security\Core\SecurityContext::__construct