1 | <?php |
||
36 | class ConfigurationFactory implements ConfigurationFactoryInterface |
||
37 | { |
||
38 | |||
39 | /** |
||
40 | * The configuration parser factory instance used to create a parser that |
||
41 | * parsers and merges the configuration from different directories. |
||
42 | * |
||
43 | * @var \TechDivision\Import\Configuration\Jms\ConfigurationParserFactoryInterface |
||
44 | */ |
||
45 | protected $configurationParserFactory; |
||
46 | |||
47 | /** |
||
48 | * Initializes the instance with the configuration parser factory instance. |
||
49 | * |
||
50 | * @param \TechDivision\Import\Configuration\Jms\ConfigurationParserFactoryInterface $configurationParserFactory The configuration parser factory instance |
||
51 | */ |
||
52 | public function __construct(ConfigurationParserFactoryInterface $configurationParserFactory) |
||
56 | |||
57 | /** |
||
58 | * Return's the configuration parser factory instance. |
||
59 | * |
||
60 | * @return \TechDivision\Import\Configuration\Jms\ConfigurationParserFactoryInterface The configuration parser factory instance |
||
61 | */ |
||
62 | protected function getConfigurationParserFactory() |
||
66 | |||
67 | /** |
||
68 | * Returns the configuration parser for the passed format. |
||
69 | * |
||
70 | * @param string $format The format of the configuration file to return the parser for (either one of json, yaml or xml) |
||
71 | * |
||
72 | * @return \TechDivision\Import\Configuration\Jms\ConfigurationParserInterface The configuration parser instance |
||
73 | */ |
||
74 | protected function getConfigurationParser($format) |
||
78 | |||
79 | /** |
||
80 | * Factory implementation to create a new initialized configuration instance. |
||
81 | * |
||
82 | * @param string $filename The configuration filename |
||
83 | * @param string $format The format of the configuration file, either one of json, yaml or xml |
||
84 | * @param string $params A serialized string with additional params that'll be passed to the configuration |
||
85 | * @param string $paramsFile A filename that contains serialized data with additional params that'll be passed to the configuration |
||
86 | * |
||
87 | * @return \TechDivision\Import\Configuration\Jms\Configuration The configuration instance |
||
88 | * @throws \Exception Is thrown, if the specified configuration file doesn't exist |
||
89 | */ |
||
90 | public function factory($filename, $format = 'json', $params = null, $paramsFile = null) |
||
102 | |||
103 | /** |
||
104 | * Factory implementation to create a new initialized configuration instance from a file |
||
105 | * with configurations that'll be parsed and merged. |
||
106 | * |
||
107 | * @param array $directories An array with diretories to parse and merge |
||
108 | * @param string $format The format of the configuration file, either one of json, yaml or xml |
||
109 | * @param string $params A serialized string with additional params that'll be passed to the configuration |
||
110 | * @param string $paramsFile A filename that contains serialized data with additional params that'll be passed to the configuration |
||
111 | * |
||
112 | * @return void |
||
113 | */ |
||
114 | public function factoryFromDirectories(array $directories = array(), $format = 'json', $params = null, $paramsFile = null) |
||
118 | |||
119 | /** |
||
120 | * Factory implementation to create a new initialized configuration instance. |
||
121 | * |
||
122 | * @param string $data The configuration data |
||
123 | * @param string $format The format of the configuration data, either one of json, yaml or xml |
||
124 | * @param string $params A serialized string with additional params that'll be passed to the configuration |
||
125 | * @param string $paramsFile A filename that contains serialized data with additional params that'll be passed to the configuration |
||
126 | * |
||
127 | * @return \TechDivision\Import\ConfigurationInterface The configuration instance |
||
128 | */ |
||
129 | public function factoryFromString($data, $format = 'json', $params = null, $paramsFile = null) |
||
162 | |||
163 | /** |
||
164 | * Creates and returns an array/object tree from the passed array. |
||
165 | * |
||
166 | * @param array $data The data to create the object tree from |
||
167 | * @param string $type The object type to create |
||
168 | * |
||
169 | * @return mixed The array/object tree from the passed array |
||
170 | */ |
||
171 | protected function fromArray(array $data, $type) |
||
175 | |||
176 | /** |
||
177 | * Deserializes the data, converts it into an array and returns it. |
||
178 | * |
||
179 | * @param string $data The data to convert |
||
180 | * @param string $type The object type for the deserialization |
||
181 | * @param string $format The data format, either one of JSON, XML or YAML |
||
182 | * |
||
183 | * @return array The data as array |
||
184 | */ |
||
185 | protected function toArray($data, $type, $format) |
||
194 | |||
195 | /** |
||
196 | * Merge the additional params in the passed configuration data and replaces existing ones with the same name. |
||
197 | * |
||
198 | * @param array $data The array with configuration data |
||
199 | * @param array $params The array with additional params to merge |
||
200 | * |
||
201 | * @return void |
||
202 | */ |
||
203 | protected function replaceParams(&$data, $params) |
||
207 | } |
||
208 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: