mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-10-31 17:29:04 +00:00 
			
		
		
		
	Added RequestedEntityAttribut
This commit is contained in:
		
							
								
								
									
										32
									
								
								application/symfony/src/Attribut/RequestedEntityAttribut.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								application/symfony/src/Attribut/RequestedEntityAttribut.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,32 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Attribut; | ||||
|  | ||||
| use App\Domain\RequestManagement\Entity\RequestedEntityInterface; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| trait RequestedEntityAttribut | ||||
| { | ||||
|     /** | ||||
|      * @var RequestedEntityInterface | ||||
|      */ | ||||
|     private $requestedEntity; | ||||
|  | ||||
|     /** | ||||
|      * @return RequestedEntityInterface | ||||
|      */ | ||||
|     public function getRequestedEntity(): RequestedEntityInterface | ||||
|     { | ||||
|         return $this->requestedEntity; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param RequestedEntityInterface $requestedEntity | ||||
|      */ | ||||
|     public function setRequestedEntity(RequestedEntityInterface $requestedEntity): void | ||||
|     { | ||||
|         $this->requestedEntity = $requestedEntity; | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,21 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Attribut; | ||||
|  | ||||
| use App\Domain\RequestManagement\Entity\RequestedEntityInterface; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| interface RequestedEntityAttributInterface | ||||
| { | ||||
|     /** | ||||
|      * @return RequestedEntityInterface | ||||
|      */ | ||||
|     public function getRequestedEntity(): RequestedEntityInterface; | ||||
|  | ||||
|     /** | ||||
|      * @param RequestedEntityInterface $requestedEntity | ||||
|      */ | ||||
|     public function setRequestedEntity(RequestedEntityInterface $requestedEntity): void; | ||||
| } | ||||
| @@ -33,7 +33,7 @@ class RequestedRight implements RequestedRightInterface | ||||
|     /** | ||||
|      * @var RequestedEntityInterface | ||||
|      */ | ||||
|     private $requestedSource; | ||||
|     private $requestedEntity; | ||||
|  | ||||
|     /** | ||||
|      * @param SourceRepositoryInterface $sourceRepository | ||||
| @@ -45,7 +45,7 @@ class RequestedRight implements RequestedRightInterface | ||||
|  | ||||
|     private function loadSource(): void | ||||
|     { | ||||
|         $this->source = $this->sourceRepository->findOneByIdOrSlug($this->requestedSource); | ||||
|         $this->source = $this->sourceRepository->findOneByIdOrSlug($this->requestedEntity); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -53,10 +53,10 @@ class RequestedRight implements RequestedRightInterface | ||||
|      */ | ||||
|     private function validateRequestedEntity(): void | ||||
|     { | ||||
|         if ($this->requestedSource->hasSlug() || $this->requestedSource->hasId()) { | ||||
|         if ($this->requestedEntity->hasSlug() || $this->requestedEntity->hasId()) { | ||||
|             return; | ||||
|         } | ||||
|         throw new PreconditionFailedException(get_class($this->requestedSource).' needs to have a defined attribut id or slug!'); | ||||
|         throw new PreconditionFailedException(get_class($this->requestedEntity).' needs to have a defined attribut id or slug!'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -88,8 +88,8 @@ class RequestedRight implements RequestedRightInterface | ||||
|      * | ||||
|      * @see \App\Domain\RequestManagement\Right\RequestedRightInterface::setRequestedEntity() | ||||
|      */ | ||||
|     final public function setRequestedEntity(RequestedEntityInterface $requestedSource) | ||||
|     final public function setRequestedEntity(RequestedEntityInterface $requestedSource): void | ||||
|     { | ||||
|         $this->requestedSource = $requestedSource; | ||||
|         $this->requestedEntity = $requestedSource; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -16,7 +16,7 @@ interface RequestedRightInterface extends CrudAttributInterface, RecieverAttribu | ||||
|     /** | ||||
|      * @param RequestedEntityInterface $requestedSource | ||||
|      */ | ||||
|     public function setRequestedEntity(RequestedEntityInterface $requestedSource); | ||||
|     public function setRequestedEntity(RequestedEntityInterface $requestedSource): void; | ||||
|  | ||||
|     /** | ||||
|      * {@inheritdoc} | ||||
|   | ||||
| @@ -105,7 +105,7 @@ class RequestedUser implements RequestedUserInterface | ||||
|     /** | ||||
|      * @param RequestedEntityInterface $requestedSource | ||||
|      */ | ||||
|     public function setRequestedEntity(RequestedEntityInterface $requestedSource) | ||||
|     public function setRequestedEntity(RequestedEntityInterface $requestedSource): void | ||||
|     { | ||||
|         $this->requestedRight->setRequestedEntity($requestedSource); | ||||
|     } | ||||
|   | ||||
| @@ -0,0 +1,39 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Tests\Unit\Attribut; | ||||
|  | ||||
| use PHPUnit\Framework\TestCase; | ||||
| use App\Attribut\RequestedEntityAttribut; | ||||
| use App\Attribut\RequestedEntityAttributInterface; | ||||
| use App\Domain\RequestManagement\Entity\RequestedEntityInterface; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| class RequestedEntityAttributTest extends TestCase | ||||
| { | ||||
|     /** | ||||
|      * @var RequestedEntityAttributInterface | ||||
|      */ | ||||
|     protected $requestedEntityAttribut; | ||||
|  | ||||
|     public function setUp(): void | ||||
|     { | ||||
|         $this->requestedEntityAttribut = new class() implements RequestedEntityAttributInterface { | ||||
|             use RequestedEntityAttribut; | ||||
|         }; | ||||
|     } | ||||
|  | ||||
|     public function testConstructor(): void | ||||
|     { | ||||
|         $this->expectException(\TypeError::class); | ||||
|         $this->requestedEntityAttribut->getRequestedEntity(); | ||||
|     } | ||||
|  | ||||
|     public function testAccessors(): void | ||||
|     { | ||||
|         $requestedEntity = $this->createMock(RequestedEntityInterface::class); | ||||
|         $this->assertNull($this->requestedEntityAttribut->setRequestedEntity($requestedEntity)); | ||||
|         $this->assertEquals($requestedEntity, $this->requestedEntityAttribut->getRequestedEntity()); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user