/** * Execute the console command. * * @return mixed */ public function fire() { $uri = $this->argument("uri"); $method = $this->argument("method"); $route_file = base_path($this->option("file")); $conditions = $this->option("where"); $action = ['uses' => $this->argument("uses"), 'after' => $this->option("after"), 'before' => $this->option("before"), 'as' => $this->option("name")]; foreach ($action as $key => $val) { if (is_null($val)) { unset($action[$key]); } } $route_generator = new RouteGenerator($method, $uri, $action); foreach ($conditions as $cond) { list($param, $regex) = explode(':', $cond, 2); $route_generator->where($param, $regex); } $route_str = strtoupper($method) . " " . $route_generator->resolvedUri(); $route_generator->generate($route_file, true); $this->info("# Generate route '{$route_str}' using '" . $route_generator->getActionName() . "'"); $action_generator = $route_generator->getActionGenerator(); $controller_class = $action_generator->getControllerClass(); $controller_method = $action_generator->getControllerMethod(); if ($action_generator->hasGenerateController()) { echo "> Generate controller '{$controller_class}'\n"; } if ($action_generator->hasGenerateMethod()) { echo "> Generate method '{$controller_method}' in controller '{$controller_class}'\n"; } }
public function __construct(RouteGenerator $route, $controller_file = null) { if (!$route->isUsingController()) { throw new \Exception("Route must use Controller as action"); } list($controller, $method) = explode('@', $route->getActionName()); $this->route = $route; $this->files = new Filesystem(); $this->controller_class = $controller; $this->controller_method = $method; $this->controller_file = $controller_file ?: app_path('controllers/' . str_replace("\\", "/", $controller)) . '.php'; }