| Total Complexity | 5 |
| Total Lines | 43 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 5 | trait CallbackTrait |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * List of ordinary callbacks to process. |
||
| 9 | * |
||
| 10 | * @var callable[] |
||
| 11 | */ |
||
| 12 | private $customCallbacks = []; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Add a callback to this match, to be called after parsing is finished and |
||
| 16 | * only if this match was part of the matched rules. |
||
| 17 | * |
||
| 18 | * @param callable $callback |
||
| 19 | * |
||
| 20 | * @return $this |
||
| 21 | */ |
||
| 22 | 401 | public function addCustomCallback(callable $callback) |
|
| 23 | { |
||
| 24 | 401 | $this->customCallbacks[] = $callback; |
|
| 25 | |||
| 26 | 401 | return $this; |
|
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Handle all registered custom callbacks for this match and any matches |
||
| 31 | * at deeper levels of this match. |
||
| 32 | */ |
||
| 33 | 373 | private function processCustomCallbacks() |
|
| 34 | { |
||
| 35 | /** @var self $success */ |
||
| 36 | 373 | foreach ($this->successes as $success) { |
|
| 37 | 241 | $success->processCustomCallbacks(); |
|
| 38 | } |
||
| 39 | |||
| 40 | 373 | foreach ($this->customCallbacks as $callback) { |
|
| 41 | 371 | $callback(); |
|
| 42 | } |
||
| 43 | 373 | } |
|
| 44 | |||
| 45 | 373 | public function getCallback() |
|
| 48 | 373 | } |
|
| 49 | } |
||
| 50 |