vendor/symfony/security-bundle/Debug/TraceableFirewallListener.php line 48

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <[email protected]>
  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 Symfony\Bundle\SecurityBundle\Debug;
  11. use Symfony\Bundle\SecurityBundle\EventListener\FirewallListener;
  12. use Symfony\Bundle\SecurityBundle\Security\FirewallContext;
  13. use Symfony\Bundle\SecurityBundle\Security\LazyFirewallContext;
  14. use Symfony\Component\HttpKernel\Event\RequestEvent;
  15. use Symfony\Component\Security\Http\Authenticator\Debug\TraceableAuthenticatorManagerListener;
  16. use Symfony\Component\Security\Http\Firewall\FirewallListenerInterface;
  17. use Symfony\Contracts\Service\ResetInterface;
  18. /**
  19. * Firewall collecting called security listeners and authenticators.
  20. *
  21. * @author Robin Chalas <[email protected]>
  22. */
  23. final class TraceableFirewallListener extends FirewallListener implements ResetInterface
  24. {
  25. private $wrappedListeners = [];
  26. private $authenticatorsInfo = [];
  27. public function getWrappedListeners()
  28. {
  29. return $this->wrappedListeners;
  30. }
  31. public function getAuthenticatorsInfo(): array
  32. {
  33. return $this->authenticatorsInfo;
  34. }
  35. public function reset(): void
  36. {
  37. $this->wrappedListeners = [];
  38. $this->authenticatorsInfo = [];
  39. }
  40. protected function callListeners(RequestEvent $event, iterable $listeners)
  41. {
  42. $wrappedListeners = [];
  43. $wrappedLazyListeners = [];
  44. $authenticatorManagerListener = null;
  45. foreach ($listeners as $listener) {
  46. if ($listener instanceof LazyFirewallContext) {
  47. \Closure::bind(function () use (&$wrappedLazyListeners, &$wrappedListeners, &$authenticatorManagerListener) {
  48. $listeners = [];
  49. foreach ($this->listeners as $listener) {
  50. if (!$authenticatorManagerListener && $listener instanceof TraceableAuthenticatorManagerListener) {
  51. $authenticatorManagerListener = $listener;
  52. }
  53. if ($listener instanceof FirewallListenerInterface) {
  54. $listener = new WrappedLazyListener($listener);
  55. $listeners[] = $listener;
  56. $wrappedLazyListeners[] = $listener;
  57. } else {
  58. $listeners[] = function (RequestEvent $event) use ($listener, &$wrappedListeners) {
  59. $wrappedListener = new WrappedListener($listener);
  60. $wrappedListener($event);
  61. $wrappedListeners[] = $wrappedListener->getInfo();
  62. };
  63. }
  64. }
  65. $this->listeners = $listeners;
  66. }, $listener, FirewallContext::class)();
  67. $listener($event);
  68. } else {
  69. $wrappedListener = $listener instanceof FirewallListenerInterface ? new WrappedLazyListener($listener) : new WrappedListener($listener);
  70. $wrappedListener($event);
  71. $wrappedListeners[] = $wrappedListener->getInfo();
  72. if (!$authenticatorManagerListener && $listener instanceof TraceableAuthenticatorManagerListener) {
  73. $authenticatorManagerListener = $listener;
  74. }
  75. }
  76. if ($event->hasResponse()) {
  77. break;
  78. }
  79. }
  80. if ($wrappedLazyListeners) {
  81. foreach ($wrappedLazyListeners as $lazyListener) {
  82. $this->wrappedListeners[] = $lazyListener->getInfo();
  83. }
  84. }
  85. $this->wrappedListeners = array_merge($this->wrappedListeners, $wrappedListeners);
  86. if ($authenticatorManagerListener) {
  87. $this->authenticatorsInfo = $authenticatorManagerListener->getAuthenticatorsInfo();
  88. }
  89. }
  90. }