From a074932fb5af23190689f1ade44200fc9d5d9b01 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Fri, 4 Jan 2019 20:10:08 +0100 Subject: [PATCH] Implemented SourceRepository --- .../src/Controller/DefaultController.php | 2 +- .../SecureSourceLoader.php | 2 +- .../src/Entity/Source/AbstractSource.php | 8 +++++++- .../Repository/Source/SourceRepository.php | 19 +++++++++++++++++++ .../src/Repository/UserSourceRepository.php | 2 ++ .../SourceFixturesIntegrationTest.php | 4 ++-- .../SecureSourceLoaderTest.php | 2 +- 7 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 application/src/Repository/Source/SourceRepository.php diff --git a/application/src/Controller/DefaultController.php b/application/src/Controller/DefaultController.php index bf48f3d..ab57868 100644 --- a/application/src/Controller/DefaultController.php +++ b/application/src/Controller/DefaultController.php @@ -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 { }; diff --git a/application/src/Domain/SecureLoadManagement/SecureSourceLoader.php b/application/src/Domain/SecureLoadManagement/SecureSourceLoader.php index 0bd2bc5..b3f29fa 100644 --- a/application/src/Domain/SecureLoadManagement/SecureSourceLoader.php +++ b/application/src/Domain/SecureLoadManagement/SecureSourceLoader.php @@ -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()); } } diff --git a/application/src/Entity/Source/AbstractSource.php b/application/src/Entity/Source/AbstractSource.php index 578d40b..62419bd 100644 --- a/application/src/Entity/Source/AbstractSource.php +++ b/application/src/Entity/Source/AbstractSource.php @@ -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; diff --git a/application/src/Repository/Source/SourceRepository.php b/application/src/Repository/Source/SourceRepository.php new file mode 100644 index 0000000..9133b66 --- /dev/null +++ b/application/src/Repository/Source/SourceRepository.php @@ -0,0 +1,19 @@ +findOneBy(['slug' => $slug]); + } +} diff --git a/application/src/Repository/UserSourceRepository.php b/application/src/Repository/UserSourceRepository.php index 62e88bc..e254868 100644 --- a/application/src/Repository/UserSourceRepository.php +++ b/application/src/Repository/UserSourceRepository.php @@ -6,6 +6,8 @@ use Doctrine\ORM\EntityRepository; /** * @author kevinfrantz + * + * @deprecated */ class UserSourceRepository extends EntityRepository { diff --git a/application/tests/Integration/DataFixtures/SourceFixturesIntegrationTest.php b/application/tests/Integration/DataFixtures/SourceFixturesIntegrationTest.php index a0138da..ffca303 100644 --- a/application/tests/Integration/DataFixtures/SourceFixturesIntegrationTest.php +++ b/application/tests/Integration/DataFixtures/SourceFixturesIntegrationTest.php @@ -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); } } diff --git a/application/tests/Unit/Domain/SecureLoadManagement/SecureSourceLoaderTest.php b/application/tests/Unit/Domain/SecureLoadManagement/SecureSourceLoaderTest.php index 00442af..084b9d8 100644 --- a/application/tests/Unit/Domain/SecureLoadManagement/SecureSourceLoaderTest.php +++ b/application/tests/Unit/Domain/SecureLoadManagement/SecureSourceLoaderTest.php @@ -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()); }