Skip to content
This repository has been archived by the owner on Feb 13, 2022. It is now read-only.

Commit

Permalink
Merge pull request #279 from leocavalcante/fix/278
Browse files Browse the repository at this point in the history
Fix #278
  • Loading branch information
leocavalcante committed Mar 14, 2020
2 parents f61e45d + df4aca9 commit 5eff901
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/Http/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Siler\Http;

use function Siler\array_get;
use function Siler\array_get_str;

/**
* Get a value from the $_COOKIE global.
Expand Down Expand Up @@ -104,15 +105,15 @@ function url(?string $path = null): string
*/
function path(): string
{
/**
* @var array<string, string> $_SERVER
* @var string $script_name
*/
$script_name = array_get($_SERVER, 'SCRIPT_NAME', '');
/** @var string $query_string */
$query_string = array_get($_SERVER, 'QUERY_STRING', '');
/** @var string $request_uri */
$request_uri = array_get($_SERVER, 'REQUEST_URI', '');
/** @var array<string, string> $_SERVER */
$script_name = array_get_str($_SERVER, 'SCRIPT_NAME', '');
$query_string = array_get_str($_SERVER, 'QUERY_STRING', '');
$request_uri = array_get_str($_SERVER, 'REQUEST_URI', '');

// NOTE: When using built-in server with a router script, SCRIPT_NAME will be same as the REQUEST_URI
if (php_sapi_name() === 'cli-server') {
$script_name = '';
}

$request_uri = str_replace('?' . $query_string, '', $request_uri);
$script_path = str_replace('\\', '/', dirname($script_name));
Expand Down

0 comments on commit 5eff901

Please sign in to comment.