From ae233e2096e4ddd6dd18831b76f7534d2414d60e Mon Sep 17 00:00:00 2001 From: Patrizio Bekerle <patrizio@bekerle.com> Date: Thu, 17 Mar 2022 15:53:24 +0100 Subject: [PATCH] Remove PersonForExternalServiceEvent --- README.md | 56 ------------------------------ src/Service/LDAPApi.php | 15 -------- src/Service/LDAPPersonProvider.php | 5 --- tests/PersonTest.php | 11 ------ 4 files changed, 87 deletions(-) diff --git a/README.md b/README.md index facef3a..6969d1b 100644 --- a/README.md +++ b/README.md @@ -93,62 +93,6 @@ class PersonUserItemSubscriber implements EventSubscriberInterface } ``` -### PersonForExternalServiceEvent - -Some integration services may need to fetch a person from an external API with a -`\Dbp\Relay\BasePersonBundle\API\PersonProviderInterface`, for example: - -```php -$person = $this->personProvider->getPersonForExternalService('SOME_SERVICE', $userId); -``` - -To implement such a fetch process from an external API this event can be used. - -An event subscriber receives a `\Dbp\Relay\BasePersonConnectorLdapBundle\Event\PersonForExternalServiceEvent` instance -in a service for example in `src/EventSubscriber/PersonForExternalServiceSubscriber.php`: - -```php -<?php - -namespace App\EventSubscriber; - -use Dbp\Relay\BasePersonConnectorLdapBundle\Event\PersonForExternalServiceEvent; -use Dbp\Relay\BasePersonConnectorLdapBundle\Service\LDAPApi; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use App\Service\ExternalApi; - -class PersonForExternalServiceSubscriber implements EventSubscriberInterface -{ - private $ldap; - private $externalApi; - - public function __construct(LDAPApi $ldap, ExternalApi $externalApi) - { - $this->ldap = $ldap; - $this->externalApi = $externalApi; - } - - public static function getSubscribedEvents(): array - { - return [ - PersonForExternalServiceEvent::NAME => 'onEvent', - ]; - } - - public function onEvent(PersonForExternalServiceEvent $event) - { - $service = $event->getService(); - $serviceID = $event->getServiceID(); - - if ($service === 'SOME_SERVICE') { - $user = $this->externalApi->getPersonUserItemByExternalUserId($serviceID); - $person = $this->ldap->personFromUserItem($user, true); - $event->setPerson($person); - } - } -} -``` - ### PersonFromUserItemPostEvent This event allows to modify the person after it is converted from an LDAP User. diff --git a/src/Service/LDAPApi.php b/src/Service/LDAPApi.php index dd8a44c..85c814a 100644 --- a/src/Service/LDAPApi.php +++ b/src/Service/LDAPApi.php @@ -15,7 +15,6 @@ use Adldap\Connections\ProviderInterface; use Adldap\Models\User; use Adldap\Query\Builder; use Dbp\Relay\BasePersonBundle\Entity\Person; -use Dbp\Relay\BasePersonConnectorLdapBundle\Event\PersonForExternalServiceEvent; use Dbp\Relay\BasePersonConnectorLdapBundle\Event\PersonFromUserItemPostEvent; use Dbp\Relay\BasePersonConnectorLdapBundle\Event\PersonFromUserItemPreEvent; use Dbp\Relay\BasePersonConnectorLdapBundle\Event\PersonUserItemPreEvent; @@ -29,7 +28,6 @@ use Psr\Log\LoggerAwareTrait; use Symfony\Component\Cache\Psr16Cache; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Contracts\Service\ServiceSubscriberInterface; @@ -285,19 +283,6 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface return $person; } - public function getPersonForExternalService(string $service, string $serviceID): Person - { - $event = new PersonForExternalServiceEvent($service, $serviceID); - $this->dispatcher->dispatch($event, PersonForExternalServiceEvent::NAME); - $person = $event->getPerson(); - - if (!$person) { - throw new BadRequestHttpException("Unknown service: $service"); - } - - return $person; - } - private function getUserSession(): UserSessionInterface { return $this->locator->get(UserSessionInterface::class); diff --git a/src/Service/LDAPPersonProvider.php b/src/Service/LDAPPersonProvider.php index 65d95b8..20557e6 100644 --- a/src/Service/LDAPPersonProvider.php +++ b/src/Service/LDAPPersonProvider.php @@ -26,11 +26,6 @@ class LDAPPersonProvider implements PersonProviderInterface return $this->ldapApi->getPerson($id); } - public function getPersonForExternalService(string $service, string $serviceID): Person - { - return $this->ldapApi->getPersonForExternalService($service, $serviceID); - } - public function getCurrentPerson(): ?Person { return $this->ldapApi->getCurrentPerson(); diff --git a/tests/PersonTest.php b/tests/PersonTest.php index 9511a1c..08ddca6 100644 --- a/tests/PersonTest.php +++ b/tests/PersonTest.php @@ -121,17 +121,6 @@ class PersonTest extends ApiTestCase $this->assertEquals($person->getExtraData('test'), 'my-test-string'); } - public function testPersonForExternalServiceEvent() - { - $user = new AdldapUser([ - 'cn' => ['foobar'], - ], $this->newBuilder()); - - $person = $this->api->getPersonForExternalService('test-service', '17'); - - $this->assertEquals($person->getExtraData('test-service'), 'my-test-service-string-17'); - } - // public function testPersonUserItemEvent() // { // $user = $this->api->getPersonUserItem('foobar'); -- GitLab