1 | <?php |
||
27 | class RestXmlCollectionLoader extends XmlFileLoader |
||
28 | { |
||
29 | protected $collectionParents = []; |
||
30 | private $processor; |
||
31 | private $includeFormat; |
||
32 | private $formats; |
||
33 | private $defaultFormat; |
||
34 | |||
35 | /** |
||
36 | * @param string[] $formats |
||
37 | */ |
||
38 | 21 | public function __construct( |
|
39 | FileLocatorInterface $locator, |
||
40 | RestRouteProcessor $processor, |
||
41 | bool $includeFormat = true, |
||
42 | array $formats = [], |
||
43 | string $defaultFormat = null |
||
44 | ) { |
||
45 | 21 | parent::__construct($locator); |
|
46 | |||
47 | 21 | $this->processor = $processor; |
|
48 | 21 | $this->includeFormat = $includeFormat; |
|
49 | 21 | $this->formats = $formats; |
|
50 | 21 | $this->defaultFormat = $defaultFormat; |
|
51 | 21 | } |
|
52 | |||
53 | /** |
||
54 | * {@inheritdoc} |
||
55 | */ |
||
56 | 9 | protected function parseNode(RouteCollection $collection, \DOMElement $node, $path, $file): void |
|
57 | { |
||
58 | 9 | switch ($node->tagName) { |
|
59 | 9 | case 'route': |
|
60 | 6 | $this->parseRoute($collection, $node, $path); |
|
61 | |||
62 | 6 | break; |
|
63 | 3 | case 'import': |
|
64 | 3 | $name = (string) $node->getAttribute('id'); |
|
65 | 3 | $resource = (string) $node->getAttribute('resource'); |
|
66 | 3 | $prefix = (string) $node->getAttribute('prefix'); |
|
67 | 3 | $namePrefix = (string) $node->getAttribute('name-prefix'); |
|
68 | 3 | $parent = (string) $node->getAttribute('parent'); |
|
69 | 3 | $type = (string) $node->getAttribute('type'); |
|
70 | 3 | $host = isset($config['host']) ? $config['host'] : null; |
|
|
|||
71 | 3 | $currentDir = dirname($path); |
|
72 | |||
73 | 3 | $parents = []; |
|
74 | 3 | if (!empty($parent)) { |
|
75 | 3 | if (!isset($this->collectionParents[$parent])) { |
|
76 | 1 | throw new \InvalidArgumentException(sprintf('Cannot find parent resource with name %s', $parent)); |
|
77 | } |
||
78 | |||
79 | 2 | $parents = $this->collectionParents[$parent]; |
|
80 | } |
||
81 | |||
82 | 2 | $imported = $this->processor->importResource($this, $resource, $parents, $prefix, $namePrefix, $type, $currentDir); |
|
83 | |||
84 | 2 | if (!empty($name) && $imported instanceof RestRouteCollection) { |
|
85 | 2 | $parents[] = (!empty($prefix) ? $prefix.'/' : '').$imported->getSingularName(); |
|
86 | 2 | $prefix = null; |
|
87 | |||
88 | 2 | $this->collectionParents[$name] = $parents; |
|
89 | } |
||
90 | |||
91 | 2 | if (!empty($host)) { |
|
92 | $imported->setHost($host); |
||
93 | } |
||
94 | |||
95 | 2 | $imported->addPrefix((string) $prefix); |
|
96 | 2 | $collection->addCollection($imported); |
|
97 | |||
98 | 2 | break; |
|
99 | default: |
||
100 | throw new \InvalidArgumentException(sprintf('Unable to parse tag "%s"', $node->tagName)); |
||
101 | } |
||
102 | 8 | } |
|
103 | |||
104 | /** |
||
105 | * {@inheritdoc} |
||
106 | */ |
||
107 | 6 | protected function parseRoute(RouteCollection $collection, \DOMElement $node, $path): void |
|
178 | |||
179 | 6 | private function getOptions(\DOMElement $node): array |
|
196 | |||
197 | /** |
||
198 | * {@inheritdoc} |
||
199 | */ |
||
200 | 2 | public function supports($resource, $type = null): bool |
|
206 | |||
207 | 10 | protected function validate(\DOMDocument $dom): void |
|
234 | |||
235 | /** |
||
236 | * {@inheritdoc} |
||
237 | * |
||
238 | * @internal |
||
239 | */ |
||
240 | 10 | protected function loadFile($file): \DOMDocument |
|
247 | |||
248 | /** |
||
249 | * Retrieves libxml errors and clears them. |
||
250 | * |
||
251 | * Note: The underscore postfix on the method name is to ensure compatibility with versions |
||
252 | * before 2.0.16 while working around a bug in PHP https://bugs.php.net/bug.php?id=62956 |
||
253 | */ |
||
254 | 1 | private function getXmlErrors_(bool $internalErrors): array |
|
274 | } |
||
275 |
This check looks for calls to
isset(...)
orempty()
on variables that are yet undefined. These calls will always produce the same result and can be removed.This is most likely caused by the renaming of a variable or the removal of a function/method parameter.