1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?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 = require APP_PATH.'routes'.EXT;
- if (is_dir(APP_PATH.'routes'))
- {
- static::$routes = array_merge(static::load(), static::$routes);
- }
- }
- 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();
-
-
- $directoryIterator = new \RecursiveDirectoryIterator(APP_PATH.'routes');
- $recursiveIterator = new \RecursiveIteratorIterator($directoryIterator, \RecursiveIteratorIterator::SELF_FIRST);
- foreach ($recursiveIterator as $file)
- {
- if (filetype($file) === 'file' and strpos($file, EXT) !== false)
- {
- $routes = array_merge(require $file, $routes);
- }
- }
- return $routes;
- }
- }
|