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 Returns true if the source is not set! */ private function isSourceNotSet(): bool { return !isset($this->source); } /** * @return bool Tells if a reload of the source is neccessary */ private function isReloadNeccessary(): bool { return $this->isSourceNotSet() || $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(); $this->setSourceIfNotSet(); } return $this->source; } private function setSourceIfNotSet(): void { if (!isset($this->source)) { $this->source = $this->requestedSource; } } /** * {@inheritdoc} * * @see \App\Domain\RightManagement\RightRequestManagement\RequestedRightInterface::setRequestedSource() */ final public function setRequestedSource(RequestedSourceInterface $requestedSource) { $this->requestedSource = $requestedSource; } }