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

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