1. Go to this page and download the library: Download brendt/php-make-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/ */
brendt / php-make-object example snippets
$post = make(Post::class)->from($postData);
$reflectionExtractor = new ReflectionExtractor();
$phpDocExtractor = new PhpDocExtractor();
$propertyTypeExtractor = new PropertyInfoExtractor(
listExtractors: [$reflectionExtractor],
typeExtractors: [$phpDocExtractor, $reflectionExtractor],
descriptionExtractors: [$phpDocExtractor],
accessExtractors: [$reflectionExtractor],
initializableExtractors: [$reflectionExtractor]
);
$normalizer = new ObjectNormalizer(
propertyTypeExtractor: $propertyTypeExtractor
);
$arrayNormalizer = new ArrayDenormalizer();
$serializer = new SymfonySerializer(
normalizers: [
$arrayNormalizer,
$normalizer,
],
encoders: [
new XmlEncoder(),
new JsonEncoder(),
],
);
$post = $serializer->denormalize($postData, Post::class)