_session instanceof Session)) { $this->setSession(); } return $this->_session; } /** * * set session object * * @param \Cube\Session $session * * @return $this */ public function setSession(Session $session = null) { if ($session === null) { $session = Front::getInstance()->getBootstrap()->getResource('session'); } if (!($session instanceof Session)) { $session = new Session(); $session->setNamespace(self::SESSION_NAMESPACE); } $this->_session = $session; return $this; } /** * * checks for a valid captcha code, and resets the code if valid * * @return bool return true if the validation is successful */ public function isValid() { $name = $this->getName(); $value = $this->getValue(); $codes = (array) $this->getSession()->get($name); if (($key = array_search($value, $codes)) !== false) { unset($codes[$key]); $this->getSession()->set($name, $codes); return true; } else { return false; } } }