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

Prepare the road to \JsonException usage #1949

Merged
merged 3 commits into from
May 31, 2021
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
7 changes: 3 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased](https://github.com/ruflin/Elastica/compare/7.1.1...master)
### Backward Compatibility Breaks
* Changed `Elastica\Exception\JSONParseException` inheritance, it now extends `\JsonException` instead of `\RuntimeException` [#1949](https://github.com/ruflin/Elastica/pull/1949)
### Added

* Added `Elastica\Aggregation\NormalizeAggregation` [#1956](https://github.com/ruflin/Elastica/pull/1956)

### Changed
* Updated `php-cs-fixer` to `2.18.6` [#1955](https://github.com/ruflin/Elastica/pull/1955)
* Updated `php-cs-fixer` to `3.0.0` [#1959](https://github.com/ruflin/Elastica/pull/1959)
* Using default Elasticsearch images for testing instead of OSS https://github.com/ruflin/Elastica/pull/1954

### Deprecated
### Removed
### Fixed
Expand All @@ -34,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Updated `composer-normalize` to `2.13.3` [#1927](https://github.com/ruflin/Elastica/pull/1927)
### Deprecated
* Deprecated `Elastica\Transport\HttpAdapter` class [#1940](https://github.com/ruflin/Elastica/pull/1940)
* Deprecated `Elastica\Exception\JSONParseException` exception, catch `\JsonException` instead [#1949](https://github.com/ruflin/Elastica/pull/1949)
### Fixed
* Fixed wrong `ltrim` usage in guzzle transport [#1783](https://github.com/ruflin/Elastica/pull/1783)
* Fixed `_seq_no` and `_primary_term` wrong initialization [#1920](https://github.com/ruflin/Elastica/pull/1920)
Expand Down Expand Up @@ -107,7 +107,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Fixed handling precision as string in `Elastica\Aggregation\GeohashGrid::setPrecision()` [#1884](https://github.com/ruflin/Elastica/pull/1884)
* Fixed calling `Elastica\Aggregation\Composite::addAfter()` with the `null` value [1877](https://github.com/ruflin/Elastica/pull/1877)
* Replaced `_routing` and `_retry_on_conflict` by `routing` and `retry_on_conflict` in `AbstractUpdateAction` [#1807](https://github.com/ruflin/Elastica/issues/1807)
### Security


## [7.0.0](https://github.com/ruflin/Elastica/compare/7.0.0-beta.4...7.0.0)
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"elasticsearch/elasticsearch": "^7.1.1",
"nyholm/dsn": "^2.0.0",
"psr/log": "^1.0",
"symfony/deprecation-contracts": "^2.2"
"symfony/deprecation-contracts": "^2.2",
"symfony/polyfill-php73": "^1.19"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems a bit overkill to have an additional dependency for a single exception change? What is the benefit of having JsonException?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For preparing smooth upgrade to native json_encode and json_decode functions with JSON_THROW_ON_ERROR option (introduced in PHP 7.3) and fully get rid of Elastica\JSON util class and JSONParseException exception class.

Copy link
Collaborator Author

@deguif deguif Mar 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This extra polyfill package can be ignored on project side by using replace composer feature.

For example that's what I use in many projects when they are running on modern PHP versions, this way these packages are not installed as they are useless:

    "replace": {
        "paragonie/random_compat": "*",
        "ralouphie/getallheaders": "*",
        "symfony/polyfill-apcu": "*",
        "symfony/polyfill-ctype": "*",
        "symfony/polyfill-iconv": "*",
        "symfony/polyfill-intl-grapheme": "*",
        "symfony/polyfill-intl-icu": "*",
        "symfony/polyfill-intl-idn": "*",
        "symfony/polyfill-intl-normalizer": "*",
        "symfony/polyfill-mbstring": "*",
        "symfony/polyfill-php73": "*",
        "symfony/polyfill-uuid": "*"
    },

},
"require-dev": {
"aws/aws-sdk-php": "^3.155",
Expand Down
4 changes: 3 additions & 1 deletion src/Exception/JSONParseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

/**
* JSON Parse exception.
*
* @deprecated since version 7.2.0, catch \JsonException instead
*/
class JSONParseException extends \RuntimeException implements ExceptionInterface
class JSONParseException extends \JsonException implements ExceptionInterface
{
}
3 changes: 1 addition & 2 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Elastica;

use Elastica\Exception\JSONParseException;
use Elastica\Exception\NotFoundException;

/**
Expand Down Expand Up @@ -217,7 +216,7 @@ public function getData()
} else {
$response = JSON::parse($response);
}
} catch (JSONParseException $e) {
} catch (\JsonException $e) {
// leave response as is if parse fails
}

Expand Down