PHP code example of nuxtifyts / php-dto

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

    

nuxtifyts / php-dto example snippets


use Nuxtifyts\PhpDto\Data;
use Nuxtifyts\PhpDto\Attributes\Property\Aliases;
use Nuxtifyts\PhpDto\Attributes\Property\Computed;

final readonly class UserData extends Data
{
    #[Computed]
    public string $fullName;

    public function __construct(
        public string $firstName,
        #[Aliases('familyName')]
        public string $lastName
    ) {
        $this->fullName = "$this->firstName $this->lastName";
    }
}

$data = [
    'firstName' => 'John',
    'lastName' => 'Doe',
];

$user = UserData::from($data);


$user = new UserData('John', 'Doe');

$userData = $user->toArray();

// Or transform to a JSON string

$userData = $user->toJson();

bash
composer