Throw an exception if a ContainerBuilder is modified *after* building the container #421

Closed
mnapoli opened this Issue Jun 2, 2016 · 0 comments

Comments

Projects
None yet
1 participant
@mnapoli
Member

mnapoli commented Jun 2, 2016

The goal is to detect errors sooner when users will do something like this:

$containerBuilder->addDefinitions(...);

$container = $containerBuilder->build();

$containerBuilder->addDefinitions([
    'foo' => 'bar',
]);

$container->get('foo'); // Exception

Definitions (or anything actually) added after the container was created is ignored, but it sometimes can be not obvious.

By "locking" the builder after the container is created (throwing an exception on all modifications) could help.

@mnapoli mnapoli added the enhancement label Jun 2, 2016

@mnapoli mnapoli added the easy-pick label Jun 12, 2016

mnapoli added a commit that referenced this issue Aug 23, 2016

#421 Lock the ContainerBuilder once the container has been built
The goal is to detect errors sooner when users will do something like this:

```php
$containerBuilder->addDefinitions(...);

$container = $containerBuilder->build();

$containerBuilder->addDefinitions([
    'foo' => 'bar',
]);

$container->get('foo'); // Exception
```

Definitions (or anything actually) added after the container was created is ignored, but it sometimes can be not obvious.

By "locking" the builder after the container is created (throwing an exception on all modifications) could help.

@mnapoli mnapoli added this to the 5.4 milestone Aug 23, 2016

@mnapoli mnapoli self-assigned this Aug 23, 2016

@mnapoli mnapoli closed this in #436 Aug 23, 2016

mnapoli added a commit that referenced this issue Aug 23, 2016

Merge pull request #436 from PHP-DI/lock-containerbuilder
#421 Lock the ContainerBuilder once the container has been built
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment