sourceRepository = $sourceRepository; } private function loadSource(): void { $this->source = $this->sourceRepository->findOneByIdOrSlug($this->requestedSource); } /** * @return bool */ private function isIdEquals(): bool { if ($this->requestedSource->hasId() && $this->source->hasId()) { return false; } return $this->requestedSource->getId() === $this->source->getId(); } /** * @return bool */ private function isSlugEquals(): bool { if ($this->requestedSource->hasSlug() && $this->source->hasSlug()) { return false; } return $this->requestedSource->getSlug() === $this->source->getSlug(); } /** * @return bool Tells if a reload of the source is neccessary */ private function isReloadNeccessary(): bool { return $this->isIdEquals() && $this->isSlugEquals(); } /** * Uses some kind of Lazy loading. * * @see https://en.wikipedia.org/wiki/Lazy_loading * {@inheritdoc} * @see \App\Domain\RightManagement\RightRequestManagement\RequestedRightInterface::getSource() */ final public function getSource(): SourceInterface { if ($this->isReloadNeccessary()) { $this->loadSource(); } return $this->source; } /** * {@inheritdoc} * * @see \App\Domain\RightManagement\RightRequestManagement\RequestedRightInterface::setRequestedSource() */ final public function setRequestedSource(RequestedSourceInterface $requestedSource) { $this->requestedSource = $requestedSource; $this->loadSource(); } }