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\ClassMetadataLoadEvent; |
15
|
|
|
use Ivory\Serializer\Event\ClassMetadataNotFoundEvent; |
16
|
|
|
use Ivory\Serializer\Event\SerializerEvents; |
17
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author GeLo <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class EventClassMetadataFactory implements ClassMetadataFactoryInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var ClassMetadataFactoryInterface |
26
|
|
|
*/ |
27
|
|
|
private $factory; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var EventDispatcherInterface |
31
|
|
|
*/ |
32
|
|
|
private $dispatcher; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param ClassMetadataFactoryInterface $factory |
36
|
|
|
* @param EventDispatcherInterface $dispatcher |
37
|
|
|
*/ |
38
|
8 |
|
public function __construct(ClassMetadataFactoryInterface $factory, EventDispatcherInterface $dispatcher) |
39
|
|
|
{ |
40
|
8 |
|
$this->factory = $factory; |
41
|
8 |
|
$this->dispatcher = $dispatcher; |
42
|
8 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritdoc} |
46
|
|
|
*/ |
47
|
8 |
|
public function getClassMetadata($class) |
48
|
|
|
{ |
49
|
8 |
|
$classMetadata = $this->factory->getClassMetadata($class); |
50
|
|
|
|
51
|
8 |
|
if ($classMetadata === null) { |
52
|
4 |
|
$this->dispatcher->dispatch( |
53
|
4 |
|
SerializerEvents::CLASS_METADATA_NOT_FOUND, |
54
|
4 |
|
$event = new ClassMetadataNotFoundEvent($class) |
55
|
2 |
|
); |
56
|
2 |
|
} else { |
57
|
4 |
|
$this->dispatcher->dispatch( |
58
|
4 |
|
SerializerEvents::CLASS_METADATA_LOAD, |
59
|
4 |
|
$event = new ClassMetadataLoadEvent($classMetadata) |
60
|
2 |
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
8 |
|
return $event->getClassMetadata(); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|