Compared to Drupal 7, a lot of the codebase in Drupal 8 has been transformed into loosely coupled components, receiving their dependencies from a DIC instead of having to pull them from somewhere.
However, everything that comes before that still has a lot of global state, intransparent interdependencies, and nasty arrays: Installer, bootstrap, settings singleton, multisite, DrupalKernel. This makes it unnecessarily difficult to write unit tests.
The solution, as I see it, is to turn all this low-level stuff into loosely coupled components, and to introduce a CoreContainer that will manage the dependencies of these components. See #2272129: [meta] Introduce a low-level DIC to organize low-level services for an approach from a while ago.
(I am currently working on this locally)
Besides this container, we can also do some preparation steps that do not require the container.
One idea was to turn the $install_state used in drupal_install() into an object.
This issue can act as a parent for the other issues.
Comments
Comment #1
catchKeeping this as 8.0.x for now, looking at some of donquixote's changes it'd make core more testable including some quite fragile and security-sensitive spots.
So if there's nothing disruptive should be still OK for 8.0.x, we can always move to 8.1.x if that turns out not to be the case.
Comment #2
donquixote commentedThis also touches the database:
#2363315: Refactor Database:: static properties and methods
Comment #3
donquixote commentedAs a preparation:
#2363341: Throw exception in Drupal::service() and friends, if container not initialized yet.
Not really sure this is required for the CoreContainer architecture, but it will be nice to have it out of the way.
Comment #4
donquixote commentedCreated an issue for multisite / settings stuff: #2363353: Refactor / split up \Drupal\Core\Site\Settings singleton, and introduce other multisite-related classes.
Maybe we can do some preparation work there, so that the CoreContainer changes become smaller.
Comment #5
donquixote commentedMore about Settings::
#2363881: Settings::__construct() should not write to self::$instance.
Comment #19
smustgrave commentedThank you for creating this issue to improve Drupal.
We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.
Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.
Thanks!
Comment #20
smustgrave commentedWanted to bump 1 more time.
Comment #21
kingdutchI'm working on a blogpost that ties this in to some other things that exist in Drupal Core, so I believe this issue is still relevant. Depending on how we structure the work we may close this as a duplicate of something else, but for now I think it's still a useful overarching issue.
Comment #22
nicxvan commentedComment #23
catchComment #24
kingdutchThe blog post is done and can be found at https://web.archive.org/web/20250908093711/https://www.alexandervarwijk.... (Web Archive Link).
Adding #3313404: Use symfony/runtime for less bespoke bootstrap/compatibility with varied runtime environments as related issue because it provides a path towards doing set-up before the
DrupalKernelis loaded without requiring end-users making constant complex changes to their application entry points.I think it makes sense to keep this issue open.
Comment #25
mondrakeAdding related issue.
+1 to keep this open