本文整理汇总了PHP中Main::get_instance方法的典型用法代码示例。如果您正苦于以下问题:PHP Main::get_instance方法的具体用法?PHP Main::get_instance怎么用?PHP Main::get_instance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Main
的用法示例。
在下文中一共展示了Main::get_instance方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: filter_by_request
public static function filter_by_request()
{
$routes = Main::get_instance()->routes;
if (!$routes) {
return;
}
return \_u::find($routes, function ($route) {
return $route->method->equalsCurrent() && ($route->path->equalsCurrent() || $route->path->matchParams()) && Agent::matchesCurrent($route->agent);
});
}
示例2: matchesCurrent
public static function matchesCurrent($agent)
{
// if user did not specify agent, return like it's found
if (!isset($agent)) {
return true;
}
$real_agent = Main::get_instance()->current_request->real_agent;
if (is_array($agent)) {
return \_u::any($agent, function ($agt) use($real_agent) {
return preg_match($agt->value, $real_agent);
});
} else {
return preg_match($agent->value, $real_agent);
}
}
示例3: equalsCurrent
public function equalsCurrent()
{
return $this->value === Main::get_instance()->current_request->method->value;
}
示例4: set_splats_params
/**
* Set splats from current request path.
* /a/b/[:star:]/f/g/[:star:]/x/y
*/
public function set_splats_params()
{
$current_path = Main::get_instance()->current_request->path->value;
$splat_path = '';
$ud_index = 0;
$splat_index = 0;
$current_path_dirs = explode('/', $current_path);
$this->splats[0] = '';
foreach ($current_path_dirs as $key => $cur_dir) {
$ud_dir = $this->dirs[$ud_index];
@($next_ud_dir = $this->dirs[$ud_index + 1]);
if ($cur_dir == $next_ud_dir && @$is_splat_region) {
$ud_index += 2;
$splat_index += 1;
$this->splats[$splat_index] = '';
$is_splat_region = false;
continue;
}
if ($cur_dir == $ud_dir) {
$ud_index += 1;
$is_splat_region = false;
} else {
if (Path::is_param($ud_dir) || Path::is_param($ud_dir, true)) {
$ud_index += 1;
$is_splat_region = false;
$this->add_param(trim($ud_dir, ':?'), $cur_dir);
} else {
if ($ud_dir == '*') {
$is_splat_region = true;
$this->splats[$splat_index] .= $cur_dir . '/';
}
}
}
}
$this->splats = array_filter($this->splats);
$this->splats = \_u::map($this->splats, function ($el) {
return trim($el, '/');
});
}