vendor/hwi/oauth-bundle/HWIOAuthBundle.php line 43

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the HWIOAuthBundle package.
  4.  *
  5.  * (c) Hardware Info <opensource@hardware.info>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace HWI\Bundle\OAuthBundle;
  11. use HWI\Bundle\OAuthBundle\DependencyInjection\CompilerPass\ResourceOwnerMapCompilerPass;
  12. use HWI\Bundle\OAuthBundle\DependencyInjection\CompilerPass\SetResourceOwnerServiceNameCompilerPass;
  13. use HWI\Bundle\OAuthBundle\DependencyInjection\HWIOAuthExtension;
  14. use HWI\Bundle\OAuthBundle\DependencyInjection\Security\Factory\OAuthAuthenticatorFactory;
  15. use HWI\Bundle\OAuthBundle\DependencyInjection\Security\Factory\OAuthFactory;
  16. use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AuthenticatorFactoryInterface;
  17. use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
  18. use Symfony\Component\DependencyInjection\ContainerBuilder;
  19. use Symfony\Component\HttpKernel\Bundle\Bundle;
  20. /**
  21.  * @author Geoffrey Bachelet <geoffrey.bachelet@gmail.com>
  22.  * @author Alexander <geoffrey.bachelet@gmail.com>
  23.  */
  24. class HWIOAuthBundle extends Bundle
  25. {
  26.     /**
  27.      * {@inheritdoc}
  28.      */
  29.     public function build(ContainerBuilder $container)
  30.     {
  31.         parent::build($container);
  32.         /** @var $extension SecurityExtension */
  33.         $extension $container->getExtension('security');
  34.         // Symfony < 5.1 BC layer: support new Authenticator-based security system in Symfony 5.1+
  35.         // and old security system in all Symfony versions.
  36.         if (interface_exists(AuthenticatorFactoryInterface::class)) {
  37.             $extension->addSecurityListenerFactory(new OAuthAuthenticatorFactory());
  38.         } else {
  39.             $extension->addSecurityListenerFactory(new OAuthFactory());
  40.         }
  41.         $container->addCompilerPass(new SetResourceOwnerServiceNameCompilerPass());
  42.         $container->addCompilerPass(new ResourceOwnerMapCompilerPass());
  43.     }
  44.     /**
  45.      * {@inheritdoc}
  46.      */
  47.     public function getContainerExtension()
  48.     {
  49.         // return the right extension instead of "auto-registering" it. Now the
  50.         // alias can be hwi_oauth instead of hwi_o_auth..
  51.         if (null === $this->extension) {
  52.             return new HWIOAuthExtension();
  53.         }
  54.         return $this->extension;
  55.     }
  56. }