Skip to content

Commit 2946be1

Browse files
committed
updated README with iterative processing docs
1 parent ebed689 commit 2946be1

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ assert('sth {"name":"spl","parameters":{"arg":"val"},"content":"cnt"} end'
8686
=== $processor->process('sth [spl arg=val]cnt[/spl] end');
8787
```
8888

89-
Recursive shortcode processing is enabled by default, use `Processor::setRecursion($status)` to control that behavior:
89+
Recursive shortcode processing is enabled by default, use `Processor::setRecursion($status)` and `Processor::setRecursionDepth($depth)` to control that behavior:
9090

9191
```
9292
$processor->addHandler('c', function(Shortcode $s) { return $s->getContent() })
@@ -96,6 +96,24 @@ $processor->setRecursion(false);
9696
assert('x[d]y[/d]z' === $processor->process('[c]x[d]y[/d]z[/c]'))
9797
```
9898

99+
Default number of iterations is `1`, but this can be controlled using `Processor::setMaxIterations()`:
100+
101+
```
102+
$processor->addHandler('c', function(Shortcode $s) { return $s->getContent() })
103+
$processor->addHandlerAlias('d', 'c');
104+
$processor->addHandlerAlias('e', 'c');
105+
$processor->setRecursionDepth(0);
106+
107+
$processor->setMaxIterations(1);
108+
assert("ab[d]cd[/d]e" === $processor->process('a[c]b[d]c[/c]d[/d]e'));
109+
110+
$processor->setMaxIterations(2);
111+
assert("ab[e]c[/e]de" === $processor->process('[c]a[d]b[e]c[/e]d[/d]e[/c]'));
112+
113+
$processor->setMaxIterations(null);
114+
assert('abcde' === $processor->process('[c]a[d]b[e]c[/e]d[/d]e[/c]'));
115+
```
116+
99117
**Extraction**
100118

101119
Create instance of class `Extractor` and use its `extract()` method to get array of shortcode matches:
@@ -173,7 +191,6 @@ Looking for contribution ideas? Here you are:
173191
* specialized parameter values (`array=value,value`, `map=key:value,key:value`),
174192
* shortcode validators and strict mode,
175193
* forced self-closing tags (`[code /][code]x[/code]` parsed as two matches),
176-
* iterative processing (`[c]x[c]y[/c]z[/c]` > `x[c]yz[/c]` > `xyz`),
177194
* ...your idea?
178195

179196
## License

tests/ProcessorTest.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,20 @@ public function testExceptionOnInvalidRecursionDepth()
109109
$processor->setRecursionDepth(new \stdClass());
110110
}
111111

112+
public function testExceptionOnInvalidMaxIterations()
113+
{
114+
$processor = $this->getProcessor();
115+
$this->setExpectedException('InvalidArgumentException');
116+
$processor->setMaxIterations(new \stdClass());
117+
}
118+
112119
public function testPreventInfiniteLoop()
113120
{
114121
$processor = $this
115122
->getProcessor()
116-
->addHandler('self', function(Shortcode $s) { return '[self]'; })
117-
->addHandler('other', function(Shortcode $s) { return '[self]'; })
118-
->addHandler('random', function(Shortcode $s) { return '[various]'; })
123+
->addHandler('self', function() { return '[self]'; })
124+
->addHandler('other', function() { return '[self]'; })
125+
->addHandler('random', function() { return '[various]'; })
119126
->setMaxIterations(null);
120127

121128
$processor->process('[self]');

0 commit comments

Comments
 (0)