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

Server URL Helper Cleanup #160

Closed
wants to merge 4 commits into from

Conversation

gsteel
Copy link
Member

@gsteel gsteel commented Mar 24, 2022

Description

Deprecates all methods in the server url helper and introduces a factory to provide the helper with the detected or configured host URI.

Brings in a hard dependency on laminas-diactoros in order to re-use the functions for detecting the host/port from the environment that are already present there.

Doesn't break BC according to tests, and also doesn't alter existing behaviour for long-running apps because the previous implementation caches the host/port in instance properties anyway.

The main improvement here is that consumers can configure the desired host and port without any attempt to figure it out from the environment which is particularly useful on the CLI or any other time when the required env vars are either wrong or not there at all.

The introduction of the factory is a potential BC break because an exception is thrown when there is neither configuration, nor usable env vars.

@gsteel
Copy link
Member Author

gsteel commented Mar 24, 2022

Oh… GHA is down again…

@gsteel gsteel closed this Mar 24, 2022
@Ocramius Ocramius reopened this Mar 27, 2022
@Ocramius Ocramius added this to the 2.21.0 milestone Mar 27, 2022
@gsteel gsteel mentioned this pull request Mar 27, 2022
@Ocramius
Copy link
Member

Ocramius commented Apr 5, 2022

@gsteel I re-opened this: was it closed on purpose?

@gsteel
Copy link
Member Author

gsteel commented Apr 5, 2022

@Ocramius - GHA confused me by being down and I had a duplicate pull - I left this one open and closed the other one.

@Ocramius
Copy link
Member

@gsteel if you can rebase this, I can throw it into 2.21.0

gsteel added 2 commits July 10, 2022 16:38
- Deprecate all methods and properties in the server url helper
- Introduce constructor to provide the helper with a configured url
- Deprecate existing tests to make them easy to remove in future

Signed-off-by: George Steel <[email protected]>
Adds laminas-diactoros as a dependency so that detection of the host URI can be delegated to existing code

Signed-off-by: George Steel <[email protected]>
composer.json Outdated Show resolved Hide resolved
@Ocramius
Copy link
Member

Nvm, needs some work, removing milestone for now, and releasing.

@Ocramius Ocramius removed this from the 2.21.0 milestone Jul 10, 2022
@gsteel gsteel force-pushed the helpers-server-url-cleanup branch from 0106980 to 3bd7f84 Compare July 10, 2022 15:46
@Ocramius Ocramius changed the base branch from 2.21.x to 2.22.x July 10, 2022 15:52
@Ocramius Ocramius added this to the 2.22.0 milestone Jul 10, 2022
…ng the deprecated method marshalUriFromSapi

Signed-off-by: George Steel <[email protected]>
@@ -30,6 +30,7 @@
"ext-filter": "*",
"ext-json": "*",
"container-interop/container-interop": "^1.2",
"laminas/laminas-diactoros": "^2.13.0",
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should drag in a dependency for this 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm with you there, but I considered it better than attempting to parse $_SERVER inside this particular view helper.

Perhaps just abandon the patch and remove the helper instead - i.e. make sure that both MVC and Mezzio have their own implementations to replace it prior to a release of 3.0.

There are probably other helpers that could do with the same treatment - thinking url and perhaps baseUrl at the very least.

Copy link
Member

Choose a reason for hiding this comment

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

Overall, I think this does bring value, and is implemented the right/safe way, but it also leads to the added dependency, which is a lot 🤔

Not sure what to do here. /cc @weierophinney maybe?

Copy link
Member

Choose a reason for hiding this comment

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

I would likely copy over that functionality here and refactor to work with laminas-http. Since Diactoros is a PSR-7 library, there's a mismatch with the primary target of laminas-view (laminas-mvc). There's a reason we provide alternate url() and serverUrl() helpers in the mezzio-template-laminasview package...

Copy link
Member Author

Choose a reason for hiding this comment

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

Can we/I create an entirely new library to contain everything that's MVC specific so that it can be stripped out in 3.0 - this could include all the supporting code around MVC events. If that's an agreeable path, I could just abandon this patch and deprecate the helper here entirely instead?

Copy link
Member

Choose a reason for hiding this comment

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

I think that would be perfect, @gsteel!

Copy link
Member

Choose a reason for hiding this comment

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

And we have to make sure that there is also a solution to create URLs with the same helpers when using laminas-cli. The server URL and the base path must be able to set via configuration, factory or something else.

Copy link
Member

Choose a reason for hiding this comment

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

@froschdesign I'd argue that should be via separate helpers. Not quite sure how to manage it (right now, CLI config is the same as web config), but having separate helpers for separate contexts makes a lot of sense here to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

@weierophinney

I've made a start on this with just the ServerUrl and Url helpers specifically for MVC:

laminas/laminas-mvc-view#1

If this is a good enough starting point, is transferring the repo ownership an option?

Copy link
Member

Choose a reason for hiding this comment

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

Yes - we usually vote on any new packages in the TSC; this sort of thing can happen between meetings, though. Feel free to initiate; contact me in Slack for tips on how to do it.

Looking forward to further decoupling!

@gsteel
Copy link
Member Author

gsteel commented Oct 11, 2022

Closing… With laminas/laminas-mvc-view#1 in progress, I suspect we'll simply delete the Url and ServerUrl helpers here in 3.0 release.

@gsteel gsteel closed this Oct 11, 2022
@gsteel gsteel deleted the helpers-server-url-cleanup branch October 11, 2022 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Won't Fix This will not be worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants