Skip to content

Commit

Permalink
New release 2.0.0 incompatible with version 1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
eclipxe13 committed Sep 21, 2017
1 parent 78dfd0c commit 37964a9
Show file tree
Hide file tree
Showing 42 changed files with 432 additions and 2,180 deletions.
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ language: php

# php compatibility
php:
- 5.6
- 7.0
- 7.1

Expand All @@ -13,7 +12,6 @@ sudo: false
before_script:
- travis_retry composer self-update
- travis_retry composer install --no-interaction --prefer-dist
- test $TRAVIS_PHP_VERSION == '7.1' && travis_retry composer require --dev --no-interaction --prefer-dist scrutinizer/ocular || true

script:
- mkdir -p build/tests/
Expand All @@ -23,7 +21,11 @@ script:
- vendor/bin/phpunit --coverage-text --coverage-clover=build/tests/coverage.xml

after_script:
- if [[ $TRAVIS_PHP_VERSION == '7.1' ]]; then php vendor/bin/ocular code-coverage:upload --format=php-clover build/tests/coverage.xml; fi
- |
if [[ $TRAVIS_PHP_VERSION == '7.0' ]]; then
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover build/tests/coverage.xml
fi
notifications:
email: false
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# Version 2.0.0
- This version does not include `Locator` nor `DownloaderInterface` implementations.
That functionality is actually outside the scope of this library and that is the reason
why it was removed. A new library was created to implement this, take a look in
`eclipxe/xmlresourceretriever` https://github.com/eclipxe13/XmlResourceRetriever/
- Constructor of `SchemaValidator` and `Schemas` changed.
- Add new method `SchemaValidator::validateWithSchemas` that do the same
thing than `SchemaValidator::validate` but you must provide the `Schemas` collection
- Change from `protected` to `public` the method `SchemaValidator::buildSchemas`,
it's usefull when used with `SchemaValidator::validateWithSchemas` to change
XSD remote locations to local or other places.
- Add `XmlSchemaValidator::LibXmlException`. It contains a method to exec a callable
isolating the use internal errors setting and other to collect libxml errors
and throw it like an exception.
- Rename `Schemas::getXsd` to `Schemas::getImporterXsd`
- Remove compatibility with PHP 5.6, minimum version is now PHP 7.0
- Add scalar type declarations
- Remove test assets from Mexican SAT
- Tests: Move files served by php built-in web server to from assets to public

# Version 1.1.4
- Fix implementation of libxml use internal errors on `SchemaValidator::validate`
- When creating the dom document avoid warnings (fix using the correct constant)
Expand Down
24 changes: 19 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,41 @@ We don't enjoy rejecting your hard work, but some features just don't fit with t
When you do begin working on your feature, here are some guidelines to consider:

