Skip to content

Commit

Permalink
Merge pull request #3308 from mostafakhudair/patch-2
Browse files Browse the repository at this point in the history
count on \Config\Services
  • Loading branch information
lonnieezell authored Jul 15, 2020
2 parents 91460ef + 01faba2 commit 31c7d41
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion system/Helpers/number_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ function number_to_currency(float $num, string $currency, string $locale = null,
function format_number(float $num, int $precision = 1, string $locale = null, array $options = []): string
{
// Locale is either passed in here, negotiated with client, or grabbed from our config file.
$locale = $locale ?? \CodeIgniter\Config\Services::request()->getLocale();
$locale = $locale ?? \Config\Services::request()->getLocale();

// Type can be any of the NumberFormatter options, but provide a default.
$type = (int) ($options['type'] ?? NumberFormatter::DECIMAL);
Expand Down
20 changes: 8 additions & 12 deletions system/Helpers/url_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function base_url($uri = '', string $protocol = null): string
// We should be using the configured baseURL that the user set;
// otherwise get rid of the path, because we have
// no way of knowing the intent...
$config = \CodeIgniter\Config\Services::request()->config;
$config = \Config\Services::request()->config;

// If baseUrl does not have a trailing slash it won't resolve
// correctly for users hosting in a subfolder.
Expand All @@ -130,7 +130,7 @@ function base_url($uri = '', string $protocol = null): string

// If the scheme wasn't provided, check to
// see if it was a secure request
if (empty($protocol) && \CodeIgniter\Config\Services::request()->isSecure())
if (empty($protocol) && \Config\Services::request()->isSecure())
{
$protocol = 'https';
}
Expand Down Expand Up @@ -160,25 +160,21 @@ function base_url($uri = '', string $protocol = null): string
*/
function current_url(bool $returnObject = false)
{
$uri = clone service('request')->uri;
$uri = clone \Config\Services::request()->uri;

// If hosted in a sub-folder, we will have additional
// segments that show up prior to the URI path we just
// grabbed from the request, so add it on if necessary.
$baseUri = new \CodeIgniter\HTTP\URI(config('App')->baseURL);
$baseUri = new \CodeIgniter\HTTP\URI(config(\Config\App::class)->baseURL);

if (! empty($baseUri->getPath()))
{
$path = rtrim($baseUri->getPath(), '/ ') . '/' . $uri->getPath();

$uri->setPath($path);
$uri->setPath(rtrim($baseUri->getPath(), '/ ') . '/' . $uri->getPath());
}

// Since we're basing off of the IncomingRequest URI,
// we are guaranteed to have a host based on our own configs.
return $returnObject
? $uri
: (string)$uri->setQuery('');
return $returnObject ? $uri : (string) $uri->setQuery('');
}
}

Expand All @@ -201,7 +197,7 @@ function previous_url(bool $returnObject = false)
// Grab from the session first, if we have it,
// since it's more reliable and safer.
// Otherwise, grab a sanitized version from $_SERVER.
$referer = $_SESSION['_ci_previous_url'] ?? \CodeIgniter\Config\Services::request()->getServer('HTTP_REFERER', FILTER_SANITIZE_URL);
$referer = $_SESSION['_ci_previous_url'] ?? \Config\Services::request()->getServer('HTTP_REFERER', FILTER_SANITIZE_URL);

$referer = $referer ?? site_url('/');

Expand All @@ -222,7 +218,7 @@ function previous_url(bool $returnObject = false)
*/
function uri_string(): string
{
return \CodeIgniter\Config\Services::request()->uri->getPath();
return \Config\Services::request()->uri->getPath();
}
}

Expand Down

0 comments on commit 31c7d41

Please sign in to comment.