Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@
fail-fast: false
matrix:
env:
- { php: 7.4, phpunit: 9 }
- { php: 8.0, phpunit: 10 }
- { php: 8.1, phpunit: 10 }
- { php: 8.2, phpunit: 10 }
- { php: 8.3, phpunit: 10 }
- { php: 8.4, phpunit: 10, main: true }
- { php: 8.5, phpunit: 10 }
- { php: 8.2, phpunit: 11 }
- { php: 8.3, phpunit: 12 }
- { php: 8.4, phpunit: 13 }
- { php: 8.5, phpunit: 13, main: true }

steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v7
- name: Composer cache
uses: actions/cache@v5
uses: actions/cache@v6
with:
path: "vendor"
key: ${{ runner.os }}-${{ matrix.env.php }}-composer-${{ hashFiles('composer.json') }}
Expand Down Expand Up @@ -63,7 +60,7 @@
thresholds: '60 80'
- name: Add Coverage PR Comment
if: "matrix.env.main == true && github.event_name == 'pull_request'"
uses: marocchino/sticky-pull-request-comment@v2
uses: marocchino/sticky-pull-request-comment@v3

Check warning

Code scanning / CodeQL

Unpinned tag for a non-immutable Action in workflow or composite action Medium

Unpinned 3rd party Action 'CI' step
Uses Step
uses 'marocchino/sticky-pull-request-comment' with ref 'v3', not a pinned commit hash
with:
recreate: true
path: code-coverage-results.md
Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,25 @@ array(3) {
}
```

## Passing custom data to `processFile`

`XmlProcessor::processFile()` accepts an optional associative array of custom data.
It is stored on the [`XmlProcessorContext`], together with the filename currently being processed,
and is available to every node processor via `$context->getXmlProcessorContext()`.

```php
$processor->processFile('file.xml', ['tenant' => 'acme']);
```

```php
public function openElement(OpenContext $context)
{
$xmlProcessorContext = $context->getXmlProcessorContext();
$filename = $xmlProcessorContext->getFilename();
$tenant = $xmlProcessorContext->get('tenant');
}
```

[`XmlProcessor`]: src/XmlProcessor.php

[`NodeProcessorInterface`]: src/NodeProcessor/NodeProcessorInterface.php
Expand All @@ -129,6 +148,8 @@ array(3) {

[`TextNodeProcessorInterface`]: src/NodeProcessor/TextNodeProcessorInterface.php

[`XmlProcessorContext`]: src/XmlProcessorContext.php

[`NodeProcessorContext`]: src/NodeProcessor/Context/NodeProcessorContext.php

[`OpenContext]: src/NodeProcessor/Context/OpenContext.php
Expand Down
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
"docs": "https://github.com/netlogix/XML-Processor/blob/main/README.md"
},
"require": {
"php": "^7.4 || ^8.0",
"ext-xmlreader": "*",
"symfony/polyfill-php80": ">=1.33.0"
"php": "^8.2",
"ext-xmlreader": "*"
},
"require-dev": {
"behat/behat": "^3.12.0",
"carthage-software/mago": "^1.43",
"ergebnis/composer-normalize": "^2.50",
"phpunit/phpunit": "^9.6.6",
"phpunit/phpunit": "^11.5.56",
"rector/rector": "^2.3"
},
"prefer-stable": true,
Expand All @@ -40,6 +40,7 @@
"scripts": {
"apply-coding-standard": [
"@composer:normalize:fix",
"@lint:fix",
"@rector:fix",
"@format:fix"
],
Expand All @@ -52,6 +53,7 @@
"format": "mago fmt --dry-run",
"format:fix": "mago fmt",
"lint": "mago lint",
"lint:fix": "mago lint --fix --unsafe",
"rector": "rector process --dry-run",
"rector:fix": "rector process",
"test": [
Expand Down
9 changes: 4 additions & 5 deletions mago.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
php-version = "8.4"
php-version = "8.2"

[source]
workspace = "."
paths = [
"src/",
"tests/",
# "importmap.php",
"migrations/",
"tests/"
]
includes = ["vendor"]
excludes = []
Expand All @@ -25,7 +23,8 @@ empty-line-before-return = true
integrations = ["phpunit"]

[linter.rules]
ambiguous-function-call = { enabled = false }
no-fully-qualified-global-function = { enabled = false, level = "warning" }
ambiguous-function-call = { enabled = true, level = "warning" }
literal-named-argument = { enabled = false }
halstead = { effort-threshold = 7000 }
final-controller = { enabled = false }
Expand Down
28 changes: 12 additions & 16 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<coverage>
<include>
<directory suffix=".php">src/</directory>
<directory suffix=".php">features/NodeProcessor</directory>
</include>
</coverage>
<testsuites>
<testsuite name="unit">
<directory>tests/Unit</directory>
</testsuite>
</testsuites>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true">
<testsuites>
<testsuite name="unit">
<directory>tests/Unit</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src/</directory>
<directory suffix=".php">features/NodeProcessor</directory>
</include>
</source>
</phpunit>
2 changes: 1 addition & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
__DIR__ . '/tests',
])
// uncomment to reach your current PHP version
->withPhpVersion(PhpVersion::PHP_74)
->withPhpVersion(PhpVersion::PHP_82)
->withSets([
PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES
])
Expand Down
8 changes: 6 additions & 2 deletions src/NodeProcessor/AbstractNodeProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@
use Netlogix\XmlProcessor\XmlProcessor;
use Netlogix\XmlProcessor\XmlProcessorContext;

use function get_class;
use function defined;
use function constant;

class AbstractNodeProcessor implements NodeProcessorInterface
{
public function getNodePath(): string
{
$constName = \get_class($this) . '::NODE_PATH';
$constName = get_class($this) . '::NODE_PATH';
if (!defined($constName)) {
throw new Exception('NODE_PATH not defined in ' . static::class);
}

return \constant($constName);
return constant($constName);
}

public function getSubscribedEvents(string $nodePath, XmlProcessorContext $context): Iterator
Expand Down
2 changes: 2 additions & 0 deletions src/NodeProcessor/Context/AbstractElementContext.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types = 1);

namespace Netlogix\XmlProcessor\NodeProcessor\Context;

class AbstractElementContext extends NodeProcessorContext
Expand Down
Loading
Loading