/** */ public function resolveController(Match $match) { // is the route target a closure? if ($match->translation instanceof Closure) { $match->controller = $match->translation; } else { // fetch all components loaded by this application $components = $this->component->getApplication()->getComponents(); // order them by namespace $namespaces = array(); foreach ($components as $uri => $component) { // skip non-routeable components for the main request if (!$component->isRoutable() and $this->factory->isMainRequest()) { continue; } $namespaces[$component->getNamespace()] = $component; } krsort($namespaces); // find a match foreach ($namespaces as $namespace => $component) { // skip if we don't have a prefix match if ($uri = $component->getUri() and strpos($match->translation, $uri) !== 0) { continue; } $match->setNamespace($namespace); // get the segments from the translated route $segments = explode('/', ltrim(substr($match->translation, strlen($uri)), '/')); $arguments = array(); while (count($segments)) { $class = $match->namespace . $this->namespacePrefix . '\\' . implode('\\', array_map('ucfirst', $segments)); if (class_exists($class)) { $match->controller = $class; break; } array_unshift($arguments, array_pop($segments)); } // did we find a match if ($match->controller) { // then stop looking break; } } // any segments left? if (!empty($segments)) { $match->action = ucfirst(array_shift($arguments)); } // more? set them as additional segments $match->uri = implode('/', $arguments); } return $match; }
public function filterTo(Match $match, $to) { list($controller, $action) = explode('@', $to); $match->setController($controller); $match->setAction($action); }