diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9ee77cc..c3cdb08 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,6 @@ name: CI -on: [ push, pull_request ] +on: [ pull_request ] jobs: test: @@ -13,13 +13,13 @@ jobs: - { php: 7.4, phpunit: 9 } - { php: 8.0, phpunit: 10 } - { php: 8.1, phpunit: 10 } - - { php: 8.2, phpunit: 10 } + - { php: 8.2, phpunit: 10, main: true } - { php: 8.3, phpunit: 10, experimental: true } steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Composer cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: "vendor" key: ${{ runner.os }}-${{ matrix.env.php }}-composer-${{ hashFiles('composer.json') }} @@ -37,7 +37,7 @@ jobs: run: composer install -o --no-interaction --no-suggest --prefer-dist - name: PHPUnit tests - uses: php-actions/phpunit@v3 + uses: php-actions/phpunit@v4 env: XDEBUG_MODE: coverage with: @@ -47,7 +47,7 @@ jobs: version: "${{ matrix.env.phpunit }}" configuration: "phpunit.xml" - name: "Code Coverage Report" - if: "matrix.env.php == '8.2' && github.event_name == 'pull_request'" + if: "matrix.env.main == true && github.event_name == 'pull_request'" uses: irongut/CodeCoverageSummary@v1.3.0 with: filename: cobertura.xml @@ -60,13 +60,12 @@ jobs: output: both thresholds: '60 80' - name: Add Coverage PR Comment - if: "matrix.env.php == '8.2' && github.event_name == 'pull_request'" + if: "matrix.env.main == true && github.event_name == 'pull_request'" uses: marocchino/sticky-pull-request-comment@v2 with: recreate: true path: code-coverage-results.md - name: Behat tests - uses: php-actions/behat@master - with: - php_version: "${{ matrix.env.php }}" + run: composer run behat + diff --git a/composer.json b/composer.json index dd19a77..d3678df 100644 --- a/composer.json +++ b/composer.json @@ -27,5 +27,8 @@ "Netlogix\\XmlProcessor\\Behat\\": "features/" } }, + "scripts": { + "behat": "behat" + }, "prefer-stable": true } diff --git a/src/XmlProcessor.php b/src/XmlProcessor.php index 703cc3b..78886f6 100644 --- a/src/XmlProcessor.php +++ b/src/XmlProcessor.php @@ -18,6 +18,7 @@ class XmlProcessor private string $currentValue = ''; private ?array $skipNodes = NULL; + private array $eventCache = []; private \XMLReader $xml; private XmlProcessorContext $context; @@ -37,7 +38,9 @@ class XmlProcessor */ public function __construct( iterable $processors, - iterable $parserProperties = [] + iterable $parserProperties = [ + \XMLReader::VALIDATE => false + ] ) { $this->xml = new \XMLReader(); @@ -158,13 +161,19 @@ private function getProcessorEvents(string $event, string $contextClass = NodePr private function getProcessorForEvent(string $event): iterable { $nodePath = implode('/', $this->nodePath); - foreach ($this->processors as $processor) { - foreach ($processor->getSubscribedEvents($nodePath, $this->context) as $e => $action) { - if ($e === $event) { - yield $action; + + if (!is_array($this->eventCache[$nodePath][$event] ?? false)) { + $this->eventCache[$nodePath][$event] = []; + foreach ($this->processors as $processor) { + foreach ($processor->getSubscribedEvents($nodePath, $this->context) as $e => $action) { + if ($e === $event) { + $this->eventCache[$nodePath][$event][] = $action; + } } } } + + yield from $this->eventCache[$nodePath][$event]; } /**