本文整理汇总了PHP中Illuminate\Routing\Route::getPrefix方法的典型用法代码示例。如果您正苦于以下问题:PHP Route::getPrefix方法的具体用法?PHP Route::getPrefix怎么用?PHP Route::getPrefix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Routing\Route
的用法示例。
在下文中一共展示了Route::getPrefix方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: matches
/**
* Validate a given rule against a route and request.
*
* @param \Illuminate\Routing\Route $route
* @param \Illuminate\Http\Request $request
*
* @return bool
*/
public function matches(Route $route, Request $request)
{
$this->route = $route;
$this->request = $request;
$uri = $route->uri();
$prefix = $route->getPrefix();
// Transform the $uri to the form of `prefix.URI-fragment` e.g. `page.about`
if (!empty($prefix)) {
$uri = str_replace('/', '.', $uri);
}
// if the current page is a generic page
// then just use the uri to test
if ($this->is_generic($uri)) {
return $this->is_it_matches($uri);
}
// if the current page is a specified page
// extract the post type and post slug
$post_info = explode('.', $uri);
$post_type = $post_info[0];
$post_slug = $post_info[1];
$post_info_greater_than_2 = count($post_info) > 2;
$post_hierarchy = array_slice($post_info, 1);
if ($post_type === 'category' and \is_category()) {
$isSubCategory = $post_info_greater_than_2;
if ($isSubCategory) {
$cat = get_category(get_query_var('cat'));
$hierarchy = $this->get_category_parents($cat);
array_push($hierarchy, urldecode($cat->slug));
return $hierarchy == $post_hierarchy;
}
}
if ($post_type === 'taxonomy' and \is_tax()) {
$isSubTerm = $post_info_greater_than_2;
if ($isSubTerm) {
$taxonomy = get_query_var('taxonomy');
$term = get_term_by('slug', get_query_var('term'), $taxonomy);
$hierarchy = $this->get_taxonomy_parents($term, $post_slug);
array_unshift($hierarchy, $taxonomy);
array_push($hierarchy, urldecode($term->slug));
return $hierarchy == $post_hierarchy;
}
return \is_tax($post_slug);
}
if ($post_type === 'page' and \is_page()) {
// if sub-page is supplied, detect if the current page matches
$isSubPage = count($post_info) > 2;
if ($isSubPage) {
$currentPost = \get_post(\get_the_ID());
$hierarchy = $this->get_page_parents($currentPost);
array_push($hierarchy, $currentPost->post_name);
return $hierarchy == $post_hierarchy;
}
}
return $this->is_it_matches($post_type, $post_slug);
}
示例2: to
/**
* @param $method
* @param array $params
* @return string
*/
protected function to($method, array $params = [])
{
$prefix = $this->route->getPrefix();
return route($prefix . '.' . $this->resource->name() . '.' . $method, $params);
}
示例3: getRouteInformation
/**
* Get the route information for a given route.
*
* @param string $name
* @param \Illuminate\Routing\Route $route
* @return array
*/
protected function getRouteInformation(Route $route)
{
$uri = implode('|', $route->methods()) . ' ' . $route->uri();
return $this->filterRoute(array('host' => $route->domain(), 'uri' => $uri, 'name' => $route->getName(), 'action' => $route->getActionName(), 'prefix' => $route->getPrefix(), 'method' => $route->methods()[0]));
}