alytvynov / loaders
类的常见特性
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-10-03 00:26:48 UTC
README
类和数据操作的特性。
- 允许通过
array
获取类数据 - 通过设置器将数据从
array
加载到对象属性中。
添加到您的项目中
composer require alytvynov/timestampable
在类中使用的示例
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; } }
将数据加载到对象中
$data = [
'title' => 'This is product',
];
$product = new Product();
$product->loadData($data);
以数组形式获取对象的数据
$product->toArray($data);
在本地运行仓库
git clone git@github.com:alytvynov/loaders.git cd loaders docker-compose up -d docker exec -it php_loaders bash -c "composer install"
运行测试
docker exec -it php_loaders bash -c "./vendor/bin/phpunit tests"
附加信息
关于我们
高级Web开发者 Anton Lytvynov。