Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tomphp opened this issue Oct 22, 2016 · 1 comment
Open

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

tomphp opened this issue Oct 22, 2016 · 1 comment
Labels

Comments

@tomphp
Copy link
Owner

tomphp commented Oct 22, 2016

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.

@tomphp tomphp added the bug label Oct 22, 2016
@kuzmenko1256
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants