pluf2

pluf2 Commit Details


Date:2009-10-11 15:06:38 (15 years 2 months ago)
Author:Loic d'Anterroches
Branch:master
Commit:af5a111ff0ae34682af3714d96d1eff4a22fe44a
Parents: 6987537800d623eb7197b1ff39ca96f8eae4bd00
Message:Added template rendering optimisations.

Changes:

File differences

src/Pluf/Template.php
3232
3333
3434
35
35
3636
3737
3838
......
4848
4949
5050
51
51
5252
5353
5454
5555
56
56
5757
5858
5959
......
6363
6464
6565
66
67
68
69
70
71
72
73
74
75
76
77
6678
6779
6880
......
7587
7688
7789
78
79
80
81
82
83
84
90
8591
8692
8793
8894
8995
9096
91
97
98
9299
93100
94101
......
112119
113120
114121
115
122
123
116124
117125
118126
......
121129
122130
123131
124
132
125133
134
135
126136
127137
128138
......
217227
218228
219229
220
221
222
223
224
225
230
231
232
233
226234
227
228
229
230
231
235
236
237
232238
233239
234240
public $compiled_template = '';
public $template_content = '';
public $context = null;
public $class = '';
/**
* Constructor.
*
function __construct($template, $folders=null, $cache=null)
{
$this->tpl = $template;
if (is_null($folders)) {
if (null == $folders) {
$this->folders = Pluf::f('template_folders');
} else {
$this->folders = $folders;
}
if (is_null($cache)) {
if (null == $cache) {
$this->cache = Pluf::f('tmp_folder');
} else {
$this->cache = $cache;
$GLOBALS['_PX_tests_templates'] = array();
}
}
$this->compiled_template = $this->getCompiledTemplateName();
$b = $this->compiled_template[1];
$this->class = 'Pluf_Template_'.$b;
$this->compiled_template = $this->compiled_template[0];
if (!class_exists($this->class, false)) {
if (!file_exists($this->compiled_template) or Pluf::f('debug')) {
$compiler = new Pluf_Template_Compiler($this->tpl, $this->folders);
$this->template_content = $compiler->getCompiledTemplate();
$this->write($b);
}
include $this->compiled_template;
}
}
/**
if (defined('IN_UNIT_TESTS')) {
$GLOBALS['_PX_tests_templates'][] = $this;
}
$this->compiled_template = $this->getCompiledTemplateName();
if (!file_exists($this->compiled_template) or Pluf::f('debug')) {
$compiler = new Pluf_Template_Compiler($this->tpl, $this->folders);
$this->template_content = $compiler->getCompiledTemplate();
$this->write();
}
if (is_null($c)) {
if (null == $c) {
$c = new Pluf_Template_Context();
}
$this->context = $c;
ob_start();
$t = $c;
try {
include $this->compiled_template;
call_user_func(array($this->class, 'render'), $t);
//include $this->compiled_template;
} catch (Exception $e) {
ob_clean();
throw $e;
// The compiled template not only depends on the file but also
// on the possible folders in which it can be found.
$_tmp = var_export($this->folders, true);
return $this->cache.'/Pluf_Template-'.md5($_tmp.$this->tpl).'.phps';
return array($this->cache.'/Pluf_Template-'.md5($_tmp.$this->tpl).'.phps',
md5($_tmp.$this->tpl));
}
/**
*
* @return bool Success in writing
*/
function write()
function write($name)
{
$this->template_content = '<?php class Pluf_Template_'.$name.' {
public static function render($c) {$t = $c; ?>'.$this->template_content.'<?php } } ';
// mode "a" to not truncate before getting the lock
$fp = @fopen($this->compiled_template, 'a');
if ($fp !== false) {
*/
function Pluf_Template_safeEcho($mixed, $echo=true)
{
if (!is_object($mixed) or 'Pluf_Template_SafeString' !== get_class($mixed)) {
if ($echo) {
echo htmlspecialchars((string) $mixed, ENT_COMPAT, 'UTF-8');
} else {
return htmlspecialchars((string) $mixed, ENT_COMPAT, 'UTF-8');
}
if ($echo) {
echo ('Pluf_Template_SafeString' !== get_class($mixed)) ?
htmlspecialchars($mixed, ENT_COMPAT, 'UTF-8') :
$mixed->value;
} else {
if ($echo) {
echo $mixed->value;
} else {
return $mixed->value;
}
return ('Pluf_Template_SafeString' !== get_class($mixed)) ?
htmlspecialchars($mixed, ENT_COMPAT, 'UTF-8') :
$mixed->value;
}
}
src/Pluf/Template/Compiler.php
622622
623623
624624
625
625
626
626627
627628
628629
if ($type == T_STRING && $inDot) {
$result .= $str;
} elseif ($type == T_VARIABLE) {
$result .= '$t->_vars[\''.substr($str, 1).'\']';
//$result .= '$t->_vars[\''.substr($str, 1).'\']';
$result .= '$t->_vars->'.substr($str, 1);
} elseif ($type == T_WHITESPACE || in_array($type, $allowed)) {
$result .= $str;
} else {
src/Pluf/Template/ContextVars.php
3030
3131
3232
33
33
34
35
36
37
38
3439
3540
3641
{
return (isset($this[$prop])) ? $this[$prop] : '';
}
function __set($prop, $value)
{
$this[$prop] = $value;
}
function __toString()
{
return var_export($this, true);

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.06744s using 13 queries.