Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use request->method for HTTP verb #2012

Merged
merged 5 commits into from
May 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -986,12 +986,13 @@ public function storePreviousURL($uri)
* Modifies the Request Object to use a different method if a POST
* variable called _method is found.
*
* Does not work on CLI commands.
*/
public function spoofRequestMethod()
{
// CLI commands always use 'cli' method
if (is_cli())
{
$this->request->setMethod('cli');
return;
}

Expand Down
7 changes: 4 additions & 3 deletions system/Router/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

namespace CodeIgniter\Router;

use Config\Services;
use CodeIgniter\Autoloader\FileLocator;
use CodeIgniter\Router\Exceptions\RouterException;

Expand Down Expand Up @@ -233,8 +234,8 @@ class RouteCollection implements RouteCollectionInterface
*/
public function __construct(FileLocator $locator, $moduleConfig)
{
// Get HTTP verb
$this->HTTPVerb = strtolower($_SERVER['REQUEST_METHOD'] ?? 'cli');
// Get HTTP verb from current request (accounts for spoofing)
$this->HTTPVerb = Services::request()->getMethod();

$this->fileLocator = $locator;

Expand Down Expand Up @@ -1115,7 +1116,7 @@ public function reverseRoute(string $search, ...$params)
{
$from = key($route['route']);
$to = $route['route'][$from];

// ignore closures
if (! is_string($to))
{
Expand Down
Loading