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

Broken InjectExtension with removed definition #94

Closed
MartinSadovy opened this issue Feb 5, 2016 · 4 comments
Closed

Broken InjectExtension with removed definition #94

MartinSadovy opened this issue Feb 5, 2016 · 4 comments

Comments

@MartinSadovy
Copy link

@MartinSadovy MartinSadovy commented Feb 5, 2016

#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'
@fprochazka

This comment has been minimized.

Copy link
Contributor

@fprochazka fprochazka commented Feb 7, 2016

Is this related to Kdyby/Doctrine#234 ?

@MartinSadovy

This comment has been minimized.

Copy link
Author

@MartinSadovy MartinSadovy commented Feb 7, 2016

@fprochazka correct, it is.

@dg

This comment has been minimized.

Copy link
Member

@dg dg commented Feb 7, 2016

You should call prepareClassList again.

dg added a commit to dg/nette-di that referenced this issue Feb 7, 2016
@MartinSadovy

This comment has been minimized.

Copy link
Author

@MartinSadovy MartinSadovy commented Feb 7, 2016

@dg I know. Testcase is same as ContainerBuilder works, otherwise the testcase will be successful.

dg added a commit to dg/nette-di that referenced this issue Feb 8, 2016
@dg dg closed this in 53b88db Feb 8, 2016
dg added a commit that referenced this issue Feb 8, 2016
ContainerBuilder: getByType() and findByType() refresh class list [Closes #94]
dg added a commit that referenced this issue Feb 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.