*/ class AbstractFactory implements AbstractFactoryInterface { /** * Determine if we can create a service with name * * @param ServiceLocatorInterface $serviceLocator * @param $name * @param $requestedName * @return bool */ public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) { return strpos($requestedName, __NAMESPACE__) === 0 && class_exists($requestedName); } /** * Create service with name * * @param ServiceLocatorInterface $serviceLocator * @param $name * @param $requestedName * @return mixed */ public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) { switch ($requestedName) { case __NAMESPACE__ . '\Ldap': $adapter = new Ldap(); break; case __NAMESPACE__ . '\Db': $adapter = new Db(); break; case __NAMESPACE__ . '\Cas': $adapter = new Cas(); break; default: throw new Exception("Service demandé inattendu : '$requestedName'!"); break; } if ($adapter instanceof \Zend\EventManager\EventManagerAwareInterface) { $userService = $serviceLocator->get('unicaen-auth_user_service'); $adapter->setEventManager($serviceLocator->get('event_manager')); $adapter->getEventManager()->attach('userAuthenticated', array($userService, 'userAuthenticated'), 1); } return $adapter; } }