aggregate( 0, static function ($count, LtiProviderRepositoryInterface $implementation) { return $count + $implementation->count(); } ); } public function searchByToolClientId(string $clientId): ?LtiProvider { foreach ($this->findAll() as $provider) { if ($clientId === $provider->getToolClientId()) { return $provider; } } return null; } /** * Gathers LTI providers found from all implementations configured. * * @return LtiProvider[] */ public function findAll(): array { return $this->aggregate( [], static function ($providers, LtiProviderRepositoryInterface $implementation) { return array_merge($providers, $implementation->findAll()); } ); } /** * Gathers LTI providers found from all implementations configured and filters them by a string contained in label. * * @return LtiProvider[] */ public function searchByLabel(string $label): array { return $this->aggregate( [], static function ($providers, LtiProviderRepositoryInterface $implementation) use ($label) { return array_merge($providers, $implementation->searchByLabel($label)); } ); } /** * Aggregates results of each implementation. * * @param array|int $result * @param callable $method * * @return array|int */ private function aggregate($result, $method) { foreach ($this->getOption(self::LTI_PROVIDER_LIST_IMPLEMENTATIONS) as $implementation) { $this->propagate($implementation); $result = $method($result, $implementation); } return $result; } public function searchById(string $id): ?LtiProvider { return current( array_filter( $this->aggregate( [], static function ($providers, LtiProviderRepositoryInterface $implementation) use ($id) { return array_merge($providers, [$implementation->searchById($id)]); } ) ) ) ?: null; } public function searchByOauthKey(string $oauthKey): ?LtiProvider { $found = array_filter($this->aggregate( [], static function ($providers, LtiProviderRepositoryInterface $implementation) use ($oauthKey) { return array_merge($providers, [$implementation->searchByOauthKey($oauthKey)]); } )); return count($found) > 0 ? reset($found) : null; } public function searchByIssuer(string $issuer, ?string $clientId = null): ?LtiProvider { $found = array_filter($this->aggregate( [], static function ($providers, LtiProviderRepositoryInterface $implementation) use ($issuer, $clientId) { return array_merge($providers, [$implementation->searchByIssuer($issuer, $clientId)]); } )); return count($found) > 0 ? reset($found) : null; } }