/** * Creates a new route in this collection. * * @param string $url The url to register * @param string $method A regular expression to match the request method with * @param callable $callback The handler of the route (has access to the scope) * @return Route * @see Route::__construct */ public function register($url = null, $method = '.*', $callback = null) { $registration = new Route($url, $method, $callback, function () { return $this->getFullPrefix(); }); $registration->before(function ($scope) { foreach ($this->globalBefores as $b) { $scope->call($b); if ($scope->isRightResource === false) { return; } if ($scope->stopRoute === true) { return; } } }); $this->routes[] = $registration; return $registration; }
<?php /* |-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ Route::before(function ($request) { header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS'); header('Access-Control-Allow-Headers: Origin, Content-Type, Accept, Authorization, X-Request-With'); header('Access-Control-Allow-Credentials: true'); }); Route::get('/', function () { return view('welcome'); })->middleware('guest'); // Task Routes Route::get('/tasks', 'TaskController@index'); Route::post('/task', 'TaskController@store'); Route::delete('/task/{task}', 'TaskController@destroy'); // Authentication Routes... Route::get('auth/login', 'Auth\\AuthController@getLogin'); Route::post('auth/login', 'Auth\\AuthController@postLogin'); Route::get('auth/logout', 'Auth\\AuthController@getLogout'); // Registration Routes... Route::get('auth/register', 'Auth\\AuthController@getRegister');
private function followPseudoRoute(&$request, &$response, $code, $scope) { $route = new Route('/', '.*', function (HTTPResponseInterface $response) use($code) { $response->setStatusCode($code); }); foreach ($this->routesCollection->getBeforeFunctions() as $r) { $route->before($r); } $this->log->debug('Following a pseudo-route that will return a ' . $code . ' status code'); $route->handleNoURLCheck($request, $response, $scope); }
public function testACompleteResponseShouldStopFurtherRouteExecution() { $route = new Route('GET', '/test', function () { return 'callback'; }); $route->before(function (Response $response) { $response->send(); }); $response = new ResponseMock(); $route->execute(Request::create(false, 'localhost', '/test'), $response); $this->assertEquals('', $response->contents()); }