diff --git a/README.md b/README.md index facef3abae63efa8c9f0a8bca6d6ee28afe30e69..6969d1bfb0a59362bae2c4e2e28e6926ce95fc89 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 dd8a44c11ae7fcbdfcefd45c3f06fb5b1d036e60..85c814aaf70ad517672bdad05630debb6b34ddef 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 65d95b879664870ee2a9d736b90a97e96136f242..20557e6c742432f6bac101039ee62cdfd4f144ad 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 9511a1c284e8b7b7608d947dc11eb94b49236ac2..08ddca6005134edc520102089e1c30c18bdbba67 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');