xref: /dokuwiki/_test/tests/Parsing/Lexer/RecordingHandler.php (revision 2e43b79909f3bc04928779d886f68c1242b5d436)
1<?php
2
3namespace dokuwiki\test\Parsing\Lexer;
4
5use dokuwiki\Parsing\Handler;
6
7/**
8 * Handler subclass that records all handleToken calls for later assertion
9 * instead of dispatching to mode objects.
10 */
11class RecordingHandler extends Handler
12{
13    /** @var array[] each entry is [method, match, state, pos] */
14    public array $recorded = [];
15
16    /**
17     * The Lexer tests drive the lexer directly and never go through mode
18     * dispatch, so this handler needs no ModeRegistry. Skip the parent
19     * constructor's registry requirement and just set up the buffers.
20     */
21    public function __construct()
22    {
23        $this->reset();
24    }
25
26    /** @inheritdoc */
27    public function handleToken($modeName, $match, $state, $pos, $originalModeName = '')
28    {
29        $this->recorded[] = [$modeName, $match, $state, $pos];
30        return true;
31    }
32}
33