-
Notifications
You must be signed in to change notification settings - Fork 32
/
MongoStorageManager.php
39 lines (30 loc) · 983 Bytes
/
MongoStorageManager.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
<?php
namespace ServerGrove\Bundle\TranslationEditorBundle;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerAware;
class MongoStorageManager extends ContainerAware
{
protected $mongo;
public function __construct(ContainerInterface $container)
{
$this->setContainer($container);
}
function getMongo()
{
if (!$this->mongo) {
$this->mongo = new \Mongo($this->container->getParameter('translation_editor.mongodb'));
}
if (!$this->mongo) {
throw new \Exception("failed to connect to mongo");
}
return $this->mongo;
}
public function getDB()
{
return $this->getMongo()->translations;
}
public function getCollection()
{
return $this->getDB()->selectCollection($this->container->getParameter('translation_editor.collection'));
}
}