laminas/laminas-hydrator
Laminas Hydrator provides flexible strategies to hydrate and extract data between objects and arrays. Supports reflection, class methods, naming strategies, and custom hydrators, making it easy to map entities, DTOs, and forms cleanly across your application.
Laminas\Hydrator\NamingStrategy\IdentityNamingStrategy uses the keys provided to
it for hydration and extraction.
$namingStrategy = new Laminas\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 Laminas\Hydrator\NamingStrategy\IdentityNamingStrategy();
$hydrator = new Laminas\Hydrator\ObjectProperty();
$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?