轨道器 / 水化器
使用反射的PHP对象水化器。
0.1.1
2022-10-20 18:26 UTC
Requires
- php: ~8.0|~8.1
- orbiter/annotations-util: ~0.5.0|~0.6.0
- psr/container: ^1.0|^2.0
Requires (Dev)
- laminas/laminas-hydrator: ^4.3.1
- php-di/php-di: ^6.3.5
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-09-20 22:53:28 UTC
README
使用反射从数据创建PHP对象的hydrator,例如,通过FactoryInterface通过PSR容器使用。
composer require orbiter/hydrator
// needs implementation:
// $factory = \Orbiter\Hydrator\FactoryInterface()
$hydrator = new \Orbiter\Hydrator\Hydrator($factory);
// params = e.g. most likely used by your factory for __construct, array of params
$hydrator->make($class_name, $params);
// data = use to hydrate after instance creation, can be associative array or stdClass
// uses keys/properties as names for the property to inject
// third parameter = true ignores missing properties
$hydrator->hydrate($class, $data, false);
$hydrator->makeAndInject($class_name, $data, false, $params);
//
// for PHP-DI users:
use function DI\autowire;
use function DI\get;
$dependencies = [
Orbiter\Hydrator\BridgePHPDIFactory::class => autowire()
->constructorParameter('factory', get(DI\FactoryInterface::class)),
Orbiter\Hydrator\Hydrator::class => autowire()
->constructorParameter('factory', get(Orbiter\Hydrator\BridgePHPDIFactory::class)),
]
开发者公告
设置和运行测试等的命令
# on windows: docker run -it --rm -v %cd%:/app composer install docker run -it --rm -v %cd%:/var/www/html php:8.1-cli-alpine sh docker run --rm -v %cd%:/var/www/html php:8.1-cli-alpine sh -c "cd /var/www/html && ./vendor/bin/phpunit --testdox -c phpunit-ci.xml --bootstrap vendor/autoload.php" # on unix: docker run -it --rm -v `pwd`:/app composer install docker run -it --rm -v `pwd`:/var/www/html php:8.1-cli-alpine sh docker run --rm -v `pwd`:/var/www/html php:8.1-cli-alpine sh -c "cd /var/www/html && ./vendor/bin/phpunit --testdox -c phpunit-ci.xml --bootstrap vendor/autoload.php"
版本
此项目遵循semver,直到 1.0.0
,从0.1.0
开始:所有0.x.0
版本都是主版本,所有0.0.x
版本都是次版本或修补版本,小于0.1.0
的模块应被视为实验性的。
许可证
本项目是免费软件,在MIT许可证下发布。
贡献者
将代码提交到代码仓库时,您同意在仓库附带的MIT许可证下发布代码。