Skip to content

Commit 1b490d8

Browse files
authored
Optimized Model/JsonResource::toJson (#6963)
1 parent f4d5636 commit 1b490d8

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/PharBuilder.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Hyperf\Phar\Ast\Visitor\RewriteConfigFactoryVisitor;
1919
use Hyperf\Phar\Ast\Visitor\RewriteConfigVisitor;
2020
use InvalidArgumentException;
21+
use JsonException;
2122
use Phar;
2223
use Psr\Log\LoggerInterface;
2324
use RuntimeException;
@@ -388,10 +389,12 @@ protected function replaceConfigFactoryReadPaths(TargetPhar $targetPhar, string
388389
*/
389390
private function loadJson(string $path): array
390391
{
391-
$result = json_decode(file_get_contents($path), true);
392-
if ($result === null) {
393-
throw new InvalidArgumentException(sprintf('Unable to parse given path %s', $path), json_last_error());
392+
try {
393+
$result = json_decode(file_get_contents($path), true, 512, JSON_THROW_ON_ERROR);
394+
} catch (JsonException $e) {
395+
throw new InvalidArgumentException(sprintf('Unable to parse given path %s', $path), $e->getCode(), $e);
394396
}
397+
395398
return $result;
396399
}
397400

0 commit comments

Comments
 (0)