/** * Loads array of routes from resource * * @param string $source Path to resource * @return array Array of routes */ public function loadResource($source = null) { $routes = array(); $source = $this->resolveResorceSource($source); $extension = Path::getExtension($source); if (file_exists($source)) { $content = File::load($source); if ($extension == 'yml') { $array = Yaml::parse($content); } elseif ($extension == 'json') { $array = json_decode($content, true); } else { throw new \Exception("Unsupported routing file type. Routes can only be loaded from yml or json files"); } if (is_array($array)) { if (isset($array['imports'])) { foreach ($array['imports'] as $import) { if (isset($import['resource'])) { $extraSource = $this->resolveResorceSource($import['resource']); foreach ($this->loadResource($import['resource']) as $name => $route) { $routes[$name] = $route; } } } } if (isset($array['routes'])) { foreach ($array['routes'] as $name => $route) { $routes[$name] = $route; } } } } $this->resource = $routes; return $routes; }
/** * @dataProvider pathsProvider */ public function testGetExtension($expected, $path) { $this->assertSame($expected, Path::getExtension($path)); }