Пример #1
0
 /**
  * @param $sessionTag
  * @param $sessionValue
  * @return QueueItem
  */
 public static function registerQueueItem($sessionTag, $sessionValue)
 {
     $session = new Session();
     $QueueItem = new QueueItem();
     $QueueItem->setSessionId($session->getId());
     $QueueItem->setSessionTag($sessionTag);
     $QueueItem->setSessionValue($sessionValue);
     return $QueueItem;
 }
Пример #2
0
 /**
  * Immediately store a new item in the queue (length = null, one).
  *
  * @param $tag
  * @param $value
  * @return mixed
  * @throws \Exception
  */
 public function pushSingle($tag, $value)
 {
     try {
         /** @var QueueItemRepository $queueItemRepository */
         $queueItemRepository = $this->container->get('queueitem_repository');
         $items = $queueItemRepository->findQueueItemsByTag($tag);
         $counter = count($items);
         if ($counter === 0) {
             $item = QueueItem::registerQueueItem($tag, $value);
         } elseif ($counter === 1) {
             /** @var QueueItem $item */
             $item = $items[0];
             $item->setSessionValue($value);
         } else {
             throw new \Exception('Illegal queue length: only one allowed,' . $counter . ' encountered.');
         }
         $queueItemRepository->store($item);
         return true;
     } catch (\Exception $e) {
         return false;
     }
 }