Mark V
1: <?php
2: namespace MOC\V\Component\Template\Component\Bridge\Repository;
3:
4: use MOC\V\Component\Template\Component\Bridge\Bridge;
5: use MOC\V\Component\Template\Component\IBridgeInterface;
6: use MOC\V\Component\Template\Component\Parameter\Repository\FileParameter;
7:
8: /**
9: * Class SmartyTemplate
10: *
11: * @package MOC\V\Component\Template\Component\Bridge
12: */
13: class SmartyTemplate extends Bridge implements IBridgeInterface
14: {
15:
16: /** @var \Smarty $Instance */
17: private $Instance = null;
18: /** @var string $Template */
19: private $Template = null;
20:
21: /**
22: *
23: */
24: public function __construct()
25: {
26:
27: if (!defined('SMARTY_DIR')) {
28: define('SMARTY_DIR', realpath(__DIR__.'/../../../Vendor/Smarty/').DIRECTORY_SEPARATOR);
29: }
30: /** @noinspection PhpIncludeInspection */
31: require_once( SMARTY_DIR.'Smarty.class.php' );
32: }
33:
34: /**
35: * @param FileParameter $Location
36: * @param bool $Reload
37: *
38: * @return IBridgeInterface
39: */
40: public function loadFile(FileParameter $Location, $Reload = false)
41: {
42:
43: $this->createInstance($Reload);
44: $this->Template = $Location->getFile();
45: return $this;
46: }
47:
48: /**
49: * @param bool|false $Reload
50: *
51: * @return \Smarty
52: */
53: public function createInstance($Reload = false)
54: {
55:
56: $this->Instance = new \Smarty();
57: $this->Instance->caching = !$Reload;
58: $this->Instance->compile_dir = __DIR__.'/SmartyTemplate';
59: $this->Instance->cache_dir = __DIR__.'/SmartyTemplate';
60: return $this->Instance;
61: }
62:
63: /**
64: * @return string
65: */
66: public function getContent()
67: {
68:
69: $this->Instance->assign($this->VariableList, null, true);
70: return $this->Instance->fetch($this->Template);
71: }
72:
73: }
74: