Mark V
1: <?php
2: namespace MOC\V\Component\Database;
3:
4: use MOC\V\Component\Database\Component\Bridge\Repository\Doctrine2ORM;
5: use MOC\V\Component\Database\Component\IBridgeInterface;
6: use MOC\V\Component\Database\Component\IVendorInterface;
7: use MOC\V\Component\Database\Component\Parameter\Repository\DatabaseParameter;
8: use MOC\V\Component\Database\Component\Parameter\Repository\DriverParameter;
9: use MOC\V\Component\Database\Component\Parameter\Repository\HostParameter;
10: use MOC\V\Component\Database\Component\Parameter\Repository\PasswordParameter;
11: use MOC\V\Component\Database\Component\Parameter\Repository\PortParameter;
12: use MOC\V\Component\Database\Component\Parameter\Repository\UsernameParameter;
13: use MOC\V\Component\Database\Vendor\Vendor;
14:
15: /**
16: * Class Database
17: *
18: * @package MOC\V\Component\Database
19: */
20: class Database implements IVendorInterface
21: {
22:
23: /** @var IVendorInterface $VendorInterface */
24: private $VendorInterface = null;
25:
26: /**
27: * @param IVendorInterface $VendorInterface
28: */
29: public function __construct(IVendorInterface $VendorInterface)
30: {
31:
32: $this->setVendorInterface($VendorInterface);
33: }
34:
35: /**
36: * @param string $Username
37: * @param string $Password
38: * @param string $Database
39: * @param int $Driver
40: * @param string $Host
41: * @param null $Port
42: *
43: * @param int $Timeout
44: *
45: * @return IBridgeInterface
46: */
47: public static function getDatabase($Username, $Password, $Database, $Driver, $Host, $Port = null, $Timeout = 5)
48: {
49:
50: return self::getDoctrineDatabase($Username, $Password, $Database, $Driver, $Host, $Port, $Timeout);
51: }
52:
53: /**
54: * @param string $Username
55: * @param string $Password
56: * @param string $Database
57: * @param int $Driver
58: * @param string $Host
59: * @param null $Port
60: *
61: * @param int $Timeout
62: *
63: * @return IBridgeInterface
64: */
65: public static function getDoctrineDatabase(
66: $Username,
67: $Password,
68: $Database,
69: $Driver,
70: $Host,
71: $Port = null,
72: $Timeout = 5
73: ) {
74:
75: $Doctrine = new Database(
76: new Vendor(
77: new Doctrine2ORM()
78: )
79: );
80:
81: $Doctrine->getBridgeInterface()->registerConnection(
82: new UsernameParameter($Username),
83: new PasswordParameter($Password),
84: new DatabaseParameter($Database),
85: new DriverParameter($Driver),
86: new HostParameter($Host),
87: new PortParameter($Port),
88: $Timeout
89: );
90:
91: return $Doctrine->getBridgeInterface();
92: }
93:
94: /**
95: * @return \MOC\V\Component\Database\Component\IBridgeInterface
96: */
97: public function getBridgeInterface()
98: {
99:
100: return $this->VendorInterface->getBridgeInterface();
101: }
102:
103: /**
104: * @return IVendorInterface
105: */
106: public function getVendorInterface()
107: {
108:
109: return $this->VendorInterface;
110: }
111:
112: /**
113: * @param IVendorInterface $VendorInterface
114: *
115: * @return IVendorInterface
116: */
117: public function setVendorInterface(IVendorInterface $VendorInterface)
118: {
119:
120: $this->VendorInterface = $VendorInterface;
121: return $this;
122: }
123:
124: /**
125: * @param IBridgeInterface $BridgeInterface
126: *
127: * @return \MOC\V\Component\Database\Component\IBridgeInterface
128: */
129: public function setBridgeInterface(IBridgeInterface $BridgeInterface)
130: {
131:
132: return $this->VendorInterface->setBridgeInterface($BridgeInterface);
133: }
134: }
135: