/** * Tag {cycle} * * @param Tokenizer $tokens * @param Template $tpl * @return string * @throws InvalidUsageException */ public static function tagCycle(Tokenizer $tokens, Template $tpl) { if ($tokens->is("[")) { $exp = $tpl->parseArray($tokens); } else { $exp = $tpl->parseExpr($tokens); } if ($tokens->valid()) { $p = $tpl->parseParams($tokens); if (empty($p["index"])) { throw new InvalidUsageException("Cycle may contain only index attribute"); } else { return 'echo ' . __CLASS__ . '::cycle(' . $exp . ', ' . $p["index"] . ')'; } } else { $var = $tpl->tmpVar(); return 'echo ' . __CLASS__ . '::cycle(' . $exp . ", isset({$var}) ? ++{$var} : ({$var} = 0) )"; } }