本文整理匯總了PHP中r::method方法的典型用法代碼示例。如果您正苦於以下問題:PHP r::method方法的具體用法?PHP r::method怎麽用?PHP r::method使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類r
的用法示例。
在下文中一共展示了r::method方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: map
function map()
{
$url = url::strip_query(server::get('request_uri'));
$url = str_replace(rtrim(c::get('router.root'), '/'), '', $url);
$method = r::method();
foreach (self::$routes as $key => $route) {
if (!in_array($method, $route['methods'])) {
continue;
}
$key = str_replace(')', ')?', $key);
$args = array();
$regex = preg_replace_callback('#@([\\w]+)(:([^/\\(\\)]*))?#', function ($matches) use(&$args) {
$args[$matches[1]] = null;
if (isset($matches[3])) {
return '(?P<' . $matches[1] . '>' . $matches[3] . ')';
}
return '(?P<' . $matches[1] . '>[^/\\?]+)';
}, $key);
if (preg_match('#^' . $regex . '(?:\\?.*)?$#i', $url, $matches)) {
foreach ($args as $k => $v) {
self::$params[$k] = array_key_exists($k, $matches) ? urldecode($matches[$k]) : null;
}
return $route['callback'];
}
}
return false;
}
示例2: run
/**
* Iterate through every route to find a matching route.
*
* @param string $path Optional path to match against
* @return Route
*/
public function run($path = null)
{
$method = r::method();
$ajax = r::ajax();
$https = r::ssl();
$routes = a::get($this->routes, $method, array());
// detect path if not set manually
if ($path === null) {
$path = implode('/', (array) url::fragments(detect::path()));
}
// empty urls should never happen
if (empty($path)) {
$path = '/';
}
foreach ($routes as $route) {
if ($route->https and !$https) {
continue;
}
if ($route->ajax and !$ajax) {
continue;
}
// handle exact matches
if ($route->pattern == $path) {
$this->route = $route;
break;
}
// We only need to check routes with regular expression since all others
// would have been able to be matched by the search for literal matches
// we just did before we started searching.
if (strpos($route->pattern, '(') === false) {
continue;
}
$preg = '#^' . $this->wildcards($route->pattern) . '$#u';
// If we get a match we'll return the route and slice off the first
// parameter match, as preg_match sets the first array item to the
// full-text match of the pattern.
if (preg_match($preg, $path, $parameters)) {
$this->route = $route;
$this->route->arguments = array_slice($parameters, 1);
break;
}
}
if ($this->route and $this->filterer($this->route->filter) !== false) {
return $this->route;
} else {
return null;
}
}
示例3: testMethod
public function testMethod()
{
$this->assertEquals('GET', r::method());
}