-
Notifications
You must be signed in to change notification settings - Fork 6
/
custom.php
37 lines (32 loc) · 1.14 KB
/
custom.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
use Spray\Serializer\AnnotationBackedPropertyInfo;
use Spray\Serializer\Cache\ArrayCache;
use Spray\Serializer\Object\DateTimeImmutableSerializer;
use Spray\Serializer\Object\DateTimeSerializer;
use Spray\Serializer\Object\ObjectSerializerGenerator;
use Spray\Serializer\Object\SerializerLocator;
use Spray\Serializer\Object\SerializerRegistry;
use Spray\Serializer\Object\StdClassSerializer;
use Spray\Serializer\ObjectListener;
use Spray\Serializer\Serializer;
chdir(dirname(__DIR__));
require 'vendor/autoload.php';
$registry = new SerializerRegistry();
$registry->add(new DateTimeSerializer());
$registry->add(new DateTimeImmutableSerializer());
$registry->add(new StdClassSerializer());
$serializer = new Serializer();
$serializer->attach(
new ObjectListener(
new SerializerLocator(
$registry,
new ObjectSerializerGenerator(
new AnnotationBackedPropertyInfo()
),
new ArrayCache('Serializer')
)
)
);
var_export($serializer->serialize(new DateTime()));
var_export($serializer->serialize(new DateTimeImmutable()));
var_export($serializer->serialize(new stdClass()));