Public Member Functions | |
setVariables (array $variables) | |
setIncludeProcessor (array $callback) | |
getIncludeProcessor () | |
filter ($value) | |
varDirective ($construction) | |
includeDirective ($construction) | |
dependDirective ($construction) | |
ifDirective ($construction) | |
Public Attributes | |
const | CONSTRUCTION_PATTERN = '/{{([a-z]{0,10})(.*?)}}/si' |
const | CONSTRUCTION_DEPEND_PATTERN = '/{{depend\s*(.*?)}}(.*?){{\\/depend\s*}}/si' |
const | CONSTRUCTION_IF_PATTERN = '/{{if\s*(.*?)}}(.*?)({{else}}(.*?))?{{\\/if\s*}}/si' |
Protected Member Functions | |
_getIncludeParameters ($value) | |
_getVariable ($value, $default='{no_value_defined}') | |
Protected Attributes | |
$_templateVars = array() | |
$_includeProcessor = null |
Definition at line 35 of file Template.php.
_getIncludeParameters | ( | $ | value | ) | [protected] |
Return associative array of include construction.
string | $value raw parameters |
Definition at line 209 of file Template.php.
00210 { 00211 $tokenizer = new Varien_Filter_Template_Tokenizer_Parameter(); 00212 $tokenizer->setString($value); 00213 $params = $tokenizer->tokenize(); 00214 foreach ($params as $key => $value) { 00215 if (substr($value, 0, 1) === '$') { 00216 $params[$key] = $this->_getVariable(substr($value, 1), null); 00217 } 00218 } 00219 return $params; 00220 }
_getVariable | ( | $ | value | ) | [protected] |
Return variable value for var construction
string | $value raw parameters | |
string | $default default value |
Definition at line 229 of file Template.php.
00229 {no_value_defined}') 00230 { 00231 Varien_Profiler::start("email_template_proccessing_variables"); 00232 $tokenizer = new Varien_Filter_Template_Tokenizer_Variable(); 00233 $tokenizer->setString($value); 00234 $stackVars = $tokenizer->tokenize(); 00235 $result = $default; 00236 $last = 0; 00237 for($i = 0; $i < count($stackVars); $i ++) { 00238 if ($i == 0 && isset($this->_templateVars[$stackVars[$i]['name']])) { 00239 // Getting of template value 00240 $stackVars[$i]['variable'] =& $this->_templateVars[$stackVars[$i]['name']]; 00241 } else if (isset($stackVars[$i-1]['variable']) 00242 && $stackVars[$i-1]['variable'] instanceof Varien_Object) { 00243 // If object calling methods or getting properties 00244 if($stackVars[$i]['type'] == 'property') { 00245 $caller = "get" . uc_words($stackVars[$i]['name'], ''); 00246 if(is_callable(array($stackVars[$i-1]['variable'], $caller))) { 00247 // If specified getter for this property 00248 $stackVars[$i]['variable'] = $stackVars[$i-1]['variable']->$caller(); 00249 } else { 00250 $stackVars[$i]['variable'] = $stackVars[$i-1]['variable'] 00251 ->getData($stackVars[$i]['name']); 00252 } 00253 } else if ($stackVars[$i]['type'] == 'method') { 00254 // Calling of object method 00255 if (is_callable(array($stackVars[$i-1]['variable'], $stackVars[$i]['name'])) || substr($stackVars[$i]['name'],0,3) == 'get') { 00256 $stackVars[$i]['variable'] = call_user_func_array(array($stackVars[$i-1]['variable'], 00257 $stackVars[$i]['name']), 00258 $stackVars[$i]['args']); 00259 } 00260 } 00261 $last = $i; 00262 } 00263 } 00264 00265 if(isset($stackVars[$last]['variable'])) { 00266 // If value for construction exists set it 00267 $result = $stackVars[$last]['variable']; 00268 } 00269 Varien_Profiler::stop("email_template_proccessing_variables"); 00270 return $result; 00271 }
dependDirective | ( | $ | construction | ) |
Definition at line 173 of file Template.php.
00174 { 00175 if (count($this->_templateVars)==0) { 00176 // If template preprocessing 00177 return $construction[0]; 00178 } 00179 00180 if($this->_getVariable($construction[1], '')=='') { 00181 return ''; 00182 } else { 00183 return $construction[2]; 00184 } 00185 }
filter | ( | $ | value | ) |
Filter the string as template.
string | $value |
Definition at line 102 of file Template.php.
00103 { 00104 // "depend" and "if" operands should be first 00105 foreach (array( 00106 self::CONSTRUCTION_DEPEND_PATTERN => 'dependDirective', 00107 self::CONSTRUCTION_IF_PATTERN => 'ifDirective', 00108 ) as $pattern => $directive) { 00109 if (preg_match_all($pattern, $value, $constructions, PREG_SET_ORDER)) { 00110 foreach($constructions as $index => $construction) { 00111 $replacedValue = ''; 00112 $callback = array($this, $directive); 00113 if(!is_callable($callback)) { 00114 continue; 00115 } 00116 try { 00117 $replacedValue = call_user_func($callback, $construction); 00118 } catch (Exception $e) { 00119 throw $e; 00120 } 00121 $value = str_replace($construction[0], $replacedValue, $value); 00122 } 00123 } 00124 } 00125 00126 if(preg_match_all(self::CONSTRUCTION_PATTERN, $value, $constructions, PREG_SET_ORDER)) { 00127 foreach($constructions as $index=>$construction) { 00128 $replacedValue = ''; 00129 $callback = array($this, $construction[1].'Directive'); 00130 if(!is_callable($callback)) { 00131 continue; 00132 } 00133 try { 00134 $replacedValue = call_user_func($callback, $construction); 00135 } catch (Exception $e) { 00136 throw $e; 00137 } 00138 $value = str_replace($construction[0], $replacedValue, $value); 00139 } 00140 } 00141 return $value; 00142 }
getIncludeProcessor | ( | ) |
Sets the proccessor of includes.
Definition at line 91 of file Template.php.
00092 { 00093 return is_callable($this->_includeProcessor) ? $this->_includeProcessor : null; 00094 }
ifDirective | ( | $ | construction | ) |
Definition at line 187 of file Template.php.
00188 { 00189 if (count($this->_templateVars) == 0) { 00190 return $construction[0]; 00191 } 00192 00193 if($this->_getVariable($construction[1], '') == '') { 00194 if (isset($construction[3]) && isset($construction[4])) { 00195 return $construction[4]; 00196 } 00197 return ''; 00198 } else { 00199 return $construction[2]; 00200 } 00201 }
includeDirective | ( | $ | construction | ) |
Definition at line 156 of file Template.php.
00157 { 00158 // Processing of {include template=... [...]} statement 00159 $includeParameters = $this->_getIncludeParameters($construction[2]); 00160 if(!isset($includeParameters['template']) or !$this->getIncludeProcessor()) { 00161 // Not specified template or not seted include processor 00162 $replacedValue = '{' . __('Error in include processing') . '}'; 00163 } else { 00164 // Including of template 00165 $templateCode = $includeParameters['template']; 00166 unset($includeParameters['template']); 00167 $includeParameters = array_merge_recursive($includeParameters, $this->_templateVars); 00168 $replacedValue = call_user_func($this->getIncludeProcessor(), $templateCode, $includeParameters); 00169 } 00170 return $replacedValue; 00171 }
setIncludeProcessor | ( | array $ | callback | ) |
Sets the proccessor of includes.
array | $callback it must return string |
Definition at line 80 of file Template.php.
setVariables | ( | array $ | variables | ) |
Sets template variables that's can be called througth {var ...} statement
array | $variables |
Definition at line 67 of file Template.php.
00068 { 00069 foreach($variables as $name=>$value) { 00070 $this->_templateVars[$name] = $value; 00071 } 00072 return $this; 00073 }
varDirective | ( | $ | construction | ) |
Definition at line 145 of file Template.php.
00146 { 00147 if (count($this->_templateVars)==0) { 00148 // If template preprocessing 00149 return $construction[0]; 00150 } 00151 00152 $replacedValue = $this->_getVariable($construction[2], ''); 00153 return $replacedValue; 00154 }
$_includeProcessor = null [protected] |
Definition at line 60 of file Template.php.
$_templateVars = array() [protected] |
Definition at line 53 of file Template.php.
const CONSTRUCTION_DEPEND_PATTERN = '/{{depend\s*(.*?)}}(.*?){{\\/depend\s*}}/si' |
Cunstruction logic regular expression
Definition at line 45 of file Template.php.
const CONSTRUCTION_IF_PATTERN = '/{{if\s*(.*?)}}(.*?)({{else}}(.*?))?{{\\/if\s*}}/si' |
Definition at line 46 of file Template.php.
const CONSTRUCTION_PATTERN = '/{{([a-z]{0,10})(.*?)}}/si' |
Cunstruction regular expression
Definition at line 40 of file Template.php.