123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php namespace System\Route;
- class Finder {
-
- public static $routes;
-
- public static $names = array();
-
- public static function find($name)
- {
- if (is_null(static::$routes))
- {
- static::$routes = (is_dir(APP_PATH.'routes')) ? static::load() : require APP_PATH.'routes'.EXT;
- }
- if (array_key_exists($name, static::$names))
- {
- return static::$names[$name];
- }
-
-
-
-
- $arrayIterator = new \RecursiveArrayIterator(static::$routes);
- $recursiveIterator = new \RecursiveIteratorIterator($arrayIterator);
- foreach ($recursiveIterator as $iterator)
- {
- $route = $recursiveIterator->getSubIterator();
- if (isset($route['name']) and $route['name'] == $name)
- {
- return static::$names[$name] = array($arrayIterator->key() => iterator_to_array($route));
- }
- }
- }
-
- private static function load()
- {
- $routes = array();
- foreach (glob(APP_PATH.'routes/*') as $file)
- {
- if (filetype($file) == 'file')
- {
- $routes = array_merge(require $file, $routes);
- }
- }
- return $routes;
- }
- }
|