DominionEnterprises\Mongo\Queue::__construct PHP Method

__construct() public method

Construct queue.
public __construct ( MongoDB\Collection | string $collectionOrUrl, string $db = null, string $collection = null )
$collectionOrUrl MongoDB\Collection | string A MongoCollection instance or the mongo connection url.
$db string the mongo db name
$collection string the collection name to use for the queue
    public function __construct($collectionOrUrl, $db = null, $collection = null)
    {
        if ($collectionOrUrl instanceof \MongoDB\Collection) {
            $this->collection = $collectionOrUrl;
            return;
        }
        if (!is_string($collectionOrUrl)) {
            throw new \InvalidArgumentException('$collectionOrUrl was not a string');
        }
        if (!is_string($db)) {
            throw new \InvalidArgumentException('$db was not a string');
        }
        if (!is_string($collection)) {
            throw new \InvalidArgumentException('$collection was not a string');
        }
        $mongo = new \MongoDB\Client($collectionOrUrl, [], ['typeMap' => ['root' => 'array', 'document' => 'array', 'array' => 'array']]);
        $mongoDb = $mongo->selectDatabase($db);
        $this->collection = $mongoDb->selectCollection($collection);
    }