1 | <?php |
||
20 | class FileClassMetadataLoader implements MappedClassMetadataLoaderInterface |
||
21 | { |
||
22 | const EXTENSION_JSON = 'json'; |
||
23 | const EXTENSION_XML = 'xml'; |
||
24 | const EXTENSION_YAML = 'yml'; |
||
25 | |||
26 | /** |
||
27 | * @var MappedClassMetadataLoaderInterface |
||
28 | */ |
||
29 | private $loader; |
||
30 | |||
31 | /** |
||
32 | * @param string $file |
||
33 | * @param TypeParserInterface|null $typeParser |
||
34 | */ |
||
35 | 784 | public function __construct($file, TypeParserInterface $typeParser = null) |
|
36 | { |
||
37 | 784 | if (!file_exists($file)) { |
|
38 | 24 | throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $file)); |
|
39 | } |
||
40 | |||
41 | 784 | switch (pathinfo($file, PATHINFO_EXTENSION)) { |
|
42 | 784 | case self::EXTENSION_JSON: |
|
43 | 364 | $this->loader = new JsonClassMetadataLoader($file, $typeParser); |
|
44 | 364 | break; |
|
45 | |||
46 | 580 | case self::EXTENSION_XML: |
|
47 | 368 | $this->loader = new XmlClassMetadataLoader($file, $typeParser); |
|
48 | 368 | break; |
|
49 | |||
50 | 372 | case self::EXTENSION_YAML: |
|
51 | 364 | $this->loader = new YamlClassMetadataLoader($file, $typeParser); |
|
52 | 364 | break; |
|
53 | 392 | } |
|
54 | |||
55 | 784 | if ($this->loader === null) { |
|
56 | 12 | throw new \InvalidArgumentException(sprintf('The file "%s" is not supported.', $file)); |
|
57 | } |
||
58 | 784 | } |
|
59 | |||
60 | /** |
||
61 | * {@inheritdoc} |
||
62 | */ |
||
63 | 688 | public function loadClassMetadata(ClassMetadataInterface $classMetadata) |
|
67 | |||
68 | /** |
||
69 | * {@inheritdoc} |
||
70 | */ |
||
71 | 320 | public function getMappedClasses() |
|
75 | } |
||
76 |