bug #14726 [Translation] fixed JSON loader on PHP 7 when file is empty (fabpot)
This PR was submitted for the 2.5 branch but it was merged into the 2.6 branch instead (closes #14726).
Discussion
----------
[Translation] fixed JSON loader on PHP 7 when file is empty
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | n/a
| License | MIT
| Doc PR | n/a
For PHP7 compat.
Commits
-------
af36c34
[Translation] fixed JSON loader on PHP 7 when file is empty
This commit is contained in:
commit
836a661d63
@ -35,11 +35,14 @@ class JsonFileLoader extends ArrayLoader implements LoaderInterface
|
|||||||
throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
|
throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
|
||||||
}
|
}
|
||||||
|
|
||||||
$messages = json_decode(file_get_contents($resource), true);
|
$messages = array();
|
||||||
|
if ($data = file_get_contents($resource)) {
|
||||||
|
$messages = json_decode($data, true);
|
||||||
|
|
||||||
if (0 < $errorCode = json_last_error()) {
|
if (0 < $errorCode = json_last_error()) {
|
||||||
throw new InvalidResourceException(sprintf('Error parsing JSON - %s', $this->getJSONErrorMessage($errorCode)));
|
throw new InvalidResourceException(sprintf('Error parsing JSON - %s', $this->getJSONErrorMessage($errorCode)));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (null === $messages) {
|
if (null === $messages) {
|
||||||
$messages = array();
|
$messages = array();
|
||||||
|
Reference in New Issue
Block a user