zendframework/zend-hydrator
Zend Hydrator provides strategies and tools to extract data from objects and hydrate objects from arrays in PHP. Supports naming strategies, custom hydrators, and flexible configuration, useful for forms, APIs, and domain model mapping.
Zend\Hydrator\NamingStrategy\IdentityNamingStrategy uses the keys provided to
it for hydration and extraction.
$namingStrategy = new Zend\Hydrator\NamingStrategy\IdentityNamingStrategy();
echo $namingStrategy->hydrate('foo'); // outputs: foo
echo $namingStrategy->extract('bar'); // outputs: bar
This strategy can be used in hydrators as well:
class Foo
{
public $foo;
}
$namingStrategy = new Zend\Hydrator\NamingStrategy\IdentityNamingStrategy();
$hydrator = new Zend\Hydrator\ObjectPropertyHydrator();
$hydrator->setNamingStrategy($namingStrategy);
$foo = new Foo();
$hydrator->hydrate(array('foo' => 123), $foo);
print_r($foo); // Foo Object ( [foo] => 123 )
print_r($hydrator->extract($foo)); // Array ( [foo] => 123 )
How can I help you explore Laravel packages today?