requestedEntity->getEntity(); if ($entity instanceof SourceInterface) { $this->source = $entity; return; } if ($entity instanceof MetaInterface) { $this->source = $entity->getSource(); return; } throw new NotCorrectInstanceCoreException('The entity instance '.get_class($entity).' can\'t be processed'); } /** * @throws NoIdentityCoreException If the source has no id or slug */ private function validateRequestedEntity(): void { if ($this->requestedEntity->hasIdentity()) { return; } throw new NoIdentityCoreException(get_class($this->requestedEntity).' needs to have a defined id or slug attribut!'); } /** * @param RequestedEntity|null $requestedEntity */ public function __construct(?RequestedEntity $requestedEntity = null) { if ($requestedEntity) { $this->setRequestedEntity($requestedEntity); } } /** * This function declares the attribute actionType as inmutable * {@inheritdoc} * * @see \Infinito\Attribut\ActionTypeAttributInterface::setActionType() */ public function setActionType(string $actionType): void { if (isset($this->actionType)) { throw new ContainsElementException("The action type is allready set! Origine: $this->actionType New: $actionType"); } $this->setActionTypeTrait($actionType); } /** * Uses some kind of Lazy loading. * * @see https://en.wikipedia.org/wiki/Lazy_loading * {@inheritdoc} * @see \Infinito\Domain\RequestManagement\Right\RequestedRightInterface::getSource() */ final public function getSource(): SourceInterface { $this->validateRequestedEntity(); $this->loadSource(); return $this->source; } /** * Overriding is neccessary to declare the correct relation. * * {@inheritdoc} * * @see \Infinito\Domain\RequestManagement\Right\RequestedRightInterface::setRequestedEntity() */ final public function setRequestedEntity(RequestedEntityInterface $requestedEntity): void { $this->requestedEntity = $requestedEntity; if (!$requestedEntity->hasRequestedRight()) { $this->requestedEntity->setRequestedRight($this); } } }