protected function filterRouteAsClass(Route $route)
 {
     if ($this->option('name') && !str_contains($route->getName(), $this->option('name')) || $this->option('path') && !str_contains(implode('|', $route->methods()) . ' ' . $route->uri(), $this->option('path'))) {
         return null;
     }
     return $route;
 }
Пример #2
0
 /**
  * Get the route information for a given route.
  *
  * @param $route \Illuminate\Routing\Route
  * @param $filter string
  * @param $namespace string
  *
  * @return array
  */
 protected function getRouteInformation(Route $route, $filter, $namespace)
 {
     $host = $route->domain();
     $methods = $route->getMethods();
     $uri = $route->uri();
     $name = $route->getName();
     $action = $route->getActionName();
     $jsroute = array_get($route->getAction(), 'jsroute', null);
     if (!empty($namespace)) {
         $a = $route->getAction();
         if (isset($a['controller'])) {
             $action = str_replace($namespace . '\\', '', $action);
         }
     }
     switch ($filter) {
         case 'all':
             if ($jsroute === false) {
                 return null;
             }
             break;
         case 'only':
             if ($jsroute !== true) {
                 return null;
             }
             break;
     }
     return compact('host', 'methods', 'uri', 'name', 'action');
 }
Пример #3
0
 public function __construct(Route $route = null)
 {
     if (!$route || !array_key_exists('controller', $route->getAction())) {
         return;
     }
     // route will be null when not called by documentor
     list($controller, $method) = explode('@', $route->getAction()['controller']);
     $this->handler = explode('\\', $route->getAction()['controller']);
     $this->handler = end($this->handler);
     $this->hash = md5($this->handler);
     $this->group = $this->getApiGroup($controller, $method);
     $this->groupHash = md5($this->group);
     $this->sort = $this->getApiSort($controller, $method);
     $this->path = $route->uri();
     $this->httpMethod = $route->getMethods()[0];
     $this->controllerMethod = $method;
     $this->controller = $controller;
     $this->title = $this->getApiTitle($controller, $method);
     $this->description = $this->getApiDescription($controller, $method);
     $requestclass = $this->getRequestClass($controller, $method, $this->path, $this->httpMethod);
     $this->inputProps = $requestclass ? $requestclass->apiFields() : [];
     $this->response = $requestclass ? $requestclass->exampleResponse() : '';
     $this->urlIdMap = $this->getUrlIdMap($controller);
     $this->responseCodes = $this->getResponseCodes($controller, $method, !!$this->inputProps);
 }
Пример #4
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);
 }
Пример #5
0
 /**
  * Validate a given rule against a route and request.
  *
  * @param  LaravelRoute   $route   illuminate route
  * @param  LaravelRequest $request illuminate request
  *
  * @return bool
  */
 public function matches(Route $route, Request $request)
 {
     $path = $request->path() == '/' ? '/' : '/' . $request->path();
     $firstSegment = $request->segment(1);
     $uri = $route->uri();
     if (strpos($uri, '{instanceGroup') === 0 && $firstSegment === null) {
         return true;
     } else {
         return preg_match($route->getCompiled()->getRegex(), rawurldecode($path));
     }
 }
 /**
  * Get all of the pattern filters matching the route.
  *
  * @param  \Illuminate\Routing\Route $route
  * @return array
  */
 protected function getPatternFilters($route)
 {
     $patterns = array();
     foreach ($route->methods() as $method) {
         // For each method supported by the route we will need to gather up the patterned
         // filters for that method. We will then merge these in with the other filters
         // we have already gathered up then return them back out to these consumers.
         $inner = $this->getMethodPatterns($route->uri(), $method);
         $patterns = array_merge($patterns, array_keys($inner));
     }
     return $patterns;
 }
Пример #7
0
 /**
  * canReview
  *
  * @param Route   $route   laravel route
  * @param Request $request laravel request
  *
  * @return bool
  */
 private function canReview(Route $route, Request $request)
 {
     $firstSegment = $request->segment(1);
     if ($firstSegment === null) {
         return true;
     }
     $uri = $route->uri();
     if (strpos($uri, '{') === false) {
         return false;
     }
     $actions = $route->getAction();
     if (isset($actions['module'])) {
         return true;
     }
     return false;
 }
 protected function getRouteInformation(Route $route)
 {
     $uri = implode('|', $route->methods()) . ' ' . $route->uri();
     return $this->filterRoute(['uri' => $uri, 'name' => $route->getName(), 'before' => $this->getBeforeFilters($route), 'after' => $this->getAfterFilters($route)]);
 }
