vendor/hwi/oauth-bundle/src/HWIOAuthBundle.php line 26

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\EnableRefreshOAuthTokenListenerCompilerPass;
  12. use HWI\Bundle\OAuthBundle\DependencyInjection\CompilerPass\ResourceOwnerCompilerPass;
  13. use HWI\Bundle\OAuthBundle\DependencyInjection\Security\Factory\OAuthAuthenticatorFactory;
  14. use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
  15. use Symfony\Component\DependencyInjection\ContainerBuilder;
  16. use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
  17. use Symfony\Component\HttpKernel\Bundle\Bundle;
  18. /**
  19.  * @author Geoffrey Bachelet <geoffrey.bachelet@gmail.com>
  20.  * @author Alexander <geoffrey.bachelet@gmail.com>
  21.  */
  22. class HWIOAuthBundle extends Bundle
  23. {
  24.     /**
  25.      * {@inheritdoc}
  26.      */
  27.     public function build(ContainerBuilder $container): void
  28.     {
  29.         parent::build($container);
  30.         /** @var SecurityExtension $extension */
  31.         $extension $container->getExtension('security');
  32.         $firewallNames $this->extension->getFirewallNames();
  33.         if (method_exists($extension'addAuthenticatorFactory')) {
  34.             $extension->addAuthenticatorFactory(new OAuthAuthenticatorFactory($firewallNames));
  35.         } elseif (method_exists($extension'addSecurityListenerFactory')) {
  36.             // Symfony < 5.4 BC layer
  37.             $extension->addSecurityListenerFactory(new OAuthAuthenticatorFactory($firewallNames));
  38.         } else {
  39.             throw new \RuntimeException('Unsupported Symfony Security component version');
  40.         }
  41.         $container->addCompilerPass(new ResourceOwnerCompilerPass());
  42.         $container->addCompilerPass(new EnableRefreshOAuthTokenListenerCompilerPass());
  43.     }
  44.     /**
  45.      * {@inheritdoc}
  46.      */
  47.     public function getContainerExtension(): ?ExtensionInterface
  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.         return $this->extension ?: $this->extension $this->createContainerExtension();
  52.     }
  53. }