* Your pull request description should clearly detail the changes you have made.
* We following by minimum the **[PSR-2 coding standard](http://www.php-fig.org/psr/psr-2/)**. Please ensure your code does, too.
* Follow our code style using `squizlabs/php_codesniffer` and `friendsofphp/php-cs-fixer`.
* Please **write tests** for any new features you add.
* Please **ensure that tests pass** before submitting your pull request. We have Travis CI automatically running tests for pull requests. However, running the tests locally will help save time.
* **Use topic/feature branches.** Please do not ask us to pull from your master branch.
* **Submit one feature per pull request.** If you have multiple features you wish to submit, please break them up into separate pull requests.
* **Send coherent history**. Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before submitting.

## Check the code style

If you are having issues with coding standars use `php-cs-fixer` and `phpcbf`

```bash
```shell
vendor/bin/php-cs-fixer fix -v
vendor/bin/phpcbf src/ tests/
```

## Running Tests

The following tests must pass before we will accept a pull request. If any of these do not pass,
it will result in a complete build failure. Before you can run these, be sure to `composer install`.
The following tests must pass before we will accept a pull request.
If any of these do not pass, it will result in a complete build failure.
Before you can run these, be sure to `composer install` or `composer update`.

```
```shell
vendor/bin/parallel-lint src/ tests/
vendor/bin/phpcs -sp src/ tests/
vendor/bin/php-cs-fixer fix -v --dry-run
vendor/bin/phpunit --coverage-text
```

## web server instance while running tests

The phpunit process in the bootstrap step uses the PHP built-in web server in port 8999 to serve the contents
of `tests/public` in order to test the validation process on remote resources.

When the phpunit process ends, the web server instance is killed.

Take a look in `tests/boostrap.php` to see how this is working.

68 changes: 43 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,65 @@

This is a library to validate XML files against multiple XSD Schemas according to its own definitions.

I create this project because I need to validate XML documents against not-always-known schemas
that have to be downloaded from Internet.

The way this works is:

1. Receive a valid xml file
1. Receive a valid xml string as the content to be evaluated
2. Scan the file for every schemaLocation
3. Compose a file that include all the schemas
3. Compose a schema that include all the schemas
4. Validate the XML against the composed file

Features:
- It can have a repository for external schemas
- Retrieve schemas from Internet
- Storage the schemas until they expire

## Installation

Use composer, so please run `composer require eclipxe/xmlschemavalidator` or include this on your `composer.json` file:

```json
{
"require": {
"eclipxe/xmlschemavalidator": "@stable"
}
}
Use [composer](https://getcomposer.org/), so please run
```shell
composer require eclipxe/xmlschemavalidator
```

## Basic usage

```php
<?php
use XmlSchemaValidator\SchemaValidator;
$validator = new SchemaValidator();
$valid = $validator->validate(file_get_contents('example.xml'));
if (! $valid) {
echo $validator->getError(), "\n";
} else {
echo "OK\n";
$contents = file_get_contents('example.xml');
$validator = new \XmlSchemaValidator\SchemaValidator($contents);
if (! $validator->validate()) {
echo 'Found error: ' . $validator->getLastError();
}
```

## Advanced usage

```php
<?php
$contents = file_get_contents('example.xml');
$validator = new \XmlSchemaValidator\SchemaValidator($contents);
// change schemas collection to override the schema location of an specific namespace
$schemas = $validator->buildSchemas();
$schemas->create('http://example.org/schemas/x1', './local-schemas/x1.xsd');

// validateWithSchemas does not return boolean, it throws an exception
try {
$validator->validateWithSchemas($schemas));
} catch (\XmlSchemaValidator\SchemaValidatorException $ex) {
echo 'Found error: ' . $ex->getMessage();
}
```

## About libxml errors

This library depends on PHP libxml and uses internal errors `libxml_use_internal_errors` to retrieve
the errors when creates the `DOMDocument` or validate against the schema files.
Instead of raise an error it creates a `LibXmlException` with the errors chained.
It also restore the value of `libxml_use_internal_errors` after execution.

## Version 1.x is deprecated

Version 1.x is no longer on development. It has a problem of concerns, the same library try to solve two different
issues: Validate an XML file and store locally a copy of the XSD files.
Version 2.x breaks this problem and give this library only one propose:
Validate an XML file against its multiple XSD files, it does not matter where are located.

Also, version 2.x uses PHP 7 with scalar type declarations, so it no longer compatible with PHP 5.6.

## Contributing

Contributions are welcome! Please read [CONTRIBUTING][] for details
Expand Down
6 changes: 3 additions & 3 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# eclipxe13/xmlschemavalidator To Do

- [ ] Deprecate PHP 5.6 to PHP 7.0 and phpunit from ^5.7 to ^6.3
- [ ] Document usage examples
- [ ] Move from standard exceptions to library exceptions
- [ ] Use better XSD samples, currently is heavely related to Mexico SAT CFDI v 3.2

## Done

- [X] Deprecate PHP 5.6 to PHP 7.0 and phpunit from ^5.7 to ^6.3
- [X] Move from standard exceptions to library exceptions
- [X] Use better XSD samples, currently is heavely related to Mexico SAT CFDI v 3.2
- [X] Create a downloader object to separate responsabilities of Locator object
- [X] Include contribute and CoC
- [X] ~~Full coverage~~ Coverage over 90%
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
}
],
"require": {
"php": ">=5.6"
"php": ">=7.0",
"ext-xml": "*"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"phpunit/phpunit": "^6.2",
"jakub-onderka/php-parallel-lint": "^0.9",
"squizlabs/php_codesniffer": "^3.0",
"friendsofphp/php-cs-fixer": "^2.4"
Expand Down
38 changes: 0 additions & 38 deletions src/XmlSchemaValidator/Downloader/CurlDownloader.php

This file was deleted.

15 changes: 0 additions & 15 deletions src/XmlSchemaValidator/Downloader/DownloaderInterface.php

This file was deleted.

10 changes: 0 additions & 10 deletions src/XmlSchemaValidator/Downloader/NullDownloader.php

This file was deleted.

24 changes: 0 additions & 24 deletions src/XmlSchemaValidator/Downloader/PhpDownloader.php

This file was deleted.

52 changes: 0 additions & 52 deletions src/XmlSchemaValidator/FileMimeChecker.php

This file was deleted.

Loading

0 comments on commit 37964a9

Please sign in to comment.