Skip to content

Ignore unspeciffied interaces when getting service by interface#6

Closed
koubas wants to merge 1 commit intoPHP-DI:masterfrom
koubas:ignore-unspeciffied-interfaces
Closed

Ignore unspeciffied interaces when getting service by interface#6
koubas wants to merge 1 commit intoPHP-DI:masterfrom
koubas:ignore-unspeciffied-interfaces

Conversation

@koubas
Copy link
Copy Markdown

@koubas koubas commented Jun 30, 2014

Hi, with current version I ran into trouble when getting a service, named with FQN of some interface. The service was provided by another abstract factory, but PHP-DI threw an exception in its AF, because it found that interface, but has no implementation mapped to it.
I had to override that behavior of PHP-DI to make canCreateServiceWithName method return FALSE in that case, instead of throwing an exception, and allow to pass the service resolution to other abstract factories that may provide that service.

If there is some simpler solution to determine, whether the interface can be injected by PHP-DI, or not, it woul be great.

Maybe we should implement some canCreate metohd to PHP-DI itself to be able to better determine, if we can create a service, without throwing/catching exceptions.

I'll try to provide some tests too

@mnapoli
Copy link
Copy Markdown
Member

mnapoli commented Jun 30, 2014

Hi there, thank you for the pull request. I had seen your fork earlier today and that's something that will be fixed soon (hopefully). The fix is here: PHP-DI/PHP-DI#169

The idea behind the fix is that PHP-DI shouldn't return true when you call $container->has('SomeInterface') if the interface is not mapped to a concrete class (because that's very confusing: it returns true which means "yes I can create this class" and then it fails very obviously).

My only reservation for the fix I wrote is detailed here: PHP-DI/PHP-DI#168 (comment). However the problem you faced is really bad, so I think I will merge it anyway.

I'm swamped for the next couple of days but afterwards I'll have plenty of time, so this will be fixed! If you have time to write a small test that would be awesome, else I'll manage to do it later.

@mnapoli mnapoli added the bug label Jun 30, 2014
@mnapoli mnapoli mentioned this pull request Jul 12, 2014
11 tasks
@mnapoli
Copy link
Copy Markdown
Member

mnapoli commented Jul 12, 2014

Sorry it took some time. FYI I merged the bugfix into the 4.2 branch, so now I'll work on releasing the 4.2.

@mnapoli mnapoli closed this Jul 12, 2014
@mnapoli
Copy link
Copy Markdown
Member

mnapoli commented Jul 30, 2014

FYI 4.2 was released yesterday

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants