https://github.com/bemit/orbiter-hydrator
PHP Object Hydrator
https://github.com/bemit/orbiter-hydrator
Last synced: 25 days ago
JSON representation
PHP Object Hydrator
- Host: GitHub
- URL: https://github.com/bemit/orbiter-hydrator
- Owner: bemit
- License: mit
- Created: 2021-10-24T14:13:21.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-10-20T18:41:50.000Z (over 2 years ago)
- Last Synced: 2025-02-15T00:32:58.244Z (3 months ago)
- Language: PHP
- Homepage:
- Size: 43.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Orbiter\Hydrator
[](https://packagist.org/packages/orbiter/hydrator)
[](https://packagist.org/packages/orbiter/hydrator)
[](https://codecov.io/gh/bemit/orbiter-hydrator)
[](https://packagist.org/packages/orbiter/hydrator)
[](https://github.com/bemit/orbiter-hydrator/actions)
[](https://packagist.org/packages/orbiter/hydrator)Hydrator to create PHP objects from data, using Reflections, use e.g. PSR Container through a [FactoryInterface](https://github.com/bemit/orbiter-hydrator/blob/master/src/FactoryInterface.php).
```shell
composer require orbiter/hydrator
``````injectablephp
// 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)),
]
```## Dev Notices
Commands to set up and run e.g. tests:
```bash
# on windows:
docker run -it --rm -v %cd%:/app composer installdocker 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 installdocker 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"
```## Versions
This project adheres to [semver](https://semver.org/), **until `1.0.0`** and beginning with `0.1.0`: all `0.x.0` releases are like MAJOR releases and all `0.0.x` like MINOR or PATCH, modules below `0.1.0` should be considered experimental.
## License
This project is free software distributed under the [**MIT LICENSE**](LICENSE).
### Contributors
By committing your code to the code repository you agree to release the code under the MIT License attached to the repository.
***
Maintained by [Michael Becker](https://mlbr.xyz)