You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 16, 2019. It is now read-only.
mikey179 edited this page Jan 23, 2012
·
2 revisions
Default implementations
Very often you only use one concrete implementation of an interface in your application and only added the interface or abstract class to make dependent classes better testable. To avoid having to bind all of your interfaces to the concrete implementations you may specify a default implementation which will be used. To achieve this, add the @ImplementedBy annotation to your interface.
/**
* All Persons should be bound to the class Schst unless Person is bound
*
* @ImplementedBy(Schst.class)
*/
interface Person {
public function sayHello();
}
$person = $injector->getInstance('Person'); // $person is now an instance of Schst
It should be noted though, that once a specific binding for Person is added to the binder that the annotation is not considered anymore: