|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the Cubiche package. |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (c) Cubiche |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Cubiche\Core\Metadata\Driver; |
|
12
|
|
|
|
|
13
|
|
|
use Cubiche\Core\Collections\ArrayCollection\ArrayList; |
|
14
|
|
|
use Cubiche\Core\Metadata\ClassMetadata; |
|
15
|
|
|
use Cubiche\Core\Metadata\Exception\MappingException; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* MergeableDriver class. |
|
19
|
|
|
* |
|
20
|
|
|
* @author Ivannis Suárez Jerez <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class MergeableDriver implements DriverInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var DriverInterface[] |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $drivers; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* MergeableDriver constructor. |
|
31
|
|
|
* |
|
32
|
|
|
* @param array $drivers |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct(array $drivers = array()) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->drivers = new ArrayList(); |
|
|
|
|
|
|
37
|
|
|
foreach ($drivers as $driver) { |
|
38
|
|
|
$this->addDriver($driver); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param DriverInterface $driver |
|
44
|
|
|
*/ |
|
45
|
|
|
public function addDriver(DriverInterface $driver) |
|
46
|
|
|
{ |
|
47
|
|
|
$this->drivers->add($driver); |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* {@inheritdoc} |
|
52
|
|
|
*/ |
|
53
|
|
|
public function loadMetadataForClass($className) |
|
54
|
|
|
{ |
|
55
|
|
|
$classMetadata = null; |
|
56
|
|
|
/** @var $driver DriverInterface */ |
|
57
|
|
|
foreach ($this->drivers->toArray() as $driver) { |
|
|
|
|
|
|
58
|
|
|
try { |
|
59
|
|
|
$metadata = $driver->loadMetadataForClass($className); |
|
60
|
|
|
} catch (MappingException $e) { |
|
61
|
|
|
continue; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
if ($metadata !== null) { |
|
65
|
|
|
if ($classMetadata === null) { |
|
66
|
|
|
$classMetadata = new ClassMetadata($className); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$classMetadata->merge($metadata); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
if ($classMetadata === null) { |
|
74
|
|
|
throw MappingException::classNotFound($className); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
return $classMetadata; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* {@inheritdoc} |
|
82
|
|
|
*/ |
|
83
|
|
|
public function getAllClassNames() |
|
84
|
|
|
{ |
|
85
|
|
|
$classNames = []; |
|
86
|
|
|
/** @var $driver DriverInterface */ |
|
87
|
|
|
foreach ($this->drivers->toArray() as $driver) { |
|
|
|
|
|
|
88
|
|
|
$classNames = array_merge($classNames, $driver->getAllClassNames()); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
return $classNames; |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..