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

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