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 | 768 | public function __construct($file, TypeParserInterface $typeParser = null) |
|
36 | { |
||
37 | 768 | if (!file_exists($file)) { |
|
38 | 24 | throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $file)); |
|
39 | } |
||
40 | |||
41 | 768 | switch (pathinfo($file, PATHINFO_EXTENSION)) { |
|
42 | 768 | case self::EXTENSION_JSON: |
|
43 | 360 | $this->loader = new JsonClassMetadataLoader($file, $typeParser); |
|
44 | 360 | break; |
|
45 | |||
46 | 564 | case self::EXTENSION_XML: |
|
47 | 360 | $this->loader = new XmlClassMetadataLoader($file, $typeParser); |
|
48 | 360 | break; |
|
49 | |||
50 | 360 | case self::EXTENSION_YAML: |
|
51 | 360 | $this->loader = new YamlClassMetadataLoader($file, $typeParser); |
|
52 | 360 | break; |
|
53 | 384 | } |
|
54 | |||
55 | 768 | if ($this->loader === null) { |
|
56 | throw new \InvalidArgumentException('The file "%s" is not supported.'); |
||
57 | } |
||
58 | 768 | } |
|
59 | |||
60 | /** |
||
61 | * {@inheritdoc} |
||
62 | */ |
||
63 | 688 | public function loadClassMetadata(ClassMetadataInterface $classMetadata) |
|
64 | { |
||
65 | 688 | return $this->loader->loadClassMetadata($classMetadata); |
|
66 | } |
||
67 | |||
68 | /** |
||
69 | * {@inheritdoc} |
||
70 | */ |
||
71 | public function getMappedClasses() |
||
75 | } |
||
76 |