-
-
Notifications
You must be signed in to change notification settings - Fork 331
feat: add integration with Mezzio #675
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
Conversation
|
I'm not the maintainer, so just a few non-normative comments:
That said, cool contribution! I personally don't use Mezzio, but open source lives from participation! |
|
Thank you for your fast response. |
|
I solve the |
|
Do you know if the project is using the PSR-12 as formatter? |
|
I tested also the the routing for |
|
Clockwork seems to use tabs to indent the code. If your IDE autoformatted the files with four-space indent (which is the default per PSR, I believe), then it breaks the formatting here. |
…uration file because Mezzio current work dir is the root project
…nject Clockwork instance in request to add new logging capabilities
|
Hey, thanks for working on this. Would you be interested in releasing this integration on your own as a separate package, with me linking it in the official Clockwork readme/website? Could you please fix the indentation to use tabs? Otherwise the diffs are impossible to read. Also, what is the meaningful difference between using |
|
Yes, I can create a separate package. The difference between |
|
https://stackoverflow.com/questions/8798294/getenv-vs-env-in-php has some info on that... |
|
https://stackoverflow.com/questions/3780866/why-is-my-env-empty may be even better. With that in mind, I'd vote for using |
|
It would be preferrable to integrate this PR and avoid to create a separate package as it would be additional installation which would make this project interesting for those who use microframework Mezzio which is a project of Laminas |
|
To make the integration with clockwork more interesting, may I add that I have the intention of requesting an amendment to Mezzio's documentation |
| // Public URI where the installed Web UI assets will be accessible | ||
| 'uri' => getenv('CLOCKWORK_WEB_URI') !== false ? getenv('CLOCKWORK_WEB_URI') : '/vendor/clockwork', | ||
|
|
||
| // host where web clockwork is accessible, used when a server side request return the html |
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.
I believe this is what CLOCKWORK_WEB_URI is supposed to be.
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.
As explained by the documentation to serve the WEB UI you need to specify this routing:
$router->get('/clockwork', function ($request) {
$clockwork = Clockwork\Support\Vanilla\Clockwork::init([
'web' => [
'enable' => true,
'path' => DIR . '/public/vendor/clockwork',
'uri' => '/vendor/clockwork'
]
]);
return $clockwork->usePsrMessage($request, new Response)->returnWeb();
}};In this case /clockwork represents the url path to the server-side request and it's different from the web uri parameter. Did I miss something? I created a new variable web host to be able to configure the server-side request url path.
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.
The Web UI in the Vanilla integration works in a bit of a funny way. It actually copies the Web UI implementation to a public directory, so the assets are served directly by the web server, this is by default public/vendor/clockwork. The code handling the main web UI route, typically /clockwork, then returns a special full-screen iframe that embeds the Web UI located at /vendor/clockwork with some special configuration to make it work.
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.
This is something that is not really clear and I believe that the different integrations differ a bit, too. Just for reference, here are the two settings I found:
// Path where to install the Web UI assets, should be publicly accessible
'path' => isset($_ENV['CLOCKWORK_WEB_PATH']) ? $_ENV['CLOCKWORK_WEB_PATH'] : __DIR__ . '/../../../../../public/vendor/clockwork',
// Public URI where the installed Web UI assets will be accessible
'uri' => isset($_ENV['CLOCKWORK_WEB_URI']) ? $_ENV['CLOCKWORK_WEB_URI'] : '/vendor/clockwork'Note that both are commented with the words "accessible" and "public" and both contain a path, which is a bit confusing.
Anyhow, just out of interest, why does the web UI copy the files between paths? I've use the Web class' assets and served them from where they are for my PSR-based middleware implementation.
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.
The Web UI in the Vanilla integration works in a bit of a funny way. It actually copies the Web UI implementation to a public directory, so the assets are served directly by the web server, this is by default
public/vendor/clockwork. The code handling the main web UI route, typically/clockwork, then returns a special full-screen iframe that embeds the Web UI located at/vendor/clockworkwith some special configuration to make it work.
This is exactly how I understood when using it. I only added a new env vars CLOCKWORK_WEB_HOST to configure the /clockwork url but if you think it's useless I can hadcode the url in the middleware and remove it.
|
Just wondering, does Mezzio come with a PSR-17 response factory, included or as dependency? Point is, using PSR-7, PSR-15 and PSR-17 as base, I think I could build a middleware that can be integrated into pretty much any framework that uses those HTTP PSRs, including Slim (which is my concern) and Mezzio. |
|
When you install Mezzio from the skeleton provided the dependency laminas-diactoros is installed which implement PSR-7 and PSR-17. |
|
Right now my middleware use the |
|
@UlrichEckhardt I was actually thinking the other day, why do we still need a custom Slim integration, when the Vanilla integration is superior and more full-featured. I think it would be a really good idea to add a generic PSR-compatible middleware to the Vanilla integration as you suggest. @DominicDetta I think I would put this on hold and explore the route of adding a generic middleware to support all these PSR-compatible micro-frameworks first. Also, I'm okay with changing the Vanilla config file to use |
|
https://github.com/UlrichEckhardt/clockwork-slim-demo/tree/feature/psr-17-middleware -- Slim doesn't need a custom integration, it provides implementations for the PSR-{7,15,17} interfaces, so it could use any middleware built on top of that. I've realized that in the above demo project, which should be seen as a proof of concept. There's still a few things to do:
|
One reason is that `putenv()` won't update `$_ENV`, which breaks code using that to set the environment. For further reference, see - itsgoingd#675 - https://stackoverflow.com/questions/3780866/why-is-my-env-empty Thanks to original author DominicDetta <[email protected]>!
Ok, that sounds right. |
|
I just added #680, including two demo projects for both Slim and Mezzio. This is still in draft form, in particular there are still a few places marked |
|
This PR will be replaced by #680 |
One reason is that `putenv()` won't update `$_ENV`, which breaks code that uses `$_ENV` to read the environment. For further reference, see - itsgoingd#675 - https://stackoverflow.com/questions/3780866/why-is-my-env-empty Thanks to original author DominicDetta <[email protected]>!
This pull request allow to use Clockwork in Mezzio application.