mrkrstphr / hydrotron
Hydrotron aids in hydrating PHP objects
Installs: 5 058
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: >=7.0,<=8.0
- mrkrstphr/instantiator: ^1.0
- peridot-php/object-path: ^1.0
Requires (Dev)
- peridot-php/leo: ^1.4
- peridot-php/peridot: ^1.17
- squizlabs/php_codesniffer: ^2.5
README
Hydrotron aids in hydrating PHP objects
Installation
composer install mrkrstphr/hydrotron
Usage
When an array key exists, call one or more callbacks:
$hydro = new Hydrotron(['foo' => 'bar']); $hydro->when('foo', $callback, [$object, 'method']);
When an array key exists, instantiate an object, and call a series of callbacks with that object:
$hydro = new Hydrotron(['foo' => 'bar', 'bizz' => 'buzz']); $hydro->instantiateWhen('foo', MyClass::class, $callback);
instantiateWhen()
uses Instantiator, which will
analyze the classes constructor arguments and pass the values of any keys within the Hydrotron
array that matches those argument names.
So if MyClass
looked like:
class MyClass { public function __construct($foo, $bizz) {} }
MyClass
would be instantiated with $foo = 'bar'
and $bizz = 'buzz'
. If an argument name is not
found within the array, null
will be passed.
Credits
Hydrotron was inspired by Keyper.