Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathUnorderedQueue.php
More file actions
Latest commit
48 lines (42 loc) · 1.48 KB
/
Copy pathUnorderedQueue.php
File metadata and controls
48 lines (42 loc) · 1.48 KB
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
42
43
44
45
46
47
48
<?php
/**
* Defines the TraderInteractive\Mongo\UnorderedQueue class.
*/
namespaceTraderInteractive\Mongo;
useMongoDB\Client;
useMongoDB\Operation\FindOneAndUpdate;
/**
* Abstraction of mongo db collection as unordered queue.
*/
finalclass UnorderedQueue extends AbstractQueue implements QueueInterface
{
/**
* Override from AbstractQueue class to remove sort options.
*
* @var array
*/
constFIND_ONE_AND_UPDATE_OPTIONS = [
'typeMap' => ['root' => 'array', 'document' => 'array', 'array' => 'array'],
'returnDocument' => FindOneAndUpdate::RETURN_DOCUMENT_AFTER,
];
/**
* 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
*/
publicfunction__construct($collectionOrUrl, string$db = null, string$collection = null)
{
if ($collectionOrUrlinstanceof \MongoDB\Collection) {
$this->collection = $collectionOrUrl;
return;
}
if (!is_string($collectionOrUrl)) {
thrownew \InvalidArgumentException('$collectionOrUrl was not a string');
}
$this->collection = (newClient($collectionOrUrl))->selectDatabase($db)->selectCollection($collection);
}
}