PHP code example of yago-o / simple-dto

1. Go to this page and download the library: Download yago-o/simple-dto library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yago-o / simple-dto example snippets



class DtoClass extends SimpleDto
{
    /** @var integer */
    private $id;

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

    /** @var int[] */
    private $idList;

    /** @var TypeClass */
    private $typeClass;

    /** @var float */
    private $rating = 3.5;
    
    /** @var bool */
    private $isAdmin = false;

    /**
     * @return int
     */
    public function getId(): int
    {
        return $this->id;
    }

    /**
     * @return null|string
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * @return int[]
     */
    public function getIdList(): array
    {
        return $this->idList;
    }

    /**
     * @return TypeClass
     */
    public function getTypeClass(): TypeClass
    {
        return $this->typeClass;
    }

    /**
     * @return float
     */
    public function getRating(): float
    {
        return $this->rating;
    }
    
    /**
     * @return bool
     */
    public function isAdmin(): bool
    {
        return $this->isAdmin;
    }
}

class TypeClass
{
}


$dto = new DtoClass([
    'id' => 5,
    'name' => 'Ivan',
    'idList' => [1,2,3,4,5],
    'typeClass' => new TypeClass(),
    'isAdmin' => true,
]);

$id = $dto->getId(); // 5
$name = $dto->getName(); // 'Ivan'
$idList = $dto->getIdList(); // [1,2,3,4,5]
$rating = $dto->getRating(); // 3.5
$typeClass = $dto->getTypeClass(); // TypeClass object
$isAdmin = $dto->isAdmin(); // true