1. Go to this page and download the library: Download atto/hydrator library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
atto / hydrator example snippets
// This is the default behaviour if omitted.
#[SerializationStrategy(SerializationStrategyType::JSON)]
private array $myList;
class MyObject
{
#[HydrationStrategy(HydrationStrategyType::Json)]
private MyNestedObject $myNestedObject;
}
class MyNestedObject
{
private int $myInt = 1;
}
['myNestedObject' => '{"myInt":1}']
class MyObject
{
#[HydrationStrategy(HydrationStrategyType::Merge)]
private MyNestedObject $myNestedObject;
}
class MyNestedObject
{
private int $myInt = 1;
}
['myNestedObject_myInt' => 1]
class MyObject
{
#[HydrationStrategy(HydrationStrategyType::Nest)]
private MyNestedObject $myNestedObject;
}
class MyNestedObject
{
private int $myInt = 1;
}
[
'myNestedObject' => ['myInt' => 1],
]
class MyStringWrapper
{
public function __construct(
private string $myString = 'Hello, World!',
) {
}
public function __toString()
{
return $this->myString;
}
}