/**
  * Get the route information for a given route.
  *
  * @param  string $name
  * @param  Route $route
  * @param  Route $current the current route
  * @param  string $base_path
  * @return array
  */
 protected function getRouteInformation($name, Route $route, $current, $base_path)
 {
     $path = $route->getPath();
     $uri = head($route->getMethods()) . ' <a href="' . $base_path . $path . '">' . $path . '</a>';
     $action = $route->getAction() ?: 'Closure';
     return array('current' => $current == $route, 'host' => $route->getHost(), 'uri' => $uri, 'name' => $this->getRouteName($name), 'action' => $action, 'before' => $this->getBeforeFilters($route), 'after' => $this->getAfterFilters($route));
 }
Example #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');
 }
Example #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);
 }
Example #4
0
 private function prepareMethods(\Illuminate\Routing\Route $route)
 {
     $methods = array_diff($route->getMethods(), config('arcanesoft.foundation.routes-viewer.methods.hide', ['HEAD']));
     $colors = config('arcanesoft.foundation.routes-viewer.methods.colors', ['GET' => 'success', 'HEAD' => 'default', 'POST' => 'primary', 'PUT' => 'warning', 'PATCH' => 'info', 'DELETE' => 'danger']);
     return array_map(function ($method) use($colors) {
         return ['name' => $method, 'color' => Arr::get($colors, $method)];
     }, $methods);
 }
 /**
  * Get all of the pattern filters matching the route.
  *
  * @param  \Illuminate\Routing\Route $route
  * @return array
  */
 protected function getPatternFilters($route)
 {
     $patterns = array();
     foreach ($route->getMethods() as $method) {
         $inner = $this->router->findPatternFilters($method, $route->getPath());
         $patterns = array_merge($patterns, $inner);
     }
     return $patterns;
 }
 private function hasGetMethod(Route $route)
 {
     return in_array('GET', $route->getMethods());
 }
 /**
  * Generate Route into standart routing in route file
  *
  * @param string $route_file
  * @param Illuminate\Routing\Route $route
  * @return void
  */
 protected function generateStandartRoute($route_file, Route $route)
 {
     $route_methods = $route->getMethods();
     $method = '';
     $uri = $route->getUri();
     $extra_param = '';
     // first param for Route::match
     switch ($route_methods) {
         case ['GET', 'HEAD']:
         case ['GET']:
             $method = 'get';
             break;
         case ['POST']:
         case ['PUT']:
         case ['PATCH']:
         case ['DELETE']:
             $method = strtolower($route_methods[0]);
             break;
         default:
             $method = 'match';
             $arr_methods = array_map(function ($val) {
                 return "'" . strtolower($val) . "'";
             }, $route_methods);
             $extra_param = '[' . implode(', ', $arr_methods) . ']';
     }
     $action = $route->getAction();
     $action_data = [];
     $uses = str_replace($action['namespace'] . "\\", "", $action['uses']);
     $action_data['uses'] = "'uses' => '{$uses}'";
     if (!empty($action['as'])) {
         $action_data['as'] = "'as' => '" . $action['as'] . "'";
     }
     if (!empty($action['middleware'])) {
         $action_data['middleware'] = "'middleware' => '" . implode('|', $action['middleware']) . "'";
     }
     if (!empty($action['prefix'])) {
         $action_data['prefix'] = "'prefix' => '" . $action['prefix'] . "'";
     }
     // if only action uses in action_data, just use string as action
     if (1 == count($action_data) and array_key_exists('uses', $action_data)) {
         $code_action_params = "'{$uses}'";
     } else {
         $code_action_params = "[\n\t" . implode(",\n\t", $action_data) . "\n]";
     }
     $route_params = [];
     if (!empty($extra_param)) {
         $route_params[] = $extra_param;
     }
     $route_params[] = "'{$uri}'";
     $route_params[] = $code_action_params;
     $route_code = "\nRoute::{$method}(" . implode(', ', $route_params) . ")";
     $code_conditions = [];
     foreach ($route->conditions as $param => $regex) {
         $code_conditions[] = "->where('{$param}', '{$regex}')";
     }
     $route_code .= implode("\n", $code_conditions) . ";";
     if (false == $this->option("no-comment")) {
         $code_comment = "\n\n/*" . "\n | -----------------------------------------------------------" . "\n | Route " . (isset($action['as']) ? "'" . $action['as'] . "'" : "") . "\n | -----------------------------------------------------------" . (!empty($route->description) ? "\n | " . str_replace("\n", "\n | ", $route->description) . "\n | " : "") . "\n | generated at: " . date('Y-m-d H:i:s') . "\n |" . "\n */";
         $route_code = $code_comment . $route_code;
     } else {
         $route_code = "\n" . $route_code;
     }
     file_put_contents($route_file, file_get_contents($route_file) . $route_code);
 }
Example #8
0
 /**
  * @return array
  */
 public function toArray()
 {
     return array_merge(['name' => $this->route->getName(), 'methods' => $this->route->getMethods(), 'domain' => $this->route->domain(), 'path' => $this->preparePath(), 'action' => $this->route->getAction(), 'wheres' => $this->extractWheres(), 'errors' => $this->errors], $this->getMeta(), $this->options);
 }