Completed
Pull Request — master (#1)
by Christian
03:15 queued 49s
created

Serializer::createSerializerBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the xAPI package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Xabbuh\XApi\Serializer;
13
14
use Symfony\Component\Serializer\Encoder\JsonEncoder;
15
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
16
use Symfony\Component\Serializer\Normalizer\PropertyNormalizer;
17
use Symfony\Component\Serializer\SerializerInterface;
18
use Symfony\Component\Serializer\Serializer as SymfonySerializer;
19
use Xabbuh\XApi\Serializer\Event\ActorEventSubscriber;
20
use Xabbuh\XApi\Serializer\Event\DocumentDataWrapper;
21
use Xabbuh\XApi\Serializer\Event\ObjectEventSubscriber;
22
use Xabbuh\XApi\Serializer\Event\SetSerializedTypeEventSubscriber;
23
use Xabbuh\XApi\Serializer\Normalizer\ActorNormalizer;
24
use Xabbuh\XApi\Serializer\Normalizer\DocumentDataNormalizer;
25
use Xabbuh\XApi\Serializer\Normalizer\ObjectNormalizer;
26
use Xabbuh\XApi\Serializer\Normalizer\ResultNormalizer;
27
use Xabbuh\XApi\Serializer\Normalizer\StatementNormalizer;
28
use Xabbuh\XApi\Serializer\Normalizer\StatementResultNormalizer;
29
30
/**
31
 * Entry point to setup the {@link \Symfony\Component\Serializer\Serializer Symfony Serializer component}
32
 * for the Experience API.
33
 *
34
 * @author Christian Flothmann <[email protected]>
35
 */
36
class Serializer
37
{
38
    /**
39
     * Creates a new Serializer.
40
     *
41
     * @return SerializerInterface The Serializer
42
     */
43
    public static function createSerializer()
44
    {
45
        $normalizers = array(
46
            new ActorNormalizer(),
47
            new DocumentDataNormalizer(),
48
            new ObjectNormalizer(),
49
            new ResultNormalizer(),
50
            new StatementNormalizer(),
51
            new StatementResultNormalizer(),
52
            new ArrayDenormalizer(),
53
            new PropertyNormalizer(),
54
        );
55
        $encoders = array(
56
            new JsonEncoder(),
57
        );
58
59
        return new SymfonySerializer($normalizers, $encoders);
60
    }
61
}
62