Mark V
1: <?php
2: namespace MOC\V\Component\Document\Component\Bridge\Repository;
3:
4: use MOC\V\Component\Document\Component\Bridge\Bridge;
5: use MOC\V\Component\Document\Component\IBridgeInterface;
6: use MOC\V\Component\Document\Component\Parameter\Repository\FileParameter;
7: use MOC\V\Component\Document\Component\Parameter\Repository\PaperOrientationParameter;
8: use MOC\V\Component\Document\Component\Parameter\Repository\PaperSizeParameter;
9: use MOC\V\Component\Template\Component\IBridgeInterface as IBridgeInterface_Template;
10:
11: /**
12: * Class DomPdf
13: *
14: * @package MOC\V\Component\Document\Component\Bridge\Repository
15: */
16: class DomPdf extends Bridge implements IBridgeInterface
17: {
18:
19: /** @var string $Source */
20: private $Source = '';
21:
22: /**
23: *
24: */
25: public function __construct()
26: {
27:
28: require_once( __DIR__.'/../../../Vendor/DomPdf/0.6.2/dompdf_config.inc.php' );
29:
30: $this->setPaperSizeParameter(new PaperSizeParameter());
31: $this->setPaperOrientationParameter(new PaperOrientationParameter());
32: }
33:
34: /**
35: * @param PaperSizeParameter $PaperSize
36: *
37: * @return IBridgeInterface
38: */
39: public function setPaperSizeParameter(PaperSizeParameter $PaperSize)
40: {
41:
42: return parent::setPaperSizeParameter($PaperSize);
43: }
44:
45: /**
46: * @param PaperOrientationParameter $PaperOrientation
47: *
48: * @return IBridgeInterface
49: */
50: public function setPaperOrientationParameter(PaperOrientationParameter $PaperOrientation)
51: {
52:
53: return parent::setPaperOrientationParameter($PaperOrientation);
54: }
55:
56: /**
57: * @param FileParameter $Location
58: *
59: * @return IBridgeInterface
60: */
61: public function loadFile(FileParameter $Location)
62: {
63:
64: $this->setFileParameter($Location);
65: return $this;
66: }
67:
68: /**
69: * @param IBridgeInterface_Template $Template
70: *
71: * @return IBridgeInterface
72: */
73: public function setContent(IBridgeInterface_Template $Template)
74: {
75:
76: $this->Source = $Template->getContent();
77: return $this;
78: }
79:
80: /**
81: * @param null|FileParameter $Location
82: *
83: * @return IBridgeInterface
84: */
85: public function saveFile(FileParameter $Location = null)
86: {
87:
88: $Content = $this->getContent();
89: if (null === $Location) {
90: file_put_contents($this->getFileParameter()->getFile(), $Content);
91: } else {
92: file_put_contents($Location->getFile(), $Content);
93: }
94: return $this;
95: }
96:
97: /**
98: * @return string
99: */
100: public function getContent()
101: {
102:
103: $Renderer = new \DOMPDF();
104: $Renderer->load_html($this->Source);
105: $Renderer->set_paper(
106: $this->getPaperSizeParameter()->getSize(),
107: $this->getPaperOrientationParameter()->getOrientation()
108: );
109: $Renderer->render();
110: return $Renderer->output();
111: }
112:
113: }
114: