Thunder\Shortcode\Processor\Processor::withMaxIterations PHP Method

withMaxIterations() public method

Maximum number of iterations, null means infinite, any integer greater than zero sets value. Zero is invalid because there must be at least one iteration. Defaults to 1. Loop breaks if result of two consequent iterations shows no change in processed text.
public withMaxIterations ( integer | null $iterations ) : self
$iterations integer | null
return self
    public function withMaxIterations($iterations)
    {
        if (null !== $iterations && !(is_int($iterations) && $iterations > 0)) {
            $msg = 'Maximum number of iterations must be null (infinite) or integer > 0!';
            throw new \InvalidArgumentException($msg);
        }
        $self = clone $this;
        $self->maxIterations = $iterations;
        return $self;
    }

Usage Example

Example #1
0
 public function testPreventInfiniteLoop()
 {
     $handlers = new HandlerContainer();
     $handlers->add('name', function (ShortcodeInterface $s) {
         return $s->getName();
     })->add('content', function (ShortcodeInterface $s) {
         return $s->getContent();
     })->add('reverse', new ReverseShortcode())->addAlias('c', 'content')->addAlias('n', 'name')->add('self', function () {
         return '[self]';
     })->add('other', function () {
         return '[self]';
     })->add('random', function () {
         return '[various]';
     });
     $processor = new Processor(new RegexParser(), $handlers);
     $processor->withMaxIterations(null);
     $processor->process('[self]');
     $processor->process('[other]');
     $processor->process('[random]');
 }
All Usage Examples Of Thunder\Shortcode\Processor\Processor::withMaxIterations