From 1a94a212636f24e2cbb23261f9f6f946a0f7fb13 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 27 Apr 2018 17:25:22 +0200 Subject: [PATCH] Prefer Json::encode() over json_encode() refs #2635 --- library/Icinga/Application/Logger.php | 3 ++- library/Icinga/Web/Announcement/AnnouncementCookie.php | 3 ++- library/Icinga/Web/Response/JsonResponse.php | 3 ++- modules/monitoring/application/clicommands/ListCommand.php | 3 ++- modules/monitoring/library/Monitoring/Web/Rest/RestRequest.php | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/library/Icinga/Application/Logger.php b/library/Icinga/Application/Logger.php index dfece064c..347af4479 100644 --- a/library/Icinga/Application/Logger.php +++ b/library/Icinga/Application/Logger.php @@ -9,6 +9,7 @@ use Icinga\Application\Logger\Writer\FileWriter; use Icinga\Application\Logger\Writer\SyslogWriter; use Icinga\Exception\ConfigurationError; use Icinga\Exception\IcingaException; +use Icinga\Util\Json; /** * Logger @@ -251,7 +252,7 @@ class Logger function ($a) { return is_string($a) ? $a : ($a instanceof Exception ? IcingaException::describe($a) - : json_encode($a)); + : Json::encode($a)); }, $arguments ) diff --git a/library/Icinga/Web/Announcement/AnnouncementCookie.php b/library/Icinga/Web/Announcement/AnnouncementCookie.php index e1f4d479d..f4398ba3a 100644 --- a/library/Icinga/Web/Announcement/AnnouncementCookie.php +++ b/library/Icinga/Web/Announcement/AnnouncementCookie.php @@ -3,6 +3,7 @@ namespace Icinga\Web\Announcement; +use Icinga\Util\Json; use Icinga\Web\Cookie; /** @@ -128,7 +129,7 @@ class AnnouncementCookie extends Cookie */ public function getValue() { - return json_encode(array( + return Json::encode(array( 'acknowledged' => $this->getAcknowledged(), 'etag' => $this->getEtag(), 'next' => $this->getNextActive() diff --git a/library/Icinga/Web/Response/JsonResponse.php b/library/Icinga/Web/Response/JsonResponse.php index d0da9a4f3..9bf97d8bf 100644 --- a/library/Icinga/Web/Response/JsonResponse.php +++ b/library/Icinga/Web/Response/JsonResponse.php @@ -3,6 +3,7 @@ namespace Icinga\Web\Response; +use Icinga\Util\Json; use Zend_Controller_Action_HelperBroker; use Icinga\Web\Response; @@ -190,7 +191,7 @@ class JsonResponse extends Response $body['data'] = $this->getSuccessData(); break; } - echo json_encode($body, $this->getEncodingOptions()); + echo Json::encode($body, $this->getEncodingOptions()); } /** diff --git a/modules/monitoring/application/clicommands/ListCommand.php b/modules/monitoring/application/clicommands/ListCommand.php index 743f9e893..64b8bdc3c 100644 --- a/modules/monitoring/application/clicommands/ListCommand.php +++ b/modules/monitoring/application/clicommands/ListCommand.php @@ -10,6 +10,7 @@ use Icinga\Cli\Command; use Icinga\File\Csv; use Icinga\Module\Monitoring\Plugin\PerfdataSet; use Exception; +use Icinga\Util\Json; /** * Icinga monitoring objects @@ -78,7 +79,7 @@ class ListCommand extends Command $query = $query->getQuery(); switch ($format) { case 'json': - echo json_encode($query->fetchAll()); + echo Json::encode($query->fetchAll()); break; case 'csv': Csv::fromQuery($query)->dump(); diff --git a/modules/monitoring/library/Monitoring/Web/Rest/RestRequest.php b/modules/monitoring/library/Monitoring/Web/Rest/RestRequest.php index cc0c3b222..fcbe0ca0b 100644 --- a/modules/monitoring/library/Monitoring/Web/Rest/RestRequest.php +++ b/modules/monitoring/library/Monitoring/Web/Rest/RestRequest.php @@ -173,7 +173,7 @@ class RestRequest { switch ($contentType) { case 'application/json': - $payload = json_encode($payload); + $payload = Json::encode($payload); break; }