-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathQueue.php
41 lines (36 loc) · 1.33 KB
/
Queue.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
/**
* Defines the TraderInteractive\Mongo\Queue class.
*/
namespace TraderInteractive\Mongo;
use MongoDB\BSON\UTCDateTime;
use MongoDB\Client;
/**
* Abstraction of mongo db collection as priority queue.
*
* Tied priorities are ordered by time. So you may use a single priority for normal queuing (default args exist for
* this purpose). Using a random priority achieves random get()
*/
final class Queue extends AbstractQueue implements QueueInterface
{
/**
* Construct queue.
*
* @param \MongoDB\Collection|string $collectionOrUrl A MongoCollection instance or the mongo connection url.
* @param string $db the mongo db name
* @param string $collection the collection name to use for the queue
*
* @throws \InvalidArgumentException $collectionOrUrl, $db or $collection was not a string
*/
public function __construct($collectionOrUrl, string $db = null, string $collection = null)
{
if ($collectionOrUrl instanceof \MongoDB\Collection) {
$this->collection = $collectionOrUrl;
return;
}
if (!is_string($collectionOrUrl)) {
throw new \InvalidArgumentException('$collectionOrUrl was not a string');
}
$this->collection = (new Client($collectionOrUrl))->selectDatabase($db)->selectCollection($collection);
}
}