Skip to content

Commit 4e3e6d3

Browse files
committed
XMLReaderIterator v0.1.11.
- fixed endless recursion in XMLAttributeIterator::getReader() - fixed dumping trailing white-space - fixed length in dumping strings - fixed xml-file-scanner example deprecated each() use (php 7.2+/php 8.0) - fixed XMLSequenceStream node expansion (php 7.4+) - fixed php internal interfaces return type deprecation messages on parse time for Iterator, Countable, ArrayAccess etc. (php 8.1+) - fixed php internal function parameter type errors for fopen(), strtok(), strlen() etc. (php 8.1+) - fixed a couple of minor code issues and typos - build: run .travis.yml (recycle) as github action - build: patch vendor for php compatibility (php 5.3 ... 8.1) - build: fixed composer version detection - build: improved composer package size - build: change autoload to classmap (from files) - build: capture errors during require/auto loading - build: pass standard error stream from phpunit - build: fix $TRAVIS reference - build: no explicit source preference with composer - improved utf-8 support for dump operations - improved use of SPDX license list (version 3.0 deprecation) - added CDATA and Whitespace node support for XMLWritingIteration (thanks CPCoder and Kacper Woźniak) - added warning on writing unsupported node-type - added SimpleXMLElement class-name support - added XMLElementIterator::skipNextRead() - added reading and writing with DOM example - added reading and writing with SimpleXML example - added XMLChildElementIterator example - example tests: skip on missing stream wrapper - example tests: clean output buffer on failure - example tests: show backtrace on failure - maintenance
1 parent 42da6ef commit 4e3e6d3

62 files changed

Lines changed: 1602 additions & 385 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitattributes

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
build* export-ignore
2+
examples export-ignore
3+
tests export-ignore
4+
vendor export-ignore
5+
.git* export-ignore
6+
.travis.yml export-ignore
7+
autoload.php export-ignore
8+
phpunit.xml.dist export-ignore

.github/workflows/main.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
name: CI
3+
4+
on:
5+
push:
6+
branches: [master]
7+
pull_request:
8+
branches: [master]
9+
10+
workflow_dispatch:
11+
12+
jobs:
13+
build:
14+
name: build (PHP ${{ matrix.php }}${{ matrix.allow-failure && ' - allow failure' || '' }})
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
php: [5.3, 5.4, 5.5, 5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1]
19+
allow-failure: [false]
20+
include:
21+
- php: 8.2
22+
allow-failure: true
23+
steps:
24+
- name: Set up php(1) version ${{ matrix.php }}
25+
uses: shivammathur/setup-php@v2
26+
with:
27+
php-version: ${{ matrix.php }}
28+
extensions: xml, bz2
29+
coverage: none
30+
env:
31+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
33+
- name: Set up XMLReaderIterator
34+
uses: actions/checkout@v3
35+
36+
- name: CI for XMLReaderIterator (run .travis.yml)
37+
uses: ktomk/run-travis-yml@v1
38+
with:
39+
allow-failure: ${{ matrix.allow-failure }}
40+
env:
41+
TRAVIS_PHP_VERSION: ${{ matrix.php }}

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ before_install:
1717
- travis_retry composer self-update
1818

1919
install:
20-
- travis_retry composer install --prefer-source --no-interaction --ignore-platform-reqs
20+
- travis_retry composer install --no-interaction --ignore-platform-reqs
2121

2222
before_script:
2323
- ./build.sh

README.md

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,73 @@
1-
## Iterators for [PHP `XMLReader`](http://php.net/XMLReader) for ease of parsing
1+
## Iterators for [PHP `XMLReader`] for Ease of Parsing
2+
3+
[PHP `XMLReader`]: http://php.net/XMLReader
24

35
### Change Log:
46

7+
- `0.1.11` maintenance release with fixes. added `XMLReader::CDATA` and
8+
`XMLReader::WHITESPACE` node support for `XMLWritingIteration`. added
9+
`XMLReaderItertor::skipNextRead()` for nested iterations.
10+
511
- `0.1.10` maintenance release with fixes.
612

