mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-10-31 09:19:08 +00:00 
			
		
		
		
	Implemented SourceRepository
This commit is contained in:
		| @@ -31,7 +31,7 @@ class DefaultController extends AbstractEntityController | ||||
|             $user = new User(); | ||||
|             $user->setSource($this->getDoctrine() | ||||
|                 ->getRepository(AbstractSource::class) | ||||
|                 ->findOneBy(['slug' => SystemSlugType::GUEST_USER])); | ||||
|                 ->findOneBySlug(SystemSlugType::GUEST_USER)); | ||||
|         } | ||||
|         $requestedSource = new class() extends AbstractSource { | ||||
|         }; | ||||
|   | ||||
| @@ -50,7 +50,7 @@ final class SecureSourceLoader implements SecureSourceLoaderInterface | ||||
|         try { | ||||
|             return $this->sourceRepository->find($this->requestedRight->getSource()->getId()); | ||||
|         } catch (\Error $error) { | ||||
|             return $this->sourceRepository->findOneBy(['slug' => $this->requestedRight->getSource()->getSlug()]); | ||||
|             return $this->sourceRepository->findOneBySlug($this->requestedRight->getSource()->getSlug()); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -23,9 +23,11 @@ use App\Entity\Meta\Relation\Member\MemberRelationInterface; | ||||
|  * | ||||
|  * For the members\memberships attribut checkout: | ||||
|  * | ||||
|  * @todo Move parts of discriminator map to subclasses | ||||
|  * | ||||
|  * @see http://www.inanzzz.com/index.php/post/h0jt/bidirectional-many-to-many-cascade-remove-and-orphan-removal-operations-in-doctrine | ||||
|  * | ||||
|  * @ORM\Entity | ||||
|  * @ORM\Entity(repositoryClass="App\Repository\Source\SourceRepository") | ||||
|  * @ORM\Table(name="source") | ||||
|  * @ORM\InheritanceType("JOINED") | ||||
|  * @ORM\DiscriminatorColumn(name="discr", type="string") | ||||
| @@ -55,6 +57,10 @@ abstract class AbstractSource extends AbstractEntity implements SourceInterface | ||||
|      * @ORM\Column(type="string",length=30,nullable=true,unique=true) | ||||
|      * @Assert\Regex(pattern="/^[a-z]+$/") | ||||
|      * | ||||
|      * @todo Check out if a plugin can solve this purpose; | ||||
|      * | ||||
|      * @see https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/sluggable.md | ||||
|      * | ||||
|      * @var string | ||||
|      */ | ||||
|     protected $slug; | ||||
|   | ||||
							
								
								
									
										19
									
								
								application/src/Repository/Source/SourceRepository.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								application/src/Repository/Source/SourceRepository.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Repository\Source; | ||||
|  | ||||
| use Doctrine\ORM\EntityRepository; | ||||
| use App\Entity\Source\SourceInterface; | ||||
|  | ||||
| final class SourceRepository extends EntityRepository | ||||
| { | ||||
|     /** | ||||
|      * @param string $slug | ||||
|      * | ||||
|      * @return SourceInterface|null | ||||
|      */ | ||||
|     public function findOneBySlug(string $slug): ?SourceInterface | ||||
|     { | ||||
|         return $this->findOneBy(['slug' => $slug]); | ||||
|     } | ||||
| } | ||||
| @@ -6,6 +6,8 @@ use Doctrine\ORM\EntityRepository; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  * | ||||
|  * @deprecated | ||||
|  */ | ||||
| class UserSourceRepository extends EntityRepository | ||||
| { | ||||
|   | ||||
| @@ -24,14 +24,14 @@ class SourceFixturesIntegrationTest extends KernelTestCase | ||||
|     public function testImpressumSource(): void | ||||
|     { | ||||
|         $sourceRepository = $this->entityManager->getRepository(AbstractSource::class); | ||||
|         $imprint = $sourceRepository->findOneBy(['slug' => SystemSlugType::IMPRINT]); | ||||
|         $imprint = $sourceRepository->findOneBySlug(SystemSlugType::IMPRINT); | ||||
|         $this->assertInternalType('string', $imprint->getText()); | ||||
|     } | ||||
|  | ||||
|     public function testGuestUserSource(): void | ||||
|     { | ||||
|         $sourceRepository = $this->entityManager->getRepository(AbstractSource::class); | ||||
|         $userSource = $sourceRepository->findOneBy(['slug' => SystemSlugType::GUEST_USER]); | ||||
|         $userSource = $sourceRepository->findOneBySlug(SystemSlugType::GUEST_USER); | ||||
|         $this->assertInstanceOf(UserSourceInterface::class, $userSource); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -67,7 +67,7 @@ class SecureSourceLoaderTest extends KernelTestCase | ||||
|         $requestedRight->setSource($requestedSource); | ||||
|         $requestedRight->setLayer(LayerType::SOURCE); | ||||
|         $requestedRight->setType(RightType::READ); | ||||
|         $requestedRight->setReciever($this->sourceRepository->findOneBy(['slug' => SystemSlugType::GUEST_USER])); | ||||
|         $requestedRight->setReciever($this->sourceRepository->findOneBySlug(SystemSlugType::GUEST_USER)); | ||||
|         $secureSourceLoader = new SecureSourceLoader($this->entityManager, $requestedRight); | ||||
|         $this->assertInstanceOf(TextSourceInterface::class, $secureSourceLoader->getSource()); | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user