1: <?php
2:
3: namespace malkusch\bav;
4:
5: use Doctrine\ORM\EntityManager;
6: use Doctrine\ORM\Tools\Setup;
7:
8: /**
9: * Container for DoctrineDataBackend objects.
10: *
11: * You will need Doctrine as composer dependency.
12: *
13: * @author Markus Malkusch <markus@malkusch.de>
14: * @link bitcoin:1335STSwu9hST4vcMRppEPgENMHD2r1REK Donations
15: * @license GPL
16: * @see DataBackend
17: * @link http://www.doctrine-project.org/
18: * @api
19: */
20: class DoctrineBackendContainer extends DataBackendContainer
21: {
22:
23: /**
24: * @var EntityManager
25: */
26: private $em;
27:
28: /**
29: * Return the paths to the XML-Mappings
30: *
31: * @return string[]
32: */
33: public static function getXMLMappings()
34: {
35: return array(__DIR__ . "/mapping/");
36: }
37:
38: /**
39: * Builds a container for a connection.
40: *
41: * @param mixed $connection Doctrine::DBAL connection
42: * @return DoctrineBackendContainer
43: */
44: public static function buildByConnection($connection, $isDevMode = false)
45: {
46: $mappings = self::getXMLMappings();
47: $config = Setup::createXMLMetadataConfiguration($mappings, $isDevMode);
48:
49: $entityManager = EntityManager::create($connection, $config);
50: return new self($entityManager);
51: }
52:
53: /**
54: * Injects the EntityManager
55: */
56: public function __construct(EntityManager $entityManager)
57: {
58: $this->em = $entityManager;
59: }
60:
61: /**
62: * Gets the EntityManager
63: *
64: * @return EntityManager
65: */
66: public function getEntityManager()
67: {
68: return $this->em;
69: }
70:
71: protected function makeDataBackend()
72: {
73: return new DoctrineDataBackend($this->em);
74: }
75: }
76: