diff --git a/composer.json b/composer.json index 864647ea9e5c986d4c9d2b5dbe506379070b286d..adc3144125c7a1e334639c614450412a9e8a1e04 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "adldap2/adldap2": "^10.3", "dbp/relay-auth-bundle": "^0.1.6", "dbp/relay-base-person-bundle": "v0.2.1", - "dbp/relay-core-bundle": "^0.1.35", + "dbp/relay-core-bundle": "dev-main as 0.1.37", "guzzlehttp/guzzle": "^7.3", "league/uri": "^6.5", "symfony/event-dispatcher": "^5.4", diff --git a/composer.lock b/composer.lock index 0fd602a19cd53b39ec5af4d6756334d62939e622..8d969175389d70d72f8b89482426ebb8d8cbe3e4 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "92bc4a145720f84a7607d0270308ac9f", + "content-hash": "1262fab1c713ea8767e23bf5b9729efc", "packages": [ { "name": "adldap2/adldap2", @@ -396,11 +396,11 @@ }, { "name": "dbp/relay-core-bundle", - "version": "0.1.37", + "version": "dev-main", "source": { "type": "git", "url": "https://gitlab.tugraz.at/dbp/relay/dbp-relay-core-bundle", - "reference": "b58c833026de0aa0572a38684d0b0f2107e46aee" + "reference": "7f2301d63ff98fa9cdd9faaac5e610f57f8c64db" }, "require": { "api-platform/core": "^2.6.6", @@ -409,6 +409,8 @@ "ext-fileinfo": "*", "ext-json": "*", "guzzlehttp/guzzle": "^7.0", + "kevinrob/guzzle-cache-middleware": "^4.0", + "league/uri": "^6.5", "nelmio/cors-bundle": "^2.1.0", "php": "^7.3 || ^8.0", "phpdocumentor/reflection-docblock": "^3.0 || ^4.0 || ^5.0", @@ -442,6 +444,7 @@ "symfony/phpunit-bridge": "^5.3", "vimeo/psalm": "^4.4" }, + "default-branch": true, "type": "symfony-bundle", "extra": { "hooks": { @@ -460,7 +463,7 @@ "AGPL-3.0-or-later" ], "description": "The core bundle of the Relay API gateway", - "time": "2022-06-22T09:04:47+00:00" + "time": "2022-08-10T12:21:15+00:00" }, { "name": "doctrine/annotations", @@ -11183,9 +11186,18 @@ "time": "2015-12-17T08:42:14+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "dbp/relay-core-bundle", + "version": "dev-main", + "alias": "0.1.37", + "alias_normalized": "0.1.37.0" + } + ], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "dbp/relay-core-bundle": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { @@ -11197,5 +11209,5 @@ "platform-overrides": { "php": "7.3" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.2.0" } diff --git a/src/Event/PersonFromUserItemPostEvent.php b/src/Event/PersonFromUserItemPostEvent.php index 52e7494d31b31ff4abd50d164ae2955be55d4d19..f278c13752f7180026c54633d04488834092c17e 100644 --- a/src/Event/PersonFromUserItemPostEvent.php +++ b/src/Event/PersonFromUserItemPostEvent.php @@ -5,9 +5,9 @@ declare(strict_types=1); namespace Dbp\Relay\BasePersonConnectorLdapBundle\Event; use Dbp\Relay\BasePersonBundle\Entity\Person; -use Dbp\Relay\CoreBundle\LocalData\LocalDataAwareEvent; +use Dbp\Relay\CoreBundle\LocalData\LocalDataAwarePostEvent; -class PersonFromUserItemPostEvent extends LocalDataAwareEvent +class PersonFromUserItemPostEvent extends LocalDataAwarePostEvent { public const NAME = 'dbp.relay.base_person_connector_ldap_bundle.person_from_user_item.post'; diff --git a/src/Service/LDAPApi.php b/src/Service/LDAPApi.php index a6148946bd4320658e6ae75863cc8a335a87c269..e519bd5a59f17a487ef92dc1af3e3ea4490c4e56 100644 --- a/src/Service/LDAPApi.php +++ b/src/Service/LDAPApi.php @@ -20,7 +20,6 @@ use Dbp\Relay\BasePersonConnectorLdapBundle\Event\PersonUserItemPreEvent; use Dbp\Relay\CoreBundle\API\UserSessionInterface; use Dbp\Relay\CoreBundle\Exception\ApiError; use Dbp\Relay\CoreBundle\Helpers\Tools as CoreTools; -use Dbp\Relay\CoreBundle\LocalData\LocalData; use Dbp\Relay\CoreBundle\LocalData\LocalDataAwareEventDispatcher; use Psr\Cache\CacheItemPoolInterface; use Psr\Container\ContainerInterface; @@ -68,11 +67,8 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface private $birthdayAttributeName; - /** @var EventDispatcherInterface */ - private $dispatcher; - /** @var LocalDataAwareEventDispatcher */ - private $localDataAwareEventDispatcher; + private $eventDispatcher; public function __construct(ContainerInterface $locator, EventDispatcherInterface $dispatcher) { @@ -81,8 +77,7 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface $this->currentPerson = null; $this->locator = $locator; $this->deploymentEnv = 'production'; - $this->dispatcher = $dispatcher; - $this->localDataAwareEventDispatcher = new LocalDataAwareEventDispatcher(Person::class, $dispatcher); + $this->eventDispatcher = new LocalDataAwareEventDispatcher(Person::class, $dispatcher); } public function setConfig(array $config) @@ -226,7 +221,7 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface public function getPersons(array $filters): array { - $this->localDataAwareEventDispatcher->initRequestedLocalDataAttributes(LocalData::getIncludeParameter($filters)); + $this->eventDispatcher->onNewOperation($filters); $persons = []; $items = $this->getPeopleUserItems($filters); @@ -241,7 +236,7 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface private function getPersonUserItem(string $identifier): User { $preEvent = new PersonUserItemPreEvent($identifier); - $this->dispatcher->dispatch($preEvent, PersonUserItemPreEvent::NAME); + $this->eventDispatcher->dispatch($preEvent, PersonUserItemPreEvent::NAME); $identifier = $preEvent->getIdentifier(); try { @@ -271,7 +266,7 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface public function personFromUserItem(User $user, bool $full): Person { // $preEvent = new PersonFromUserItemPreEvent($user, $full); -// $this->dispatcher->dispatch($preEvent, PersonFromUserItemPreEvent::NAME); +// $this->eventDispatcher->dispatch($preEvent, PersonFromUserItemPreEvent::NAME); // $user = $preEvent->getUser(); $identifier = $user->getFirstAttribute($this->identifierAttributeName) ?? ''; @@ -305,14 +300,14 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface } $postEvent = new PersonFromUserItemPostEvent($attributes, $person, $full); - $this->localDataAwareEventDispatcher->dispatch($postEvent, PersonFromUserItemPostEvent::NAME); + $this->eventDispatcher->dispatch($postEvent, PersonFromUserItemPostEvent::NAME); return $postEvent->getPerson(); } public function getPerson(string $id, array $options = []): Person { - $this->localDataAwareEventDispatcher->initRequestedLocalDataAttributes(LocalData::getIncludeParameter($options)); + $this->eventDispatcher->onNewOperation($options); // extract username in case $id is an iri, e.g. /base/people/{user} $parts = explode('/', $id); @@ -353,7 +348,7 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface if ($this->currentPerson) { if ($this->currentPerson->getIdentifier() === $currentIdentifier) { - if (!$checkLocalDataAttributes || $this->localDataAwareEventDispatcher->checkRequestedAttributesIdentitcal($this->currentPerson)) { + if (!$checkLocalDataAttributes || $this->eventDispatcher->checkRequestedAttributesIdentical($this->currentPerson)) { return $this->currentPerson; } else { // cache a new instance of Person because the cached instance's local data attributes do not match the requested attributes