getServices($type); if (!in_array($serviceId, $services[$type], true)) { $services[$type][] = $serviceId; } $this->setOption(self::OPTION_SERVICES, $services); } public function removeService(string $type, string $serviceId): void { $services = $this->getServices($type); $key = array_search($serviceId, $services[$type]); if ($key !== false) { unset($services[$type][$key]); } $this->setOption(self::OPTION_SERVICES, $services); } public function findRelations(FindAllQuery $query): ResourceRelationCollection { $relations = []; foreach ($this->getOption(self::OPTION_SERVICES, []) as $type => $services) { if ($query->getType() !== $type) { continue; } foreach ($services as $serviceId) { $relations = array_merge( $relations, $this->getResourceRelationService($serviceId) ->findRelations($query) ->getIterator() ->getArrayCopy() ); } } return new ResourceRelationCollection(...$relations); } private function getResourceRelationService(string $serviceId): ResourceRelationServiceInterface { return $this->getServiceLocator()->get($serviceId); } private function getServices(string $type): array { $services = (array)$this->getOption(self::OPTION_SERVICES, []); if (!isset($services[$type])) { $services[$type] = []; } return $services; } }