1. Go to this page and download the library: Download krzar/array-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/ */
krzar / array-dto example snippets
use KrZar\ArrayDto\ArrayDto;
class UserData extends ArrayDto {
public string $name;
public string $email;
public int $age;
public float $money;
public bool $isActive = false;
public array $roles = [];
}
class CompanyData extends ArrayObject {
public string $name;
public string $city;
public string $street;
}
class UserData extends ArrayObject {
public string $name;
public string $email;
public int $age;
public float $money;
public bool $isActive = false;
public array $roles = [];
public CompanyData $company;
}
class UserData extends ArrayObject {
public string $name;
public string $email;
public int $age;
public float $money;
public bool $isActive = false;
public array $roles = [];
public CompanyData $company;
public array $children;
protected function casts(): array {
return [
'children' => new \KrZar\ArrayDto\Casts\MultidimensionalCast(UserData::class),
];
}
}
class UserData extends ArrayObject {
public string $name;
public string $email;
public int $age;
public float $money;
public bool $isActive = false;
public array $roles = [];
public CompanyData $company;
public array $children;
protected function casts(): array {
return [
'children' => new \KrZar\ArrayDto\Casts\MultidimensionalCast(UserData::class),
'is_active' => new \KrZar\ArrayDto\Casts\NameCast('isActive')
];
}
}
class UserData extends ArrayObject {
public string $name;
public string $email;
public int $age;
public float $money;
public bool $isActive = false;
public array $roles = [];
public CompanyData $company;
public array $children;
public int $agePlusTen;
protected function casts(): array {
return [
'children' => new \KrZar\ArrayDto\Casts\MultidimensionalCast(UserData::class),
'is_active' => new \KrZar\ArrayDto\Casts\NameCast('isActive'),
'agePlusTen' => new \KrZar\ArrayDto\Casts\CustomCast(
fn(mixed $value, array $raw) => $raw['age'] + 10
),
];
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.