Comments

donquixote’s picture

This installs and boots just fine for me. Let's see what testbot says.

donquixote’s picture

Note: The above includes #2016629-201: Refactor bootstrap to better utilize the kernel.

same as #1 on github:
https://github.com/donquixote/drupal/compare/D8-2279423-1-low-level-DIC

I am now uploading a patch that only contains the first step, where the basic container architecture is introduced, but not many services.
(but still with #2016629 included)
I want to see what testbot says to this.

The last submitted patch, 2: D8-2279423-2-low-level-DIC.firststep.patch, failed testing.

donquixote’s picture

If anyone wants to argue about the magic __get():
The benefit is to have type hints through the @property docblock.
E.g. $core_services->Request is immediately recognized by the IDE as an object of type \Symfony\Component\HttpFoundation\Request, whereas $core_services->get('request') would only be recognized as a plain object.

One great thing about this low-level container is that we can introduce ways to swap out services or parameters.
E.g. tests can do $core_services->setSitePath(..), and then we no longer need drupal_valid_test_ua().

I think this concept will allow us to get rid of procedural, singletons and globals, and it will allow to split up the DrupalKernel god class radically, but still in nice steps.

donquixote’s picture

The last submitted patch, 2: D8-2279423-2-low-level-DIC.firststep.patch, failed testing.

The last submitted patch, 7: D8-2279423-7-low-level-DIC.format-patch.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 7: D8-2279423-7-low-level-DIC.patch, failed testing.

The last submitted patch, 7: D8-2279423-7-low-level-DIC.firststep.patch, failed testing.

donquixote’s picture

Next step will be to make the CoreServices container flexible for different scenarios:
commandline mode, testing, installation, update, container rebuild.
Maybe with swappable factories.
Or with a configurable "Kernel class" parameter, as long as we are still working with DrupalKernel.

The last submitted patch, 7: D8-2279423-7-low-level-DIC.firststep.format-patch.patch, failed testing.

The last submitted patch, 11: D8-2279423-11-low-level-DIC.format-patch.patch, failed testing.

The last submitted patch, 11: D8-2279423-11-low-level-DIC.firststep.format-patch.patch, failed testing.

donquixote’s picture

Issue summary: View changes
donquixote’s picture

StatusFileSize
new201.19 KB

Some explanation.

Container design:
The container has a magic __get() that will lazy-instantiate a service using a factory method.
E.g. $core_services->Request; will trigger the protected method $core_services->getRequest().
The "Request" property is documented with a @property tag in the class docblock, so your IDE will know the type of $core_services->Request.

List of "core services" in current implementation:
- Request
- ClassLoader
- StaticContext (*)
- BootState (*)
- RawDrupalKernel (**)
- SitePathFinder
- SiteDirectory
- SiteSettings
- SiteDrupalKernel (**)
- BootstrappedDrupalKernel (**)
- LegacyPreparedDrupalKernel (**)
- Container
- CoreRequestHandler (***)

(*) In addition to service objects, there are other things participating in the dependencies game:
- non-object values ("parameters"), which can also be lazy-initialized, unless explicitly set.
- global state. Until we get rid of this, we have "StaticContext" and "BootState" to manage that.

Parameters:
- Environment ('prod', 'testing', etc)
- AllowContainerDumping (true or false)
- SitePath

StaticContext:
- BootstrapIncIncluded: includes bootstrap.inc.
- PhpEnvironmentReady: calls Drupalkernel::bootEnvironment()

BootState:
- SiteSettingsInitialized:
- BootstrapComplete: calls $kernel->boot()
- LegacyRequestPrepared: calls $kernel->handleLegacyRequest()

(**) Kernel versions:
Ultimately I would like to split up the Kernel into smaller pieces.
But for the time being, I simply ship the same Kernel under different service names. So, 4 services that are all the same instance.
- RawDrupalKernel: Just after __construct().
- SiteDrupalKernel: after $kernel->setSitePath().
- BootstrappedDrupalKernel: after $kernel->boot().
- LegacyPreparedDrupalKernel: after $kernel->handleLegacyRequest()

(***) CoreRequestHandler:
Wraps the stuff that happens in index.php, core/modules/system/tests/https.php and core/modules/system/tests/http.php.

Example: ./index.php

try {
  $core_services = CoreServices::create();
  $core_services->CoreRequestHandler->handleRequestAndExit();
}
catch (Exception $e) {
  ...

Status: Needs review » Needs work

The last submitted patch, 18: D8-2279423-18-low-level-DIC.patch, failed testing.

donquixote’s picture

donquixote’s picture

Rethinking some of this.

Container no longer a "core service":
- Generally, no core services should ever be removed or replaced, once initialized.
- Container should not be a core service, because it may need to be replaced during the request.

Core site state services:
- CoreModuleHandler: to enable or disable modules.
- CoreConfiguration: other configuration that can be managed without a container.
- act as "active record" objects.

Container management:
- $core_services->ContainerManager->getContainer();
- Container is never replaced during the lifetime of other higher-level services.

Container rebuild:
- higher-level services (e.g. form submit handlers) can write to CoreModuleHandler and CoreConfiguration (active record)
- higher-level services can NOT call save() on the active record thingies.
- save() is called on active records AFTER the higher-level services (request handling, form handling) are finished.
- if hook_install() stuff needs to be called, an ad-hoc container will be created during save(), with a new instance of all services.

dawehner’s picture

We kinda have that now with the bootstrap container.
There is also https://github.com/php-fig/fig-standards/blob/master/proposed/container.md which describes some ideas about multiple/nested containers.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

markhalliwell’s picture

Status: Needs work » Closed (outdated)

I think maybe this can be closed as outdated?