topolis/queue

一个动态队列系统

1.0.0 2019-05-27 09:25 UTC

This package is not auto-updated.

Last update: 2024-09-18 14:43:32 UTC


README

一个简单的队列系统。你可以将项目添加到列表中,并按优先级或项目顺序进行排序。优先级或项目键不需要唯一。

注意,如果键已占用,对象的键可能会得到一个唯一的后缀

示例

你可以在 sample 文件夹中找到示例

  • silex.php 在 silex 应用程序中演示队列使用和延迟加载
  • simple 简单的独立队列使用
$queue = new Queue();

// Add item at priority
$queue->add($item, Queue::EARLY);

// Add item with specific key at priority
$queue->add($item, Queue::EARLY, "myItem");

// Add item before other item in queue
$queue->addBefore($item, $otherItem);

// Add item before key of other item in queue
$queue->addAfter($item, "otherItem");

// Check if item with key is in queue
$check = $queue->has("myItem");

// Check if item is in queue
$check = $queue->has($item);

// Iterate through queue in order
foreach($queue as $item){
    $item->doSomething()
}