-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Runtime] a new component to decouple applications from global state #38465
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
0a47c30
to
e26da8a
Compare
bd97d14
to
c3ce2c9
Compare
PR is rebased and ready. Let me know if you have any further questions. In symfony/recipes#787 (comment), @javiereguiluz asks if this could work: return function (Context $context) {
$kernel = new Kernel($context->env(), $context->debug());
return new Application($kernel);
}; The answer is yes. It could be nice for a separate PR. |
src/Symfony/Component/Runtime/StartedApp/Symfony/ApplicationStarted.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Runtime/StartedApp/Symfony/ApplicationStarted.php
Outdated
Show resolved
Hide resolved
78f178f
to
21fd256
Compare
@fabpot thanks for the review, comments addressed. |
21fd256
to
97780e8
Compare
2d7b9f4
to
768c50b
Compare
768c50b
to
760d089
Compare
f2d8ffd
to
9338d22
Compare
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've made my review live with @nicolas-grekas, mainly cosmetic changes + a few bugs.
I think it's ready now.
I will do a final review tonight. If someone really want to merge this before then, I'll follow up with PRs instead of comments (if any). |
As this is a significant change in the front controllers, I would kindly, but strongly, ask to consider to first prepare updates for the documentation (and maybe SymfonyCasts) before merging this PR 🙏 |
@nicolas-grekas is going to create a doc PR ASAP, I think/hope that the diff will be very minimal 🤞. |
4283e08
to
b402d7d
Compare
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.
Here are some smaller comments.
I'll start testing this now.
d448522
to
35459d8
Compare
Thank you Nicolas for the updates. I've been carefully reviewing and testing this while writing some docs. See symfony/symfony-docs#15081 |
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.
Im happy with this PR.
Thank you
Thank you @nicolas-grekas. |
This PR was merged into the 5.3-dev branch. Discussion ---------- [Runtime] Init Runtime component This is documentation for symfony/symfony#38465 The docs is focus on "how to use" instead of "how it works". I will add a "creating your own Runtime" which will include "how it works". As you may notice. I use two concepts: "the callback" and "the application". The fact that "the application" can be a callback and will be wrapped in callbacks is irrelevant here. I found it much easier to understand this way. Commits ------- ef5f04b Apply suggestions from code review 76de973 [symfony#15081] Finish the new Runtime docs e7bacf1 Apply suggestions from code review 06414b7 Apply suggestions from code review 7388cc9 Init Runtime docs
Follow up of #36652, see discussion there.
What if we could decouple the bootstrapping logic of our apps from any global state?
This PR makes it possible via a new proposed
symfony/runtime
component.The immediate benefit this provides is easier maintenance of Symfony apps: code that is currently shipped by recipes will be able to move to
vendor/
. Read the previous sentence twice, this is big :)Check the following PR to see how far this goes: symfony/recipes#787
The longer-term benefit is being able to run the exact same app under several runtimes: PHP-FPM, CLI, but also PHP-PM and similar. Thanks to the proposed interface, this benefit could span to any PHP apps; not only to apps using the Symfony HttpKernel/HttpFoundation components. This part could be moved to
symfony/contracts
in the future.Performance-wise, I measured no significant difference with the current way of running apps.
RuntimeInterface
The core of this component is the
RuntimeInterface
which describes a high-orderruntime logic.
It is designed to be totally generic and able to run any application outside of
the global state in 6 steps:
RuntimeInterface::getResolver()
, which returns aResolverInterface
; this resolver returns an array with the (potentiallydecorated) callable at index 0, and all its resolved arguments at index 1;
represents the application;
RuntimeInterface::getRunner()
, which returns aRunnerInterface
: an instance that knows how to "run" the object;run()
and returns the exit status code asint
;This process is extremely flexible as it allows implementations of
RuntimeInterface
to hook into any critical steps.Autoloading
This package registers itself as a Composer plugin to generate a
vendor/autoload_runtime.php
file. This file shall be required instead of theusual
vendor/autoload.php
in front-controllers that leverage this componentand return a callable.
Before requiring the
vendor/autoload_runtime.php
file, set the$_SERVER['APP_RUNTIME']
variable to a class that implementsRuntimeInterface
and that should be used to run the returned callable.
Alternatively, the class of the runtime can be defined in the
extra.runtime.class
entry of the
composer.json
file.A
SymfonyRuntime
is used by default. It knows the conventions to runSymfony and native PHP applications.
Examples
This
public/index.php
is a "Hello World" that handles a "name" query parameter:This
bin/console.php
is a single-command "Hello World" application(run
composer require symfony/console
before launching it):The
SymfonyRuntime
can resolve and handle many types related to thesymfony/http-foundation
andsymfony/console
components.Check its source code for more information.