vendor/lexik/jwt-authentication-bundle/LexikJWTAuthenticationBundle.php line 24

Open in your IDE?
  1. <?php
  2. namespace Lexik\Bundle\JWTAuthenticationBundle;
  3. use Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Compiler\DeprecateLegacyGuardAuthenticatorPass;
  4. use Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Compiler\RegisterLegacyGuardAuthenticatorPass;
  5. use Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Compiler\WireGenerateTokenCommandPass;
  6. use Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Security\Factory\JWTAuthenticatorFactory;
  7. use Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Security\Factory\JWTFactory;
  8. use Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Security\Factory\JWTSecurityFactory;
  9. use Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Security\Factory\JWTUserFactory;
  10. use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface;
  11. use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
  12. use Symfony\Component\Console\Application;
  13. use Symfony\Component\DependencyInjection\Compiler\PassConfig;
  14. use Symfony\Component\DependencyInjection\ContainerBuilder;
  15. use Symfony\Component\HttpKernel\Bundle\Bundle;
  16. /**
  17.  * LexikJWTAuthenticationBundle.
  18.  *
  19.  * @author Nicolas Cabot <n.cabot@lexik.fr>
  20.  */
  21. class LexikJWTAuthenticationBundle extends Bundle
  22. {
  23.     /**
  24.      * {@inheritdoc}
  25.      */
  26.     public function build(ContainerBuilder $container)
  27.     {
  28.         parent::build($container);
  29.         $container->addCompilerPass(new WireGenerateTokenCommandPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION0);
  30.         $container->addCompilerPass(new DeprecateLegacyGuardAuthenticatorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION0);
  31.         /** @var SecurityExtension $extension */
  32.         $extension $container->getExtension('security');
  33.         $extension->addUserProviderFactory(new JWTUserFactory());
  34.         // Authenticator factory for Symfony 5.4 and later
  35.         if (method_exists($extension'addAuthenticatorFactory')) {
  36.             $extension->addAuthenticatorFactory(new JWTAuthenticatorFactory());
  37.             return;
  38.         }
  39.         // Security listener factory for Symfony 5.3 and earlier
  40.         if (method_exists($extension'addSecurityListenerFactory')) {
  41.             $extension->addSecurityListenerFactory(new JWTAuthenticatorFactory());
  42.             return;
  43.         }
  44.         // Security listener factory for Symfony 4.4
  45.         if (method_exists($extension'addSecurityListenerFactory')) {
  46.             $extension->addSecurityListenerFactory(new JWTFactory(false)); // BC 1.x, to be removed in 3.0
  47.         }
  48.     }
  49.     /**
  50.      * {@inheritdoc}
  51.      */
  52.     public function registerCommands(Application $application)
  53.     {
  54.         // noop
  55.     }
  56. }