1 | <?php |
||
35 | class ConfigurationFactory implements ConfigurationFactoryInterface |
||
36 | { |
||
37 | |||
38 | /** |
||
39 | * Factory implementation to create a new initialized configuration instance. |
||
40 | * |
||
41 | * @param string $filename The configuration filename |
||
42 | * @param string $type The format of the configuration file, either one of json, yaml or xml |
||
43 | * |
||
44 | * @return \TechDivision\Import\Configuration\Jms\Configuration The configuration instance |
||
45 | * @throws \Exception Is thrown, if the specified configuration file doesn't exist |
||
46 | */ |
||
47 | public function factory($filename, $type = 'json') |
||
48 | { |
||
49 | |||
50 | // try to load the JSON data |
||
51 | if ($data = file_get_contents($filename)) { |
||
52 | // initialize the JMS serializer, load and return the configuration |
||
53 | return $this->factoryFromString($data, $type); |
||
54 | } |
||
55 | |||
56 | // throw an exception if the data can not be loaded from the passed file |
||
57 | throw new \Exception(sprintf('Can\'t load configuration file %s', $filename)); |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Factory implementation to create a new initialized configuration instance. |
||
62 | * |
||
63 | * @param string $data The configuration data |
||
64 | * @param string $type The format of the configuration data, either one of json, yaml or xml |
||
65 | * |
||
66 | * @return \TechDivision\Import\Configuration\Jms\Configuration The configuration instance |
||
67 | */ |
||
68 | public function factoryFromString($data, $type = 'json') |
||
73 | } |
||
74 |