-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
URL Class #4647
URL Class #4647
Conversation
Haven't looked at the code yet but my initial thought is - this is making the framework more complex and confusing than it needs to be. Can we just start prepping for a bigger release and fix this in the existing URI class? Have two classes so closely related to each other are going to be super confusing for any devs that dig into the inner workings. Or just to those who's IDE starts to suggest both classes for them. Additionally - isn't the purpose of |
We really need both. It doesn't need to be implemented this way, but we need to be able to do two things:
Currently this is a real problem: CodeIgniter4/system/HTTP/URI.php Lines 566 to 584 in 4cc1452
I've tried to mitigate it in #4646 but this "bleeds" point 2 into point 1. Currently we handle "project-specific" URIs with the URL Helper functions ( I originally had |
Exactly. |
*/ | ||
public static function base() | ||
{ | ||
return static::public(''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the class is final
, then inheritance is no more possible. So, there's no need to use the static
keyword. Instead use self
.
return static::public(''); | |
return self::public(''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the topic, how do you think the class should be scoped? Originally I had a normal class with final
static and constructor methods (hence the leftover static
references here) but I decided that nobody would go through the hassle of extending for the few allowed methods so made the whole thing final
.
$config = clone config('App'); | ||
$config->indexPage = ''; | ||
|
||
return new static($uri, $config); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return new static($uri, $config); | |
return new self($uri, $config); |
$config = clone config('App'); | ||
$config->indexPage = ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$config = clone config('App'); | |
$config->indexPage = ''; | |
$config = clone config('App'); | |
$config->indexPage = ''; |
return self::$current; | ||
} | ||
|
||
return static::fromRequest(Services::request()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return static::fromRequest(Services::request()); | |
return self::fromRequest(Services::request()); |
*/ | ||
public static function to(string $uri) | ||
{ | ||
return new static(rtrim($uri, '/ ')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return new static(rtrim($uri, '/ ')); | |
return new self(rtrim($uri, '/ ')); |
* | ||
* @param string $uri Additional URI string to include | ||
* | ||
* @return static |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @return static | |
* @return self |
/** | ||
* Returns an instance representing the current URL. | ||
* | ||
* @return static |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @return static | |
* @return self |
* | ||
* @param string $uri | ||
* | ||
* @return static |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @return static | |
* @return self |
* | ||
* @param string $uri Named or reverse route | ||
* | ||
* @return static |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @return static | |
* @return self |
* | ||
* @param IncomingRequest $request | ||
* | ||
* @return static |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @return static | |
* @return self |
I'll be honest. I'm not a fan of having both. I understand your reasoning but think it will make things more complex/confusing for the developers. I wish we could find a way to refactor the current class to work in conjunction with the url helpers. That being said, if the rest of the team is fine with it then I'll shut up :) |
@lonnieezell I understand. Let's think of ways we could make this better. I do think the helpers could be "beefed" up to cover this class but we would lose the ability to distinguish path parts (see my comment about "what is project" versus "what is path"). That might be an acceptable tradeoff? But there are some real issues with the current setup that need addressing. Just an example, CodeIgniter4/system/HTTP/IncomingRequest.php Lines 153 to 160 in 2e0e020
... but then this is the entirety of
I believe that a support class (in this case |
Description
"Stage Three", this PR introduces a companion class to
URI
:URL
. TheURL
class handles internal URIs (i.e. specific to the project) in the following manner:URL
is always constructed with a relative pathURL
will always use the App config values from its construction (baseURL
,indexPage
,forceGlobalSecureRequest
)URL
is immutable, not affected by changes to$_SERVER
or services once it has been createdI would like
URL
to become the definitive source for internal URLs within the framework (e.g. replace the logic inbase_url()
andcurrent_url()
, be used byRedirectResponse
, etc) but for now this PR is just introducing the concept and demonstrating the tests. Please be thorough with any reviews, since URLs have been a long pain point (particularly around subfolders).Note: This PR relies on #4644 and #4646.
Checklist: