1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Configuration\Jms\Parsers\JsonParser |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Tim Wagner <[email protected]> |
15
|
|
|
* @copyright 2019 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/techdivision/import-configuration-jms |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Configuration\Jms\Parsers; |
22
|
|
|
|
23
|
|
|
use TechDivision\Import\Configuration\Jms\ConfigurationParserInterface; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The JSON configuration parser implementation. |
27
|
|
|
* |
28
|
|
|
* @author Tim Wagner <[email protected]> |
29
|
|
|
* @copyright 2019 TechDivision GmbH <[email protected]> |
30
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
31
|
|
|
* @link https://github.com/techdivision/import-configuration-jms |
32
|
|
|
* @link http://www.techdivision.com |
33
|
|
|
*/ |
34
|
|
|
class JsonParser implements ConfigurationParserInterface |
35
|
|
|
{ |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Parsing the configuration and merge it recursively. |
39
|
|
|
* |
40
|
|
|
* @param array $directories An array with diretories to parse |
41
|
|
|
* @param string $format The format of the configuration data, either one of json, yaml or xml |
|
|
|
|
42
|
|
|
* |
43
|
|
|
* @return void |
44
|
|
|
*/ |
45
|
|
|
public function parse(array $directories) |
46
|
|
|
{ |
47
|
|
|
|
48
|
|
|
$main = array(); |
49
|
|
|
|
50
|
|
|
foreach ($directories as $directory) { |
51
|
|
|
|
52
|
|
|
$directory = new \RecursiveDirectoryIterator($directory); |
53
|
|
|
$iterator = new \RecursiveIteratorIterator($directory); |
54
|
|
|
$regex = new \RegexIterator($iterator, '/^.+\.json$/i', \RecursiveRegexIterator::GET_MATCH); |
55
|
|
|
|
56
|
|
|
$filenames = array_keys(iterator_to_array($regex)); |
57
|
|
|
|
58
|
|
|
foreach ($filenames as $filename) { |
59
|
|
|
|
60
|
|
|
if ($content = json_decode(file_get_contents($filename), true)) { |
61
|
|
|
$main = array_merge_recursive($main, $content); |
62
|
|
|
} else { |
63
|
|
|
error_log(sprintf('Can\'t load content of file %s', $filename)); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return json_encode($main, JSON_PRETTY_PRINT); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.