Files
spa-api/system/routing/finder.php

43 lines
986 B
PHP
Raw Normal View History

<?php namespace System\Routing;
2011-06-14 17:27:11 -05:00
class Finder {
2011-06-14 17:27:11 -05:00
/**
* The named routes that have been found so far.
*
* @var array
*/
public static $names = array();
/**
* Find a named route in a given array of routes.
2011-06-14 17:27:11 -05:00
*
* @param string $name
* @param array $routes
2011-06-14 17:27:11 -05:00
* @return array
*/
public static function find($name, $routes)
2011-06-14 17:27:11 -05:00
{
if (array_key_exists($name, static::$names))
{
return static::$names[$name];
}
$arrayIterator = new \RecursiveArrayIterator($routes);
$recursiveIterator = new \RecursiveIteratorIterator($arrayIterator);
2011-06-14 17:27:11 -05:00
// Since routes can be nested deep within sub-directories, we need to recursively
// iterate through each directory and gather all of the routes.
2011-06-14 17:27:11 -05:00
foreach ($recursiveIterator as $iterator)
{
$route = $recursiveIterator->getSubIterator();
if (isset($route['name']) and $route['name'] == $name)
2011-06-14 17:27:11 -05:00
{
return static::$names[$name] = array($arrayIterator->key() => iterator_to_array($route));
}
}
}
}