mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-11-03 02:37:57 +00:00 
			
		
		
		
	Implemented setIdentity for RequestedEntity
This commit is contained in:
		@@ -4,13 +4,7 @@ namespace App\Controller;
 | 
			
		||||
 | 
			
		||||
use Symfony\Component\Routing\Annotation\Route;
 | 
			
		||||
use Symfony\Component\HttpFoundation\Response;
 | 
			
		||||
use App\DBAL\Types\SystemSlugType;
 | 
			
		||||
use App\Entity\Meta\Right;
 | 
			
		||||
use App\DBAL\Types\Meta\Right\LayerType;
 | 
			
		||||
use App\DBAL\Types\Meta\Right\CRUDType;
 | 
			
		||||
use Doctrine\ORM\EntityManagerInterface;
 | 
			
		||||
use App\Entity\Source\PureSource;
 | 
			
		||||
use App\Domain\ResponseManagement\SourceRESTResponseManager;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This controller offers the standart routes for the template.
 | 
			
		||||
@@ -27,15 +21,6 @@ final class DefaultController extends AbstractController
 | 
			
		||||
     */
 | 
			
		||||
    public function imprint(EntityManagerInterface $entityManager): Response
 | 
			
		||||
    {
 | 
			
		||||
        $requestedSource = new PureSource();
 | 
			
		||||
        $requestedSource->setSlug(SystemSlugType::IMPRINT);
 | 
			
		||||
        $requestedRight = new Right();
 | 
			
		||||
        $requestedRight->setSource($requestedSource);
 | 
			
		||||
        $requestedRight->setLayer(LayerType::SOURCE);
 | 
			
		||||
        $requestedRight->setCrud(CRUDType::READ);
 | 
			
		||||
        $sourceResponseManager = new SourceRESTResponseManager($this->getUser(), $entityManager, $requestedRight, $this->getViewHandler());
 | 
			
		||||
 | 
			
		||||
        return $sourceResponseManager->getResponse();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -3,10 +3,29 @@
 | 
			
		||||
namespace App\Domain\RequestManagement\Entity;
 | 
			
		||||
 | 
			
		||||
use App\Entity\AbstractEntity;
 | 
			
		||||
use App\Attribut\SlugAttribut;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
class RequestedEntity extends AbstractEntity implements RequestedEntityInterface
 | 
			
		||||
{
 | 
			
		||||
    use SlugAttribut;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     *
 | 
			
		||||
     * @see \App\Domain\RequestManagement\Entity\RequestedEntityInterface::setIdentity()
 | 
			
		||||
     */
 | 
			
		||||
    public function setIdentity($identity): void
 | 
			
		||||
    {
 | 
			
		||||
        if (is_numeric($identity)) {
 | 
			
		||||
            $this->setId($identity);
 | 
			
		||||
            $this->slug = null;
 | 
			
		||||
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        $this->setSlug($identity);
 | 
			
		||||
        $this->id = null;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -3,10 +3,19 @@
 | 
			
		||||
namespace App\Domain\RequestManagement\Entity;
 | 
			
		||||
 | 
			
		||||
use App\Entity\EntityInterface;
 | 
			
		||||
use App\Attribut\SlugAttributInterface;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A requested entity containes the stumb attributes to load an entity.
 | 
			
		||||
 *
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
interface RequestedEntityInterface extends EntityInterface
 | 
			
		||||
interface RequestedEntityInterface extends EntityInterface, SlugAttributInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Sets the slug or the id.
 | 
			
		||||
     *
 | 
			
		||||
     * @param string|int $identity
 | 
			
		||||
     */
 | 
			
		||||
    public function setIdentity($identity): void;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,6 @@ namespace App\Domain\RequestManagement\Entity;
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
interface RequestedEntityServiceInterface
 | 
			
		||||
interface RequestedEntityServiceInterface extends RequestedEntityInterface
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -5,15 +5,13 @@ namespace App\Entity;
 | 
			
		||||
use App\Attribut\IdAttribut;
 | 
			
		||||
use Doctrine\ORM\Mapping as ORM;
 | 
			
		||||
use App\Attribut\VersionAttribut;
 | 
			
		||||
use App\Attribut\SlugAttribut;
 | 
			
		||||
use Symfony\Component\Validator\Constraints as Assert;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
abstract class AbstractEntity implements EntityInterface
 | 
			
		||||
{
 | 
			
		||||
    use IdAttribut, VersionAttribut,SlugAttribut;
 | 
			
		||||
    use IdAttribut, VersionAttribut;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @ORM\Id()
 | 
			
		||||
@@ -31,21 +29,6 @@ abstract class AbstractEntity implements EntityInterface
 | 
			
		||||
     */
 | 
			
		||||
    protected $version;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * System slugs should be writen in UPPER CASES
 | 
			
		||||
     * Slugs which are defined by the user are checked via the assert.
 | 
			
		||||
     *
 | 
			
		||||
     * @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;
 | 
			
		||||
 | 
			
		||||
    public function __construct()
 | 
			
		||||
    {
 | 
			
		||||
        $this->version = 0;
 | 
			
		||||
 
 | 
			
		||||
@@ -4,11 +4,10 @@ namespace App\Entity;
 | 
			
		||||
 | 
			
		||||
use App\Attribut\VersionAttributInterface;
 | 
			
		||||
use App\Attribut\IdAttributInterface;
 | 
			
		||||
use App\Attribut\SlugAttributInterface;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
interface EntityInterface extends VersionAttributInterface, IdAttributInterface, SlugAttributInterface
 | 
			
		||||
interface EntityInterface extends VersionAttributInterface, IdAttributInterface
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -15,6 +15,8 @@ use App\Entity\Meta\Relation\Parent\CreatorRelation;
 | 
			
		||||
use App\Attribut\MemberRelationAttribut;
 | 
			
		||||
use App\Entity\Meta\Relation\Member\MemberRelation;
 | 
			
		||||
use App\Entity\Meta\Relation\Member\MemberRelationInterface;
 | 
			
		||||
use App\Attribut\SlugAttribut;
 | 
			
		||||
use Symfony\Component\Validator\Constraints as Assert;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
@@ -47,7 +49,22 @@ use App\Entity\Meta\Relation\Member\MemberRelationInterface;
 | 
			
		||||
 */
 | 
			
		||||
abstract class AbstractSource extends AbstractEntity implements SourceInterface
 | 
			
		||||
{
 | 
			
		||||
    use  LawAttribut,CreatorRelationAttribut, MemberRelationAttribut;
 | 
			
		||||
    use  LawAttribut,CreatorRelationAttribut, MemberRelationAttribut, SlugAttribut;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * System slugs should be writen in UPPER CASES
 | 
			
		||||
     * Slugs which are defined by the user are checked via the assert.
 | 
			
		||||
     *
 | 
			
		||||
     * @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;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var CreatorRelationInterface
 | 
			
		||||
 
 | 
			
		||||
@@ -7,10 +7,11 @@ use App\Entity\EntityInterface;
 | 
			
		||||
use App\Attribut\LawAttributInterface;
 | 
			
		||||
use App\Attribut\CreatorRelationAttributInterface;
 | 
			
		||||
use App\Attribut\MemberRelationAttributInterface;
 | 
			
		||||
use App\Attribut\SlugAttributInterface;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
interface SourceInterface extends IdAttributInterface, EntityInterface, LawAttributInterface, CreatorRelationAttributInterface, MemberRelationAttributInterface
 | 
			
		||||
interface SourceInterface extends IdAttributInterface, EntityInterface, LawAttributInterface, CreatorRelationAttributInterface, MemberRelationAttributInterface, SlugAttributInterface
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,25 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace tests\Unit\Domain\RequestManagement\Entity;
 | 
			
		||||
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use App\Domain\RequestManagement\Entity\RequestedEntity;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
class RequestedEntityTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    public function testSetByIdentity(): void
 | 
			
		||||
    {
 | 
			
		||||
        $requestedEntity = new RequestedEntity();
 | 
			
		||||
        $slug = 'test';
 | 
			
		||||
        $requestedEntity->setIdentity($slug);
 | 
			
		||||
        $this->assertEquals($slug, $requestedEntity->getSlug());
 | 
			
		||||
        $this->assertFalse($requestedEntity->hasId());
 | 
			
		||||
        $id = 123;
 | 
			
		||||
        $requestedEntity->setIdentity($id);
 | 
			
		||||
        $this->assertEquals($id, $requestedEntity->getId());
 | 
			
		||||
        $this->assertFalse($requestedEntity->hasSlug());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user