Prefer Json::encode() over json_encode()

refs #2635
This commit is contained in:
Alexander A. Klimov 2018-04-27 17:25:22 +02:00
parent 9219cea776
commit 1a94a21263
5 changed files with 9 additions and 5 deletions

View File

@ -9,6 +9,7 @@ use Icinga\Application\Logger\Writer\FileWriter;
use Icinga\Application\Logger\Writer\SyslogWriter; use Icinga\Application\Logger\Writer\SyslogWriter;
use Icinga\Exception\ConfigurationError; use Icinga\Exception\ConfigurationError;
use Icinga\Exception\IcingaException; use Icinga\Exception\IcingaException;
use Icinga\Util\Json;
/** /**
* Logger * Logger
@ -251,7 +252,7 @@ class Logger
function ($a) { function ($a) {
return is_string($a) ? $a : ($a instanceof Exception return is_string($a) ? $a : ($a instanceof Exception
? IcingaException::describe($a) ? IcingaException::describe($a)
: json_encode($a)); : Json::encode($a));
}, },
$arguments $arguments
) )

View File

@ -3,6 +3,7 @@
namespace Icinga\Web\Announcement; namespace Icinga\Web\Announcement;
use Icinga\Util\Json;
use Icinga\Web\Cookie; use Icinga\Web\Cookie;
/** /**
@ -128,7 +129,7 @@ class AnnouncementCookie extends Cookie
*/ */
public function getValue() public function getValue()
{ {
return json_encode(array( return Json::encode(array(
'acknowledged' => $this->getAcknowledged(), 'acknowledged' => $this->getAcknowledged(),
'etag' => $this->getEtag(), 'etag' => $this->getEtag(),
'next' => $this->getNextActive() 'next' => $this->getNextActive()

View File

@ -3,6 +3,7 @@
namespace Icinga\Web\Response; namespace Icinga\Web\Response;
use Icinga\Util\Json;
use Zend_Controller_Action_HelperBroker; use Zend_Controller_Action_HelperBroker;
use Icinga\Web\Response; use Icinga\Web\Response;
@ -190,7 +191,7 @@ class JsonResponse extends Response
$body['data'] = $this->getSuccessData(); $body['data'] = $this->getSuccessData();
break; break;
} }
echo json_encode($body, $this->getEncodingOptions()); echo Json::encode($body, $this->getEncodingOptions());
} }
/** /**

View File

@ -10,6 +10,7 @@ use Icinga\Cli\Command;
use Icinga\File\Csv; use Icinga\File\Csv;
use Icinga\Module\Monitoring\Plugin\PerfdataSet; use Icinga\Module\Monitoring\Plugin\PerfdataSet;
use Exception; use Exception;
use Icinga\Util\Json;
/** /**
* Icinga monitoring objects * Icinga monitoring objects
@ -78,7 +79,7 @@ class ListCommand extends Command
$query = $query->getQuery(); $query = $query->getQuery();
switch ($format) { switch ($format) {
case 'json': case 'json':
echo json_encode($query->fetchAll()); echo Json::encode($query->fetchAll());
break; break;
case 'csv': case 'csv':
Csv::fromQuery($query)->dump(); Csv::fromQuery($query)->dump();

View File

@ -173,7 +173,7 @@ class RestRequest
{ {
switch ($contentType) { switch ($contentType) {
case 'application/json': case 'application/json':
$payload = json_encode($payload); $payload = Json::encode($payload);
break; break;
} }