Пример #1
0
 /**
  * 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;
 }
Пример #2
0
 function it_current()
 {
     $this->get()->shouldHaveType(AccessEntity::getClass());
 }
Пример #3
0
 /**
  * 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;
 }