Implemented SourceRepository

This commit is contained in:
Kevin Frantz
2019-01-04 20:10:08 +01:00
parent ae737b6923
commit a074932fb5
7 changed files with 33 additions and 6 deletions

View File

@@ -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 {
};

View File

@@ -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());
}
}

View File

@@ -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;

View 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]);
}
}

View File

@@ -6,6 +6,8 @@ use Doctrine\ORM\EntityRepository;
/**
* @author kevinfrantz
*
* @deprecated
*/
class UserSourceRepository extends EntityRepository
{