1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| # Symfony\Component\Routing\Loader\YamlFileLoader public function load($file, $type = null) { try { // 将yaml格式解析成 php 数组 $parsedConfig = $this->yamlParser->parse(file_get_contents($path), Yaml::PARSE_KEYS_AS_STRINGS); } catch (ParseException $e) { // ...... } $collection = new RouteCollection(); // ...... foreach ($parsedConfig as $name => $config) { // 如果路由配置中存在key resource // 对resource指定的文件目录中的路由定义进行处理 if (isset($config['resource'])) { $this->parseImport($collection, $config, $path, $file); } else { // 不存在直接进行路由解析 $this->parseRoute($collection, $name, $config, $path); } } }
protected function parseImport(RouteCollection $collection, array $config, $path, $file) { $subCollection = $this->import($config['resource'], $type, false, $file); $collection->addCollection($subCollection); } public function import($resource, $type = null, $ignoreErrors = false, $sourceResource = null) { // ...... return $this->doImport($resource, $type, $ignoreErrors, $sourceResource); } private function doImport($resource, $type = null, $ignoreErrors = false, $sourceResource = null) { try { // $loader = \Symfony\Component\Routing\Loader\AnnotationDirectoryLoader $loader = $this->resolve($resource, $type); // ...... try { // 执行Loader中的 load 方法 $ret = $loader->load($resource, $type); } finally { // ...... }
return $ret; } catch (FileLoaderImportCircularReferenceException $e) { // ...... } catch (\Exception $e) { // ...... } }
|