alytvynov / loaders
Common traits for classes
0.0.6
2021-08-25 08:42 UTC
Requires
- php: ^7.4
Requires (Dev)
- phpunit/phpunit: 9.*
This package is not auto-updated.
Last update: 2024-11-14 00:59:55 UTC
README
Traits for classes and data manipulations.
- Permits get class data in the
array
- Load data from
array
to object properties by setters.
Add to your project
composer require alytvynov/timestampable
Example of usage in class
use Common\Traits\DataLoader; use Common\Traits\RawLoader; class Product { use DataLoader; use RawLoader; /** * @var string */ protected string $title; /** * @return string */ public function getTitle(): string { return $this->title; } /** * @param string $title * * @return $this */ public function setTitle(string $title): self { $this->title = $title; return $this; } }
Load data to object
$data = [
'title' => 'This is product',
];
$product = new Product();
$product->loadData($data);
Get object's data as array
$product->toArray($data);
To run repository locally
git clone git@github.com:alytvynov/loaders.git cd loaders docker-compose up -d docker exec -it php_loaders bash -c "composer install"
Run tests
docker exec -it php_loaders bash -c "./vendor/bin/phpunit tests"
Additional information
About Us
Senior Web developer Anton Lytvynov.