public function match($uri) { list($uri) = explode("&", $uri); list($uri) = explode("?", $uri); $atoms = (array) explode("/", $uri); $uri = ""; foreach ($atoms as $atom) { if (empty($atom)) { continue; } $uri .= "/{$atom}"; } $uri = sprintf("%s", trim($uri, DIRECTORY_SEPARATOR)); $site_root = trim($this->config->application->get("application/site_root"), DIRECTORY_SEPARATOR); if (!empty($site_root)) { $uri = str_replace($site_root, "", $uri); } foreach ($this->_items as $key => $item) { // check uri if (preg_match("/^{$item->filter}/i", "/{$uri}/", $matches)) { $matched_uri = str_replace($matches[0], "", $uri); array_shift($matches); // match uri $action_arguments = array(); if ($matched_uri != "") { $action_arguments = explode("/", trim($matched_uri, DIRECTORY_SEPARATOR)); } // merge filter variables $parameters = array(); foreach ($item->variables as $key) { if (!empty($key)) { $parameters[$key] = trim(array_shift($matches), DIRECTORY_SEPARATOR); } } // set controller variable if (!isset($item->controller)) { $item->controller = $parameters["controller"]; unset($parameters["controller"]); } // set action variable if (!isset($item->action)) { $item->action = $parameters["action"]; unset($parameters["action"]); } // set action arguments $item->action_arguments = array_merge(array_values((array) $parameters), (array) $action_arguments); // clear action from extension $action_info = explode(".", $item->action); // set extension variable if (!isset($item->action_extension)) { array_shift($action_info); $item->action_extension = count($action_info) ? implode(".", $action_info) : null; } //set parameters $item->parameters = array_merge((array) $parameters, $_REQUEST); // unset filter values unset($item->filter); unset($item->variables); // set render variable if (!isset($item->render)) { $item->render = Joy_Render_Factory::get($item->action_extension); } // set request method $item->method = $_SERVER["REQUEST_METHOD"]; // controller exists $result = clone $item; if (Joy_Controller::exists($result->controller)) { break; } } else { $result = null; } } return is_null($result) ? null : new Joy_Router_Match($result); }
public static function factory($className) { return Joy_Render_Factory::newInstance($className); }