Mark V
1: <?php
2: namespace MOC\V\Component\Template;
3:
4: use MOC\V\Component\Template\Component\Bridge\Repository\SmartyTemplate;
5: use MOC\V\Component\Template\Component\Bridge\Repository\TwigTemplate;
6: use MOC\V\Component\Template\Component\IBridgeInterface;
7: use MOC\V\Component\Template\Component\IVendorInterface;
8: use MOC\V\Component\Template\Component\Parameter\Repository\FileParameter;
9: use MOC\V\Component\Template\Exception\TemplateTypeException;
10: use MOC\V\Component\Template\Vendor\Vendor;
11:
12: /**
13: * Class Template
14: *
15: * @package MOC\V\Component\Template
16: */
17: class Template implements IVendorInterface
18: {
19:
20: /** @var IVendorInterface $VendorInterface */
21: private $VendorInterface = null;
22:
23: /**
24: * @param IVendorInterface $VendorInterface
25: */
26: public function __construct(IVendorInterface $VendorInterface)
27: {
28:
29: $this->setVendorInterface($VendorInterface);
30: }
31:
32: /**
33: * @param string $Location
34: *
35: * @throws TemplateTypeException
36: * @return IBridgeInterface
37: */
38: public static function getTemplate($Location)
39: {
40:
41: switch ($Type = strtoupper(pathinfo($Location, PATHINFO_EXTENSION))) {
42: case 'TWIG': {
43: return self::getTwigTemplate($Location);
44: break;
45: }
46: case 'TPL': {
47: return self::getSmartyTemplate($Location);
48: break;
49: }
50: default: {
51: throw new TemplateTypeException(( $Type ? $Type : '-NA-' ));
52: break;
53: }
54: }
55: }
56:
57: /**
58: * @param string $Location
59: *
60: * @return IBridgeInterface
61: */
62: public static function getTwigTemplate($Location)
63: {
64:
65: $Template = new Template(
66: new Vendor(
67: new TwigTemplate()
68: )
69: );
70:
71: $Template->getBridgeInterface()->loadFile(new FileParameter($Location), false);
72:
73: return $Template->getBridgeInterface();
74: }
75:
76: /**
77: * @return IBridgeInterface
78: */
79: public function getBridgeInterface()
80: {
81:
82: return $this->VendorInterface->getBridgeInterface();
83: }
84:
85: /**
86: * @param string $Location
87: *
88: * @return IBridgeInterface
89: */
90: public static function getSmartyTemplate($Location)
91: {
92:
93: $Template = new Template(
94: new Vendor(
95: new SmartyTemplate()
96: )
97: );
98:
99: $Template->getBridgeInterface()->loadFile(new FileParameter($Location), false);
100:
101: return $Template->getBridgeInterface();
102: }
103:
104: /**
105: * @param string $String
106: *
107: * @return IBridgeInterface
108: */
109: public static function getTwigTemplateString($String)
110: {
111:
112: $Template = new Template(
113: new Vendor(
114: new TwigTemplate()
115: )
116: );
117: $Template->getBridgeInterface()->loadString($String, true);
118:
119: return $Template->getBridgeInterface();
120: }
121:
122: /**
123: * @return IVendorInterface
124: */
125: public function getVendorInterface()
126: {
127:
128: return $this->VendorInterface;
129: }
130:
131: /**
132: * @param IVendorInterface $VendorInterface
133: *
134: * @return IVendorInterface
135: */
136: public function setVendorInterface(IVendorInterface $VendorInterface)
137: {
138:
139: $this->VendorInterface = $VendorInterface;
140: return $this;
141: }
142:
143: /**
144: * @param IBridgeInterface $BridgeInterface
145: *
146: * @return IBridgeInterface
147: */
148: public function setBridgeInterface(IBridgeInterface $BridgeInterface)
149: {
150:
151: return $this->VendorInterface->setBridgeInterface($BridgeInterface);
152: }
153: }
154: