PHP code example of maxiviper117 / dtokit-core

1. Go to this page and download the library: Download maxiviper117/dtokit-core 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/ */

    

maxiviper117 / dtokit-core example snippets


use DTOKit\InputData;

final readonly class CreatePostData extends InputData
{
    public function __construct(
        public string $title,
        public string $body,
        public ?int $categoryId = null,
    ) {}
}

$post = CreatePostData::from([
    'title' => 'Hello',
    'body' => 'World',
]);

$payload = $post->toArray();

use DTOKit\Attribute\ListOf;
use DTOKit\Attribute\MapInputName;

final readonly class OrderData extends InputData
{
    /** @param list<LineData> $lines */
    public function __construct(
        #[MapInputName('order_id')] public int $orderId,
        #[ListOf(LineData::class)] public array $lines,
    ) {}
}