Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/routing/Loader/YamlFileLoader.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 | 4c8ae668cc8c |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
25 * @author Tobias Schultze <http://tobion.de> | 25 * @author Tobias Schultze <http://tobion.de> |
26 */ | 26 */ |
27 class YamlFileLoader extends FileLoader | 27 class YamlFileLoader extends FileLoader |
28 { | 28 { |
29 private static $availableKeys = array( | 29 private static $availableKeys = array( |
30 'resource', 'type', 'prefix', 'path', 'host', 'schemes', 'methods', 'defaults', 'requirements', 'options', 'condition', | 30 'resource', 'type', 'prefix', 'path', 'host', 'schemes', 'methods', 'defaults', 'requirements', 'options', 'condition', 'controller', |
31 ); | 31 ); |
32 private $yamlParser; | 32 private $yamlParser; |
33 | 33 |
34 /** | 34 /** |
35 * Loads a Yaml file. | 35 * Loads a Yaml file. |
55 | 55 |
56 if (null === $this->yamlParser) { | 56 if (null === $this->yamlParser) { |
57 $this->yamlParser = new YamlParser(); | 57 $this->yamlParser = new YamlParser(); |
58 } | 58 } |
59 | 59 |
60 $prevErrorHandler = set_error_handler(function ($level, $message, $script, $line) use ($file, &$prevErrorHandler) { | |
61 $message = E_USER_DEPRECATED === $level ? preg_replace('/ on line \d+/', ' in "'.$file.'"$0', $message) : $message; | |
62 | |
63 return $prevErrorHandler ? $prevErrorHandler($level, $message, $script, $line) : false; | |
64 }); | |
65 | |
60 try { | 66 try { |
61 $parsedConfig = $this->yamlParser->parse(file_get_contents($path)); | 67 $parsedConfig = $this->yamlParser->parseFile($path); |
62 } catch (ParseException $e) { | 68 } catch (ParseException $e) { |
63 throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $path), 0, $e); | 69 throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $path), 0, $e); |
70 } finally { | |
71 restore_error_handler(); | |
64 } | 72 } |
65 | 73 |
66 $collection = new RouteCollection(); | 74 $collection = new RouteCollection(); |
67 $collection->addResource(new FileResource($path)); | 75 $collection->addResource(new FileResource($path)); |
68 | 76 |
112 $options = isset($config['options']) ? $config['options'] : array(); | 120 $options = isset($config['options']) ? $config['options'] : array(); |
113 $host = isset($config['host']) ? $config['host'] : ''; | 121 $host = isset($config['host']) ? $config['host'] : ''; |
114 $schemes = isset($config['schemes']) ? $config['schemes'] : array(); | 122 $schemes = isset($config['schemes']) ? $config['schemes'] : array(); |
115 $methods = isset($config['methods']) ? $config['methods'] : array(); | 123 $methods = isset($config['methods']) ? $config['methods'] : array(); |
116 $condition = isset($config['condition']) ? $config['condition'] : null; | 124 $condition = isset($config['condition']) ? $config['condition'] : null; |
125 | |
126 if (isset($config['controller'])) { | |
127 $defaults['_controller'] = $config['controller']; | |
128 } | |
117 | 129 |
118 $route = new Route($config['path'], $defaults, $requirements, $options, $host, $schemes, $methods, $condition); | 130 $route = new Route($config['path'], $defaults, $requirements, $options, $host, $schemes, $methods, $condition); |
119 | 131 |
120 $collection->add($name, $route); | 132 $collection->add($name, $route); |
121 } | 133 } |
138 $host = isset($config['host']) ? $config['host'] : null; | 150 $host = isset($config['host']) ? $config['host'] : null; |
139 $condition = isset($config['condition']) ? $config['condition'] : null; | 151 $condition = isset($config['condition']) ? $config['condition'] : null; |
140 $schemes = isset($config['schemes']) ? $config['schemes'] : null; | 152 $schemes = isset($config['schemes']) ? $config['schemes'] : null; |
141 $methods = isset($config['methods']) ? $config['methods'] : null; | 153 $methods = isset($config['methods']) ? $config['methods'] : null; |
142 | 154 |
155 if (isset($config['controller'])) { | |
156 $defaults['_controller'] = $config['controller']; | |
157 } | |
158 | |
143 $this->setCurrentDir(dirname($path)); | 159 $this->setCurrentDir(dirname($path)); |
144 | 160 |
145 $subCollection = $this->import($config['resource'], $type, false, $file); | 161 $imported = $this->import($config['resource'], $type, false, $file); |
146 /* @var $subCollection RouteCollection */ | 162 |
147 $subCollection->addPrefix($prefix); | 163 if (!is_array($imported)) { |
148 if (null !== $host) { | 164 $imported = array($imported); |
149 $subCollection->setHost($host); | 165 } |
150 } | 166 |
151 if (null !== $condition) { | 167 foreach ($imported as $subCollection) { |
152 $subCollection->setCondition($condition); | 168 /* @var $subCollection RouteCollection */ |
153 } | 169 $subCollection->addPrefix($prefix); |
154 if (null !== $schemes) { | 170 if (null !== $host) { |
155 $subCollection->setSchemes($schemes); | 171 $subCollection->setHost($host); |
156 } | 172 } |
157 if (null !== $methods) { | 173 if (null !== $condition) { |
158 $subCollection->setMethods($methods); | 174 $subCollection->setCondition($condition); |
159 } | 175 } |
160 $subCollection->addDefaults($defaults); | 176 if (null !== $schemes) { |
161 $subCollection->addRequirements($requirements); | 177 $subCollection->setSchemes($schemes); |
162 $subCollection->addOptions($options); | 178 } |
163 | 179 if (null !== $methods) { |
164 $collection->addCollection($subCollection); | 180 $subCollection->setMethods($methods); |
181 } | |
182 $subCollection->addDefaults($defaults); | |
183 $subCollection->addRequirements($requirements); | |
184 $subCollection->addOptions($options); | |
185 | |
186 $collection->addCollection($subCollection); | |
187 } | |
165 } | 188 } |
166 | 189 |
167 /** | 190 /** |
168 * Validates the route configuration. | 191 * Validates the route configuration. |
169 * | 192 * |
201 throw new \InvalidArgumentException(sprintf( | 224 throw new \InvalidArgumentException(sprintf( |
202 'You must define a "path" for the route "%s" in file "%s".', | 225 'You must define a "path" for the route "%s" in file "%s".', |
203 $name, $path | 226 $name, $path |
204 )); | 227 )); |
205 } | 228 } |
229 if (isset($config['controller']) && isset($config['defaults']['_controller'])) { | |
230 throw new \InvalidArgumentException(sprintf('The routing file "%s" must not specify both the "controller" key and the defaults key "_controller" for "%s".', $path, $name)); | |
231 } | |
206 } | 232 } |
207 } | 233 } |