Copyright 2013-2021 Zordius Chen. All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Origin: https://github.com/zordius/lightncandy
*/
/**
* file to keep LightnCandy Validator
*
* @package LightnCandy
* @author Zordius <zordius@gmail.com>
*/
namespaceLightnCandy;
/**
* LightnCandy Validator
*/
classValidator
{
/**
* Verify template
*
* @param array<string,array|string|integer> $context Current context
$context['error'][]='Bad token '.Token::toString($token).' ! Do you mean '.Token::toString($token,array(Token::POS_BEGINRAW=>'',Token::POS_ENDRAW=>'')).' or '.Token::toString($token,array(Token::POS_BEGINRAW=>'{',Token::POS_ENDRAW=>'}')).'?';
returntrue;
}
// {{{# }}} or {{{! }}} or {{{/ }}} or {{{^ }}} are invalid.
$context['error'][]='Bad token '.Token::toString($token).' ! Do you mean '.Token::toString($token,array(Token::POS_BEGINRAW=>'',Token::POS_ENDRAW=>'')).' ?';
returntrue;
}
}
/**
* Verify operators
*
* @param string $operator the operator string
* @param array<string,array|string|integer> $context current compile context
* @param array<boolean|integer|string|array> $vars parsed arguments list
*
* @return boolean|integer|null Return true when invalid or detected
* @param array<string,array|string|integer> $context current compile context
*
* @return string|array<string,array|string|integer>|null $token string when rawblock; array when valid token require to be compiled, null when skip the token.
* @param array<string,array|string|integer> $context current compile context
* @param array<boolean|integer|string|array> $vars parsed arguments list
*
* @return boolean Return true always
*/
protectedstaticfunctioninline(&$context,$vars)
{
if(!$context['flags']['runpart']){
$context['error'][]="Do not support {{#*{$context['currentToken'][Token::POS_INNERTAG]}}}, you should do compile with LightnCandy::FLAG_RUNTIMEPARTIAL flag";
$context['error'][]="Do not support {{#*{$context['currentToken'][Token::POS_INNERTAG]}}}, now we only support {{#*inline \"partialName\"}}template...{{/inline}}";
}
if(!isset($vars[1][0])){
$context['error'][]="Error in {{#*{$context['currentToken'][Token::POS_INNERTAG]}}}: inline require 1 argument for partial name!";
}
returntrue;
}
/**
* validate partial
*
* @param array<string,array|string|integer> $context current compile context
* @param array<boolean|integer|string|array> $vars parsed arguments list
*
* @return integer|boolean Return 1 or larger number for runtime partial, return true for other case
*/
protectedstaticfunctionpartial(&$context,$vars)
{
if(Parser::isSubExp($vars[0])){
if($context['flags']['runpart']){
return$context['usedFeature']['dynpartial']++;
}else{
$context['error'][]="You use dynamic partial name as '{$vars[0][2]}', this only works with option FLAG_RUNTIMEPARTIAL enabled";
$context['error'][]="Do not support {{>{$context['currentToken'][Token::POS_INNERTAG]}}}, you should do compile with LightnCandy::FLAG_RUNTIMEPARTIAL flag";