Skip to content

Commit bd994a6

Browse files
committed
Move json{En,De}code functions to Utils
They don't depend on any DOMjudge internals.
1 parent 82f1192 commit bd994a6

19 files changed

+64
-58
lines changed

webapp/src/Command/CallApiActionCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Entity\User;
66
use App\Service\DOMJudgeService;
7+
use App\Utils\Utils;
78
use Doctrine\ORM\EntityManagerInterface;
89
use Symfony\Component\Console\Attribute\AsCommand;
910
use Symfony\Component\Console\Command\Command;
@@ -114,7 +115,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
114115
}
115116

116117
if ($json = $input->getOption('json')) {
117-
$data = array_merge($data, $this->dj->jsonDecode($json));
118+
$data = array_merge($data, Utils::jsonDecode($json));
118119
}
119120

120121
foreach ($input->getOption('file') as $fileItem) {

webapp/src/Controller/API/ContestController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function addContestAction(Request $request): string
114114
return $cid;
115115
}
116116
} elseif ($jsonFile) {
117-
$data = $this->dj->jsonDecode(file_get_contents($jsonFile->getRealPath()));
117+
$data = Utils::jsonDecode(file_get_contents($jsonFile->getRealPath()));
118118
if ($this->importExportService->importContestData($data, $message, $cid)) {
119119
return $cid;
120120
}
@@ -870,7 +870,7 @@ public function getEventFeedAction(
870870
$result['time'] = Utils::absTime($event->getEventtime());
871871
}
872872

873-
echo $this->dj->jsonEncode($result) . "\n";
873+
echo Utils::jsonEncode($result) . "\n";
874874
ob_flush();
875875
flush();
876876
$lastUpdate = Utils::now();

webapp/src/Controller/API/JudgehostController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ public function internalErrorAction(Request $request): ?int
734734
}
735735
}
736736

737-
$disabled = $this->dj->jsonDecode($disabled);
737+
$disabled = Utils::jsonDecode($disabled);
738738

739739
/** @var Contest|null $contest */
740740
$contest = null;
@@ -770,7 +770,7 @@ public function internalErrorAction(Request $request): ?int
770770
->andWhere('e.disabled = :disabled')
771771
->andWhere('e.status = :status')
772772
->setParameter('description', $description)
773-
->setParameter('disabled', $this->dj->jsonEncode($disabled))
773+
->setParameter('disabled', Utils::jsonEncode($disabled))
774774
->setParameter('status', 'open')
775775
->setMaxResults(1);
776776

webapp/src/Controller/API/LanguageController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Entity\ExecutableFile;
66
use App\Entity\ImmutableExecutable;
77
use App\Entity\Language;
8+
use App\Utils\Utils;
89
use Doctrine\ORM\NonUniqueResultException;
910
use Doctrine\ORM\QueryBuilder;
1011
use FOS\RestBundle\Controller\Annotations as Rest;
@@ -139,7 +140,7 @@ public function configureLanguagesAction(Request $request): Response
139140
if (!$jsonFile) {
140141
throw new BadRequestHttpException('No JSON file supplied.');
141142
}
142-
$newLanguages = $this->dj->jsonDecode(file_get_contents($jsonFile->getRealPath()));
143+
$newLanguages = Utils::jsonDecode(file_get_contents($jsonFile->getRealPath()));
143144

144145
// Disable submission for all current languages, we will enable it for all new languages below.
145146
$curLanguages = $this->em->getRepository(Language::class)->findAll();

webapp/src/Controller/API/ProblemController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use App\Service\EventLogService;
1414
use App\Service\ImportExportService;
1515
use App\Service\ImportProblemService;
16+
use App\Utils\Utils;
1617
use Doctrine\ORM\EntityManagerInterface;
1718
use Doctrine\ORM\NonUniqueResultException;
1819
use Doctrine\ORM\QueryBuilder;
@@ -108,7 +109,7 @@ public function addProblemsAction(Request $request): array
108109
}
109110
$message = "Error while adding problems";
110111
if (!empty($messages)) {
111-
$message .= ': ' . $this->dj->jsonEncode($messages);
112+
$message .= ': ' . Utils::jsonEncode($messages);
112113
}
113114
throw new BadRequestHttpException($message);
114115
}

webapp/src/Controller/Jury/BalloonController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use App\Service\ConfigurationService;
1010
use App\Service\DOMJudgeService;
1111
use App\Service\EventLogService;
12+
use App\Utils\Utils;
1213
use Doctrine\ORM\EntityManagerInterface;
1314
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1415
use Symfony\Component\ExpressionLanguage\Expression;
@@ -77,7 +78,7 @@ public function indexAction(BalloonService $balloonService): Response
7778
}
7879

