getStorage()->isEmpty()) { return true; } $identity = $this->getStorage()->read(); if ($identity === null) { $this->clear(); return true; } return false; } /** * Returns the contents of storage * * Behavior is undefined when storage is empty. * * @throws \Zend\Authentication\Exception\InvalidArgumentException If reading contents from storage is impossible * @return mixed */ public function read() { if (null !== $this->resolvedIdentity) { return $this->resolvedIdentity; } $identity = $this->getStorage()->read(); if (is_int($identity) || is_scalar($identity)) { $identity = $this->getMapper()->findById($identity); } if ($identity) { $this->resolvedIdentity = $identity; } else { $this->resolvedIdentity = null; } return $this->resolvedIdentity; } /** * Writes $contents to storage * * @param mixed $contents * @throws \Zend\Authentication\Exception\InvalidArgumentException If writing $contents to storage is impossible * @return void */ public function write($contents) { $this->resolvedIdentity = null; $this->getStorage()->write($contents); } /** * Clears contents from storage * * @throws \Zend\Authentication\Exception\InvalidArgumentException If clearing contents from storage is impossible * @return void */ public function clear() { $this->resolvedIdentity = null; $this->getStorage()->clear(); } /** * 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 Db */ public function setStorage(Storage\StorageInterface $storage) { $this->storage = $storage; return $this; } /** * getMapper * * @return UserMapper */ public function getMapper() { if (null === $this->mapper) { $this->mapper = $this->getServiceManager()->get('zfcuser_user_mapper'); } return $this->mapper; } /** * setMapper * * @param UserMapper $mapper * @return Db */ public function setMapper(UserMapper $mapper) { $this->mapper = $mapper; return $this; } /** * Retrieve service manager instance * * @return ServiceManager */ public function getServiceManager() { return $this->serviceManager; } /** * Set service manager instance * * @param ContainerInterface $locator * @return void */ public function setServiceManager(ContainerInterface $serviceManager) { $this->serviceManager = $serviceManager; } }