Storage
1 day ago
FileSeekableQueue.php
1 day ago
FinishedQueueException.php
5 years ago
Queue.php
1 day ago
QueueInterface.php
1 day ago
SeekableQueueInterface.php
1 day ago
Queue.php
150 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | namespace WPStaging\Framework\Queue; |
| 7 | |
| 8 | use WPStaging\Framework\Queue\Storage\CacheStorage; |
| 9 | use WPStaging\Framework\Queue\Storage\StorageInterface; |
| 10 | use WPStaging\Framework\Job\Task\AbstractTask; |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | class Queue implements QueueInterface |
| 17 | { |
| 18 | |
| 19 | private $name; |
| 20 | |
| 21 | |
| 22 | private $storage; |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | public function setName($name) |
| 28 | { |
| 29 | $this->name = $name; |
| 30 | $this->init(); |
| 31 | } |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | public function getName() |
| 37 | { |
| 38 | return $this->name; |
| 39 | } |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | public function setStorage(StorageInterface $storage) |
| 45 | { |
| 46 | $this->storage = $storage; |
| 47 | $this->init(); |
| 48 | |
| 49 | return $this; |
| 50 | } |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | public function getStorage() |
| 56 | { |
| 57 | return $this->storage; |
| 58 | } |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | public function count() |
| 64 | { |
| 65 | return $this->storage->count(); |
| 66 | } |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | public function current() |
| 74 | { |
| 75 | return $this->storage->current(); |
| 76 | } |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | public function pop() |
| 82 | { |
| 83 | return $this->storage->first(); |
| 84 | } |
| 85 | |
| 86 | public function last() |
| 87 | { |
| 88 | return $this->storage->last(); |
| 89 | } |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | public function push($value) |
| 95 | { |
| 96 | $this->storage->append($value); |
| 97 | } |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | public function pushAsArray(array $value = []) |
| 103 | { |
| 104 | foreach ($value as $item) { |
| 105 | $this->storage->append($item); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | public function prepend($value) |
| 113 | { |
| 114 | $this->storage->prepend($value); |
| 115 | } |
| 116 | |
| 117 | protected function init() |
| 118 | { |
| 119 | if (!$this->name || !$this->storage) { |
| 120 | return; |
| 121 | } |
| 122 | |
| 123 | $this->storage->setKey($this->name); |
| 124 | } |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | public function reset() |
| 130 | { |
| 131 | $this->storage->reset(); |
| 132 | } |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | public function reverse() |
| 138 | { |
| 139 | $this->storage->reverse(); |
| 140 | } |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | public function save() |
| 146 | { |
| 147 | $this->storage->commit(); |
| 148 | } |
| 149 | } |
| 150 |