7980
// Load preselected filters
80-
$filters = $this->dj->jsonDecode((string)$this->dj->getCookie('domjudge_balloonsfilter') ?: '[]');
81+
$filters = Utils::jsonDecode((string)$this->dj->getCookie('domjudge_balloonsfilter') ?: '[]');
8182
$haveFilters = $this->dj->getCookie('domjudge_balloonsfilter') != null;
8283
$filteredAffiliations = [];
8384
$filteredLocations = [];

webapp/src/Controller/Jury/ContestController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ public function prefetchAction(Request $request, int $contestId): Response
708708
// TODO: dedup here?
709709
$compareExec = $this->dj->getImmutableCompareExecutable($contestProblem);
710710
$runExec = $this->dj->getImmutableRunExecutable($contestProblem);
711-
$runConfig = $this->dj->jsonEncode(
711+
$runConfig = Utils::jsonEncode(
712712
[
713713
'hash' => $runExec->getHash(),
714714
'combined_run_compare' => $problem->getCombinedRunCompare(),
@@ -720,7 +720,7 @@ public function prefetchAction(Request $request, int $contestId): Response
720720
->setJudgehost($judgehost)
721721
->setPriority(JudgeTask::PRIORITY_DEFAULT)
722722
->setCompareScriptId($compareExec->getImmutableExecId())
723-
->setCompareConfig($this->dj->jsonEncode(['hash' => $compareExec->getHash()]))
723+
->setCompareConfig(Utils::jsonEncode(['hash' => $compareExec->getHash()]))
724724
->setRunScriptId($runExec->getImmutableExecId())
725725
->setRunConfig($runConfig);
726726
$this->em->persist($judgeTask);
@@ -741,7 +741,7 @@ public function prefetchAction(Request $request, int $contestId): Response
741741
->setJudgehost($judgehost)
742742
->setPriority(JudgeTask::PRIORITY_DEFAULT)
743743
->setCompileScriptId($compileExec->getImmutableExecId())
744-
->setCompileConfig($this->dj->jsonEncode(['hash' => $compileExec->getHash()]));
744+
->setCompileConfig(Utils::jsonEncode(['hash' => $compileExec->getHash()]));
745745
$this->em->persist($judgeTask);
746746
$cnt++;
747747
}

webapp/src/Controller/Jury/ExternalContestController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function indexAction(Request $request): Response
102102
$this->sourceService->setSource($externalContestSource);
103103

104104
// Load preselected filters
105-
$filters = $this->dj->jsonDecode((string)$this->dj->getCookie('domjudge_external_source_filter') ?: '[]');
105+
$filters = Utils::jsonDecode((string)$this->dj->getCookie('domjudge_external_source_filter') ?: '[]');
106106

107107
// Build the filter form.
108108
$form = $this->createForm(ExternalSourceWarningsFilterType::class, $filters);

webapp/src/Controller/Jury/InternalErrorController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public function handleAction(Request $request, ?Profiler $profiler, int $errorId
162162
if ($request->isXmlHttpRequest()) {
163163
$profiler?->disable();
164164
$progressReporter = function (int $progress, string $log, ?string $message = null) {
165-
echo $this->dj->jsonEncode(['progress' => $progress, 'log' => htmlspecialchars($log), 'message' => $message]);
165+
echo Utils::jsonEncode(['progress' => $progress, 'log' => htmlspecialchars($log), 'message' => $message]);
166166
ob_flush();
167167
flush();
168168
};

webapp/src/Controller/Jury/JuryMiscController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use App\Service\DOMJudgeService;
1616
use App\Service\EventLogService;
1717
use App\Service\ScoreboardService;
18+
use App\Utils\Utils;
1819
use Doctrine\ORM\EntityManagerInterface;
1920
use Doctrine\ORM\Query\Expr\Join;
2021
use Symfony\Component\DependencyInjection\Attribute\Autowire;
@@ -213,7 +214,7 @@ public function refreshCacheAction(Request $request, ScoreboardService $scoreboa
213214

214215
if ($request->isXmlHttpRequest() && $request->isMethod('POST')) {
215216
$progressReporter = function (int $progress, string $log, ?string $message = null) {
216-
echo $this->dj->jsonEncode(['progress' => $progress, 'log' => htmlspecialchars($log), 'message' => $message]);
217+
echo Utils::jsonEncode(['progress' => $progress, 'log' => htmlspecialchars($log), 'message' => $message]);
217218
ob_flush();
218219
flush();
219220
};

0 commit comments

Comments
 (0)