|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* View |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright (c) Garrett Whitehorn (http://garrettw.net/) |
|
6
|
|
|
* @license http://opensource.org/licenses/MIT MIT License |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Pimf\View; |
|
10
|
|
|
|
|
11
|
|
|
use Pimf\Contracts\Reunitable; |
|
12
|
|
|
use Pimf\View; |
|
13
|
|
|
use Pimf\Config; |
|
14
|
|
|
use Pimf\Cache\Storages\File as FileCache; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* A view for the Transphporm template engine which uses CSS-style syntax and |
|
18
|
|
|
* separates templates from data logic. |
|
19
|
|
|
* |
|
20
|
|
|
* For use please add the following code to the end of the config.app.php file: |
|
21
|
|
|
* |
|
22
|
|
|
* <code> |
|
23
|
|
|
* |
|
24
|
|
|
* 'view' => array( |
|
25
|
|
|
* |
|
26
|
|
|
* 'transphporm' => array( |
|
27
|
|
|
* 'cache' => true, // if compilation caching should be used |
|
28
|
|
|
* ), |
|
29
|
|
|
* |
|
30
|
|
|
* ), |
|
31
|
|
|
* |
|
32
|
|
|
* </code> |
|
33
|
|
|
* |
|
34
|
|
|
* @link https://github.com/Level-2/Transphporm |
|
35
|
|
|
* @package View |
|
36
|
|
|
* @author Garrett Whitehorn <[email protected]> |
|
37
|
|
|
* @codeCoverageIgnore |
|
38
|
|
|
*/ |
|
39
|
|
|
class Transphporm extends View implements Reunitable |
|
40
|
|
|
{ |
|
41
|
|
|
/** |
|
42
|
|
|
* @var \Pimf\Cache\Storages\File |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $cache; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param string $template |
|
48
|
|
|
* @param array $data |
|
49
|
|
|
*/ |
|
50
|
|
|
public function __construct($template, array $data = []) |
|
51
|
|
|
{ |
|
52
|
|
|
parent::__construct($template, $data); |
|
53
|
|
|
|
|
54
|
|
|
$conf = Config::get('view.transphporm'); |
|
55
|
|
|
|
|
56
|
|
|
if ($conf['cache'] === true) { |
|
57
|
|
|
$this->cache = new FileCache($this->path . '/transphporm_cache/'); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
require_once BASE_PATH . "Transphporm/vendor/autoload.php"; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Puts the template and the TSS/data together. |
|
65
|
|
|
* |
|
66
|
|
|
* @return string |
|
67
|
|
|
*/ |
|
68
|
|
|
public function reunite() |
|
69
|
|
|
{ |
|
70
|
|
|
$xml = $this->template; |
|
71
|
|
|
$xmlpath = $this->path . '/' . $xml; |
|
72
|
|
|
|
|
73
|
|
|
$tss = $this->data['tss']; |
|
74
|
|
|
$tsspath = $this->path . '/' . $tss; |
|
75
|
|
|
|
|
76
|
|
|
$template = new \Transphporm\Builder( |
|
77
|
|
|
(is_file($xmlpath)) ? $xmlpath : $xml, |
|
78
|
|
|
(is_file($tsspath)) ? $tsspath : $tss |
|
79
|
|
|
); |
|
80
|
|
|
|
|
81
|
|
|
if (isset($this->cache)) { |
|
82
|
|
|
$template->setCache($this->cache); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
if (isset($this->data['data'])) { |
|
86
|
|
|
return $template->output($this->data['data'])->body; |
|
87
|
|
|
} |
|
88
|
|
|
return $template->output()->body; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|