for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the Kreta package.
*
* (c) Beñat Espiña <[email protected]>
* (c) Gorka Laucirica <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Kreta\Notifier\Infrastructure\Serialization\Inbox;
use Kreta\Notifier\Domain\Model\Inbox\UserId;
use Kreta\Notifier\Domain\Model\Inbox\UserSignedUp;
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
final class SymfonyUserSignedUpDenormalizer implements DenormalizerInterface
{
private $nameConverter;
public function __construct(NameConverterInterface $nameConverter)
$this->nameConverter = $nameConverter;
}
public function denormalize($data, $class, $format = null, array $context = []) : UserSignedUp
$userSignedUp = new UserSignedUp(
UserId::generate($data['payload']['user_id'])
);
$reflectionClass = new \ReflectionClass($userSignedUp);
$reflectionProperty = $reflectionClass->getProperty('occurredOn');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue(
$userSignedUp,
\DateTimeImmutable::createFromFormat('U', (string) $data['occurred_on'])
return $userSignedUp;
public function supportsDenormalization($data, $type, $format = null) : bool
return isset($data['type']) && $this->nameConverter->denormalize($data['type']) === UserSignedUp::class;