Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match attribute names in a case-insensitive manner. #219

Merged
merged 14 commits into from
Jan 3, 2024
51 changes: 40 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,44 @@ on: [push, pull_request]
jobs:
composer:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ 8.0, 8.1, 8.2, 8.3 ]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Cache Composer dependencies
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
key: ${{ runner.os }}-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}

- uses: php-actions/composer@v6
- name: Composer
uses: php-actions/composer@run-as-current-user
with:
php_version: ${{ matrix.php }}

- name: Archive build
run: mkdir /tmp/github-actions/ && tar -cvf /tmp/github-actions/build.tar ./

- name: Upload build archive for test runners
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: build-artifact
name: build-php${{ matrix.php }}
path: /tmp/github-actions

phpunit:
runs-on: ubuntu-latest
needs: [composer]
strategy:
matrix:
php: [ 8.0, 8.1, 8.2, 8.3 ]

steps:
- uses: actions/download-artifact@v2
- uses: actions/download-artifact@v4
with:
name: build-artifact
name: build-php${{ matrix.php }}
path: /tmp/github-actions

- name: Extract build archive
Expand All @@ -42,19 +51,23 @@ jobs:
- name: PHP Unit tests
uses: php-actions/phpunit@v3
with:
php_version: 7.3
version: 9
php_version: ${{ matrix.php }}
php_extensions: xdebug
configuration: test/phpunit/phpunit.xml
bootstrap: vendor/autoload.php

phpstan:
runs-on: ubuntu-latest
needs: [composer]
strategy:
matrix:
php: [ 8.0, 8.1, 8.2, 8.3 ]

steps:
- uses: actions/download-artifact@v2
- uses: actions/download-artifact@v4
with:
name: build-artifact
name: build-php${{ matrix.php }}
path: /tmp/github-actions

- name: Extract build archive
Expand All @@ -64,3 +77,19 @@ jobs:
uses: php-actions/phpstan@v3
with:
path: src/
php_version: ${{ matrix.php }}

remove_old_artifacts:
runs-on: ubuntu-latest

steps:
- name: Remove old artifacts for prior workflow runs on this repository
env:
GH_TOKEN: ${{ github.token }}
run: |
gh api "/repos/${{ github.repository }}/actions/artifacts" | jq ".artifacts[] | .id" > artifact-id-list.txt
while read id
do
echo -n "Deleting artifact ID $id ... "
gh api --method DELETE /repos/${{ github.repository }}/actions/artifacts/$id && echo "Done" || true
done <artifact-id-list.txt
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,15 @@ $xpath = new DOMXPath($document);
$inputElementList = $xpath->query(new Translator("form>label>input");
```

## Using this library with XML Documents

To correctly work with XML documents, where the attributes are case-sensitive, pass `false` to the `htmlMode` property of the constructor.

```php
$translator = new Translator("[data-FOO='bar']", htmlMode: false);
```

It's perhaps worth noting that for XML-style matching to work, you must load the document content with DOMDocument->load/DOMDocument->loadXML instead of DOMDocument->loadHTMLFile/DOMDocument->loadHTML, as the HTML loading methods automatically convert the tags and attribute names to lowercase. This is handled automatically when using [PHP.Gt/Dom][gt-dom].

[qsa]: https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll
[gt-dom]: https://www.php.gt/dom
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "library",

"require": {
"php": ">=7.3"
"php": ">=8.0"
},

"require-dev": {
Expand Down
Loading