Skip to content

Commit e5e833e

Browse files
authored
feat: add event cache (#8)
* feat: add event cache * feat: update php-actions in workflow * feat: add vendored_behat_path to workflow action * fix: vendored_behat_path * fix: vendored_behat_path * fix: vendored_behat_path * feat: remove php-action/behat and use installed behat * feat: trigger workflow only on pull_request
1 parent 28dba4f commit e5e833e

3 files changed

Lines changed: 26 additions & 15 deletions

File tree

.github/workflows/ci.yml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: CI
22

3-
on: [ push, pull_request ]
3+
on: [ pull_request ]
44

55
jobs:
66
test:
@@ -13,13 +13,13 @@ jobs:
1313
- { php: 7.4, phpunit: 9 }
1414
- { php: 8.0, phpunit: 10 }
1515
- { php: 8.1, phpunit: 10 }
16-
- { php: 8.2, phpunit: 10 }
16+
- { php: 8.2, phpunit: 10, main: true }
1717
- { php: 8.3, phpunit: 10, experimental: true }
1818

1919
steps:
20-
- uses: actions/checkout@v3
20+
- uses: actions/checkout@v4
2121
- name: Composer cache
22-
uses: actions/cache@v3
22+
uses: actions/cache@v4
2323
with:
2424
path: "vendor"
2525
key: ${{ runner.os }}-${{ matrix.env.php }}-composer-${{ hashFiles('composer.json') }}
@@ -37,7 +37,7 @@ jobs:
3737
run: composer install -o --no-interaction --no-suggest --prefer-dist
3838

3939
- name: PHPUnit tests
40-
uses: php-actions/phpunit@v3
40+
uses: php-actions/phpunit@v4
4141
env:
4242
XDEBUG_MODE: coverage
4343
with:
@@ -47,7 +47,7 @@ jobs:
4747
version: "${{ matrix.env.phpunit }}"
4848
configuration: "phpunit.xml"
4949
- name: "Code Coverage Report"
50-
if: "matrix.env.php == '8.2' && github.event_name == 'pull_request'"
50+
if: "matrix.env.main == true && github.event_name == 'pull_request'"
5151
uses: irongut/CodeCoverageSummary@v1.3.0
5252
with:
5353
filename: cobertura.xml
@@ -60,13 +60,12 @@ jobs:
6060
output: both
6161
thresholds: '60 80'
6262
- name: Add Coverage PR Comment
63-
if: "matrix.env.php == '8.2' && github.event_name == 'pull_request'"
63+
if: "matrix.env.main == true && github.event_name == 'pull_request'"
6464
uses: marocchino/sticky-pull-request-comment@v2
6565
with:
6666
recreate: true
6767
path: code-coverage-results.md
6868

6969
- name: Behat tests
70-
uses: php-actions/behat@master
71-
with:
72-
php_version: "${{ matrix.env.php }}"
70+
run: composer run behat
71+

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,8 @@
2727
"Netlogix\\XmlProcessor\\Behat\\": "features/"
2828
}
2929
},
30+
"scripts": {
31+
"behat": "behat"
32+
},
3033
"prefer-stable": true
3134
}

src/XmlProcessor.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class XmlProcessor
1818
private string $currentValue = '';
1919

2020
private ?array $skipNodes = NULL;
21+
private array $eventCache = [];
2122

2223
private \XMLReader $xml;
2324
private XmlProcessorContext $context;
@@ -37,7 +38,9 @@ class XmlProcessor
3738
*/
3839
public function __construct(
3940
iterable $processors,
40-
iterable $parserProperties = []
41+
iterable $parserProperties = [
42+
\XMLReader::VALIDATE => false
43+
]
4144
)
4245
{
4346
$this->xml = new \XMLReader();
@@ -158,13 +161,19 @@ private function getProcessorEvents(string $event, string $contextClass = NodePr
158161
private function getProcessorForEvent(string $event): iterable
159162
{
160163
$nodePath = implode('/', $this->nodePath);
161-
foreach ($this->processors as $processor) {
162-
foreach ($processor->getSubscribedEvents($nodePath, $this->context) as $e => $action) {
163-
if ($e === $event) {
164-
yield $action;
164+
165+
if (!is_array($this->eventCache[$nodePath][$event] ?? false)) {
166+
$this->eventCache[$nodePath][$event] = [];
167+
foreach ($this->processors as $processor) {
168+
foreach ($processor->getSubscribedEvents($nodePath, $this->context) as $e => $action) {
169+
if ($e === $event) {
170+
$this->eventCache[$nodePath][$event][] = $action;
171+
}
165172
}
166173
}
167174
}
175+
176+
yield from $this->eventCache[$nodePath][$event];
168177
}
169178

170179
/**

0 commit comments

Comments
 (0)