Skip to content

Broken InjectExtension with removed definition #94

@MartinSadovy

Description

@MartinSadovy

#71 #72 broke InjectExtension. When another extension override definition with own definition, it removes class from $classes, but ->addDefinition does not add new.

certain description (see link):

  1. $classes is prepared by https://github.com/nette/di/blob/master/src/DI/Compiler.php#L202
  2. OrmExtension override definition https://github.com/Kdyby/Doctrine/blob/master/src/Kdyby/Doctrine/DI/OrmExtension.php#L741 (beforeCompile) - remove $classes https://github.com/nette/di/blob/master/src/DI/ContainerBuilder.php#L81
  3. Next extension (InjectExtension) want to service by class in beforeCompile https://github.com/nette/di/blob/master/src/DI/Extensions/InjectExtension.php#L126 (btw. see second param which missing)
  4. there is null https://github.com/nette/di/blob/master/src/DI/ContainerBuilder.php#L210

testcase:

$builder = new DI\ContainerBuilder;

$builder->addDefinition('one')
    ->setClass('stdClass');

$builder->prepareClassList();

$builder->removeDefinition('one');
$builder->addDefinition('one')
    ->setClass('stdClass');

Assert::count(1, $builder->findByType('stdClass')); // Failed: Count 0 should be 1
Assert::same('one', $builder->getByType('stdClass')); // Failed: NULL should be 'one'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions