luky/dto

Basic DTO's

Maintainers

Details

gitlab.com/Luky/dto

0.1.1 2017-12-28 20:51 UTC

This package is auto-updated.

Last update: 2022-06-20 05:49:11 UTC


README

Source code: Master status Master coverage

Package: Downloads this Month Stable Version

License

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');

Source code

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'];

Source code