Complex classes like Validator often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Validator, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 25 | class Validator |
||
| 26 | { |
||
| 27 | /** |
||
| 28 | * Verify template |
||
| 29 | * |
||
| 30 | * @param array<string,array|string|integer> $context Current context |
||
| 31 | * @param string $template handlebars template |
||
| 32 | */ |
||
| 33 | 795 | public static function verify(&$context, $template) |
|
| 71 | |||
| 72 | /** |
||
| 73 | * push left string of current token and clear it |
||
| 74 | * |
||
| 75 | * @param array<string,array|string|integer> $context Current context |
||
| 76 | */ |
||
| 77 | 782 | protected static function pushLeft(&$context) |
|
| 83 | |||
| 84 | /** |
||
| 85 | * push a string into the partial stacks |
||
| 86 | * |
||
| 87 | * @param array<string,array|string|integer> $context Current context |
||
| 88 | * @param string $append a string to be appended int partial stacks |
||
| 89 | */ |
||
| 90 | 784 | protected static function pushPartial(&$context, $append) |
|
| 98 | |||
| 99 | /** |
||
| 100 | * push a token into the stack when it is not empty string |
||
| 101 | * |
||
| 102 | * @param array<string,array|string|integer> $context Current context |
||
| 103 | * @param string|array $token a parsed token or a string |
||
| 104 | */ |
||
| 105 | 795 | protected static function pushToken(&$context, $token) |
|
| 129 | |||
| 130 | /** |
||
| 131 | * push current token into the section stack |
||
| 132 | * |
||
| 133 | * @param array<string,array|string|integer> $context Current context |
||
| 134 | * @param string $operation operation string |
||
| 135 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 136 | */ |
||
| 137 | 395 | protected static function pushStack(&$context, $operation, $vars) |
|
| 138 | { |
||
| 139 | 395 | list($levels, $spvar, $var) = Expression::analyze($context, $vars[0]); |
|
| 140 | 395 | $context['stack'][] = $context['currentToken'][Token::POS_INNERTAG]; |
|
| 141 | 395 | $context['stack'][] = Expression::toString($levels, $spvar, $var); |
|
| 142 | 395 | $context['stack'][] = $operation; |
|
| 143 | 395 | $context['level']++; |
|
| 144 | 395 | } |
|
| 145 | |||
| 146 | /** |
||
| 147 | * Verify delimiters and operators |
||
| 148 | * |
||
| 149 | * @param string[] $token detected handlebars {{ }} token |
||
| 150 | * @param array<string,array|string|integer> $context current compile context |
||
| 151 | * |
||
| 152 | * @return boolean|null Return true when invalid |
||
| 153 | * |
||
| 154 | * @expect null when input array_fill(0, 11, ''), array() |
||
| 155 | * @expect null when input array(0, 0, 0, 0, 0, '{{', '#', '...', '}}'), array() |
||
| 156 | * @expect true when input array(0, 0, 0, 0, 0, '{', '#', '...', '}'), array() |
||
| 157 | */ |
||
| 158 | 783 | protected static function delimiter($token, &$context) |
|
| 159 | { |
||
| 160 | // {{ }}} or {{{ }} are invalid |
||
| 161 | 783 | if (strlen($token[Token::POS_BEGINRAW]) !== strlen($token[Token::POS_ENDRAW])) { |
|
| 162 | 6 | $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 => '}')) . '?'; |
|
| 163 | 6 | return true; |
|
| 164 | } |
||
| 165 | // {{{# }}} or {{{! }}} or {{{/ }}} or {{{^ }}} are invalid. |
||
| 166 | 777 | if ((strlen($token[Token::POS_BEGINRAW]) == 1) && $token[Token::POS_OP] && ($token[Token::POS_OP] !== '&')) { |
|
| 167 | 5 | $context['error'][] = 'Bad token ' . Token::toString($token) . ' ! Do you mean ' . Token::toString($token, array(Token::POS_BEGINRAW => '', Token::POS_ENDRAW => '')) . ' ?'; |
|
| 168 | 5 | return true; |
|
| 169 | } |
||
| 170 | 773 | } |
|
| 171 | |||
| 172 | /** |
||
| 173 | * Verify operators |
||
| 174 | * |
||
| 175 | * @param string $operator the operator string |
||
| 176 | * @param array<string,array|string|integer> $context current compile context |
||
| 177 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 178 | * |
||
| 179 | * @return boolean|integer|null Return true when invalid or detected |
||
| 180 | * |
||
| 181 | * @expect null when input '', array(), array() |
||
| 182 | * @expect 2 when input '^', array('usedFeature' => array('isec' => 1), 'level' => 0, 'currentToken' => array(0,0,0,0,0,0,0,0), 'elselvl' => array(), 'flags' => array('spvar' => 0), 'elsechain' => false, 'helperresolver' => 0), array(array('foo')) |
||
| 183 | * @expect true when input '/', array('stack' => array('[with]', '#'), 'level' => 1, 'currentToken' => array(0,0,0,0,0,0,0,'with'), 'flags' => array('nohbh' => 0)), array(array()) |
||
| 184 | * @expect 4 when input '#', array('usedFeature' => array('sec' => 3), 'level' => 0, 'currentToken' => array(0,0,0,0,0,0,0,0), 'flags' => array('spvar' => 0), 'elsechain' => false, 'elselvl' => array(), 'helperresolver' => 0), array(array('x')) |
||
| 185 | * @expect 5 when input '#', array('usedFeature' => array('if' => 4), 'level' => 0, 'currentToken' => array(0,0,0,0,0,0,0,0), 'flags' => array('spvar' => 0, 'nohbh' => 0), 'elsechain' => false, 'elselvl' => array(), 'helperresolver' => 0), array(array('if')) |
||
| 186 | * @expect 6 when input '#', array('usedFeature' => array('with' => 5), 'level' => 0, 'flags' => array('nohbh' => 0, 'runpart' => 0, 'spvar' => 0), 'currentToken' => array(0,0,0,0,0,0,0,0), 'elsechain' => false, 'elselvl' => array(), 'helperresolver' => 0), array(array('with')) |
||
| 187 | * @expect 7 when input '#', array('usedFeature' => array('each' => 6), 'level' => 0, 'currentToken' => array(0,0,0,0,0,0,0,0), 'flags' => array('spvar' => 0, 'nohbh' => 0), 'elsechain' => false, 'elselvl' => array(), 'helperresolver' => 0), array(array('each')) |
||
| 188 | * @expect 8 when input '#', array('usedFeature' => array('unless' => 7), 'level' => 0, 'currentToken' => array(0,0,0,0,0,0,0,0), 'flags' => array('spvar' => 0, 'nohbh' => 0), 'elsechain' => false, 'elselvl' => array(), 'helperresolver' => 0), array(array('unless')) |
||
| 189 | * @expect 9 when input '#', array('helpers' => array('abc' => ''), 'usedFeature' => array('helper' => 8), 'level' => 0, 'currentToken' => array(0,0,0,0,0,0,0,0), 'flags' => array('spvar' => 0), 'elsechain' => false, 'elselvl' => array()), array(array('abc')) |
||
| 190 | * @expect 11 when input '#', array('helpers' => array('abc' => ''), 'usedFeature' => array('helper' => 10), 'level' => 0, 'currentToken' => array(0,0,0,0,0,0,0,0), 'flags' => array('spvar' => 0), 'elsechain' => false, 'elselvl' => array()), array(array('abc')) |
||
| 191 | * @expect true when input '>', array('partialresolver' => false, 'usedFeature' => array('partial' => 7), 'level' => 0, 'flags' => array('skippartial' => 0, 'runpart' => 0, 'spvar' => 0), 'currentToken' => array(0,0,0,0,0,0,0,0), 'elsechain' => false, 'elselvl' => array()), array('test') |
||
| 192 | */ |
||
| 193 | 744 | protected static function operator($operator, &$context, &$vars) |
|
| 194 | { |
||
| 195 | 744 | switch ($operator) { |
|
| 196 | 744 | case '#*': |
|
| 197 | 16 | if (!$context['compile']) { |
|
| 198 | 16 | $context['stack'][] = count($context['parsed'][0]) + ($context['currentToken'][Token::POS_LOTHER] . $context['currentToken'][Token::POS_LSPACE] === '' ? 0 : 1); |
|
| 199 | 16 | static::pushStack($context, '#*', $vars); |
|
| 200 | } |
||
| 201 | 16 | return static::inline($context, $vars); |
|
| 202 | |||
| 203 | 741 | case '#>': |
|
| 204 | 28 | if (!$context['compile']) { |
|
| 205 | 28 | $context['stack'][] = count($context['parsed'][0]) + ($context['currentToken'][Token::POS_LOTHER] . $context['currentToken'][Token::POS_LSPACE] === '' ? 0 : 1); |
|
| 206 | 28 | $vars[Parser::PARTIALBLOCK] = ++$context['usedFeature']['pblock']; |
|
| 207 | 28 | static::pushStack($context, '#>', $vars); |
|
| 208 | } |
||
| 209 | // no break |
||
| 210 | 733 | case '>': |
|
| 211 | 119 | return static::partial($context, $vars); |
|
| 212 | |||
| 213 | 685 | case '^': |
|
| 214 | 64 | if (!isset($vars[0][0])) { |
|
| 215 | 24 | if (!$context['flags']['else']) { |
|
| 216 | 1 | $context['error'][] = 'Do not support {{^}}, you should do compile with LightnCandy::FLAG_ELSE flag'; |
|
| 217 | 1 | return; |
|
| 218 | } else { |
||
| 219 | 23 | return static::doElse($context, $vars); |
|
| 220 | } |
||
| 221 | } |
||
| 222 | |||
| 223 | 40 | static::doElseChain($context); |
|
| 224 | |||
| 225 | 40 | if (static::isBlockHelper($context, $vars)) { |
|
| 226 | 1 | static::pushStack($context, '#', $vars); |
|
| 227 | 1 | return static::blockCustomHelper($context, $vars, true); |
|
| 228 | } |
||
| 229 | |||
| 230 | 39 | static::pushStack($context, '^', $vars); |
|
| 231 | 39 | return static::invertedSection($context, $vars); |
|
| 232 | |||
| 233 | 685 | case '/': |
|
| 234 | 362 | $r = static::blockEnd($context, $vars); |
|
| 235 | 362 | if ($r !== Token::POS_BACKFILL) { |
|
| 236 | 362 | array_pop($context['stack']); |
|
| 237 | 362 | array_pop($context['stack']); |
|
| 238 | 362 | array_pop($context['stack']); |
|
| 239 | } |
||
| 240 | 362 | return $r; |
|
| 241 | |||
| 242 | 660 | case '#': |
|
| 243 | 338 | static::doElseChain($context); |
|
| 244 | 338 | static::pushStack($context, '#', $vars); |
|
| 245 | |||
| 246 | 338 | if (static::isBlockHelper($context, $vars)) { |
|
| 247 | 64 | return static::blockCustomHelper($context, $vars); |
|
| 248 | } |
||
| 249 | |||
| 250 | 283 | return static::blockBegin($context, $vars); |
|
| 251 | } |
||
| 252 | 556 | } |
|
| 253 | |||
| 254 | /** |
||
| 255 | * validate inline partial begin token |
||
| 256 | * |
||
| 257 | * @param array<string,array|string|integer> $context current compile context |
||
| 258 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 259 | * |
||
| 260 | * @return boolean|null Return true when inline partial ends |
||
| 261 | */ |
||
| 262 | 743 | protected static function inlinePartial(&$context, $vars) |
|
| 281 | |||
| 282 | /** |
||
| 283 | * validate partial block token |
||
| 284 | * |
||
| 285 | * @param array<string,array|string|integer> $context current compile context |
||
| 286 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 287 | * |
||
| 288 | * @return boolean|null Return true when partial block ends |
||
| 289 | */ |
||
| 290 | 743 | protected static function partialBlock(&$context, $vars) |
|
| 316 | |||
| 317 | /** |
||
| 318 | * handle else chain |
||
| 319 | * |
||
| 320 | * @param array<string,array|string|integer> $context current compile context |
||
| 321 | */ |
||
| 322 | 367 | protected static function doElseChain(&$context) |
|
| 323 | { |
||
| 324 | 367 | if ($context['elsechain']) { |
|
| 325 | 14 | $context['elsechain'] = false; |
|
| 326 | } else { |
||
| 327 | 367 | array_unshift($context['elselvl'], array()); |
|
| 328 | } |
||
| 329 | 367 | } |
|
| 330 | |||
| 331 | /** |
||
| 332 | * validate block begin token |
||
| 333 | * |
||
| 334 | * @param array<string,array|string|integer> $context current compile context |
||
| 335 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 336 | * |
||
| 337 | * @return boolean Return true always |
||
| 338 | */ |
||
| 339 | 282 | protected static function blockBegin(&$context, $vars) |
|
| 354 | |||
| 355 | /** |
||
| 356 | * validate builtin helpers |
||
| 357 | * |
||
| 358 | * @param array<string,array|string|integer> $context current compile context |
||
| 359 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 360 | */ |
||
| 361 | 166 | protected static function builtin(&$context, $vars) |
|
| 362 | { |
||
| 363 | 166 | if ($context['flags']['nohbh']) { |
|
| 364 | 8 | if (isset($vars[1][0])) { |
|
| 365 | 8 | $context['error'][] = "Do not support {{#{$vars[0][0]} var}} because you compile with LightnCandy::FLAG_NOHBHELPERS flag"; |
|
| 366 | } |
||
| 367 | } else { |
||
| 368 | 158 | if (count($vars) < 2) { |
|
| 369 | 5 | $context['error'][] = "No argument after {{#{$vars[0][0]}}} !"; |
|
| 370 | } |
||
| 371 | } |
||
| 372 | 166 | $context['usedFeature'][$vars[0][0]]++; |
|
| 373 | 166 | } |
|
| 374 | |||
| 375 | /** |
||
| 376 | * validate section token |
||
| 377 | * |
||
| 378 | * @param array<string,array|string|integer> $context current compile context |
||
| 379 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 380 | * @param boolean $isEach the section is #each |
||
| 381 | * |
||
| 382 | * @return boolean Return true always |
||
| 383 | */ |
||
| 384 | 185 | protected static function section(&$context, $vars, $isEach = false) |
|
| 396 | |||
| 397 | /** |
||
| 398 | * validate with token |
||
| 399 | * |
||
| 400 | * @param array<string,array|string|integer> $context current compile context |
||
| 401 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 402 | * |
||
| 403 | * @return boolean Return true always |
||
| 404 | */ |
||
| 405 | 36 | protected static function with(&$context, $vars) |
|
| 410 | |||
| 411 | /** |
||
| 412 | * validate unless token |
||
| 413 | * |
||
| 414 | * @param array<string,array|string|integer> $context current compile context |
||
| 415 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 416 | * |
||
| 417 | * @return boolean Return true always |
||
| 418 | */ |
||
| 419 | 7 | protected static function unless(&$context, $vars) |
|
| 424 | |||
| 425 | /** |
||
| 426 | * validate if token |
||
| 427 | * |
||
| 428 | * @param array<string,array|string|integer> $context current compile context |
||
| 429 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 430 | * |
||
| 431 | * @return boolean Return true always |
||
| 432 | */ |
||
| 433 | 80 | protected static function doIf(&$context, $vars) |
|
| 438 | |||
| 439 | /** |
||
| 440 | * validate block custom helper token |
||
| 441 | * |
||
| 442 | * @param array<string,array|string|integer> $context current compile context |
||
| 443 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 444 | * @param boolean $inverted the logic will be inverted |
||
| 445 | * |
||
| 446 | * @return integer|null Return number of used custom helpers |
||
| 447 | */ |
||
| 448 | 64 | protected static function blockCustomHelper(&$context, $vars, $inverted = false) |
|
| 449 | { |
||
| 450 | 64 | if (is_string($vars[0][0])) { |
|
| 451 | 64 | if (static::resolveHelper($context, $vars)) { |
|
| 452 | 64 | return ++$context['usedFeature']['helper']; |
|
| 453 | } |
||
| 454 | } |
||
| 455 | } |
||
| 456 | |||
| 457 | /** |
||
| 458 | * validate inverted section |
||
| 459 | * |
||
| 460 | * @param array<string,array|string|integer> $context current compile context |
||
| 461 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 462 | * |
||
| 463 | * @return integer Return number of inverted sections |
||
| 464 | */ |
||
| 465 | 38 | protected static function invertedSection(&$context, $vars) |
|
| 469 | |||
| 470 | /** |
||
| 471 | * Return compiled PHP code for a handlebars block end token |
||
| 472 | * |
||
| 473 | * @param array<string,array|string|integer> $context current compile context |
||
| 474 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 475 | * @param string|null $match should also match to this operator |
||
| 476 | * |
||
| 477 | * @return boolean|integer Return true when required block ended, or Token::POS_BACKFILL when backfill happened. |
||
| 478 | */ |
||
| 479 | 388 | protected static function blockEnd(&$context, &$vars, $match = null) |
|
| 525 | |||
| 526 | /** |
||
| 527 | * handle delimiter change |
||
| 528 | * |
||
| 529 | * @param array<string,array|string|integer> $context current compile context |
||
| 530 | * |
||
| 531 | * @return boolean|null Return true when delimiter changed |
||
| 532 | */ |
||
| 533 | 772 | protected static function isDelimiter(&$context) |
|
| 534 | { |
||
| 535 | 772 | if (preg_match('/^=\s*([^ ]+)\s+([^ ]+)\s*=$/', $context['currentToken'][Token::POS_INNERTAG], $matched)) { |
|
| 536 | 15 | $context['usedFeature']['delimiter']++; |
|
| 537 | 15 | Parser::setDelimiter($context, $matched[1], $matched[2]); |
|
| 538 | 15 | return true; |
|
| 539 | } |
||
| 540 | 763 | } |
|
| 541 | |||
| 542 | /** |
||
| 543 | * handle raw block |
||
| 544 | * |
||
| 545 | * @param string[] $token detected handlebars {{ }} token |
||
| 546 | * @param array<string,array|string|integer> $context current compile context |
||
| 547 | * |
||
| 548 | * @return boolean|null Return true when in rawblock mode |
||
| 549 | */ |
||
| 550 | 782 | protected static function rawblock(&$token, &$context) |
|
| 551 | { |
||
| 552 | 782 | $inner = $token[Token::POS_INNERTAG]; |
|
| 553 | 782 | trim($inner); |
|
| 554 | |||
| 555 | // skip parse when inside raw block |
||
| 556 | 782 | if ($context['rawblock'] && !(($token[Token::POS_BEGINRAW] === '{{') && ($token[Token::POS_OP] === '/') && ($context['rawblock'] === $inner))) { |
|
| 557 | 6 | return true; |
|
| 558 | } |
||
| 559 | |||
| 560 | 782 | $token[Token::POS_INNERTAG] = $inner; |
|
| 561 | |||
| 562 | // Handle raw block |
||
| 563 | 782 | if ($token[Token::POS_BEGINRAW] === '{{') { |
|
| 564 | 9 | if ($token[Token::POS_ENDRAW] !== '}}') { |
|
| 565 | 1 | $context['error'][] = 'Bad token ' . Token::toString($token) . ' ! Do you mean ' . Token::toString($token, array(Token::POS_ENDRAW => '}}')) . ' ?'; |
|
| 566 | } |
||
| 567 | 9 | if ($context['rawblock']) { |
|
| 568 | 6 | Parser::setDelimiter($context); |
|
| 569 | 6 | $context['rawblock'] = false; |
|
| 570 | } else { |
||
| 571 | 9 | if ($token[Token::POS_OP]) { |
|
| 572 | 1 | $context['error'][] = "Wrong raw block begin with " . Token::toString($token) . ' ! Remove "' . $token[Token::POS_OP] . '" to fix this issue.'; |
|
| 573 | } |
||
| 574 | 9 | $context['rawblock'] = $token[Token::POS_INNERTAG]; |
|
| 575 | 9 | Parser::setDelimiter($context); |
|
| 576 | 9 | $token[Token::POS_OP] = '#'; |
|
| 577 | } |
||
| 578 | 9 | $token[Token::POS_ENDRAW] = '}}'; |
|
| 579 | } |
||
| 580 | 782 | } |
|
| 581 | |||
| 582 | /** |
||
| 583 | * handle comment |
||
| 584 | * |
||
| 585 | * @param string[] $token detected handlebars {{ }} token |
||
| 586 | * @param array<string,array|string|integer> $context current compile context |
||
| 587 | * |
||
| 588 | * @return boolean|null Return true when is comment |
||
| 589 | */ |
||
| 590 | 763 | protected static function comment(&$token, &$context) |
|
| 591 | { |
||
| 592 | 763 | if ($token[Token::POS_OP] === '!') { |
|
| 593 | 26 | $context['usedFeature']['comment']++; |
|
| 594 | 26 | return true; |
|
| 595 | } |
||
| 596 | 743 | } |
|
| 597 | |||
| 598 | /** |
||
| 599 | * Collect handlebars usage information, detect template error. |
||
| 600 | * |
||
| 601 | * @param string[] $token detected handlebars {{ }} token |
||
| 602 | * @param array<string,array|string|integer> $context current compile context |
||
| 603 | * |
||
| 604 | * @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. |
||
| 605 | */ |
||
| 606 | 782 | protected static function token(&$token, &$context) |
|
| 683 | |||
| 684 | /** |
||
| 685 | * Return 1 or larger number when else token detected |
||
| 686 | * |
||
| 687 | * @param array<string,array|string|integer> $context current compile context |
||
| 688 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 689 | * |
||
| 690 | * @return integer Return 1 or larger number when else token detected |
||
| 691 | */ |
||
| 692 | 61 | protected static function doElse(&$context, $vars) |
|
| 708 | |||
| 709 | /** |
||
| 710 | * Return true when this is {{log ...}} |
||
| 711 | * |
||
| 712 | * @param array<string,array|string|integer> $context current compile context |
||
| 713 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 714 | * |
||
| 715 | * @return boolean|null Return true when it is custom helper |
||
| 716 | */ |
||
| 717 | 374 | public static function log(&$context, $vars) |
|
| 718 | { |
||
| 719 | 374 | if (isset($vars[0][0]) && ($vars[0][0] === 'log')) { |
|
| 720 | 3 | if (!$context['flags']['nohbh']) { |
|
| 721 | 3 | if (count($vars) < 2) { |
|
| 722 | 1 | $context['error'][] = "No argument after {{log}} !"; |
|
| 723 | } |
||
| 724 | 3 | $context['usedFeature']['log']++; |
|
| 725 | 3 | return true; |
|
| 726 | } |
||
| 727 | } |
||
| 728 | 371 | } |
|
| 729 | |||
| 730 | /** |
||
| 731 | * Return true when this is {{lookup ...}} |
||
| 732 | * |
||
| 733 | * @param array<string,array|string|integer> $context current compile context |
||
| 734 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 735 | * |
||
| 736 | * @return boolean|null Return true when it is custom helper |
||
| 737 | */ |
||
| 738 | 374 | public static function lookup(&$context, $vars) |
|
| 739 | { |
||
| 740 | 374 | if (isset($vars[0][0]) && ($vars[0][0] === 'lookup')) { |
|
| 741 | 7 | if (!$context['flags']['nohbh']) { |
|
| 742 | 7 | if (count($vars) < 2) { |
|
| 743 | 1 | $context['error'][] = "No argument after {{lookup}} !"; |
|
| 744 | 6 | } elseif (count($vars) < 3) { |
|
| 745 | 1 | $context['error'][] = "{{lookup}} requires 2 arguments !"; |
|
| 746 | } |
||
| 747 | 7 | $context['usedFeature']['lookup']++; |
|
| 748 | 7 | return true; |
|
| 749 | } |
||
| 750 | } |
||
| 751 | 367 | } |
|
| 752 | |||
| 753 | /** |
||
| 754 | * Return true when the name is listed in helper table |
||
| 755 | * |
||
| 756 | * @param array<string,array|string|integer> $context current compile context |
||
| 757 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 758 | * @param boolean $checkSubexp true when check for subexpression |
||
| 759 | * |
||
| 760 | * @return boolean Return true when it is custom helper |
||
| 761 | */ |
||
| 762 | 500 | public static function helper(&$context, $vars, $checkSubexp = false) |
|
| 782 | |||
| 783 | /** |
||
| 784 | * use helperresolver to resolve helper, return true when helper founded |
||
| 785 | * |
||
| 786 | * @param array<string,array|string|integer> $context Current context of compiler progress. |
||
| 787 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 788 | * |
||
| 789 | * @return boolean $found helper exists or not |
||
| 790 | */ |
||
| 791 | 669 | public static function resolveHelper(&$context, &$vars) |
|
| 810 | |||
| 811 | /** |
||
| 812 | * detect for block custom helper |
||
| 813 | * |
||
| 814 | * @param array<string,array|string|integer> $context current compile context |
||
| 815 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 816 | * |
||
| 817 | * @return boolean|null Return true when this token is block custom helper |
||
| 818 | */ |
||
| 819 | 367 | protected static function isBlockHelper($context, $vars) |
|
| 831 | |||
| 832 | /** |
||
| 833 | * validate inline partial |
||
| 834 | * |
||
| 835 | * @param array<string,array|string|integer> $context current compile context |
||
| 836 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 837 | * |
||
| 838 | * @return boolean Return true always |
||
| 839 | */ |
||
| 840 | 16 | protected static function inline(&$context, $vars) |
|
| 853 | |||
| 854 | /** |
||
| 855 | * validate partial |
||
| 856 | * |
||
| 857 | * @param array<string,array|string|integer> $context current compile context |
||
| 858 | * @param array<boolean|integer|string|array> $vars parsed arguments list |
||
| 859 | * |
||
| 860 | * @return integer|boolean Return 1 or larger number for runtime partial, return true for other case |
||
| 861 | */ |
||
| 862 | 118 | protected static function partial(&$context, $vars) |
|
| 885 | |||
| 886 | /** |
||
| 887 | * Modify $token when spacing rules matched. |
||
| 888 | * |
||
| 889 | * @param array<string> $token detected handlebars {{ }} token |
||
| 890 | * @param array<string,array|string|integer> $context current compile context |
||
| 891 | * @param boolean $nost do not do stand alone logic |
||
| 892 | * |
||
| 893 | * @return string|null Return compiled code segment for the token |
||
| 894 | */ |
||
| 895 | 772 | protected static function spacing(&$token, &$context, $nost = false) |
|
| 896 | { |
||
| 948 | } |
||
| 949 |