Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/routing/Loader/XmlFileLoader.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 7a779792577d |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
34 * @param string $file An XML file path | 34 * @param string $file An XML file path |
35 * @param string|null $type The resource type | 35 * @param string|null $type The resource type |
36 * | 36 * |
37 * @return RouteCollection A RouteCollection instance | 37 * @return RouteCollection A RouteCollection instance |
38 * | 38 * |
39 * @throws \InvalidArgumentException When the file cannot be loaded or when the XML cannot be | 39 * @throws \InvalidArgumentException when the file cannot be loaded or when the XML cannot be |
40 * parsed because it does not validate against the scheme. | 40 * parsed because it does not validate against the scheme |
41 */ | 41 */ |
42 public function load($file, $type = null) | 42 public function load($file, $type = null) |
43 { | 43 { |
44 $path = $this->locator->locate($file); | 44 $path = $this->locator->locate($file); |
45 | 45 |
144 | 144 |
145 list($defaults, $requirements, $options, $condition) = $this->parseConfigs($node, $path); | 145 list($defaults, $requirements, $options, $condition) = $this->parseConfigs($node, $path); |
146 | 146 |
147 $this->setCurrentDir(dirname($path)); | 147 $this->setCurrentDir(dirname($path)); |
148 | 148 |
149 $subCollection = $this->import($resource, ('' !== $type ? $type : null), false, $file); | 149 $imported = $this->import($resource, ('' !== $type ? $type : null), false, $file); |
150 /* @var $subCollection RouteCollection */ | 150 |
151 $subCollection->addPrefix($prefix); | 151 if (!is_array($imported)) { |
152 if (null !== $host) { | 152 $imported = array($imported); |
153 $subCollection->setHost($host); | 153 } |
154 } | 154 |
155 if (null !== $condition) { | 155 foreach ($imported as $subCollection) { |
156 $subCollection->setCondition($condition); | 156 /* @var $subCollection RouteCollection */ |
157 } | 157 $subCollection->addPrefix($prefix); |
158 if (null !== $schemes) { | 158 if (null !== $host) { |
159 $subCollection->setSchemes($schemes); | 159 $subCollection->setHost($host); |
160 } | 160 } |
161 if (null !== $methods) { | 161 if (null !== $condition) { |
162 $subCollection->setMethods($methods); | 162 $subCollection->setCondition($condition); |
163 } | 163 } |
164 $subCollection->addDefaults($defaults); | 164 if (null !== $schemes) { |
165 $subCollection->addRequirements($requirements); | 165 $subCollection->setSchemes($schemes); |
166 $subCollection->addOptions($options); | 166 } |
167 | 167 if (null !== $methods) { |
168 $collection->addCollection($subCollection); | 168 $subCollection->setMethods($methods); |
169 } | |
170 $subCollection->addDefaults($defaults); | |
171 $subCollection->addRequirements($requirements); | |
172 $subCollection->addOptions($options); | |
173 | |
174 $collection->addCollection($subCollection); | |
175 } | |
169 } | 176 } |
170 | 177 |
171 /** | 178 /** |
172 * Loads an XML file. | 179 * Loads an XML file. |
173 * | 180 * |
227 default: | 234 default: |
228 throw new \InvalidArgumentException(sprintf('Unknown tag "%s" used in file "%s". Expected "default", "requirement", "option" or "condition".', $n->localName, $path)); | 235 throw new \InvalidArgumentException(sprintf('Unknown tag "%s" used in file "%s". Expected "default", "requirement", "option" or "condition".', $n->localName, $path)); |
229 } | 236 } |
230 } | 237 } |
231 | 238 |
239 if ($controller = $node->getAttribute('controller')) { | |
240 if (isset($defaults['_controller'])) { | |
241 $name = $node->hasAttribute('id') ? sprintf('"%s"', $node->getAttribute('id')) : sprintf('the "%s" tag', $node->tagName); | |
242 | |
243 throw new \InvalidArgumentException(sprintf('The routing file "%s" must not specify both the "controller" attribute and the defaults key "_controller" for %s.', $path, $name)); | |
244 } | |
245 | |
246 $defaults['_controller'] = $controller; | |
247 } | |
248 | |
232 return array($defaults, $requirements, $options, $condition); | 249 return array($defaults, $requirements, $options, $condition); |
233 } | 250 } |
234 | 251 |
235 /** | 252 /** |
236 * Parses the "default" elements. | 253 * Parses the "default" elements. |