Skip to content

Commit

Permalink
[Translation] fixed JSON loader on PHP 7 when file is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed May 22, 2015
1 parent cdd2168 commit d030b3d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Loader/JsonFileLoader.php
Expand Up @@ -35,10 +35,13 @@ public function load($resource, $locale, $domain = 'messages')
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()) {
throw new InvalidResourceException(sprintf('Error parsing JSON - %s', $this->getJSONErrorMessage($errorCode)));
if (0 < $errorCode = json_last_error()) {
throw new InvalidResourceException(sprintf('Error parsing JSON - %s', $this->getJSONErrorMessage($errorCode)));
}
}

if (null === $messages) {
Expand Down

0 comments on commit d030b3d

Please sign in to comment.