7-
- `0.1.9` maintenance release with fixes. added XMLReaderNode::expand().
13+
- `0.1.9` maintenance release with fixes. added `XMLReaderNode::expand()`.
814

915
- `0.1.8` maintenance release with fixes.
1016

1117
- `0.1.7` maintenance release with fixes.
1218

13-
- `0.1.6` maintenance release with fixes. added xml-file-scanner command-line tool example.
19+
- `0.1.6` maintenance release with fixes. added xml-file-scanner
20+
command-line tool example.
1421

15-
- `0.1.5` maintenance release with tests and new `XMLReaderNextIteration` to iterate in `XMLReader::next()` fashion.
22+
- `0.1.5` maintenance release with tests and new `XMLReaderNextIteration`
23+
to iterate in `XMLReader::next()` fashion.
1624

1725
- `0.1.4` maintenance release with fixes.
1826

19-
- `0.1.3` added `XMLSequenceStream`, a PHP stream wrapper to read XML from files which are a sequence of XML
20-
documents. Works transparently with `XMLReader`.
27+
- `0.1.3` added `XMLSequenceStream`, a PHP stream wrapper to read XML from
28+
files which are a sequence of XML documents. Works transparently with
29+
`XMLReader`.
2130

22-
- `0.1.2` added `XMLWritingIteration`, an iteration to write with `XMLWriter` from `XMLReader`.
31+
- `0.1.2` added `XMLWritingIteration`, an iteration to write with
32+
`XMLWriter` from `XMLReader`.
2333

2434
- `0.1.0` composer support has been added.
2535

26-
- `0.0.23` first try of a compatibility layer for PHP installs with a libxml version below version 2.6.20.
27-
Functions with compatibility checks are `XMLReaderNode::readOuterXml()` and `XMLReaderNode::readString()`.
36+
- `0.0.23` first try of a compatibility layer for PHP installs with a libxml
37+
version below version 2.6.20.
38+
functions with compatibility checks are `XMLReaderNode::readOuterXml()`
39+
and `XMLReaderNode::readString()`.
40+
41+
- `0.0.21` moved library into new repository and added
42+
`XMLReaderAggregate`.
2843

29-
- `0.0.21` moved library into new repository and added `XMLReaderAggregate`.
44+
- `0.0.19` added `XMLElementXpathFilter`, a `FilterIterator` for
45+
`XMLReaderIterator` by an xpath expression.
3046

31-
- `0.0.19` added `XMLElementXpathFilter`, a `FilterIterator` for `XMLReaderIterator` by an Xpath
32-
expression.
47+
~~~php
48+
$reader = new XMLReader();
49+
$reader->open($xmlFile);
50+
$it = new XMLElementIterator($reader);
3351

34-
$reader = new XMLReader();
35-
$reader->open($xmlFile);
36-
$it = new XMLElementIterator($reader);
37-
$list = new XMLElementXpathFilter($it, '//user[@id = "1" or @id = "6"]//message');
52+
$list = new XMLElementXpathFilter(
53+
$it,
54+
'//user[@id = "1" or @id = "6"]//message'
55+
);
3856

39-
foreach($list as $message) {
40-
echo " * ", $message->readString(), "\n";
41-
}
57+
foreach($list as $message) {
58+
echo " * ", $message->readString(), "\n";
59+
}
60+
~~~
4261

43-
### Code examples for the XMLReader Iterators (latest on top):
62+
### Stackoverflow Q&A for the XMLReader Iterators
4463

