Completed
Push — master ( 027522...84e71e )
by Eric
04:54
created

EventClassMetadataFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 2
1
<?php
2
3
/*
4
 * This file is part of the Ivory Serializer package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\Serializer\Mapping\Factory;
13
14
use Ivory\Serializer\Event\LoadClassMetadataEvent;
15
use Ivory\Serializer\Event\SerializerEvents;
16
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
17
18
/**
19
 * @author GeLo <[email protected]>
20
 */
21
class EventClassMetadataFactory implements ClassMetadataFactoryInterface
22
{
23
    /**
24
     * @var ClassMetadataFactoryInterface
25
     */
26
    private $factory;
27
28
    /**
29
     * @var EventDispatcherInterface
30
     */
31
    private $dispatcher;
32
33
    /**
34
     * @param ClassMetadataFactoryInterface $factory
35
     * @param EventDispatcherInterface      $dispatcher
36
     */
37
    public function __construct(ClassMetadataFactoryInterface $factory, EventDispatcherInterface $dispatcher)
38
    {
39
        $this->factory = $factory;
40
        $this->dispatcher = $dispatcher;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function getClassMetadata($class)
47
    {
48
        $classMetadata = $this->factory->getClassMetadata($class);
49
50
        if ($classMetadata !== null) {
51
            $this->dispatcher->dispatch(
52
                SerializerEvents::LOAD_CLASS_METADATA,
53
                new LoadClassMetadataEvent($classMetadata)
54
            );
55
        }
56
57
        return $classMetadata;
58
    }
59
}
60