Skip to content

When merging config there's no way to remove anything #79

Description

@tomphp

Say you have these 2 configs:

$config1 = [
  'di' => [
    'services' => [
      'db' => [
        MySQLDB::class,
        'arguments' => [
          'username',
          'password',
          'hostname',
        ],
      ],
    ],
  ],
];
$config2 = [
  'di' => [
    'services' => [
      'db' => [
        FileDB::class,
        'arguments' => [
          'filename',
        ],
      ],
    ],
  ],
];

When loading the configs like so:

Configurator::apply()
  ->configFromArray($config1)
  ->configFromArray($config2)
  ->to($container);

You end up with a config definition like this:

$config2 = [
  'di' => [
    'services' => [
      'db' => [
        FileDB::class,
        'arguments' => [
          'filename',  // from $config2
          'password', // from $config1
          'hostname', // from $config1
        ],
      ],
    ],
  ],
];

Sometimes this is desired behaviour, sometimes it is not. I'm trying to decide if this is a problem and how it should be addressed.

Current options:

1. Treat the config as additive only?

Basically, claim that this isn't a problem and replacing services in this way is not the intended use case.

2. Add method to wrap specific sections

For example:

$config2 = [
  'di' => [
    'services' => [
      'db' => Configurator::replace([
        FileDB::class,
        'arguments' => [
          'filename',
        ],
      ]),
    ],
  ],
];

It's a decent idea but it won't work for non-PHP config files.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions