From 455fe57493b065f764bbaf6cca8bef51fa256923 Mon Sep 17 00:00:00 2001 From: tuutti Date: Mon, 7 Nov 2022 10:28:43 +0200 Subject: [PATCH 1/2] UHF-4826: Pass Tunnistamo client to RedirectUrlEvent --- src/Event/RedirectUrlEvent.php | 35 ++++++++++--------- src/Plugin/OpenIDConnectClient/Tunnistamo.php | 3 +- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/Event/RedirectUrlEvent.php b/src/Event/RedirectUrlEvent.php index 27076d9..44bb462 100644 --- a/src/Event/RedirectUrlEvent.php +++ b/src/Event/RedirectUrlEvent.php @@ -5,6 +5,7 @@ namespace Drupal\helfi_tunnistamo\Event; use Drupal\Core\Url; +use Drupal\helfi_tunnistamo\Plugin\OpenIDConnectClient\Tunnistamo; use Symfony\Component\HttpFoundation\Request; use Symfony\Contracts\EventDispatcher\Event; @@ -13,20 +14,6 @@ */ final class RedirectUrlEvent extends Event { - /** - * The redirect url. - * - * @var \Drupal\Core\Url - */ - private Url $redirectUrl; - - /** - * The request. - * - * @var \Symfony\Component\HttpFoundation\Request - */ - private Request $request; - /** * Gets the redirect url. * @@ -34,10 +21,24 @@ final class RedirectUrlEvent extends Event { * The redirect url. * @param \Symfony\Component\HttpFoundation\Request $request * The request. + * @param \Drupal\helfi_tunnistamo\Plugin\OpenIDConnectClient\Tunnistamo $client + * The Tunnistamo client. */ - public function __construct(Url $redirectUrl, Request $request) { - $this->redirectUrl = $redirectUrl; - $this->request = $request; + public function __construct( + public Url $redirectUrl, + public Request $request, + public Tunnistamo $client + ) { + } + + /** + * Gets the Tunnistamo client. + * + * @return \Drupal\helfi_tunnistamo\Plugin\OpenIDConnectClient\Tunnistamo + * The Tunnistamo client. + */ + public function getClient() : Tunnistamo { + return $this->client; } /** diff --git a/src/Plugin/OpenIDConnectClient/Tunnistamo.php b/src/Plugin/OpenIDConnectClient/Tunnistamo.php index b7ba342..a3d7791 100644 --- a/src/Plugin/OpenIDConnectClient/Tunnistamo.php +++ b/src/Plugin/OpenIDConnectClient/Tunnistamo.php @@ -108,7 +108,8 @@ protected function getRedirectUrl( /** @var \Drupal\helfi_tunnistamo\Event\RedirectUrlEvent $urlEvent */ $urlEvent = $this->eventDispatcher->dispatch(new RedirectUrlEvent( $url, - $this->requestStack->getCurrentRequest() + $this->requestStack->getCurrentRequest(), + $this )); return $urlEvent->getRedirectUrl(); } From 2275a59de7f6797bbf2e03344bfaafe5c2b7a523 Mon Sep 17 00:00:00 2001 From: tuutti Date: Mon, 7 Nov 2022 10:29:53 +0200 Subject: [PATCH 2/2] UHF-4826: Revert property visibility back to private --- src/Event/RedirectUrlEvent.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Event/RedirectUrlEvent.php b/src/Event/RedirectUrlEvent.php index 44bb462..86ae0b5 100644 --- a/src/Event/RedirectUrlEvent.php +++ b/src/Event/RedirectUrlEvent.php @@ -25,9 +25,9 @@ final class RedirectUrlEvent extends Event { * The Tunnistamo client. */ public function __construct( - public Url $redirectUrl, - public Request $request, - public Tunnistamo $client + private Url $redirectUrl, + private Request $request, + private Tunnistamo $client ) { }