kosmcode / simple-dto
Package to create simple flexible DTOs
1.0.0
2023-04-20 17:16 UTC
Requires
- php: 7.4|^8.0|^8.1|^8.2
Requires (Dev)
- phpunit/phpunit: >=7
This package is not auto-updated.
Last update: 2025-04-19 01:35:36 UTC
README
Package to create simple&flexible DTOs - just magic :)
Create DTOs 'on the fly'
How to use
Create and extend class by AbstractDTO
.. and this is all! You can define properties, but you don't have to.
Example class:
use Kosmcode\SimpleDto\AbstractDTO;
/**
* @method bool getExistsField()
* @method self setExistsField(bool $value)
*/
class ExampleDTO extends AbstractDTO
{
}
...
$exampleDTO = (new ExampleDTO())
->setExistsField(true);
$exampleDTO->getExistsField();
// true
$exampleDTO->isExistsField();
// true
$exampleDTO->hasNotExistsField();
// false
$exampleDTO->setNewFieldInFly('yes!');
$exampleDTO->hasNewFieldInFly();
// true
$exampleDTO->getNewFieldInFly();
// yes!
If the logic of any of magic methods doesn't suit you - just overwrite it ;)
abstract class \Kosmcode\SimpleDto\AbstractDTO {
protected function getFieldValue(string $methodName): mixed
protected function setFieldValue(string $methodName, mixed $value): self
protected function isFieldValue(string $methodName): bool
protected function hasFieldValue(string $methodName): bool
}