Work in progress
This commit is contained in:
parent
12f8191001
commit
4e3f67c36c
50
TplBlock.php
50
TplBlock.php
|
@ -107,6 +107,12 @@ class TplBlock
|
||||||
*/
|
*/
|
||||||
private $replaceNonGivenVars = true;
|
private $replaceNonGivenVars = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use strict mode?
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
private $strictMode = true;
|
||||||
/**
|
/**
|
||||||
* Initialize TplBlock
|
* Initialize TplBlock
|
||||||
*
|
*
|
||||||
|
@ -200,6 +206,19 @@ class TplBlock
|
||||||
. '/is';
|
. '/is';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make some tests to check template consistency.
|
||||||
|
* Return error message if needed, return 1 otherwise.
|
||||||
|
*
|
||||||
|
* @param string $str the string to check
|
||||||
|
* @return string message
|
||||||
|
*/
|
||||||
|
public function checkConsistency($str){
|
||||||
|
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shake the template string and input vars then returns the parsed text.
|
* Shake the template string and input vars then returns the parsed text.
|
||||||
*
|
*
|
||||||
|
@ -211,6 +230,14 @@ class TplBlock
|
||||||
*/
|
*/
|
||||||
public function applyTplStr($str, $subBlocsPath = "")
|
public function applyTplStr($str, $subBlocsPath = "")
|
||||||
{
|
{
|
||||||
|
if($this->strictMode){
|
||||||
|
$consistency = self::checkConsistency($str);
|
||||||
|
if($consistency <> 1 ){
|
||||||
|
throw new \UnexpectedValueException($consistency);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Replace all simple vars.
|
// Replace all simple vars.
|
||||||
$prefix = $subBlocsPath === "" ? "" : $subBlocsPath . ".";
|
$prefix = $subBlocsPath === "" ? "" : $subBlocsPath . ".";
|
||||||
|
|
||||||
|
@ -315,4 +342,27 @@ class TplBlock
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable mode strict. If template is inconsistent, will throw an exception
|
||||||
|
* and return nothing
|
||||||
|
*
|
||||||
|
* @return TplBlock For chaining.
|
||||||
|
*/
|
||||||
|
public function doStrictMode()
|
||||||
|
{
|
||||||
|
$this->strictMode = true;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable mode strict. If template is inconsistent, will be parsed anyway.
|
||||||
|
* and no errors will be returned.
|
||||||
|
*
|
||||||
|
* @return TplBlock For chaining.
|
||||||
|
*/
|
||||||
|
public function dontStrictMode(){
|
||||||
|
$this->strictMode = false;
|
||||||
|
return $this;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user