1 | <?php |
||
22 | class MongoManager implements InjectorInterface, SingletonInterface |
||
23 | { |
||
24 | /** |
||
25 | * @var MongoDatabase[] |
||
26 | */ |
||
27 | private $databases = []; |
||
28 | |||
29 | /** |
||
30 | * @var MongoConfig |
||
31 | */ |
||
32 | protected $config; |
||
33 | |||
34 | /** |
||
35 | * @var FactoryInterface |
||
36 | */ |
||
37 | protected $factory; |
||
38 | |||
39 | /** |
||
40 | * @param MongoConfig $config |
||
41 | * @param FactoryInterface $factory |
||
42 | */ |
||
43 | public function __construct(MongoConfig $config, FactoryInterface $factory = null) |
||
48 | |||
49 | /** |
||
50 | * Add new database in a database pull, database name will be automatically selected from given |
||
51 | * instance. |
||
52 | * |
||
53 | * @param string $name Internal database name. |
||
54 | * @param MongoDatabase $database |
||
55 | * |
||
56 | * @return self|$this |
||
57 | * |
||
58 | * @throws ODMException |
||
59 | */ |
||
60 | public function addDatabase(string $name, MongoDatabase $database): MongoManager |
||
70 | |||
71 | /** |
||
72 | * Register new mongo database using given name and connection options (compatible with MongoDB |
||
73 | * class). |
||
74 | * |
||
75 | * @param string $name Internal database name (for injections and etc). |
||
76 | * @param string $server Server uri. |
||
77 | * @param string $database Database name. |
||
78 | * @param array $driverOptions |
||
79 | * @param array $options Database options. |
||
80 | * |
||
81 | * @return MongoDatabase |
||
82 | */ |
||
83 | public function createDatabase( |
||
101 | |||
102 | /** |
||
103 | * Create specified or select default instance of MongoDatabase. |
||
104 | * |
||
105 | * @param string $database Database name (internal). |
||
106 | * |
||
107 | * @return MongoDatabase |
||
108 | * |
||
109 | * @throws ODMException |
||
110 | */ |
||
111 | public function database(string $database = null): MongoDatabase |
||
141 | |||
142 | /** |
||
143 | * Get every know database. |
||
144 | * |
||
145 | * @return MongoDatabase[] |
||
146 | */ |
||
147 | public function getDatabases(): array |
||
158 | |||
159 | /** |
||
160 | * Automatic injection of MongoDatabase. |
||
161 | * |
||
162 | * {@inheritdoc} |
||
163 | * |
||
164 | * @return MongoDatabase |
||
165 | */ |
||
166 | public function createInjection(\ReflectionClass $class, string $context = null) |
||
170 | } |