本文整理汇总了PHP中helpers\Url::detectUri方法的典型用法代码示例。如果您正苦于以下问题:PHP Url::detectUri方法的具体用法?PHP Url::detectUri怎么用?PHP Url::detectUri使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类helpers\Url
的用法示例。
在下文中一共展示了Url::detectUri方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dispatch
/**
* Dispatch
* @return bool
*/
public function dispatch()
{
// Detect the current URI.
$uri = Url::detectUri();
// First, we will supose that URI is associated with an Asset File.
if (Request::isGet() && $this->dispatchFile($uri)) {
return true;
}
// Not an Asset File URI? Routes the current request.
$method = Request::getMethod();
// Search the defined Routes for matches; invoke the associated Callback, if any.
foreach ($this->routes as $route) {
if ($route->match($uri, $method, false)) {
// Found a valid Route; process it.
$this->matchedRoute = $route;
$callback = $route->callback();
if (is_object($callback)) {
// Invoke the Route's Callback with the associated parameters.
call_user_func_array($callback, $route->params());
return true;
}
// Pattern based Route.
$regex = $route->regex();
// Prepare the URI used by autoDispatch, applying the REGEX if exists.
if (!empty($regex)) {
$uri = preg_replace('#^' . $regex . '$#', $callback, $uri);
} else {
$uri = $callback;
}
break;
}
}
// Auto-dispatch the processed URI; quit if the attempt finished successfully.
if ($this->autoDispatch($uri)) {
return true;
}
// The dispatching failed; invoke the Error Callback with the current URI as parameter.
$params = array(htmlspecialchars($uri, ENT_COMPAT, 'ISO-8859-1', true));
$this->invokeObject($this->callback(), $params);
return false;
}
示例2: dispatch
/**
* Dispatch route
* @return bool
*/
public function dispatch()
{
// Detect the current URI.
$uri = Url::detectUri();
// First, we will supose that URI is associated with an Asset File.
if (Request::isGet() && $this->dispatchFile($uri)) {
return true;
}
// Not an Asset File URI? Routes the current request.
$method = Request::getMethod();
// If there exists a Catch-All Route, firstly we add it to Routes list.
if ($this->defaultRoute !== null) {
array_push($this->routes, $this->defaultRoute);
}
foreach ($this->routes as $route) {
if ($route->match($uri, $method)) {
// Found a valid Route; process it.
$this->matchedRoute = $route;
$callback = $route->callback();
if ($callback !== null) {
// Invoke the Route's Callback with the associated parameters.
return $this->invokeObject($callback, $route->params());
}
return true;
}
}
// No valid Route found; invoke the Error Callback with the current URI as parameter.
$params = array(htmlspecialchars($uri, ENT_COMPAT, 'ISO-8859-1', true));
$this->invokeObject($this->callback(), $params);
return false;
}