luky / dto
Basic DTO's
0.1.1
2017-12-28 20:51 UTC
Requires
- php: >=7.1
- nette/utils: ^2.4
Requires (Dev)
- codeception/codeception: ^2.3
- jakub-onderka/php-console-highlighter: ^0.3.2
- jakub-onderka/php-parallel-lint: ^0.9.2
- mockery/mockery: ^1.0
- phpstan/phpstan: ^0.9.1
- slevomat/coding-standard: ^4.1
This package is auto-updated.
Last update: 2022-06-20 05:49:11 UTC
README
Installation
$ composer require luky/dto
Testing
php vendor/bin/codecept run --coverage --coverage-xml --coverage-html
DTO's
Why DTO's? Because' type checking!
// some class code snippet
public function run() {
$email = new \Luky\DTO\EmailAddress('my@email.com');
$this->process($email);
}
public function process(\Luky\DTO\EmailAddress $email) {
// safety use of email value in $email
$email->getEmail();
}
EmailAddress
$email = new \Luky\DTO\EmailAddress('valid.email@address.com');
JSON
// created from raw JSON string
$json = new \Luky\DTO\Json('{"some": "valid json"}');
// ... or from php array
$json = new \Luky\DTO\Json(['some' => 'valid json']);
// get JSON as string
$json->getString(); // return '{"some": "valid json"}';
// get JSON as array
$json->getArray(); // return ['some' => 'valid json'];