Пример #9
0
 /**
  * @param \Illuminate\Routing\Route $route
  *
  * @return array
  */
 protected function getRouteInformation(Route $route)
 {
     return $this->filterRoute(['host' => $route->domain(), 'method' => implode('|', $route->methods()), 'uri' => $route->uri(), 'name' => $route->getName(), 'action' => $route->getActionName(), 'middleware' => $this->getMiddleware($route)]);
 }
Пример #10
0
 /**
  * Get the route information for a given route.
  *
  * @param \Illuminate\Routing\Route $route
  * @return array
  */
 protected function getRouteInformation(Route $route)
 {
     return $this->filterRoute(array('host' => $route->domain(), 'uri' => implode('|', $route->methods()) . ' ' . $route->uri(), 'name' => $route->getName(), 'action' => $route->getActionName(), 'version' => implode(', ', array_get($route->getAction(), 'version')), 'protected' => array_get($route->getAction(), 'protected') ? 'Yes' : 'No', 'scopes' => $this->getScopes($route)));
 }
Пример #11
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)
 {
     /** @var \LaraPress\Routing\Route $route */
     return $route->wordpressConditional() == null || call_user_func($route->wordpressConditional(), $route->uri());
 }
Пример #12
0
 /**
  * canReview
  *
  * @param Route   $route   laravel route
  * @param Request $request laravel request
  *
  * @return bool
  */
 private function canReview(Route $route, Request $request)
 {
     if (!is_null($route->getCompiled()->getHostRegex())) {
         return false;
     }
     $uri = $route->uri();
     if (strpos($uri, '{instanceGroup') !== 0) {
         return false;
     }
     $actions = $route->getAction();
     if (isset($actions['module'])) {
         return true;
     }
     return false;
 }
Пример #13
0
 /**
  * Get the route information for a given route.
  *
  * @param  \Illuminate\Routing\Route $route
  * @return array
  */
 protected function getRouteInformation(Route $route)
 {
     return $this->filterRoute(['uri' => $route->uri(), 'methods' => $route->methods(), 'name' => $route->getName(), 'action' => $route->getActionName()]);
 }
Пример #14
0
 /**
  * Reset the properties that need to be updated.
  *
  * @param Route $route
  * @param Request $request
  */
 private function refreshState(Route $route, Request $request)
 {
     $this->route = $route;
     $this->request = $request;
     $this->uri = str_replace('/', '.', $route->uri());
     // Transform the $uri to the form of `prefix.URI-fragment`   e.g. `page.about`
     $uriComponents = explode('.', $this->uri);
     // e.g.  `page.foo.bar` =>  ['page', 'foo', 'bar']
     if (count($uriComponents) === 1) {
         // the current page is a generic page
         $this->isGenericPage = true;
         $this->pageType = $uriComponents[0];
         // e.g.  `page` `home`
         $this->mainSelector = null;
         $this->routingHierarchy = null;
     } else {
         // the current page is a specified page
         $this->isGenericPage = false;
         $this->pageType = $uriComponents[0];
         // e.g.  `{page}.foo.bar`
         $this->mainSelector = $uriComponents[1];
         // e.g.  `page.{foo}.bar`
         $this->routingHierarchy = array_slice($uriComponents, 1);
         // e.g.  `page.{foo.bar}`
     }
     // get and set the queried object only once
     if ($this->queriedObject === false) {
         $this->queriedObject = get_queried_object();
     }
 }
 /**
  * Get all of the pattern filters matching the route.
  *
  * @param  \Illuminate\Routing\Route  $route
  * @return array
  */
 protected function getPatternFilters($route)
 {
     $patterns = [];
     foreach ($route->methods() as $method) {
         $inner = $this->getMethodPatterns($route->uri(), $method);
         $patterns = array_merge($patterns, array_keys($inner));
     }
     return $patterns;
 }
Пример #16
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]));
 }
Пример #17
0
 /**
  * @param Route $route
  *
  * @return array
  */
 protected function getRouteInformation(Route $route)
 {
     return ['method' => implode('|', $route->methods()), 'uri' => $route->uri(), 'name' => $route->getName(), 'action' => $route->getActionName()];
 }