-
Notifications
You must be signed in to change notification settings - Fork 824
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
RFC: App object to encapsulate global state and services #6681
Comments
Required for making manifest caches configurable through PSR-16: #6647 |
I have written up a new RFC covering the full interface for App and DefautAppFactory Please see https://gist.github.com/tractorcow/c0656a334c13eac8ae252610d226a1c6 |
Don't have time to delve too deeply right now, but a few years back AJShort did some extensive work down this line. There's a full commit list still at https://github.com/ajshort/sapphire/commits/composer , with relevant code mostly in https://github.com/ajshort/sapphire/tree/composer/src/SilverStripe/Framework |
I don't really get the whole This leads on to my next question...
|
Nesting is important to ensure that state is retained at the point of nesting. This means that nesting at the application level includes not only nesting of the various direct dependencies, but also the current state of each dependent nested chains. E.g.
|
If you never called unnest, then how could you return to the original state? You would end up with a different config in your local variable clone vs App::inst()->getConfig(). |
Well, simply App::inst() is a getter, and the constructor is only used when creating the initial app. The end goal is to consolidate global state into an object. |
Yes. |
@nyeholt main class found at https://github.com/ajshort/sapphire/blob/composer/src/SilverStripe/Framework/Core/Application.php It does look VERY similar doesn't it? :) |
Also just to add, I dislike injecting everything with an |
If the use-case is for testing, then the variable (nested app) would only exist for the length of the test so would be destroyed and forgot about automatically. You would never actually nest. eg.
This wouldn't work if you called |
I see your point. If we did use an app property on every object, but that's very risk prone, given that it only takes a single object to have a mis-assigned app var for it to be running in an incorrect state. This could easily come around when pre-existing objects are created at the point the application is nested; It'll only affect future objects, and we have no way to guarantee they won't interact with the prior ones. This is why I'm against per-object app assignment. |
What are we testing that would require the entire app to be cloned/nested anyway? Sounds like a pretty big coupling problem we have :p |
FunctionalTest doesn't use process isolation. |
I feel like we need to be looking at https://github.com/symfony/http-kernel for a lot of inspiration here - perhaps even looking to use it - though that may be impossible because it can't accept our DI and so on. But initially from looking at the proposals it's not clear to me how a request is handled. I feel we should be aiming for a startup script with bare bones like this: <?php
$request = HTTPRequest::createFromGlobals();
$response = HTTPResponse::create();
$app = new SilverStripe();
$app->handleRequest($request, $response);
$response->output(); At the moment it's not clear to me how this app object would be used? Or is it really just a holder of state and we are shifting our current global state onto the app object but still leaving a lot of the boot up as is? |
This is generally my feeling; It's a refactor not a radical behavioural change. |
The 3 pieces that aren't easily refactored are, module manifest -> config -> injector. The app object can provide these. I don't think that the app object should provide |
On nest() / unnest(): There's no longer a case where you need to run tests and have the parent global app object — we deleted the dev/tests/ URL. So you could probably build tests using The areas where it would be more likely to be of use would be things like staticpublisher where you want to craft an altered global state for a portion of execution. This is kind of an advanced case and could be handled as an API addition beyond the initial implementation, if needs be. I don't think we would need For example, rather than nest / unnest we might have something closer |
We could drop App::nest() and continue to use individual Injector::nest() / Config::nest() as-is for now. Would that be a fair compromise to get v1 of app done? |
No, I think that's worse than creating |
Note that cookie reading is part of PSR-7, but writing isn't (only indirectly via https://laravel.com/docs/5.4/responses#attaching-cookies-to-responses
|
Do we have to fix cookies (and everything else related to the controller stack) as part of this ticket? It feels like it's turning into a cascade of "fix everything annoying" ;-) If I were to refactor cookie, I'd probably have a middleware that
However that's well beyond the scope of this card |
I've had a discussion with @chillu and decided to update the scope of the request / response refactor. https://gist.github.com/tractorcow/2bb76d12074b885b9b2923dafa07ae88 Cookies API remains unchanged, but we will move Session::inst() into $request->getSession(). |
Old ACs:
New ACs:
|
Nice +1 thanks @chillu |
Just so that everyone here is clear, we are going to close and accept this RFC pretty early next week. Please get in your concerns early if you have anything you would like to add. |
Hello, the discussion seems to have tailed off, and given our general agreement on approach we will close this discussion and move onto implementation. |
todo : update A/C and task. |
I've just updated the tasks for this story. Quite a lot of progress made so far!
|
I've added WIP branches to the initial story body. New progress:
|
See #7037 and #6681 Squashed commit of the following: commit 8f65e56 Author: Ingo Schommer <[email protected]> Date: Thu Jun 22 22:25:50 2017 +1200 Fixed upgrade guide spelling commit 76f9594 Author: Damian Mooyman <[email protected]> Date: Thu Jun 22 16:38:34 2017 +1200 BUG Fix non-test class manifest including sapphiretest / functionaltest commit 9379834 Author: Damian Mooyman <[email protected]> Date: Thu Jun 22 15:50:47 2017 +1200 BUG Fix nesting bug in Kernel commit 188ce35 Author: Damian Mooyman <[email protected]> Date: Thu Jun 22 15:14:51 2017 +1200 BUG fix db bootstrapping issues commit 7ed4660 Author: Damian Mooyman <[email protected]> Date: Thu Jun 22 14:49:07 2017 +1200 BUG Fix issue in DetailedErrorFormatter commit 738f50c Author: Damian Mooyman <[email protected]> Date: Thu Jun 22 11:49:19 2017 +1200 Upgrading notes on mysite/_config.php commit 6279d28 Author: Damian Mooyman <[email protected]> Date: Thu Jun 22 11:43:28 2017 +1200 Update developer documentation commit 5c90d53 Author: Damian Mooyman <[email protected]> Date: Thu Jun 22 10:48:44 2017 +1200 Update installer to not use global databaseConfig commit f9b2ba4 Author: Damian Mooyman <[email protected]> Date: Wed Jun 21 21:04:39 2017 +1200 Fix behat issues commit 5b59a91 Author: Damian Mooyman <[email protected]> Date: Wed Jun 21 17:07:11 2017 +1200 Move HTTPApplication to SilverStripe\Control namespace commit e2c4a18 Author: Damian Mooyman <[email protected]> Date: Wed Jun 21 16:29:03 2017 +1200 More documentation Fix up remaining tests Refactor temp DB into TempDatabase class so it’s available outside of unit tests. commit 5d235e6 Author: Damian Mooyman <[email protected]> Date: Wed Jun 21 12:13:15 2017 +1200 API HTTPRequestBuilder::createFromEnvironment() now cleans up live globals BUG Fix issue with SSViewer Fix Security / View tests commit d88d4ed Author: Damian Mooyman <[email protected]> Date: Tue Jun 20 16:39:43 2017 +1200 API Refactor AppKernel into CoreKernel commit f7946ae Author: Damian Mooyman <[email protected]> Date: Tue Jun 20 16:00:40 2017 +1200 Docs and minor cleanup commit 12bd31f Author: Damian Mooyman <[email protected]> Date: Tue Jun 20 15:34:34 2017 +1200 API Remove OutputMiddleware API Move environment / global / ini management into Environment class API Move getTempFolder into TempFolder class API Implement HTTPRequestBuilder / CLIRequestBuilder BUG Restore SS_ALLOWED_HOSTS check in original location API CoreKernel now requires $basePath to be passed in API Refactor installer.php to use application to bootstrap API move memstring conversion globals to Convert BUG Fix error in CoreKernel nesting not un-nesting itself properly. commit bba9791 Author: Damian Mooyman <[email protected]> Date: Mon Jun 19 18:07:53 2017 +1200 API Create HTTPMiddleware and standardise middleware for request handling commit 2a10c23 Author: Damian Mooyman <[email protected]> Date: Mon Jun 19 17:42:42 2017 +1200 Fixed ORM tests commit d75a8d1 Author: Damian Mooyman <[email protected]> Date: Mon Jun 19 17:15:07 2017 +1200 FIx i18n tests commit 06364af Author: Damian Mooyman <[email protected]> Date: Mon Jun 19 16:59:34 2017 +1200 Fix controller namespace Move states to sub namespace commit 2a278e2 Author: Damian Mooyman <[email protected]> Date: Mon Jun 19 12:49:45 2017 +1200 Fix forms namespace commit b65c212 Author: Damian Mooyman <[email protected]> Date: Thu Jun 15 18:56:48 2017 +1200 Update API usages commit d1d4375 Author: Damian Mooyman <[email protected]> Date: Thu Jun 15 18:41:44 2017 +1200 API Refactor $flush into HTPPApplication API Enforce health check in Controller::pushCurrent() API Better global backup / restore Updated Director::test() to use new API commit b220534 Author: Damian Mooyman <[email protected]> Date: Tue Jun 13 22:05:57 2017 +1200 Move app nesting to a test state helper commit 6037041 Author: Damian Mooyman <[email protected]> Date: Tue Jun 13 21:46:04 2017 +1200 Restore kernel stack to fix multi-level nesting commit 2f6336a Author: Damian Mooyman <[email protected]> Date: Tue Jun 13 17:23:21 2017 +1200 API Implement kernel nesting commit fc7188d Author: Damian Mooyman <[email protected]> Date: Tue Jun 13 15:43:13 2017 +1200 Fix core tests commit a0ae723 Author: Damian Mooyman <[email protected]> Date: Tue Jun 13 15:23:52 2017 +1200 Fix manifest tests commit ca03395 Author: Damian Mooyman <[email protected]> Date: Tue Jun 13 15:00:00 2017 +1200 API Move extension management into test state commit c66d433 Author: Damian Mooyman <[email protected]> Date: Tue Jun 13 14:10:59 2017 +1200 API Refactor SapphireTest state management into SapphireTestState API Remove Injector::unregisterAllObjects() API Remove FakeController commit f26ae75 Author: Damian Mooyman <[email protected]> Date: Mon Jun 12 18:04:34 2017 +1200 Implement basic CLI application object commit 001d559 Author: Damian Mooyman <[email protected]> Date: Mon Jun 12 17:39:38 2017 +1200 Remove references to SapphireTest::is_running_test() Upgrade various code commit de079c0 Author: Damian Mooyman <[email protected]> Date: Wed Jun 7 18:07:33 2017 +1200 API Implement APP object API Refactor of Session
🎉🎉🎉 |
See silverstripe#7037 and silverstripe#6681 Squashed commit of the following: commit 8f65e56 Author: Ingo Schommer <[email protected]> Date: Thu Jun 22 22:25:50 2017 +1200 Fixed upgrade guide spelling commit 76f9594 Author: Damian Mooyman <[email protected]> Date: Thu Jun 22 16:38:34 2017 +1200 BUG Fix non-test class manifest including sapphiretest / functionaltest commit 9379834 Author: Damian Mooyman <[email protected]> Date: Thu Jun 22 15:50:47 2017 +1200 BUG Fix nesting bug in Kernel commit 188ce35 Author: Damian Mooyman <[email protected]> Date: Thu Jun 22 15:14:51 2017 +1200 BUG fix db bootstrapping issues commit 7ed4660 Author: Damian Mooyman <[email protected]> Date: Thu Jun 22 14:49:07 2017 +1200 BUG Fix issue in DetailedErrorFormatter commit 738f50c Author: Damian Mooyman <[email protected]> Date: Thu Jun 22 11:49:19 2017 +1200 Upgrading notes on mysite/_config.php commit 6279d28 Author: Damian Mooyman <[email protected]> Date: Thu Jun 22 11:43:28 2017 +1200 Update developer documentation commit 5c90d53 Author: Damian Mooyman <[email protected]> Date: Thu Jun 22 10:48:44 2017 +1200 Update installer to not use global databaseConfig commit f9b2ba4 Author: Damian Mooyman <[email protected]> Date: Wed Jun 21 21:04:39 2017 +1200 Fix behat issues commit 5b59a91 Author: Damian Mooyman <[email protected]> Date: Wed Jun 21 17:07:11 2017 +1200 Move HTTPApplication to SilverStripe\Control namespace commit e2c4a18 Author: Damian Mooyman <[email protected]> Date: Wed Jun 21 16:29:03 2017 +1200 More documentation Fix up remaining tests Refactor temp DB into TempDatabase class so it’s available outside of unit tests. commit 5d235e6 Author: Damian Mooyman <[email protected]> Date: Wed Jun 21 12:13:15 2017 +1200 API HTTPRequestBuilder::createFromEnvironment() now cleans up live globals BUG Fix issue with SSViewer Fix Security / View tests commit d88d4ed Author: Damian Mooyman <[email protected]> Date: Tue Jun 20 16:39:43 2017 +1200 API Refactor AppKernel into CoreKernel commit f7946ae Author: Damian Mooyman <[email protected]> Date: Tue Jun 20 16:00:40 2017 +1200 Docs and minor cleanup commit 12bd31f Author: Damian Mooyman <[email protected]> Date: Tue Jun 20 15:34:34 2017 +1200 API Remove OutputMiddleware API Move environment / global / ini management into Environment class API Move getTempFolder into TempFolder class API Implement HTTPRequestBuilder / CLIRequestBuilder BUG Restore SS_ALLOWED_HOSTS check in original location API CoreKernel now requires $basePath to be passed in API Refactor installer.php to use application to bootstrap API move memstring conversion globals to Convert BUG Fix error in CoreKernel nesting not un-nesting itself properly. commit bba9791 Author: Damian Mooyman <[email protected]> Date: Mon Jun 19 18:07:53 2017 +1200 API Create HTTPMiddleware and standardise middleware for request handling commit 2a10c23 Author: Damian Mooyman <[email protected]> Date: Mon Jun 19 17:42:42 2017 +1200 Fixed ORM tests commit d75a8d1 Author: Damian Mooyman <[email protected]> Date: Mon Jun 19 17:15:07 2017 +1200 FIx i18n tests commit 06364af Author: Damian Mooyman <[email protected]> Date: Mon Jun 19 16:59:34 2017 +1200 Fix controller namespace Move states to sub namespace commit 2a278e2 Author: Damian Mooyman <[email protected]> Date: Mon Jun 19 12:49:45 2017 +1200 Fix forms namespace commit b65c212 Author: Damian Mooyman <[email protected]> Date: Thu Jun 15 18:56:48 2017 +1200 Update API usages commit d1d4375 Author: Damian Mooyman <[email protected]> Date: Thu Jun 15 18:41:44 2017 +1200 API Refactor $flush into HTPPApplication API Enforce health check in Controller::pushCurrent() API Better global backup / restore Updated Director::test() to use new API commit b220534 Author: Damian Mooyman <[email protected]> Date: Tue Jun 13 22:05:57 2017 +1200 Move app nesting to a test state helper commit 6037041 Author: Damian Mooyman <[email protected]> Date: Tue Jun 13 21:46:04 2017 +1200 Restore kernel stack to fix multi-level nesting commit 2f6336a Author: Damian Mooyman <[email protected]> Date: Tue Jun 13 17:23:21 2017 +1200 API Implement kernel nesting commit fc7188d Author: Damian Mooyman <[email protected]> Date: Tue Jun 13 15:43:13 2017 +1200 Fix core tests commit a0ae723 Author: Damian Mooyman <[email protected]> Date: Tue Jun 13 15:23:52 2017 +1200 Fix manifest tests commit ca03395 Author: Damian Mooyman <[email protected]> Date: Tue Jun 13 15:00:00 2017 +1200 API Move extension management into test state commit c66d433 Author: Damian Mooyman <[email protected]> Date: Tue Jun 13 14:10:59 2017 +1200 API Refactor SapphireTest state management into SapphireTestState API Remove Injector::unregisterAllObjects() API Remove FakeController commit f26ae75 Author: Damian Mooyman <[email protected]> Date: Mon Jun 12 18:04:34 2017 +1200 Implement basic CLI application object commit 001d559 Author: Damian Mooyman <[email protected]> Date: Mon Jun 12 17:39:38 2017 +1200 Remove references to SapphireTest::is_running_test() Upgrade various code commit de079c0 Author: Damian Mooyman <[email protected]> Date: Wed Jun 7 18:07:33 2017 +1200 API Implement APP object API Refactor of Session
Acceptance Criteria
Excludes
Notes
$this->app->get('my-dependency')
)RFC Versions
https://gist.github.com/tractorcow/8be54d6b019412c037049c8caddf39eb
Related
Tasks
WIP branches
The text was updated successfully, but these errors were encountered: