Exemple #1
0
 /**
  * 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);
 }
Exemple #2
0
 /**
  * @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);
 }
Exemple #3
0
 /**
  * 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]));
 }