Skip to content

[Config] Enable injection of service reference or definition into configuration nodes #62142

@GromNaN

Description

@GromNaN

Description

With the PHP configuration format, it's possible to set PHP objects (while Yaml has restricted types, extended using tags).

Benefit: define service directly in the configuration, so that they are colocated.

That would also enable other types of objects; each node allowing a list of class names.

Example

In framework.cache.pools.*.adapter, the config node only accepts a string for the service Id.

It could accept a Reference:

  return App::config([
      'framework' => [
          'cache' => [
              'pools' => [
                  'cache.mycache' => [
-                     'adapter' => 'cache.adapter.redis',
+                     'adapter' => reference('cache.adapter.redis'),
                      'default_lifetime' => 3600,
                  ],
              ],
          ],
      ],
  ]);

Or inline service Definition:

  return App::config([
      'framework' => [
          'cache' => [
              'pools' => [
                  'cache.mycache' => [
-                     'adapter' => 'cache.adapter.redis',
+                     'adapter' => inline_service(RedisAdapter::class)->...,
                      'default_lifetime' => 3600,
                  ],
              ],
          ],
      ],
  ]);

The configuration tree would be like this:

->prototype(['string', Definition::class, Reference::class])

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions