Work in progress

This commit is contained in:
Gnieark 2018-03-26 08:12:01 +02:00
parent 12f8191001
commit 4e3f67c36c

View File

@ -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 . ".";
@ -314,5 +341,28 @@ class TplBlock
return $this; return $this;
} }
/**
* 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;
}
} }