PHP code example of bernard / normalt
1. Go to this page and download the library: Download bernard/normalt 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/ */
bernard / normalt example snippets
php
class User
{
protected $name;
public function setName($name)
{
$this->name = $name;
}
public function getName()
{
return $this->name;
}
}
php
use Normalt\Normalizer\AggregateNormalizer;
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
$aggregate = new AggregateNormalizer([new GetSetMethodNormalizer]);
$user = new User;
$user->setName('henrik');
$array = $aggregate->normalize($user);
// $array now contains ['name' => 'henrik']
$user = $aggregate->denormalize($array, 'User');
echo $user->getName(); // outputs Henrik