mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-11-03 18:58:01 +00:00 
			
		
		
		
	Implemented draft for PureSourceCreateType Test and adapted classes to it
This commit is contained in:
		@@ -4,6 +4,8 @@ namespace App\Attribut;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 *
 | 
			
		||||
 * @see IdAttributInterface
 | 
			
		||||
 */
 | 
			
		||||
trait IdAttribut
 | 
			
		||||
{
 | 
			
		||||
@@ -12,16 +14,25 @@ trait IdAttribut
 | 
			
		||||
     */
 | 
			
		||||
    protected $id;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param int $id
 | 
			
		||||
     */
 | 
			
		||||
    public function setId(int $id): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->id = $id;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getId(): int
 | 
			
		||||
    /**
 | 
			
		||||
     * @return int|null
 | 
			
		||||
     */
 | 
			
		||||
    public function getId(): ?int
 | 
			
		||||
    {
 | 
			
		||||
        return $this->id;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return bool
 | 
			
		||||
     */
 | 
			
		||||
    public function hasId(): bool
 | 
			
		||||
    {
 | 
			
		||||
        return isset($this->id);
 | 
			
		||||
 
 | 
			
		||||
@@ -13,9 +13,14 @@ interface IdAttributInterface
 | 
			
		||||
    public function setId(int $id): void;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return int
 | 
			
		||||
     * Don't use this function to check if an id is set.
 | 
			
		||||
     * Use instead:.
 | 
			
		||||
     *
 | 
			
		||||
     * @see self::hasId()
 | 
			
		||||
     *
 | 
			
		||||
     * @return int|null
 | 
			
		||||
     */
 | 
			
		||||
    public function getId(): int;
 | 
			
		||||
    public function getId(): ?int;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return bool Checks if attribute is set
 | 
			
		||||
 
 | 
			
		||||
@@ -30,9 +30,9 @@ trait SlugAttribut
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return string
 | 
			
		||||
     * @return string|null
 | 
			
		||||
     */
 | 
			
		||||
    public function getSlug(): string
 | 
			
		||||
    public function getSlug(): ?string
 | 
			
		||||
    {
 | 
			
		||||
        return $this->slug;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -15,9 +15,14 @@ interface SlugAttributInterface
 | 
			
		||||
    public function setSlug(string $slug): void;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return string
 | 
			
		||||
     * Don't use this function to check if a slug is set
 | 
			
		||||
     * Use instead:.
 | 
			
		||||
     *
 | 
			
		||||
     * @see self::hasSlug()
 | 
			
		||||
     *
 | 
			
		||||
     * @return string|null
 | 
			
		||||
     */
 | 
			
		||||
    public function getSlug(): string;
 | 
			
		||||
    public function getSlug(): ?string;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return bool Checks if a slug is set
 | 
			
		||||
 
 | 
			
		||||
@@ -35,11 +35,16 @@ final class CreateSourceAction extends AbstractCreateAction
 | 
			
		||||
        $this->sourceClass = $request->get(SourceType::CLASS_PARAMETER_NAME, self::DEFAULT_CLASS);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function setFormClass(): void
 | 
			
		||||
    private function setForm(): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->form = $this->actionService->getCurrentFormBuilder()->getForm();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function setRequestedEntityClass(): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->actionService->getRequestedAction()->getRequestedEntity()->setClass($this->sourceClass);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function handleRequest(): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->form->handleRequest($this->actionService->getRequest());
 | 
			
		||||
@@ -53,7 +58,8 @@ final class CreateSourceAction extends AbstractCreateAction
 | 
			
		||||
    protected function prepare(): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->setSourceClass();
 | 
			
		||||
        $this->setFormClass();
 | 
			
		||||
        $this->setRequestedEntityClass();
 | 
			
		||||
        $this->setForm();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -63,6 +69,11 @@ final class CreateSourceAction extends AbstractCreateAction
 | 
			
		||||
     */
 | 
			
		||||
    protected function isValid(): bool
 | 
			
		||||
    {
 | 
			
		||||
        //The following Exception just exists out of debuging reasons during the development process
 | 
			
		||||
        if (!$this->form->isSubmitted()) {
 | 
			
		||||
            throw new \Exception('The form is not submitted!');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $this->form->isValid();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -16,6 +16,6 @@ final class PureSourceCreateType extends SourceType
 | 
			
		||||
     */
 | 
			
		||||
    public function buildForm(FormBuilderInterface $builder, array $options)
 | 
			
		||||
    {
 | 
			
		||||
        $builder->add('slug')->add('class');
 | 
			
		||||
        $builder->add('slug');
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user