Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DI][RFC] Container scripts #22365

Closed
Closed
@backbone87

Description

@backbone87
Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? yes

In #21837 there was basically a hack used to add some load time code to the container.

Besides that the service configuration defined in the different config files is heavily altered by extensions/configurators/compiler passes so you need to consult a different sources scattered around various places: Resources/config, *Bundle.php (for compiler passes actually used), *Extension.php (dynamic config), *Pass.php (for container building code) and some more depending on how sophisticated your feature's DI integration is.

The container:debug commands helps only to some degree, to at least get a view of the final result, but still gives no clue about where to look for the configuration of a specific service.

To consolidate these various sources, I propose something like "container-scripts". An example how #21837 could be solved with it:

<container ... >
  <services>
    <service id="annotations.reader" class="Doctrine\Common\Annotations\AnnotationReader" public="false">
      ...
    </service>
  <services>
  <factory-script type="php/closure" depends="annotations.reader" on-missing="skip"><![CDATA[
    Doctrine\Common\Annotations\AnnotationRegistry::registerLoader('class_exists');
  ]]></factory-script>
</container>

This would execute the script each time the service "annotations.reader" is initialized/created ("newed").

Script scenarios:

  • <config-script> script executed during configuration, maybe to include config resources depending on the env; would be executed right after the config resource is loaded (before following config resources are loaded)
  • <build-script> like extensions
  • <compile-script> like compiler passes
  • <load-script> executed when the container is loaded/booted
  • <factory-script> executed when services are "newed"

WDYT

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions