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

feat: add SiteURIFactory #7256

Merged
merged 11 commits into from
Jul 25, 2023
Merged

feat: add SiteURIFactory #7256

merged 11 commits into from
Jul 25, 2023

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Feb 15, 2023

Needs #7252

Description
Supersedes #7239

Add SiteURIFactory to create the current URI object.

To create the current URI object before the Request object creation.
Also, to remove all URI adjustment processing currently performed in the constructor of the Request object.

This PR does not change any existing features yet. The next #7282 changes the behavior.

  • add SiteURIFactory::createFromGlobals()
  • add Superglobals

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis added enhancement PRs that improve existing functionalities 4.4 labels Feb 15, 2023
@kenjis kenjis mentioned this pull request Feb 15, 2023
5 tasks
@kenjis kenjis force-pushed the feat-SiteURIFactory branch 2 times, most recently from 77d43a8 to e1d9a9c Compare February 17, 2023 01:21
@kenjis kenjis marked this pull request as draft February 17, 2023 04:18
@kenjis kenjis force-pushed the feat-SiteURIFactory branch 6 times, most recently from 157d9cb to d68e8ac Compare February 20, 2023 07:48
@kenjis kenjis mentioned this pull request Feb 20, 2023
5 tasks
@kenjis kenjis force-pushed the feat-SiteURIFactory branch 7 times, most recently from b629857 to b5308b0 Compare February 26, 2023 06:51
Comment on lines 177 to 185
private function updateServer(string $key, string $value): void
{
$_SERVER[$key] = $value;
}

private function updateGetArray(array $array): void
{
$_GET = $array;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These make me pretty uneasy. What about an external service dependency that handles Globals, so it can be mocked or replaced? This behavior within a Factory is very counterintuitive.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean?
Adding another class that handles globals?

    private $superglobals;

    private function updateServer(string $key, string $value): void
    {
        $this->superglobals->setServer($key, $value);
    }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, precisely. It could be adapted to anywhere else in the framework we touch globals.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added class Superglobals.

@kenjis kenjis force-pushed the feat-SiteURIFactory branch 2 times, most recently from 239b2cc to 61beca5 Compare July 12, 2023 01:15

// Strip the SCRIPT_NAME path from the URI
if (
$path !== '' && isset($this->superglobals->server('SCRIPT_NAME')[0])
Copy link
Member Author

@kenjis kenjis Jul 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isset($this->superglobals->server('SCRIPT_NAME')[0])
What is this condition checked?
$_SERVER['SCRIPT_NAME'] is a string.

The condition comes from:

// Strip the SCRIPT_NAME path from the URI
if (
$uri !== '' && isset($_SERVER['SCRIPT_NAME'][0])
&& pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_EXTENSION) === 'php'
) {

And it came from:
bcit-ci/CodeIgniter@ead327f7

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that end up being translated as this, because of string array access?

$_SERVER['SCRIPT_NAME'] !== ''

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I assume this is unintended but that's the equivalence.

https://3v4l.org/XC3NO
https://3v4l.org/hqebU

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored. fde3216

@kenjis kenjis marked this pull request as ready for review July 12, 2023 01:38
system/HTTP/SiteURIFactory.php Outdated Show resolved Hide resolved
system/Superglobals.php Show resolved Hide resolved
system/HTTP/SiteURIFactory.php Outdated Show resolved Hide resolved
@kenjis kenjis merged commit 988906c into codeigniter4:4.4 Jul 25, 2023
50 checks passed
@kenjis kenjis deleted the feat-SiteURIFactory branch July 25, 2023 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.4 enhancement PRs that improve existing functionalities
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants