@@ -25,16 +25,21 @@ final class Queue implements QueueInterface
2525 /**
2626 * Construct queue.
2727 *
28- * @param string $url the mongo url
28+ * @param \MongoCollection| string $collectionOrUrl A MongoCollection instance or the mongo connection url.
2929 * @param string $db the mongo db name
3030 * @param string $collection the collection name to use for the queue
3131 *
32- * @throws \InvalidArgumentException $url , $db or $collection was not a string
32+ * @throws \InvalidArgumentException $collectionOrUrl , $db or $collection was not a string
3333 */
34- public function __construct ($ url , $ db , $ collection )
34+ public function __construct ($ collectionOrUrl , $ db = null , $ collection = null )
3535 {
36- if (!is_string ($ url )) {
37- throw new \InvalidArgumentException ('$url was not a string ' );
36+ if ($ collectionOrUrl instanceof \MongoCollection) {
37+ $ this ->collection = $ collectionOrUrl ;
38+ return ;
39+ }
40+
41+ if (!is_string ($ collectionOrUrl )) {
42+ throw new \InvalidArgumentException ('$collectionOrUrl was not a string ' );
3843 }
3944
4045 if (!is_string ($ db )) {
@@ -45,7 +50,7 @@ public function __construct($url, $db, $collection)
4550 throw new \InvalidArgumentException ('$collection was not a string ' );
4651 }
4752
48- $ mongo = new \MongoClient ($ url );
53+ $ mongo = new \MongoClient ($ collectionOrUrl );
4954 $ mongoDb = $ mongo ->selectDB ($ db );
5055 $ this ->collection = $ mongoDb ->selectCollection ($ collection );
5156 }
0 commit comments