Skip to content

Instantly share code, notes, and snippets.

@MatteoOreficeIT
Last active April 5, 2017 08:34
Show Gist options
  • Save MatteoOreficeIT/aa5c48df728b1fcc67cfff9854ab790b to your computer and use it in GitHub Desktop.
Save MatteoOreficeIT/aa5c48df728b1fcc67cfff9854ab790b to your computer and use it in GitHub Desktop.
Undocumented way to setup route in laravel 5.4 ?
<?php
Route::get('/params/{name}', [
'middleware' => 'App\Http\Middleware\DumpMiddleware',
function () {
return view('welcome');
}]);
namespace Illuminate\Routing;
class Route
{
use RouteDependencyResolverTrait;
/**
* Create a new Route instance.
*
* @param array|string $methods
* @param string $uri
* @param \Closure|array $action ---->>> action has been normalize to only Closure or array
* @return void
*/
public function __construct($methods, $uri, $action)
{
$this->uri = $uri;
$this->methods = (array) $methods;
$this->action = $this->parseAction($action);
}
}
use LogicException;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use UnexpectedValueException;
class RouteAction
{
/**
* Parse the given action into an array.
*
* @param string $uri
* @param mixed $action
* @return array
*/
public static function parse($uri, $action)
{
// If no action is passed in right away, we assume the user will make use of
// fluent routing. In that case, we set a default closure, to be executed
// if the user never explicitly sets an action to handle the given uri.
if (is_null($action)) {
return static::missingAction($uri);
}
// If the action is already a Closure instance, we will just set that instance
// as the "uses" property, because there is nothing else we need to do when
// it is available. Otherwise we will need to find it in the action list.
if (is_callable($action)) {
return ['uses' => $action];
}
// If no "uses" property has been set, we will dig through the array to find a
// Closure instance within this list. We will set the first Closure we come
// across into the "uses" property that will get fired off by this route.
elseif (! isset($action['uses'])) {
$action['uses'] = static::findCallable($action);
}
if (is_string($action['uses']) && ! Str::contains($action['uses'], '@')) {
$action['uses'] = static::makeInvokable($action['uses']);
}
return $action;
}
}
/**
* Create a new route instance.
*
* @param array|string $methods
* @param string $uri
* @param mixed $action ----->> could be an array ????
* @return \Illuminate\Routing\Route
*/
// protected function createRoute($methods, $uri, $action)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment