*/ class Ldap implements Storage\StorageInterface, ServiceManagerAwareInterface { /** * @var StorageInterface */ protected $storage; /** * @var LdapPeopleMapper */ protected $mapper; /** * @var ModuleOptions */ protected $options; /** * @var People */ protected $resolvedIdentity; /** * @var ServiceManager */ protected $serviceManager; /** * 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() { return $this->getStorage()->isEmpty(); } /** * Returns the contents of storage * * Behavior is undefined when storage is empty. * * @throws InvalidArgumentException If reading contents from storage is impossible * @return People */ public function read() { if (null !== $this->resolvedIdentity) { return $this->resolvedIdentity; } $identity = $this->getStorage()->read(); if (is_scalar($identity)) { $identity = $this->getMapper()->findOneByUsername($identity); } if ($identity) { $this->resolvedIdentity = $identity; } else { $this->resolvedIdentity = null; } return $this->resolvedIdentity; } /** * Writes $contents to storage * * @param mixed $contents * @throws InvalidArgumentException If writing $contents to storage is impossible * @return void */ public function write($contents) { $this->resolvedIdentity = null; $this->getStorage()->write($contents); return $this; } /** * Clears contents from storage * * @throws InvalidArgumentException If clearing contents from storage is impossible * @return void */ public function clear() { $this->resolvedIdentity = null; $this->getStorage()->clear(); return $this; } /** * getStorage * * @return Storage\StorageInterface */ public function getStorage() { if (null === $this->storage) { $this->setStorage(new Storage\Session); } return $this->storage; } /** * setStorage * * @param Storage\StorageInterface $storage * @access public * @return Ldap */ public function setStorage(Storage\StorageInterface $storage) { $this->storage = $storage; return $this; } /** * getMapper * * @return LdapPeopleMapper */ public function getMapper() { if (null === $this->mapper) { $this->mapper = $this->getServiceManager()->get('ldap_people_mapper'); } return $this->mapper; } /** * setMapper * * @param LdapPeopleMapper $mapper * @return Ldap */ public function setMapper(LdapPeopleMapper $mapper) { $this->mapper = $mapper; return $this; } /** * Retrieve service manager instance * * @return ServiceManager */ public function getServiceManager() { return $this->serviceManager; } /** * Set service manager instance * * @param ServiceManager $locator * @return void */ public function setServiceManager(ServiceManager $serviceManager) { $this->serviceManager = $serviceManager; return $this; } /** * @param ModuleOptions $options */ public function setOptions(ModuleOptions $options) { $this->options = $options; return $this; } /** * @return ModuleOptions */ public function getOptions() { if (!$this->options instanceof ModuleOptions) { $this->setOptions($this->getServiceManager()->get('unicaen-auth_module_options')); } return $this->options; } }