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

count on \Config\Services #3308

Merged
merged 2 commits into from
Jul 15, 2020
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
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