64+
the latest on top (for more examples, checkout the
65+
[`examples`] folder):
66+
67+
- [Add Tag Element using XMLReader and SimpleXML or XMLWriter](https://stackoverflow.com/q/69455574/367456)
4568
- [How to distinguish between empty element and null-size string in DOMDocument?](http://stackoverflow.com/a/24109776/367456)
4669
- [PHP XML parser: How to read only part of the XML document?](http://stackoverflow.com/a/15443517/367456)
4770
- [Parse XML with PHP and XMLReader](http://stackoverflow.com/a/15351723/367456)
4871
- [Getting XML Attribute with XMLReader and PHP](http://stackoverflow.com/a/15399491/367456)
72+
73+
[`examples`]: https://github.com/hakre/XMLReaderIterator/tree/master/examples

build.php

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
$errors = 0;
1212
$warnings = 0;
1313

14-
$buildDir = __DIR__ . '/build';
14+
$projectDir = __DIR__;
15+
$buildDir = $projectDir . '/build';
1516
$concatenateDir = $buildDir . '/include';
1617
$concatenateFile = $concatenateDir . '/xmlreader-iterators.php';
17-
$autoLoadFile = __DIR__ . '/autoload.php';
18+
$autoLoadFile = $projectDir . '/autoload.php';
1819

1920
### test if composer.json validates ###
2021
built_test_composer_validate_json($errors);
@@ -43,8 +44,9 @@ function built_test_git_tag($version, &$errors)
4344
}
4445
}
4546

46-
### test if autoload.php contains all classes ###
47+
### test autoload contains all classes ###
4748
build_test_autoload_file($errors, $autoLoadFile);
49+
build_test_autoload_file($errors, $projectDir . '/vendor/autoload.php');
4850

4951
### test if tests run clean ###
5052
build_test_tests($errors);
@@ -59,6 +61,7 @@ function built_test_git_tag($version, &$errors)
5961

6062
### create concatenateFile ###
6163
build_create_concatenate_file($errors, $concatenateFile, $autoLoadFile, $readmeVersion);
64+
build_test_autoload_file($errors, $concatenateFile);
6265
copy_file_to_dir(__DIR__ . '/README.md', $concatenateDir);
6366

6467
### conditional build target into gist ###
@@ -144,7 +147,7 @@ function built_test_composer_validate_json(&$errors)
144147

145148
exec($command, $output, $exitCode);
146149
list($versionLine) = $output;
147-
if (!preg_match('~^Composer version (?:1.0-dev \([0-9a-f]{40}\)|[0-9a-f]{40}) 2\d{3}-(?:0\d|1[0-2])-(?:[0-2]\d|3[0-1]) (?:[0-1]\d|2[0-3]):[0-5]\d:(?:[0-5]\d|60)$~', $versionLine)) {
150+
if (!preg_match('~^Composer version (?:[12]\.\d+\.\d+|1\.0-dev \([0-9a-f]{40}\)|[0-9a-f]{40}) 2\d{3}-(?:0\d|1[0-2])-(?:[0-2]\d|3[0-1]) (?:[0-1]\d|2[0-3]):[0-5]\d:(?:[0-5]\d|60)$~', $versionLine)) {
148151
echo "ERROR: Unable to invoke Composer.\n";
149152
$errors++;
150153
return;
@@ -169,9 +172,9 @@ function built_test_composer_validate_json(&$errors)
169172
*/
170173
function build_test_tests(&$errors)
171174
{
172-
echo "INFO: Running phpunit testuite before building:\n";
175+
echo "INFO: Running phpunit testsuite before building:\n";
173176

174-
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
177+
if (stripos(PHP_OS, 'WIN') === 0) {
175178
$phpunit = '.\vendor\bin\phpunit.bat';
176179
} else {
177180
$phpunit = './vendor/bin/phpunit';
@@ -188,9 +191,9 @@ function build_test_tests(&$errors)
188191
return;
189192
}
190193

191-
$command = "$phpunit --stop-on-failure tests";
194+
$command = "$phpunit --stop-on-failure --testsuite default";
192195

193-
$result = system($command, $exitCode);
196+
$result = passthru($command, $exitCode);
194197

195198
if ($result === false) {
196199
echo "ERROR: Unable to invoke PHPUnit tests.\n";
@@ -206,7 +209,7 @@ function build_test_tests(&$errors)
206209
return;
207210
}
208211

209-
echo "INFO: phpunit testuite did pass.\n";
212+
echo "INFO: phpunit testsuite did pass.\n";
210213

211214
return;
212215
}
@@ -217,16 +220,12 @@ function build_test_tests(&$errors)
217220
*/
218221
function build_test_autoload_file(&$errors, $autoLoadFile)
219222
{
220-
require_once($autoLoadFile);
223+
$command = sprintf('php -f %s -- --verbose --require %s', escapeshellarg(__DIR__ . '/tests/autoload/test.php'), escapeshellarg($autoLoadFile));
224+
passthru($command, $exitCode);
221225

222-
foreach (glob('src/*.php') as $file) {
223-
$class = basename($file, '.php');
224-
225-
226-
if (!class_exists($class) && !interface_exists($class)) {
227-
echo "ERROR: ", $class, " does not exists.\n";
228-
$errors++;
229-
}
226+
if (0 !== $exitCode) {
227+
echo "ERROR: autoload file '", $autoLoadFile ,"' broken.\n";
228+
$errors++;
230229
}
231230
}
232231

@@ -330,8 +329,8 @@ function build_create_concatenate_file(&$errors, $concatenateFile, $autoLoadFile
330329

331330
$buffer = file_get_contents($concatenateFile);
332331

333-
$search = " * @license AGPL-3.0 <http://spdx.org/licenses/AGPL-3.0>\n */";
334-
$replace = " * @license AGPL-3.0 <http://spdx.org/licenses/AGPL-3.0>\n * @version $version\n */";
332+
$search = " * @license AGPL-3.0-or-later <https://spdx.org/licenses/AGPL-3.0-or-later>\n */";
333+
$replace = " * @license AGPL-3.0-or-later <https://spdx.org/licenses/AGPL-3.0-or-later>\n * @version $version\n */";
335334

336335
$pos = strpos($buffer, $search);
337336
if (!$pos) {

build.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# build script on clean checkout
44
#
55

6-
if [ -n "TRAVIS" ]; then
6+
if [ -n "$TRAVIS" ]; then
77
echo "build on travis with php ${TRAVIS_PHP_VERSION}"
88
if [ "${TRAVIS_PHP_VERSION}" == "5.2" ]; then
99
echo "5.2 is not a composer version, can't build, exiting."
@@ -21,4 +21,9 @@ if [ ! -d vendor ]; then
2121
exit 1
2222
fi
2323

24+
if [ -f vendor/vendor-dev.patch ] && command -v git &> /dev/null; then
25+
git --version
26+
git apply --unsafe-paths --directory=vendor -- vendor/vendor-dev.patch
27+
fi
28+
2429
php -f build.php

build/include/README.md

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,73 @@
1-
## Iterators for [PHP `XMLReader`](http://php.net/XMLReader) for ease of parsing
1+
## Iterators for [PHP `XMLReader`] for Ease of Parsing
2+
3+
[PHP `XMLReader`]: http://php.net/XMLReader
24

35
### Change Log:
46

7+
- `0.1.11` maintenance release with fixes. added `XMLReader::CDATA` and
8+
`XMLReader::WHITESPACE` node support for `XMLWritingIteration`. added
9+
`XMLReaderItertor::skipNextRead()` for nested iterations.
10+
511
- `0.1.10` maintenance release with fixes.
612

7-
- `0.1.9` maintenance release with fixes. added XMLReaderNode::expand().
13+
- `0.1.9` maintenance release with fixes. added `XMLReaderNode::expand()`.
814

915
- `0.1.8` maintenance release with fixes.
1016

1117
- `0.1.7` maintenance release with fixes.
1218

13-
- `0.1.6` maintenance release with fixes. added xml-file-scanner command-line tool example.
19+
- `0.1.6` maintenance release with fixes. added xml-file-scanner
20+
command-line tool example.
1421

15-
- `0.1.5` maintenance release with tests and new `XMLReaderNextIteration` to iterate in `XMLReader::next()` fashion.
22+
- `0.1.5` maintenance release with tests and new `XMLReaderNextIteration`
23+
to iterate in `XMLReader::next()` fashion.
1624

1725
- `0.1.4` maintenance release with fixes.
1826

19-
- `0.1.3` added `XMLSequenceStream`, a PHP stream wrapper to read XML from files which are a sequence of XML
20-
documents. Works transparently with `XMLReader`.
27+
- `0.1.3` added `XMLSequenceStream`, a PHP stream wrapper to read XML from
28+
files which are a sequence of XML documents. Works transparently with
29+
`XMLReader`.
2130

22-
- `0.1.2` added `XMLWritingIteration`, an iteration to write with `XMLWriter` from `XMLReader`.
31+
- `0.1.2` added `XMLWritingIteration`, an iteration to write with
32+
`XMLWriter` from `XMLReader`.
2333

2434
- `0.1.0` composer support has been added.
2535

26-
- `0.0.23` first try of a compatibility layer for PHP installs with a libxml version below version 2.6.20.
27-
Functions with compatibility checks are `XMLReaderNode::readOuterXml()` and `XMLReaderNode::readString()`.
36+
- `0.0.23` first try of a compatibility layer for PHP installs with a libxml
37+
version below version 2.6.20.
38+
functions with compatibility checks are `XMLReaderNode::readOuterXml()`
39+
and `XMLReaderNode::readString()`.
40+
41+
- `0.0.21` moved library into new repository and added
42+
`XMLReaderAggregate`.
2843

29-
- `0.0.21` moved library into new repository and added `XMLReaderAggregate`.
44+
- `0.0.19` added `XMLElementXpathFilter`, a `FilterIterator` for
45+
`XMLReaderIterator` by an xpath expression.
3046

31-
- `0.0.19` added `XMLElementXpathFilter`, a `FilterIterator` for `XMLReaderIterator` by an Xpath
32-
expression.
47+
~~~php
48+
$reader = new XMLReader();
49+
$reader->open($xmlFile);
50+
$it = new XMLElementIterator($reader);
3351

34-
$reader = new XMLReader();
35-
$reader->open($xmlFile);
36-
$it = new XMLElementIterator($reader);
37-
$list = new XMLElementXpathFilter($it, '//user[@id = "1" or @id = "6"]//message');
52+
$list = new XMLElementXpathFilter(
53+
$it,
54+
'//user[@id = "1" or @id = "6"]//message'
55+
);
3856

39-
foreach($list as $message) {
40-
echo " * ", $message->readString(), "\n";
41-
}
57+
foreach($list as $message) {
58+
echo " * ", $message->readString(), "\n";
59+
}
60+
~~~
4261

43-
### Code examples for the XMLReader Iterators (latest on top):
62+
### Stackoverflow Q&A for the XMLReader Iterators
4463

64+
the latest on top (for more examples, checkout the
65+
[`examples`] folder):
66+
67+
- [Add Tag Element using XMLReader and SimpleXML or XMLWriter](https://stackoverflow.com/q/69455574/367456)
4568
- [How to distinguish between empty element and null-size string in DOMDocument?](http://stackoverflow.com/a/24109776/367456)
4669
- [PHP XML parser: How to read only part of the XML document?](http://stackoverflow.com/a/15443517/367456)
4770
- [Parse XML with PHP and XMLReader](http://stackoverflow.com/a/15351723/367456)
4871
- [Getting XML Attribute with XMLReader and PHP](http://stackoverflow.com/a/15399491/367456)
72+
73+
[`examples`]: https://github.com/hakre/XMLReaderIterator/tree/master/examples

0 commit comments

Comments
 (0)