/** * Register a controller with the router. * * @param string|array $controllers * @param string|array $defaults * @param bool $https * @return void */ public static function controller($controllers, $defaults = 'index', $https = null) { foreach ((array) $controllers as $identifier) { list($bundle, $controller) = Bundle::parse($identifier); // First we need to replace the dots with slashes in the controller name // so that it is in directory format. The dots allow the developer to use // a cleaner syntax when specifying the controller. We will also grab the // root URI for the controller's bundle. $controller = str_replace('.', '/', $controller); $root = Bundle::option($bundle, 'handles'); // If the controller is a "home" controller, we'll need to also build an // index method route for the controller. We'll remove "home" from the // route root and setup a route to point to the index method. if (ends_with($controller, 'home')) { static::root($identifier, $controller, $root); } // The number of method arguments allowed for a controller is set by a // "segments" constant on this class which allows for the developer to // increase or decrease the limit on method arguments. $wildcards = static::repeat('(:any?)', static::$segments); // Once we have the path and root URI we can build a simple route for // the controller that should handle a conventional controller route // setup of controller/method/segment/segment, etc. $pattern = trim("{$root}/{$controller}/{$wildcards}", '/'); // Finally we can build the "uses" clause and the attributes for the // controller route and register it with the router with a wildcard // method so it is available on every request method. $uses = "{$identifier}@(:1)"; $attributes = compact('uses', 'defaults', 'https'); static::register('*', $pattern, $attributes); } }
public static function controller($controllers, $defaults = 'index', $https = null) { foreach ((array) $controllers as $identifier) { list($bundle, $controller) = Bundle::parse($identifier); $controller = str_replace('.', '/', $controller); $root = Bundle::option($bundle, 'handles'); if (ends_with($controller, 'home')) { static::root($identifier, $controller, $root); } $wildcards = static::repeat('(:any?)', static::$segments); $pattern = trim("{$root}/{$controller}/{$wildcards}", '/'); $uses = "{$identifier}@(:1)"; $attributes = compact('uses', 'defaults', 'https'); static::register('*', $pattern, $attributes); } }