/** * Return auth from session * * @return AccessEntity|null * @throws \RuntimeException */ public function get() { if ($this->session()->has(self::KEY)) { $data = $this->session()->get(self::KEY); if ($data !== null) { $access = new AccessEntity(); $access->setData($data, true); return $access; } } return null; }
function it_current() { $this->get()->shouldHaveType(AccessEntity::getClass()); }
/** * Clear olds token * * @param integer $day * @return true * @throws \RuntimeException */ public function clearOld($day) { $time = $this->date()->convertTimeStamp(time() - $day * 3600 * 24); $filter = ['<' . AccessEntity::C_TIMESTAMP_X => $time]; $repo = new Repository($this->repository_name); $entities = self::finder(AccessEntity::getClass())->filter($filter)->all(); foreach ($entities as $entity) { $repo->delete($this, $entity); } if (!$repo->commit()) { $mess = print_r($repo->getErrorEntity()->getErrors()->all(), 1); throw new \RuntimeException("Error delete old access token. Error: {$mess}."); } return true; }