1<?php
2
3declare(strict_types=1);
4
5namespace JMS\Serializer\Tests\Fixtures;
6
7use JMS\Serializer\Construction\ObjectConstructorInterface;
8use JMS\Serializer\Construction\UnserializeObjectConstructor;
9use JMS\Serializer\DeserializationContext;
10use JMS\Serializer\Metadata\ClassMetadata;
11use JMS\Serializer\Visitor\DeserializationVisitorInterface;
12
13class InitializedBlogPostConstructor implements ObjectConstructorInterface
14{
15    private $fallback;
16
17    public function __construct()
18    {
19        $this->fallback = new UnserializeObjectConstructor();
20    }
21
22    public function construct(DeserializationVisitorInterface $visitor, ClassMetadata $metadata, $data, array $type, DeserializationContext $context): ?object
23    {
24        if ('JMS\Serializer\Tests\Fixtures\BlogPost' !== $type['name']) {
25            return $this->fallback->construct($visitor, $metadata, $data, $type, $context);
26        }
27
28        return new BlogPost('This is a nice title.', new Author('Foo Bar'), new \DateTime('2011-07-30 00:00', new \DateTimeZone('UTC')), new Publisher('Bar Foo'));
29    }
30}
31