mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-21 22:32:41 +01:00
Use phutil_json_decode instead of json_decode
Summary: Generally, `phutil_json_decode` should be preferred over `json_decode`. Test Plan: Eyellballed. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin, epriestley Differential Revision: https://secure.phabricator.com/D12680
This commit is contained in:
parent
05e745d9b8
commit
70c8649142
34 changed files with 144 additions and 89 deletions
|
@ -53,7 +53,7 @@ foreach ($sheets as $name => $sheet) {
|
|||
if (!$args->getArg('force')) {
|
||||
if (Filesystem::pathExists($manifest_path)) {
|
||||
$data = Filesystem::readFile($manifest_path);
|
||||
$data = json_decode($data, true);
|
||||
$data = phutil_json_decode($data);
|
||||
if (!$sheet->needsRegeneration($data)) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -647,12 +647,15 @@ final class PhabricatorConduitAPIController
|
|||
// entire param dictionary JSON encoded.
|
||||
$params_json = $request->getStr('params');
|
||||
if (strlen($params_json)) {
|
||||
$params = json_decode($params_json, true);
|
||||
if (!is_array($params)) {
|
||||
throw new Exception(
|
||||
"Invalid parameter information was passed to method ".
|
||||
"'{$method}', could not decode JSON serialization. Data: ".
|
||||
$params_json);
|
||||
$params = null;
|
||||
try {
|
||||
$params = phutil_json_decode($params_json);
|
||||
} catch (PhutilJSONParserException $ex) {
|
||||
throw new PhutilProxyException(
|
||||
pht(
|
||||
"Invalid parameter information was passed to method '%s'",
|
||||
$method),
|
||||
$ex);
|
||||
}
|
||||
|
||||
$metadata = idx($params, '__conduit__', array());
|
||||
|
|
|
@ -26,13 +26,17 @@ final class ConduitSSHWorkflow extends PhabricatorSSHWorkflow {
|
|||
$method = head($methodv);
|
||||
|
||||
$json = $this->readAllInput();
|
||||
$raw_params = json_decode($json, true);
|
||||
if (!is_array($raw_params)) {
|
||||
throw new Exception('Invalid JSON input.');
|
||||
$raw_params = null;
|
||||
try {
|
||||
$raw_params = phutil_json_decode($json);
|
||||
} catch (PhutilJSONParserException $ex) {
|
||||
throw new PhutilProxyException(
|
||||
pht('Invalid JSON input.'),
|
||||
$ex);
|
||||
}
|
||||
|
||||
$params = idx($raw_params, 'params', '[]');
|
||||
$params = json_decode($params, true);
|
||||
$params = phutil_json_decode($params);
|
||||
$metadata = idx($params, '__conduit__', array());
|
||||
unset($params['__conduit__']);
|
||||
|
||||
|
|
|
@ -33,9 +33,9 @@ final class DarkConsoleDataController extends PhabricatorController {
|
|||
return new Aphront400Response();
|
||||
}
|
||||
|
||||
$result = json_decode($result, true);
|
||||
|
||||
if (!is_array($result)) {
|
||||
try {
|
||||
$result = phutil_json_decode($result);
|
||||
} catch (PhutilJSONParserException $ex) {
|
||||
return new Aphront400Response();
|
||||
}
|
||||
|
||||
|
|
|
@ -17,9 +17,12 @@ final class DifferentialParseRenderTestCase extends PhabricatorTestCase {
|
|||
$opt_file = $dir.$file.'.options';
|
||||
if (Filesystem::pathExists($opt_file)) {
|
||||
$options = Filesystem::readFile($opt_file);
|
||||
$options = json_decode($options, true);
|
||||
if (!is_array($options)) {
|
||||
throw new Exception("Invalid options file: {$opt_file}.");
|
||||
try {
|
||||
$options = phutil_json_decode($options);
|
||||
} catch (PhutilJSONParserException $ex) {
|
||||
throw new PhutilProxyException(
|
||||
pht('Invalid options file: %s.', $opt_file),
|
||||
$ex);
|
||||
}
|
||||
} else {
|
||||
$options = array();
|
||||
|
|
|
@ -86,7 +86,7 @@ final class DifferentialSetDiffPropertyConduitAPIMethod
|
|||
protected function execute(ConduitAPIRequest $request) {
|
||||
$diff_id = $request->getValue('diff_id');
|
||||
$name = $request->getValue('name');
|
||||
$data = json_decode($request->getValue('data'), true);
|
||||
$data = phutil_json_decode($request->getValue('data'));
|
||||
|
||||
self::updateDiffProperty($diff_id, $name, $data);
|
||||
|
||||
|
|
|
@ -154,9 +154,11 @@ final class DiffusionLintSaveRunner {
|
|||
$files);
|
||||
|
||||
foreach (new LinesOfALargeExecFuture($future) as $json) {
|
||||
$paths = json_decode($json, true);
|
||||
if (!is_array($paths)) {
|
||||
fprintf(STDERR, "Invalid JSON: {$json}\n");
|
||||
$paths = null;
|
||||
try {
|
||||
$paths = phutil_json_decode($json);
|
||||
} catch (PhutilJSONParserException $ex) {
|
||||
fprintf(STDERR, pht("Invalid JSON: %s\n", $json));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,8 +11,9 @@ final class DiffusionLastModifiedController extends DiffusionController {
|
|||
$viewer = $request->getUser();
|
||||
|
||||
$paths = $request->getStr('paths');
|
||||
$paths = json_decode($paths, true);
|
||||
if (!is_array($paths)) {
|
||||
try {
|
||||
$paths = phutil_json_decode($paths);
|
||||
} catch (PhutilJSONParserException $ex) {
|
||||
return new Aphront400Response();
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ final class DiffusionMercurialWireSSHTestCase extends PhabricatorTestCase {
|
|||
$raw = Filesystem::readFile($data.$file);
|
||||
$raw = explode("\n~~~~~~~~~~\n", $raw, 2);
|
||||
$this->assertEqual(2, count($raw));
|
||||
$expect = json_decode($raw[1], true);
|
||||
$expect = phutil_json_decode($raw[1]);
|
||||
$this->assertTrue(is_array($expect), $file);
|
||||
|
||||
$this->assertParserResult($expect, $raw[0], $file);
|
||||
|
|
|
@ -7,8 +7,9 @@ final class DoorkeeperTagsController extends PhabricatorController {
|
|||
$viewer = $request->getUser();
|
||||
|
||||
$tags = $request->getStr('tags');
|
||||
$tags = json_decode($tags, true);
|
||||
if (!is_array($tags)) {
|
||||
try {
|
||||
$tags = phutil_json_decode($tags);
|
||||
} catch (PhutilJSONParserException $ex) {
|
||||
$tags = array();
|
||||
}
|
||||
|
||||
|
|
|
@ -12,8 +12,9 @@ final class PhabricatorHelpKeyboardShortcutController
|
|||
$user = $request->getUser();
|
||||
|
||||
$keys = $request->getStr('keys');
|
||||
$keys = json_decode($keys, true);
|
||||
if (!is_array($keys)) {
|
||||
try {
|
||||
$keys = phutil_json_decode($keys);
|
||||
} catch (PhutilJSONParserException $ex) {
|
||||
return new Aphront400Response();
|
||||
}
|
||||
|
||||
|
|
|
@ -633,14 +633,16 @@ abstract class HeraldAdapter {
|
|||
// dictionary. The first regexp must match the dictionary key, and the
|
||||
// second regexp must match the dictionary value. If any key/value pair
|
||||
// in the dictionary matches both regexps, the condition is satisfied.
|
||||
$regexp_pair = json_decode($condition_value, true);
|
||||
if (!is_array($regexp_pair)) {
|
||||
$regexp_pair = null;
|
||||
try {
|
||||
$regexp_pair = phutil_json_decode($condition_value);
|
||||
} catch (PhutilJSONParserException $ex) {
|
||||
throw new HeraldInvalidConditionException(
|
||||
'Regular expression pair is not valid JSON!');
|
||||
pht('Regular expression pair is not valid JSON!'));
|
||||
}
|
||||
if (count($regexp_pair) != 2) {
|
||||
throw new HeraldInvalidConditionException(
|
||||
'Regular expression pair is not a pair!');
|
||||
pht('Regular expression pair is not a pair!'));
|
||||
}
|
||||
|
||||
$key_regexp = array_shift($regexp_pair);
|
||||
|
@ -705,8 +707,10 @@ abstract class HeraldAdapter {
|
|||
}
|
||||
break;
|
||||
case self::CONDITION_REGEXP_PAIR:
|
||||
$json = json_decode($condition_value, true);
|
||||
if (!is_array($json)) {
|
||||
$json = null;
|
||||
try {
|
||||
$json = phutil_json_decode($condition_value);
|
||||
} catch (PhutilJSONParserException $ex) {
|
||||
throw new HeraldInvalidConditionException(
|
||||
pht(
|
||||
'The regular expression pair "%s" is not valid JSON. Enter a '.
|
||||
|
|
|
@ -258,7 +258,15 @@ final class HeraldRuleController extends HeraldController {
|
|||
$errors[] = pht('Rule must have a name.');
|
||||
}
|
||||
|
||||
$data = json_decode($request->getStr('rule'), true);
|
||||
$data = null;
|
||||
try {
|
||||
$data = phutil_json_decode($request->getStr('rule'));
|
||||
} catch (PhutilJSONParserException $ex) {
|
||||
throw new PhutilProxyException(
|
||||
pht('Failed to decode rule data.'),
|
||||
$ex);
|
||||
}
|
||||
|
||||
if (!is_array($data) ||
|
||||
!$data['conditions'] ||
|
||||
!$data['actions']) {
|
||||
|
|
|
@ -47,7 +47,7 @@ final class ManiphestBatchEditController extends ManiphestController {
|
|||
|
||||
$actions = $request->getStr('actions');
|
||||
if ($actions) {
|
||||
$actions = json_decode($actions, true);
|
||||
$actions = phutil_json_decode($actions);
|
||||
}
|
||||
|
||||
if ($request->isFormPost() && is_array($actions)) {
|
||||
|
|
|
@ -74,7 +74,7 @@ final class ManiphestTransactionPreviewController extends ManiphestController {
|
|||
break;
|
||||
case PhabricatorTransactions::TYPE_EDGE:
|
||||
if ($value) {
|
||||
$value = json_decode($value);
|
||||
$value = phutil_json_decode($value);
|
||||
}
|
||||
if (!$value) {
|
||||
$value = array();
|
||||
|
|
|
@ -120,9 +120,13 @@ final class PhabricatorMailImplementationMailgunAdapter
|
|||
|
||||
list($body) = $future->resolvex();
|
||||
|
||||
$response = json_decode($body, true);
|
||||
if (!is_array($response)) {
|
||||
throw new Exception("Failed to JSON decode response: {$body}");
|
||||
$response = null;
|
||||
try {
|
||||
$response = phutil_json_decode($body);
|
||||
} catch (PhutilJSONParserException $ex) {
|
||||
throw new PhutilProxyException(
|
||||
pht('Failed to JSON decode response.'),
|
||||
$ex);
|
||||
}
|
||||
|
||||
if (!idx($response, 'id')) {
|
||||
|
|
|
@ -78,8 +78,10 @@ final class PhabricatorMailImplementationSendGridAdapter
|
|||
|
||||
if (!$user || !$key) {
|
||||
throw new Exception(
|
||||
"Configure 'sendgrid.api-user' and 'sendgrid.api-key' to use ".
|
||||
"SendGrid for mail delivery.");
|
||||
pht(
|
||||
"Configure '%s' and '%s' to use SendGrid for mail delivery.",
|
||||
'sendgrid.api-user',
|
||||
'sendgrid.api-key'));
|
||||
}
|
||||
|
||||
$params = array();
|
||||
|
@ -142,14 +144,18 @@ final class PhabricatorMailImplementationSendGridAdapter
|
|||
|
||||
list($body) = $future->resolvex();
|
||||
|
||||
$response = json_decode($body, true);
|
||||
if (!is_array($response)) {
|
||||
throw new Exception("Failed to JSON decode response: {$body}");
|
||||
$response = null;
|
||||
try {
|
||||
$response = phutil_json_decode($body);
|
||||
} catch (PhutilJSONParserException $ex) {
|
||||
throw new PhutilProxyException(
|
||||
pht('Failed to JSON decode response.'),
|
||||
$ex);
|
||||
}
|
||||
|
||||
if ($response['message'] !== 'success') {
|
||||
$errors = implode(';', $response['errors']);
|
||||
throw new Exception("Request failed with errors: {$errors}.");
|
||||
throw new Exception(pht('Request failed with errors: %s.', $errors));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -32,7 +32,7 @@ final class PhabricatorContentSource {
|
|||
}
|
||||
|
||||
public static function newFromSerialized($serialized) {
|
||||
$dict = json_decode($serialized, true);
|
||||
$dict = phutil_json_decode($serialized);
|
||||
if (!is_array($dict)) {
|
||||
$dict = array();
|
||||
}
|
||||
|
|
|
@ -93,15 +93,18 @@ final class PhameSkinSpecification {
|
|||
}
|
||||
|
||||
private static function loadSkinSpecification($path) {
|
||||
|
||||
$config_path = $path.DIRECTORY_SEPARATOR.'skin.json';
|
||||
$config = array();
|
||||
if (Filesystem::pathExists($config_path)) {
|
||||
$config = Filesystem::readFile($config_path);
|
||||
$config = json_decode($config, true);
|
||||
if (!is_array($config)) {
|
||||
throw new Exception(
|
||||
"Skin configuration file '{$config_path}' is not a valid JSON file.");
|
||||
try {
|
||||
$config = phutil_json_decode($config);
|
||||
} catch (PhutilJSONParserException $ex) {
|
||||
throw new PhutilProxyException(
|
||||
pht(
|
||||
"Skin configuration file '%s' is not a valid JSON file.",
|
||||
$config_path),
|
||||
$ex);
|
||||
}
|
||||
$type = idx($config, 'type', self::TYPE_BASIC);
|
||||
} else {
|
||||
|
|
|
@ -94,20 +94,23 @@ final class PhortunePaymentMethodCreateController
|
|||
|
||||
if (!$errors) {
|
||||
$client_token_raw = $request->getStr('token');
|
||||
$client_token = json_decode($client_token_raw, true);
|
||||
if (!is_array($client_token)) {
|
||||
$client_token = null;
|
||||
try {
|
||||
$client_token = phutil_json_decode($client_token_raw);
|
||||
} catch (PhutilJSONParserException $ex) {
|
||||
$errors[] = pht(
|
||||
'There was an error decoding token information submitted by the '.
|
||||
'client. Expected a JSON-encoded token dictionary, received: %s.',
|
||||
nonempty($client_token_raw, pht('nothing')));
|
||||
} else {
|
||||
if (!$provider->validateCreatePaymentMethodToken($client_token)) {
|
||||
$errors[] = pht(
|
||||
'There was an error with the payment token submitted by the '.
|
||||
'client. Expected a valid dictionary, received: %s.',
|
||||
$client_token_raw);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$provider->validateCreatePaymentMethodToken($client_token)) {
|
||||
$errors[] = pht(
|
||||
'There was an error with the payment token submitted by the '.
|
||||
'client. Expected a valid dictionary, received: %s.',
|
||||
$client_token_raw);
|
||||
}
|
||||
|
||||
if (!$errors) {
|
||||
$errors = $provider->createPaymentMethodFromRequest(
|
||||
$request,
|
||||
|
@ -215,8 +218,10 @@ final class PhortunePaymentMethodCreateController
|
|||
|
||||
$errors = array();
|
||||
|
||||
$client_errors = json_decode($client_errors_raw, true);
|
||||
if (!is_array($client_errors)) {
|
||||
$client_errors = null;
|
||||
try {
|
||||
$client_errors = phutil_json_decode($client_errors_raw);
|
||||
} catch (PhutilJSONParserException $ex) {
|
||||
$errors[] = pht(
|
||||
'There was an error decoding error information submitted by the '.
|
||||
'client. Expected a JSON-encoded list of error codes, received: %s.',
|
||||
|
|
|
@ -52,9 +52,12 @@ final class PhabricatorPolicyEditController
|
|||
$errors = array();
|
||||
if ($request->isFormPost()) {
|
||||
$data = $request->getStr('rules');
|
||||
$data = @json_decode($data, true);
|
||||
if (!is_array($data)) {
|
||||
throw new Exception('Failed to JSON decode rule data!');
|
||||
try {
|
||||
$data = phutil_json_decode($data);
|
||||
} catch (PhutilJSONParserException $ex) {
|
||||
throw new PhutilProxyException(
|
||||
pht('Failed to JSON decode rule data!'),
|
||||
$ex);
|
||||
}
|
||||
|
||||
$rule_data = array();
|
||||
|
|
|
@ -39,7 +39,7 @@ final class DifferentialReleephRequestFieldSpecification {
|
|||
|
||||
public function setValueFromStorage($json) {
|
||||
if ($json) {
|
||||
$dict = json_decode($json, true);
|
||||
$dict = phutil_json_decode($json);
|
||||
$this->releephAction = idx($dict, 'releephAction');
|
||||
$this->releephPHIDs = idx($dict, 'releephPHIDs');
|
||||
}
|
||||
|
|
|
@ -397,12 +397,13 @@ final class PhabricatorElasticSearchEngine extends PhabricatorSearchEngine {
|
|||
return null;
|
||||
}
|
||||
|
||||
$body = json_decode($body, true);
|
||||
if (!is_array($body)) {
|
||||
throw new Exception('elasticsearch server returned invalid JSON!');
|
||||
try {
|
||||
return phutil_json_decode($body);
|
||||
} catch (PhutilJSONParserException $ex) {
|
||||
throw new PhutilProxyException(
|
||||
pht('ElasticSearch server returned invalid JSON!'),
|
||||
$ex);
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,9 +21,12 @@ final class PhabricatorXHProfProfileController
|
|||
}
|
||||
|
||||
$data = $file->loadFileData();
|
||||
$data = @json_decode($data, true);
|
||||
if (!$data) {
|
||||
throw new Exception('Failed to unserialize XHProf profile!');
|
||||
try {
|
||||
$data = phutil_json_decode($data);
|
||||
} catch (PhutilJSONParserException $ex) {
|
||||
throw new PhutilProxyException(
|
||||
pht('Failed to unserialize XHProf profile!'),
|
||||
$ex);
|
||||
}
|
||||
|
||||
$symbol = $request->getStr('symbol');
|
||||
|
|
|
@ -11,7 +11,7 @@ final class PhabricatorCustomFieldConfigOptionType
|
|||
$errors = array();
|
||||
$storage_value = $request->getStr('value');
|
||||
|
||||
$in_value = json_decode($storage_value, true);
|
||||
$in_value = phutil_json_decode($storage_value);
|
||||
if (!is_array($in_value)) {
|
||||
$in_value = array();
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ abstract class PhabricatorStandardCustomFieldPHIDs
|
|||
$old = array();
|
||||
}
|
||||
|
||||
$new = json_decode($xaction->getNewValue());
|
||||
$new = phutil_json_decode($xaction->getNewValue());
|
||||
if (!is_array($new)) {
|
||||
$new = array();
|
||||
}
|
||||
|
|
|
@ -23,9 +23,12 @@ final class PhabricatorBot extends PhabricatorDaemon {
|
|||
}
|
||||
|
||||
$json_raw = Filesystem::readFile($argv[0]);
|
||||
$config = json_decode($json_raw, true);
|
||||
if (!is_array($config)) {
|
||||
throw new Exception("File '{$argv[0]}' is not valid JSON!");
|
||||
try {
|
||||
$config = phutil_json_decode($json_raw);
|
||||
} catch (PhutilJSONParserException $ex) {
|
||||
throw new PhutilProxyException(
|
||||
pht("File '%s' is not valid JSON!", $argv[0]),
|
||||
$ex);
|
||||
}
|
||||
|
||||
$nick = idx($config, 'nick', 'phabot');
|
||||
|
|
|
@ -124,7 +124,7 @@ abstract class PhabricatorBotBaseStreamingProtocolAdapter
|
|||
$message = substr($buffer, 0, $until + 1);
|
||||
$buffer = substr($buffer, $until + 2);
|
||||
|
||||
$m_obj = json_decode($message, true);
|
||||
$m_obj = phutil_json_decode($message);
|
||||
if ($message = $this->processMessage($m_obj)) {
|
||||
return $message;
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ abstract class PhabricatorBotBaseStreamingProtocolAdapter
|
|||
|
||||
$output = trim($output);
|
||||
if (strlen($output)) {
|
||||
return json_decode($output, true);
|
||||
return phutil_json_decode($output);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -165,6 +165,6 @@ abstract class PhabricatorBotBaseStreamingProtocolAdapter
|
|||
|
||||
abstract protected function buildStreamingUrl($channel);
|
||||
|
||||
abstract protected function processMessage($raw_object);
|
||||
abstract protected function processMessage(array $raw_object);
|
||||
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ final class PhabricatorBotFlowdockProtocolAdapter
|
|||
return $url;
|
||||
}
|
||||
|
||||
protected function processMessage($m_obj) {
|
||||
protected function processMessage(array $m_obj) {
|
||||
$command = null;
|
||||
switch ($m_obj['event']) {
|
||||
case 'message':
|
||||
|
|
|
@ -16,7 +16,7 @@ final class PhabricatorCampfireProtocolAdapter
|
|||
return $url;
|
||||
}
|
||||
|
||||
protected function processMessage($m_obj) {
|
||||
protected function processMessage(array $m_obj) {
|
||||
$command = null;
|
||||
switch ($m_obj['type']) {
|
||||
case 'TextMessage':
|
||||
|
|
|
@ -191,7 +191,7 @@ final class PhabricatorWorkerLeaseQuery extends PhabricatorQuery {
|
|||
foreach ($data as $row) {
|
||||
$tasks[$row['id']]->setServerTime($row['_serverTime']);
|
||||
if ($row['_taskData']) {
|
||||
$task_data = json_decode($row['_taskData'], true);
|
||||
$task_data = phutil_json_decode($row['_taskData']);
|
||||
} else {
|
||||
$task_data = null;
|
||||
}
|
||||
|
|
|
@ -201,7 +201,7 @@ final class PhabricatorEdgeQuery extends PhabricatorQuery {
|
|||
$data_ids);
|
||||
foreach ($data_rows as $row) {
|
||||
$data_map[$row['id']] = idx(
|
||||
json_decode($row['data'], true),
|
||||
phutil_json_decode($row['data']),
|
||||
'data');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1637,7 +1637,7 @@ abstract class LiskDAO {
|
|||
break;
|
||||
case self::SERIALIZATION_JSON:
|
||||
if ($deserialize) {
|
||||
$data[$col] = json_decode($data[$col], true);
|
||||
$data[$col] = phutil_json_decode($data[$col]);
|
||||
} else {
|
||||
$data[$col] = json_encode($data[$col]);
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ final class PHUIIconView extends AphrontTagView {
|
|||
$root = dirname(phutil_get_library_root('phabricator'));
|
||||
$path = $root.'/resources/sprite/manifest/'.$sheet.'.json';
|
||||
$data = Filesystem::readFile($path);
|
||||
return idx(json_decode($data, true), 'sprites');
|
||||
return idx(phutil_json_decode($data), 'sprites');
|
||||
}
|
||||
|
||||
public static function getFontIcons() {
|
||||
|
|
Loading…
Reference in a new issue