forked from Sammaye/mongoyii-php7
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Database.php
58 lines (46 loc) · 1.22 KB
/
Database.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace sammaye\mongoyii;
use MongoDB\GridFS\Bucket;
use sammaye\monogyii\Collection;
use sammaye\mongoyii\Exception;
class Database
{
public $client;
/** @var \MongoDB\Database */
public $database;
public function __debugInfo()
{
return $this->database->__debugInfo();
}
public function __get($collectionName)
{
return $this->database->__get($collectionName);
}
public function __toString()
{
return $this->database->__toString();
}
public function __call($name, $parameters = [])
{
if(method_exists($this->database, $name)){
return call_user_func_array(array($this->database, $name), $parameters);
}
throw new Exception("$name is not a callable function");
}
public function __construct($database, $client)
{
$this->database = $database;
$this->client = $client;
}
public function selectCollection($collectionName, array $options = [])
{
return new Collection(
$this->database->selectCollection($collectionName, $options),
$this->client
);
}
public function getGridFs($options = [])
{
return new Bucket($this->client, $this->database->getDatabaseName(), $options);
}
}