Skip to content

Commit

Permalink
Always get the method and path from the Illuminate Request
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Allan committed Feb 17, 2017
1 parent 4f76ea2 commit 83fd12f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 71 deletions.
38 changes: 5 additions & 33 deletions src/Concerns/RoutesRequests.php
Expand Up @@ -547,15 +547,13 @@ public function dispatch($request = null)
*/
protected function parseIncomingRequest($request)
{
if ($request) {
$this->instance(Request::class, $this->prepareRequest($request));
if (! $request) {
$request = Request::capture();
}

return [$request->getMethod(), $request->getPathInfo()];
} else {
$this->instance(Request::class, Request::capture());
$this->instance(Request::class, $this->prepareRequest($request));

return [$this->getMethod(), $this->getPathInfo()];
}
return [$request->getMethod(), $request->getPathInfo()];
}

/**
Expand Down Expand Up @@ -802,32 +800,6 @@ public function prepareResponse($response)
return $response;
}

/**
* Get the current HTTP request method.
*
* @return string
*/
protected function getMethod()
{
if (isset($_POST['_method'])) {
return strtoupper($_POST['_method']);
} else {
return $_SERVER['REQUEST_METHOD'];
}
}

/**
* Get the current HTTP path info.
*
* @return string
*/
protected function getPathInfo()
{
$query = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';

return '/'.trim(str_replace('?'.$query, '', $_SERVER['REQUEST_URI']), '/');
}

/**
* Get the raw routes for the application.
*
Expand Down
38 changes: 0 additions & 38 deletions tests/FullApplicationTest.php
Expand Up @@ -57,44 +57,6 @@ public function testAddRouteMultipleMethodRequest()
$this->assertEquals('Hello World', $response->getContent());
}

public function testRequestWithoutSymfonyClass()
{
$app = new Application;

$app->get('/', function () {
return response('Hello World');
});

$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/';

$response = $app->dispatch();

$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('Hello World', $response->getContent());

unset($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);
}

public function testRequestWithoutSymfonyClassTrailingSlash()
{
$app = new Application;

$app->get('/foo', function () {
return response('Hello World');
});

$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/foo/';

$response = $app->dispatch();

$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('Hello World', $response->getContent());

unset($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);
}

public function testRequestWithParameters()
{
$app = new Application;
Expand Down

0 comments on commit 83fd12f

Please sign in to comment.