/** * Add the given route to the arrays of routes. * * @param \Illuminate\Routing\Route $route * @return void */ protected function addToCollections($route) { foreach ($route->methods() as $method) { $this->routes[$method][$route->domain() . $route->getUri()] = $route; } $this->allRoutes[$method . $route->domain() . $route->getUri()] = $route; }
/** * Add the given route to the arrays of routes. * * @param \Illuminate\Routing\Route $route * @return void */ protected function addToCollections($route) { $domainAndUri = $route->domain() . $route->getUri() . $route->getPriority(); foreach ($route->methods() as $method) { $this->routes[$method][$domainAndUri] = $route; } $this->allRoutes[$method . $domainAndUri] = $route; }
public function isAlternate(LaravelRoute $route) { if (!$route instanceof Route) { return false; } // Validate methods if ($this->methods() != $route->methods()) { return false; } // Validate scheme if ($this->httpOnly() !== $route->httpOnly()) { return false; } // Validate base uri if ($this->getBaseUri() !== $route->getBaseUri()) { return false; } if ($this->getUri() === $route->getUri()) { return false; } return true; }
/** * Display a listing of the resource. * * @return Response */ public function index(Route $route) { return view('pages.category_index')->with('data', ['items' => $this->getModel(), 'route' => $route, 'uri' => $route->getUri(), 'body_class' => $route->getUri(), 'title' => $this->getPageTitle()]); }
/** * Returns a given route's children as an array. A parent route like /users would return (if they existed) all routes * like /users/{userid}, /users/new. * * @param Route $parentRoute * @return Route[] */ public function subordinates(Route $parentRoute) { if (array_key_exists($parentRoute->getUri(), $this->subordinateRouteCache)) { return $this->subordinateRouteCache[$parentRoute->getUri()]; } $routes = $this->router->getRoutes(); $children = []; /** @var Route $route */ foreach ($routes as $route) { if (!self::isValid($route)) { continue; } // if the route does not start with the same uri as the current route -> skip if ($parentRoute->getUri() != '/' && !starts_with($route->getUri(), $parentRoute->getUri())) { continue; } // if route equals the parent route if ($parentRoute->getActionName() == $route->getActionName()) { continue; } $children[] = $route; } return $this->subordinateRouteCache[$parentRoute->getUri()] = $children; }
/** * @param Route $route * * @return mixed */ protected function getUri($route) { return $route->getUri(); }
/** * @return string */ public function getUri() { return parent::getUri() . $this->getRouteIntent(); }
private function generateJsString(Route $route) { $jsRoutes = "'" . $this->appUrl . '/' . $route->getUri() . "',"; return $jsRoutes; }
/** * 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); }