From f129e838265d0f9ee3197d5133676e7695dad758 Mon Sep 17 00:00:00 2001 From: "Eric Richer eric.richer@vistoconsulting.com" Date: Thu, 27 Jun 2024 09:11:42 -0400 Subject: [PATCH] to fix #74 Signed-off-by: Eric Richer eric.richer@vistoconsulting.com --- src/Authentication/Adapter/AdapterChain.php | 3 +++ .../Adapter/AdapterChainServiceFactory.php | 4 ++++ src/Authentication/Adapter/Db.php | 11 +++++++++++ tests/Authentication/Adapter/DbTest.php | 10 ++++++++++ 4 files changed, 28 insertions(+) diff --git a/src/Authentication/Adapter/AdapterChain.php b/src/Authentication/Adapter/AdapterChain.php index a4c250e..9feaad6 100644 --- a/src/Authentication/Adapter/AdapterChain.php +++ b/src/Authentication/Adapter/AdapterChain.php @@ -105,6 +105,9 @@ public function resetAdapters() } } } + $event = $this->getEvent(); + $event->setName('reset'); + $this->getEventManager()->triggerEvent($event); return $this; } diff --git a/src/Authentication/Adapter/AdapterChainServiceFactory.php b/src/Authentication/Adapter/AdapterChainServiceFactory.php index a473e14..cdeae6a 100644 --- a/src/Authentication/Adapter/AdapterChainServiceFactory.php +++ b/src/Authentication/Adapter/AdapterChainServiceFactory.php @@ -27,6 +27,10 @@ public function __invoke(ContainerInterface $serviceLocator, $requestedName, arr if (is_callable(array($adapter, 'logout'))) { $chain->getEventManager()->attach('logout', array($adapter, 'logout'), $priority); } + + if (is_callable(array($adapter, 'reset'))) { + $chain->getEventManager()->attach('reset', array($adapter, 'reset'), $priority); + } } return $chain; diff --git a/src/Authentication/Adapter/Db.php b/src/Authentication/Adapter/Db.php index a566ff2..a872bde 100644 --- a/src/Authentication/Adapter/Db.php +++ b/src/Authentication/Adapter/Db.php @@ -43,6 +43,17 @@ public function logout(AdapterChainEvent $e) $this->getStorage()->clear(); } + /** + * Called when authentication adapter is reset + * @param AdapterChainEvent $e + * + */ + public function reset(AdapterChainEvent $e): void + { + $this->getStorage()->clear(); + } + + /** * @param AdapterChainEvent $e * @return bool diff --git a/tests/Authentication/Adapter/DbTest.php b/tests/Authentication/Adapter/DbTest.php index dd40307..2b169f0 100644 --- a/tests/Authentication/Adapter/DbTest.php +++ b/tests/Authentication/Adapter/DbTest.php @@ -86,6 +86,16 @@ public function testLogout() $this->db->logout($this->authEvent); } + /** + * @covers \LmcUser\Authentication\Adapter\Db::reset + */ + public function testReset() + { + $this->storage->expects($this->once()) + ->method('clear'); + $this->db->reset($this->authEvent); + } + /** * @covers \LmcUser\Authentication\Adapter\Db::Authenticate */