Memory.php in Drupal 10
File
core/lib/Drupal/Core/Queue/Memory.php
View source
<?php
namespace Drupal\Core\Queue;
class Memory implements QueueInterface {
protected $queue;
protected $idSequence;
public function __construct($name) {
$this->queue = [];
$this->idSequence = 0;
}
public function createItem($data) {
$item = new \stdClass();
$item->item_id = $this->idSequence++;
$item->data = $data;
$item->created = \Drupal::time()
->getCurrentTime();
$item->expire = 0;
$this->queue[$item->item_id] = $item;
return $item->item_id;
}
public function numberOfItems() {
return count($this->queue);
}
public function claimItem($lease_time = 30) {
foreach ($this->queue as $key => $item) {
if ($item->expire == 0) {
$item->expire = \Drupal::time()
->getCurrentTime() + $lease_time;
$this->queue[$key] = $item;
return $item;
}
}
return FALSE;
}
public function deleteItem($item) {
unset($this->queue[$item->item_id]);
}
public function releaseItem($item) {
if (isset($this->queue[$item->item_id]) && $this->queue[$item->item_id]->expire != 0) {
$this->queue[$item->item_id]->expire = 0;
return TRUE;
}
return FALSE;
}
public function createQueue() {
}
public function deleteQueue() {
$this->queue = [];
$this->idSequence = 0;
}
}
Classes
Name |
Description |
Memory |
Static queue implementation. |