| 1 | <?php |
||
| 20 | class AclFactory implements FactoryInterface |
||
| 21 | { |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Create an object |
||
| 25 | * |
||
| 26 | * @param ContainerInterface $container |
||
| 27 | * @param string $requestedName |
||
| 28 | * @param null|array $options |
||
| 29 | * |
||
| 30 | * @return object |
||
| 31 | * @throws ServiceNotFoundException if unable to resolve the service. |
||
| 32 | * @throws ServiceNotCreatedException if an exception is raised when |
||
| 33 | * creating a service. |
||
| 34 | * @throws ContainerException if any other error occurs |
||
| 35 | */ |
||
| 36 | public function __invoke(ContainerInterface $container, $requestedName, array $options = null) |
||
| 44 | |||
| 45 | /* (non-PHPdoc) |
||
| 46 | * @see \Zend\ServiceManager\FactoryInterface::createService() |
||
| 47 | */ |
||
| 48 | public function createService(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) |
||
| 52 | } |
||
| 53 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: