/** * @see Pluf_Template_Tag::start() * @throws InvalidArgumentException If no argument is provided. */ public function start() { $nargs = func_num_args(); if (1 > $nargs) { throw new InvalidArgumentException('`cycle` tag requires at least one argument'); } $result = ''; list($key, $index) = $this->_computeIndex(func_get_args()); switch ($nargs) { # (array or mixed) argument case 1: $arg = func_get_arg(0); if (is_array($arg)) { $result = $arg[$index % count($arg)]; } else { $result = $arg; } break; # (array) arguments, (string) assign # (array) arguments, (string) assign case 2: $args = func_get_args(); if (is_array($args[0])) { $last = array_pop($args); if (is_string($last) && '' === $this->context->get($last)) { $value = Pluf_Utils::flattenArray($args[0]); $this->context->set($last, $value); list($assign_key, $assign_index) = $this->_computeIndex(array($value)); $result = $value[0]; } break; } # considers all the arguments as a value to use in the cycle # considers all the arguments as a value to use in the cycle default: $args = Pluf_Utils::flattenArray(func_get_args()); $result = $args[$index % count($args)]; break; } echo Pluf_Template::markSafe((string) $result); }