Skip to content

Instantly share code, notes, and snippets.

@zoka123
Last active February 20, 2020 14:21
Show Gist options
  • Save zoka123/67d57de528899e7c0169df96226b9e5b to your computer and use it in GitHub Desktop.
Save zoka123/67d57de528899e7c0169df96226b9e5b to your computer and use it in GitHub Desktop.
DTO usage example
<?php

declare(strict_types=1);

namespace App\Application\Query\Article\Cms;

use App\Application\Query\QueryInterface;

class ArticleQuery implements QueryInterface
{
    /** @var int */
    private $offset;

    /** @var int */
    private $size;

    /** @var null|string */
    private $category;

    /** @var null|string */
    private $publishDate;

    /** @var bool */
    private $published;

    /** @var null|string */
    private $searchTerm;

    public function __construct(
        int $offset,
        int $size,
        ?string $category,
        ?string $publishDate,
        bool $published,
        ?string $searchTerm
    ) {
        $this->offset = $offset;
        $this->size = $size;
        $this->category = $category;
        $this->publishDate = $publishDate;
        $this->published = $published;
        $this->searchTerm = $searchTerm;
    }

    public function getOffset(): int
    {
        return $this->offset;
    }

    public function getSize(): int
    {
        return $this->size;
    }

    public function getCategory(): ?string
    {
        return $this->category;
    }

    public function getPublishDate(): ?string
    {
        return $this->publishDate;
    }

    public function isPublished(): bool
    {
        return $this->published;
    }

    public function getSearchTerm(): ?string
    {
        return $this->searchTerm;
    }
}
<?php

declare(strict_types=1);

namespace App\Application\Query\Article\Cms;

use App\Application\Query\QueryInterface;

class ArticleQuery implements QueryInterface
{
    private int $offset;
    private int $size;
    private ?string $categoryId;
    private ?string $publishDate;
    private bool $published;
    private ?string $searchTerm;

    public function __construct(
        int $offset,
        int $size,
        ?string $categoryId,
        ?string $publishDate,
        bool $published,
        ?string $searchTerm
    ) {
        $this->offset = $offset;
        $this->size = $size;
        $this->categoryId = $categoryId;
        $this->publishDate = $publishDate;
        $this->published = $published;
        $this->searchTerm = $searchTerm;
    }


    public function getOffset(): int
    {
        return $this->offset;
    }

    public function getSize(): int
    {
        return $this->size;
    }

    public function getCategory(): ?string
    {
        return $this->category;
    }

    public function getPublishDate(): ?string
    {
        return $this->publishDate;
    }

    public function isPublished(): bool
    {
        return $this->published;
    }

    public function getSearchTerm(): ?string
    {
        return $this->searchTerm;
    }
}
<?php

declare(strict_types=1);

namespace App\Application\Query\Article\Cms;

use App\Application\Query\QueryInterface;

/** @psalm-immutable */
class ArticleQuery implements QueryInterface
{
    public int $offset;
    public int $size;
    public ?string $categoryId;
    public ?string $publishDate;
    public bool $published;
    public ?string $searchTerm;

    public function __construct(
        int $offset,
        int $size,
        ?string $categoryId,
        ?string $publishDate,
        bool $published,
        ?string $searchTerm
    ) {
        $this->offset = $offset;
        $this->size = $size;
        $this->categoryId = $categoryId;
        $this->publishDate = $publishDate;
        $this->published = $published;
        $this->searchTerm = $searchTerm;
    }
-
-    public function getOffset(): int
-    {
-        return $this->offset;
-    }
-
-    public function getSize(): int
-    {
-        return $this->size;
-    }
-
-    public function getCategory(): ?string
-    {
-        return $this->category;
-    }
-
-    public function getPublishDate(): ?string
-    {
-        return $this->publishDate;
-    }
-
-    public function isPublished(): bool
-    {
-        return $this->published;
-    }
-
-    public function getSearchTerm(): ?string
-    {
-        return $this->searchTerm;
-    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment