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\Loader; |
13
|
|
|
|
14
|
|
|
use Ivory\Serializer\Type\Parser\TypeParserInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @author GeLo <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
abstract class AbstractFileClassMetadataLoader |
20
|
|
|
extends AbstractClassMetadataLoader |
|
|
|
|
21
|
|
|
implements MappedClassMetadataLoaderInterface |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
private $file; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var mixed[] |
30
|
|
|
*/ |
31
|
|
|
private $data; |
|
|
|
|
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param string $file |
35
|
1396 |
|
* @param TypeParserInterface|null $typeParser |
36
|
|
|
*/ |
37
|
1396 |
|
public function __construct($file, TypeParserInterface $typeParser = null) |
38
|
|
|
{ |
39
|
1396 |
|
parent::__construct($typeParser); |
40
|
24 |
|
|
41
|
|
|
if (!is_file($file)) { |
42
|
|
|
throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $file)); |
43
|
1396 |
|
} |
44
|
|
|
|
45
|
|
|
if (!is_readable($file)) { |
46
|
|
|
throw new \InvalidArgumentException(sprintf('The file "%s" is not readable.', $file)); |
47
|
1396 |
|
} |
48
|
1396 |
|
|
49
|
|
|
$this->file = $file; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
|
|
public function getMappedClasses() |
56
|
|
|
{ |
57
|
|
|
if ($this->data === null) { |
58
|
|
|
$this->data = $this->loadFile($this->file); |
59
|
|
|
} |
60
|
1236 |
|
|
61
|
|
|
return array_keys($this->data); |
62
|
1236 |
|
} |
63
|
1236 |
|
|
64
|
556 |
|
/** |
65
|
|
|
* @param string $file |
66
|
1112 |
|
* |
67
|
1084 |
|
* @return mixed[] |
68
|
|
|
*/ |
69
|
28 |
|
abstract protected function loadFile($file); |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* {@inheritdoc} |
73
|
|
|
*/ |
74
|
|
|
protected function loadData($class) |
75
|
|
|
{ |
76
|
|
|
if ($this->data === null) { |
77
|
|
|
$this->data = $this->loadFile($this->file); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
if (isset($this->data[$class])) { |
81
|
|
|
return $this->data[$class]; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|