Download the PHP package main-echo/simple-dto without Composer
On this page you can find all versions of the php package main-echo/simple-dto. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download main-echo/simple-dto
More information about main-echo/simple-dto
Files in main-echo/simple-dto
Package simple-dto
Short Description A fork of `phpexperts/simple-dto`—a quick and easy DTO package.
License MIT
Homepage https://www.phpexperts.pro/
Informations about the package simple-dto
SimpleDTO
SimpleDTO is a PHP Experts, Inc., Project meant to facilitate easy Data Transfer Objects.
Basically, any protected property on the DTO can be set as an array element passed in to the __constructor and/or as a default value on the property itself.
The DTOs are immutable: Once created, they cannot be changed. Create a new object instead.
Installation
Via Composer
Usage
As of version 2, you must define class-level @property docblocks for each one of your properties.
You also must define the data type.
Fuzzy Data Types
But what if you aren't ready / able to dive into strict PHP data types yet?
Well, just instantiate the parent class like this:
NestedDTOs
You can nest DTOs inside of each other.
Use cases
PHPExperts\SimpleDTO\SimpleDTO
✔ Properties are set via the constructor
✔ Properties are accessed as public properties
✔ Public, private and static protected properties will be ignored
✔ Each DTO is immutable
✔ Setting any property returns an exception
✔ Concrete properties can be used to set default values
✔ Properties with the type carbon become carbon dates
✔ Can easily output to array
✔ Can easily be json encoded
✔ Can easily be json decoded
✔ Nullable properties are allowed
✔ Every property is nullable with permissive mode
✔ Can be serialized
✔ Can be unserialized
✔ Extra validation can be added
PHPExperts\SimpleDTO\NestedDTO
✔ Will construct nested DTOs
✔ Can construct arrays of nested DTOs
✔ Will convert arrays into the appropriate Nested DTOs
✔ Will convert stdClasses into the appropriate Nested DTOs
✔ Nested DTOs use Loose typing
✔ All registered Nested DTOs are required
✔ Optional, unregistered, Nested DTOs are handled gracefully
✔ Can be serialized
✔ Can be unserialized
PHPExperts\SimpleDTO\WriteOnceTrait
✔ Can accept null values
✔ Will validate on serialize
✔ Will validate on to array
✔ Can write each null value once
✔ Write-Once values must validate
SimpleDTO Sad Paths
✔ Cannot initialize with a nonexisting property
✔ Accessing a nonexisting property throws an error
✔ A DTO must have class property docblocks for each concrete property
✔ Carbon date strings must be parsable dates
✔ Properties must match their data types
✔ Will not unserialize DTOs with invalid data
✔ Cannot overwrite a non-existing property
Testing
Contributors
Theodore R. Smith [email protected]
GPG Fingerprint: 4BF8 2613 1C34 87AC D28F 2AD8 EB24 A91D D612 5690
CEO: PHP Experts, Inc.
License
MIT license. Please see the license file for more information.
All versions of simple-dto with dependencies
ext-json Version *
nesbot/carbon Version 1.*|2.*
phpexperts/datatype-validator Version ^1.5