at path:ROOT / clients / vendor / seld / jsonlint / bin / jsonlint
run:R W Run
2.91 KB
2026-04-08 19:35:12
R W Run
error_log
📄jsonlint
1#!/usr/bin/env php
2<?php
3
4/*
5 * This file is part of the JSON Lint package.
6 *
7 * (c) Jordi Boggiano <j.boggiano@seld.be>
8 *
9 * For the full copyright and license information, please view the LICENSE
10 * file that was distributed with this source code.
11 */
12
13function includeIfExists($file)
14{
15 if (file_exists($file)) {
16 return include $file;
17 }
18}
19
20if (!includeIfExists(__DIR__.'/../vendor/autoload.php') && !includeIfExists(__DIR__.'/../../../autoload.php')) {
21 $msg = 'You must set up the project dependencies, run the following commands:'.PHP_EOL.
22 'curl -sS https://getcomposer.org/installer | php'.PHP_EOL.
23 'php composer.phar install'.PHP_EOL;
24 fwrite(STDERR, $msg);
25 exit(1);
26}
27
28use Seld\JsonLint\JsonParser;
29
30$files = array();
31$quiet = false;
32
33if (isset($_SERVER['argc']) && $_SERVER['argc'] > 1) {
34 for ($i = 1; $i < $_SERVER['argc']; $i++) {
35 $arg = $_SERVER['argv'][$i];
36 if ($arg == '-q' || $arg == '--quiet') {
37 $quiet = true;
38 } else {
39 if ($arg == '-h' || $arg == '--help') {
40 showUsage();
41 } else {
42 $files[] = $arg;
43 }
44 }
45 }
46}
47
48if (!empty($files)) {
49 // file linting
50 $exitCode = 0;
51 foreach ($files as $file) {
52 $result = lintFile($file, $quiet);
53 if ($result === false) {
54 $exitCode = 1;
55 }
56 }
57 exit($exitCode);
58} else {
59 //stdin linting
60 if ($contents = file_get_contents('php://stdin')) {
61 lint($contents);
62 } else {
63 fwrite(STDERR, 'No file name or json input given' . PHP_EOL);
64 exit(1);
65 }
66}
67
68// stdin lint function
69function lint($content, $quiet = false)
70{
71 $parser = new JsonParser();
72 if ($err = $parser->lint($content)) {
73 fwrite(STDERR, $err->getMessage() . ' (stdin)' . PHP_EOL);
74 exit(1);
75 }
76 if (!$quiet) {
77 echo 'Valid JSON (stdin)' . PHP_EOL;
78 exit(0);
79 }
80}
81
82// file lint function
83function lintFile($file, $quiet = false)
84{
85 if (!preg_match('{^https?://}i', $file)) {
86 if (!file_exists($file)) {
87 fwrite(STDERR, 'File not found: ' . $file . PHP_EOL);
88 return false;
89 }
90 if (!is_readable($file)) {
91 fwrite(STDERR, 'File not readable: ' . $file . PHP_EOL);
92 return false;
93 }
94 }
95
96 $content = file_get_contents($file);
97 $parser = new JsonParser();
98 if ($err = $parser->lint($content)) {
99 fwrite(STDERR, $file . ': ' . $err->getMessage() . PHP_EOL);
100 return false;
101 }
102 if (!$quiet) {
103 echo 'Valid JSON (' . $file . ')' . PHP_EOL;
104 }
105 return true;
106}
107
108// usage text function
109function showUsage()
110{
111 echo 'Usage: jsonlint file [options]'.PHP_EOL;
112 echo PHP_EOL;
113 echo 'Options:'.PHP_EOL;
114 echo ' -q, --quiet Cause jsonlint to be quiet when no errors are found'.PHP_EOL;
115 echo ' -h, --help Show this message'.PHP_EOL;
116 exit(0);
117}
118