1. Go to this page and download the library: Download squidit/array-to-object 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/ */
use SquidIT\Hydrator\DotNotationToMultiDimensional;
$dotNotationToMultiDimensional = new DotNotationToMultiDimensional($dataDotNotationJavascript);
$nestedData = $dotNotationToMultiDimensional->convert();
declare(strict_types=1);
use SquidIT\Hydrator\Class\ClassInfoGenerator;
use SquidIT\Hydrator\DtoToObject;
final class CarInputDto
{
public function __construct(
public string $color,
public int $nrOfDoors,
) {}
}
final class CarSummary
{
public function __construct(
public string $color,
public int $nrOfDoors,
) {}
}
$sourceDto = new CarInputDto('black', 4);
$hydrator = new DtoToObject(new ClassInfoGenerator());
$carSummary = $hydrator->hydrate($sourceDto, CarSummary::class);
$arrayHydrator = new ArrayToObject(new ClassInfoGenerator());
$dtoHydrator = new DtoToObject(new ClassInfoGenerator());
$carCompleteList = $arrayHydrator->hydrateMulti([$data, $data], CarComplete::class);
$carSummaryList = $dtoHydrator->hydrateMulti([$sourceDto, $sourceDto], CarSummary::class);
class Car
{
public function __construct(
public string $color,
public Honda $manufacturer,
) {}
}
$data = [
'color' => 'black',
'manufacturer' => [ // <-- Honda::class
'name' => 'Beautiful Street 124',
'city' => 'Rotterdam',
'employeeList' => []
],
];
use SquidIT\Hydrator\Attributes\ArrayOf;
class Honda implements ManufacturerInterface
{
/**
* @param array<int, Employee> $employeeList
*/
public function __construct(
public string $name,
public string $city,
#[ArrayOf(Employee::class)]
public array $employeeList,
) {}
}
final class Car
{
public function __construct(
public string $color,
public bool $isInsured = true,
) {}
}
use SquidIT\Hydrator\Exceptions\ValidationFailureException;
use SquidIT\Hydrator\Interface\ObjectValidatorInterface;
use SquidIT\Hydrator\Property\PathTracker;
class CarWithCustomEngine implements ObjectValidatorInterface
{
public function __construct(
public int $engineDisplacementInCc,
) {}
/**
* @throws ValidationFailureException
*/
public function validate(PathTracker $pathTracker): void
{
if ($this->engineDisplacementInCc < 600 || $this->engineDisplacementInCc > 8000) {
$propertyPath = $pathTracker->getPath('engineDisplacementInCc');
throw new ValidationFailureException(
sprintf('Invalid value received for property: %s, value needs to be between 600 and 8000', $propertyPath)
);
}
}
}
use SquidIT\Hydrator\ArrayToObject;
use SquidIT\Hydrator\Class\ClassInfoGenerator;
use SquidIT\Hydrator\DotNotationArrayToObject;
use SquidIT\Hydrator\DtoToObject;
use SquidIT\Hydrator\Property\DotNotationFormat;
$arrayHydrator = new ArrayToObject(new ClassInfoGenerator(), true);
$dtoHydrator = new DtoToObject(new ClassInfoGenerator(), true);
$dotNotationHydrator = new DotNotationArrayToObject(
new ClassInfoGenerator(),
DotNotationFormat::JAVASCRIPT,
true,
);
declare(strict_types=1);
use DateTimeImmutable;
use SquidIT\Hydrator\Abstract\AbstractObjectToDto;
final class CarDto extends AbstractObjectToDto
{
public function __construct(
public string $color,
public DateTimeImmutable $createdAt,
) {}
}
$carDto = new CarDto('black', new DateTimeImmutable('2026-05-18 12:34:56.123456'));
echo json_encode($carDto, JSON_THROW_ON_ERROR);
// {"color":"black","createdAt":"2026-05-18T12:34:56.123456"}
final class PublicCarDto extends AbstractObjectToDto
{
protected const string DATE_TIME_FORMAT = 'Y-m-d';
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.