Mark V
1: <?php
2: namespace MOC\V\Component\Document;
3:
4: use MOC\V\Component\Document\Component\Bridge\Repository\DomPdf;
5: use MOC\V\Component\Document\Component\Bridge\Repository\MPdf;
6: use MOC\V\Component\Document\Component\Bridge\Repository\PhpExcel;
7: use MOC\V\Component\Document\Component\Bridge\Repository\UniversalXml;
8: use MOC\V\Component\Document\Component\IBridgeInterface;
9: use MOC\V\Component\Document\Component\IVendorInterface;
10: use MOC\V\Component\Document\Component\Parameter\Repository\FileParameter;
11: use MOC\V\Component\Document\Exception\DocumentTypeException;
12: use MOC\V\Component\Document\Vendor\Vendor;
13:
14: /**
15: * Class Document
16: *
17: * @package MOC\V\Component\Document
18: */
19: class Document implements IVendorInterface
20: {
21:
22: /** @var IVendorInterface $VendorInterface */
23: private $VendorInterface = null;
24:
25: /**
26: * @param IVendorInterface $VendorInterface
27: */
28: public function __construct(IVendorInterface $VendorInterface)
29: {
30:
31: $this->setVendorInterface($VendorInterface);
32: }
33:
34: /**
35: * @param string $Location
36: *
37: * @return IBridgeInterface
38: * @throws DocumentTypeException
39: */
40: public static function getDocument($Location)
41: {
42:
43: $FileInfo = new \SplFileInfo($Location);
44: switch (strtolower($FileInfo->getExtension())) {
45: case 'pdf': {
46: return self::getPdfDocument($Location);
47: }
48: case 'csv':
49: case 'xls':
50: case 'xlsx': {
51: return self::getExcelDocument($Location);
52: }
53: case 'xml': {
54: return self::getXmlDocument($Location);
55: }
56: default:
57: throw new DocumentTypeException();
58: }
59: }
60:
61: /**
62: * @param string $Location
63: *
64: * @return IBridgeInterface
65: */
66: public static function getPdfDocument($Location)
67: {
68:
69: $Document = new Document(
70: new Vendor(
71: new DomPdf()
72: )
73: );
74:
75: if (file_exists(new FileParameter($Location))) {
76: $Document->getBridgeInterface()->loadFile(new FileParameter($Location));
77: }
78:
79: return $Document->getBridgeInterface();
80: }
81:
82: /**
83: * @return IBridgeInterface
84: */
85: public function getBridgeInterface()
86: {
87:
88: return $this->VendorInterface->getBridgeInterface();
89: }
90:
91: /**
92: * @param string $Location
93: *
94: * @return IBridgeInterface
95: */
96: public static function getExcelDocument($Location)
97: {
98:
99: $Document = new Document(
100: new Vendor(
101: new PhpExcel()
102: )
103: );
104: /** @var PhpExcel $Bridge */
105: $Bridge = $Document->getBridgeInterface();
106: if (file_exists(new FileParameter($Location))) {
107: $Bridge->loadFile(new FileParameter($Location));
108: } else {
109: $Bridge->newFile(new FileParameter($Location));
110: }
111:
112: return $Bridge;
113: }
114:
115: /**
116: * @param string $Location
117: *
118: * @return IBridgeInterface
119: */
120: public static function getXmlDocument($Location)
121: {
122:
123: $Document = new Document(
124: new Vendor(
125: new UniversalXml()
126: )
127: );
128:
129: if (file_exists(new FileParameter($Location))) {
130: $Document->getBridgeInterface()->loadFile(new FileParameter($Location));
131: }
132:
133: return $Document->getBridgeInterface();
134: }
135:
136: /**
137: * @param string $Location
138: *
139: * @return IBridgeInterface
140: */
141: public static function getPdfCreator($Location)
142: {
143:
144: $Document = new Document(
145: new Vendor(
146: new MPdf()
147: )
148: );
149:
150: if (file_exists(new FileParameter($Location))) {
151: $Document->getBridgeInterface()->loadFile(new FileParameter($Location));
152: }
153:
154: return $Document->getBridgeInterface();
155: }
156:
157: /**
158: * @return IVendorInterface
159: */
160: public function getVendorInterface()
161: {
162:
163: return $this->VendorInterface;
164: }
165:
166: /**
167: * @param IVendorInterface $VendorInterface
168: *
169: * @return IVendorInterface
170: */
171: public function setVendorInterface(IVendorInterface $VendorInterface)
172: {
173:
174: $this->VendorInterface = $VendorInterface;
175: return $this;
176: }
177:
178: /**
179: * @param IBridgeInterface $BridgeInterface
180: *
181: * @return IBridgeInterface
182: */
183: public function setBridgeInterface(IBridgeInterface $BridgeInterface)
184: {
185:
186: return $this->VendorInterface->setBridgeInterface($BridgeInterface);
187: }
188: }
189: