close #4
This commit is contained in:
parent
5ac0e03e26
commit
8149c44997
32
TplBlock.php
32
TplBlock.php
|
@ -207,19 +207,6 @@ 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.
|
||||||
*
|
*
|
||||||
|
@ -231,14 +218,6 @@ 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 . ".";
|
||||||
|
|
||||||
|
@ -278,6 +257,17 @@ class TplBlock
|
||||||
$str = preg_replace( "/" .self::STARTENCLOSURE .'([a-z][a-z0-9.]*)' .self::ENDENCLOSURE ."/", '', $str );
|
$str = preg_replace( "/" .self::STARTENCLOSURE .'([a-z][a-z0-9.]*)' .self::ENDENCLOSURE ."/", '', $str );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//check if loops patterns are still presents
|
||||||
|
if (($this->strictMode)
|
||||||
|
&& (
|
||||||
|
preg_match( "/".self::BLOCKSTARTSTART."/", $str)
|
||||||
|
|| preg_match( "/".self::BLOCKENDSTART."/", $str)
|
||||||
|
)
|
||||||
|
){
|
||||||
|
throw new \UnexpectedValueException("Template string not consistent");
|
||||||
|
|
||||||
|
}
|
||||||
return $str;
|
return $str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -183,5 +183,37 @@ class TplBlockTest extends TestCase
|
||||||
$this->assertFalse(strpos("name", $resultWithReplace));
|
$this->assertFalse(strpos("name", $resultWithReplace));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Test if error on non consistent tpl.
|
||||||
|
* @expectedException UnexpectedValueException
|
||||||
|
*/
|
||||||
|
public function testNonConsistentTemplate(){
|
||||||
|
$str = "
|
||||||
|
Bhah blah wpooie456
|
||||||
|
<!-- BEGIN bloc -->
|
||||||
|
have to be shown
|
||||||
|
<!-- BEGIN blocTwo -->
|
||||||
|
SHOULD be shown
|
||||||
|
<!-- END bloc -->
|
||||||
|
WONT to be shown
|
||||||
|
<!-- END blocTwo -->";
|
||||||
|
$tpl = new TplBlock();
|
||||||
|
$tpl->applyTplStr($str);
|
||||||
|
}
|
||||||
|
public function testNonConsistentTemplateNonStrictMode(){
|
||||||
|
$str = "
|
||||||
|
Bhah blah wpooie456
|
||||||
|
<!-- BEGIN bloc -->
|
||||||
|
have to be shown
|
||||||
|
<!-- BEGIN blocTwo -->
|
||||||
|
SHOULD be shown
|
||||||
|
<!-- END bloc -->
|
||||||
|
WONT to be shown
|
||||||
|
<!-- END blocTwo -->";
|
||||||
|
$tpl = new TplBlock();
|
||||||
|
$tpl-> dontStrictMode();
|
||||||
|
$this->assertContains("wpooie456",$tpl-> applyTplStr($str));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user