Skip to content

Commit

Permalink
refactor code for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
pjsde committed Sep 26, 2023
1 parent 49fd2c1 commit 223d5fe
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
20 changes: 12 additions & 8 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1063,14 +1063,18 @@ public function storePreviousURL($uri)
$uri = new URI($uri);
}

if (isset($_SESSION)) {
session()->set('_ci_previous_url', URI::createURIString(
$uri->getScheme(),
$uri->getAuthority(),
$uri->getPath(),
$uri->getQuery(),
$uri->getFragment()
));
$previousUrl = URI::createURIString(
$uri->getScheme(),
$uri->getAuthority(),
$uri->getPath(),
$uri->getQuery(),
$uri->getFragment()
);

if (ENVIRONMENT === 'testing') {
$_SESSION['_ci_previous_url'] = $previousUrl;
} elseif (session_status() === PHP_SESSION_ACTIVE) {
session()->set('_ci_previous_url', $previousUrl);
}
}

Expand Down
2 changes: 1 addition & 1 deletion system/HTTP/IncomingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ public function getOldInput(string $key)
}

// Get previously saved in session
$old = session('_ci_old_input');
$old = ENVIRONMENT === 'testing' ? $_SESSION['_ci_old_input'] ?? null : session('_ci_old_input');

// If no data was previously saved, we're done.
if ($old === null) {
Expand Down
4 changes: 1 addition & 3 deletions system/Helpers/url_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ function previous_url(bool $returnObject = false)
{
// Grab from the session first, if we have it,
// since it's more reliable and safer.
if (isset($_SESSION)) {
$referer = session('_ci_previous_url');
}
$referer = ENVIRONMENT === 'testing' ? $_SESSION['_ci_previous_url'] ?? null : session('_ci_previous_url');

// Otherwise, grab a sanitized version from $_SERVER.
$referer ??= Services::request()->getServer('HTTP_REFERER', FILTER_SANITIZE_URL);
Expand Down

0 comments on commit 223d5fe

Please sign in to comment.