*/ class LdapDb implements Storage\StorageInterface, ServiceManagerAwareInterface { /** * @var ServiceManager */ protected $serviceManager; /** * @var Ldap */ protected $ldapStorage; /** * @var Db */ protected $dbStorage; /** * @var ModuleOptions */ protected $options; /** * Returns true if and only if storage is empty * * @throws InvalidArgumentException If it is impossible to determine whether storage is empty * @return boolean */ public function isEmpty() { if (!$this->getLdapStorage()->isEmpty()) { return false; } if (!$this->getDbStorage()->isEmpty()) { return false; } return true; } /** * Returns the contents of storage * * Behavior is undefined when storage is empty. * * @throws InvalidArgumentException If reading contents from storage is impossible * @return UserInterface */ public function read() { $identity = null; $userId = null; if (($dbIdentity = $this->getDbStorage()->read())) { $userId = $dbIdentity->getId(); $identity = $dbIdentity; } // moyen de savoir si l'utilisateur a été créé à partir de l'annuaire LDAP: mdp = 'ldap' dans la table if (!$dbIdentity || $dbIdentity->getPassword() == 'ldap') { $ldapIdentity = $this->getLdapStorage()->read(); if ($ldapIdentity) { $identity = new PeopleAdapter($ldapIdentity->getData(), $userId); } } return $identity; } /** * Writes $contents to storage * * @param mixed $contents * @throws InvalidArgumentException If writing $contents to storage is impossible * @return void */ public function write($contents) { $this->getLdapStorage()->write($contents); $this->getDbStorage()->write($contents); } /** * Clears contents from storage * * @throws InvalidArgumentException If clearing contents from storage is impossible * @return void */ public function clear() { $this->getLdapStorage()->clear(); $this->getDbStorage()->clear(); } /** * Retrieve service manager instance * * @return ServiceManager */ public function getServiceManager() { return $this->serviceManager; } /** * Set service manager * * @param ServiceManager $serviceManager * @return LdapDb */ public function setServiceManager(ServiceManager $serviceManager) { $this->serviceManager = $serviceManager; return $this; } /** * get db Storage * * @return Db */ public function getDbStorage() { return $this->dbStorage; } /** * set db Storage * * @param Db $storage * @access public * @return LdapDb */ public function setDbStorage(Db $storage) { $this->dbStorage = $storage; return $this; } /** * get ldap Storage * * @return Ldap */ public function getLdapStorage() { return $this->ldapStorage; } /** * set ldap Storage * * @param Ldap $storage * @access public * @return LdapDb */ public function setLdapStorage(Ldap $storage) { $this->ldapStorage = $storage; return $this; } /** * @param ModuleOptions $options * @return LdapDb */ public function setOptions(ModuleOptions $options) { $this->options = $options; return $this; } /** * @return ModuleOptions */ public function getOptions() { if (null === $this->options) { $this->setOptions($this->getServiceManager()->get('unicaen-auth_module_options')); } return $this->options; } }