Skip to content

Conversation

@TomasVotruba
Copy link
Contributor

Use case:

$containerBuilder->addDefintion('one')->setClass('stdClass');
$containerBuilder->addDefintion('two')->setClass('stdClass');
$containerBuilder->removeDefinition('two');
$containerBuilder->getByType('stdClass'); // breaks, because reference to 'two' is still saved under 'stdClass'

@fprochazka
Copy link
Contributor

Nice addition. If you could also add tests, that would be awesome.

@TomasVotruba
Copy link
Contributor Author

I'm on it.

@TomasVotruba
Copy link
Contributor Author

It's ready now.

@fprochazka
Copy link
Contributor

nice 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about $this->classes[$class][FALSE]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dg Added!

@dg
Copy link
Member

dg commented Jun 3, 2015

All occurrences should be removed, not only in $this->classes[$class].

@TomasVotruba
Copy link
Contributor Author

@dg What do you mean?

@dg
Copy link
Member

dg commented Jun 3, 2015

for example $this->classes[get_parent_class($class)] etc.

@TomasVotruba
Copy link
Contributor Author

@dg I still don't undestand the point. I'm not familiar with $classes content in such depth. Could you provide failing usecase?

@dg
Copy link
Member

dg commented Jun 3, 2015

class A extends stdClass {}

$containerBuilder->addDefintion('two')->setClass('A');

@TomasVotruba
Copy link
Contributor Author

This might do it. Please check.

Edit: other test is failing. Will check tomorrow

@dg
Copy link
Member

dg commented Jun 3, 2015

foreach ($this->classes as $class => $tmp) 
   foreach ($tmp as $mode => $nm) {
     if ($name = $nm) unset($this->classes[$class][$tmp])
}

(cca, written on phone on a bike)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, and what about this? $this->classes[$class][$mode] = array_diff($this->classes[$class][$mode], [$name]).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's less readable. It might be faster, container compilation is cached though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dev code, I shall removed it.

@dg dg closed this in 77b09ba Jun 4, 2015
@TomasVotruba
Copy link
Contributor Author

Parfe!

@dg
Copy link
Member

dg commented Jun 4, 2015

Thanx

@TomasVotruba
Copy link
Contributor Author

One more related bug:

$someInterface => [
    0 => FirstService
    1 => SecondService
];

Remove 'FirstService':

$someInterface => [
    1 => SecondService
];

Then, getByType will try to get [0] => FAIL

Solution? Something like:

return reset($this->classes[$class][TRUE]);

What do you think?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants