1. Go to this page and download the library: Download eve/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/ */
eve / dto example snippets
// UserService.php
public function createUser(array $attributes): User
{
return User::create($attributes);
}
// UserController.php
public function store(CreateUserRequest $request)
{
$this->userService->create($request->toArray());
}
// UserCreationData.php
class UserCreationData
{
public string $email;
public string $password;
public ?int $age;
}
// UserService.php
public function createUser(UserCreationData $data): User
{
return User::create($data->toArray());
}
// UserController.php
public function store(CreateUserRequest $request)
{
$this->userService->create(UserCreationData::fromRequest($request));
}
class UserCreationData extends \Eve\DTO\DataTransferObject
{
public string $email;
public string $password;
public ?int $age;
}
$data = UserCreationData::make([
'email' => '[email protected]',
'password' => 'SoSecureWow',
]);
$data->get('email'); // '[email protected]'
$data->password; // 'SoSecureWow'
$data->age; // throws "UserCreationData::$age must not be accessed before initialization."
$data->get('age', 30); // 30
$data->get('nope'); // throws "Public property $nope does not exist in class UserCreationData."
$data->nope; // throws "Public property $nope does not exist in class UserCreationData."
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.