Skip to content

Commit 4359cde

Browse files
authored
Merge pull request #6617 from WoltLab/63-use-native-json-function
Replace the usage of `wcf\util\JSON`
2 parents c638ecb + 87ac367 commit 4359cde

File tree

61 files changed

+109
-165
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+109
-165
lines changed

wcfsetup/install/files/acp/update_com.woltlab.wcf_6.2_contactOptions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use wcf\data\contact\option\ContactOptionEditor;
88
use wcf\data\contact\option\ContactOptionList;
9-
use wcf\util\JSON;
9+
1010
use wcf\util\OptionUtil;
1111

1212
$contactOptionList = new ContactOptionList();
@@ -39,7 +39,7 @@
3939
$editor = new ContactOptionEditor($contactOption);
4040
$editor->update([
4141
'optionType' => $optionType,
42-
'configuration' => JSON::encode($configuration),
42+
'configuration' => \json_encode($configuration, \JSON_THROW_ON_ERROR),
4343
]);
4444
}
4545

@@ -57,5 +57,5 @@ function convertSelectOptions(string $selectOptions): string
5757
];
5858
}
5959

60-
return JSON::encode($options);
60+
return \json_encode($options, \JSON_THROW_ON_ERROR);
6161
}

wcfsetup/install/files/lib/acp/action/WorkerProxyAction.class.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use wcf\system\exception\SystemException;
99
use wcf\system\WCF;
1010
use wcf\system\worker\IWorker;
11-
use wcf\util\JSON;
1211

1312
/**
1413
* Handles worker actions.
@@ -143,7 +142,7 @@ protected function sendResponse($progress = 0, ?array $parameters = null, $proce
143142

144143
// send JSON-encoded response
145144
\header('Content-type: application/json; charset=UTF-8');
146-
echo JSON::encode($returnValues);
145+
echo \json_encode($returnValues, \JSON_THROW_ON_ERROR);
147146

148147
exit;
149148
}

wcfsetup/install/files/lib/acp/form/AbstractFormOptionAddForm.class.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use wcf\system\form\builder\IFormDocument;
1313
use wcf\system\form\option\FormOptionHandler;
1414
use wcf\system\form\option\SharedConfigurationFormFields;
15-
use wcf\util\JSON;
1615

1716
/**
1817
* Default implementation for a form that adds custom options based on the form option system.
@@ -47,7 +46,7 @@ function (IFormDocument $document, array $parameters) {
4746
}
4847
}
4948

50-
$parameters['data']['configuration'] = JSON::encode($configuration);
49+
$parameters['data']['configuration'] = \json_encode($configuration, \JSON_THROW_ON_ERROR);
5150

5251
return $parameters;
5352
},
@@ -56,7 +55,7 @@ function (IFormDocument $document, array $data, IStorableObject $object) {
5655

5756
// @phpstan-ignore property.notFound
5857
if ($object->configuration) {
59-
$data = \array_merge($data, JSON::decode($object->configuration));
58+
$data = \array_merge($data, \json_decode($object->configuration, true, flags: \JSON_THROW_ON_ERROR));
6059
}
6160

6261
return $data;

wcfsetup/install/files/lib/action/AJAXFileDeleteAction.class.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use wcf\system\exception\UserInputException;
77
use wcf\system\file\upload\UploadFile;
88
use wcf\system\file\upload\UploadHandler;
9-
use wcf\util\JSON;
109

1110
/**
1211
* Copy of the default implementation for file uploads using the AJAX-API.
@@ -97,7 +96,7 @@ public function execute()
9796
*/
9897
protected function sendJsonResponse(array $data)
9998
{
100-
$json = JSON::encode($data);
99+
$json = \json_encode($data, \JSON_THROW_ON_ERROR);
101100

102101
// send JSON response
103102
\header('Content-type: application/json; charset=UTF-8');

wcfsetup/install/files/lib/action/AJAXFileUploadAction.class.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use wcf\system\WCF;
1010
use wcf\util\FileUtil;
1111
use wcf\util\ImageUtil;
12-
use wcf\util\JSON;
1312

1413
/**
1514
* Copy of the default implementation for file uploads using the AJAX-API.
@@ -153,7 +152,7 @@ public function execute()
153152
*/
154153
protected function sendJsonResponse(array $data)
155154
{
156-
$json = JSON::encode($data);
155+
$json = \json_encode($data, \JSON_THROW_ON_ERROR);
157156

158157
// send JSON response
159158
\header('Content-type: application/json; charset=UTF-8');

wcfsetup/install/files/lib/action/AJAXInvokeAction.class.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use wcf\system\IAJAXInvokeAction;
1212
use wcf\system\SingletonFactory;
1313
use wcf\system\WCF;
14-
use wcf\util\JSON;
1514
use wcf\util\StringUtil;
1615

1716
/**
@@ -168,7 +167,7 @@ protected function invoke()
168167
protected function sendResponse()
169168
{
170169
\header('Content-type: application/json; charset=UTF-8');
171-
echo JSON::encode($this->response);
170+
echo \json_encode($this->response, \JSON_THROW_ON_ERROR);
172171

173172
exit;
174173
}

wcfsetup/install/files/lib/action/AbstractAjaxAction.class.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace wcf\action;
44

5-
use wcf\util\JSON;
6-
75
/**
86
* @deprecated 5.5 Use PSR-7 responses (e.g. Laminas' JsonResponse).
97
*/
@@ -17,7 +15,7 @@ abstract class AbstractAjaxAction extends AbstractAction
1715
*/
1816
protected function sendJsonResponse(array $data)
1917
{
20-
$json = JSON::encode($data);
18+
$json = \json_encode($data, \JSON_THROW_ON_ERROR);
2119

2220
// send JSON response
2321
\header('Content-type: application/json; charset=UTF-8');

wcfsetup/install/files/lib/action/AbstractOauth2Action.class.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use wcf\system\user\authentication\oauth\User as OauthUser;
1818
use wcf\system\WCF;
1919
use wcf\util\HtmlString;
20-
use wcf\util\JSON;
2120

2221
/**
2322
* Generic implementation to handle the OAuth 2 flow.
@@ -182,7 +181,7 @@ protected function codeToAccessToken(string $code): array
182181
}
183182
}
184183

185-
$parsed = JSON::decode((string)$response->getBody());
184+
$parsed = \json_decode((string)$response->getBody(), true, flags: \JSON_THROW_ON_ERROR);
186185

187186
if (!empty($parsed['error'])) {
188187
throw new \Exception(\sprintf(

wcfsetup/install/files/lib/action/AbstractOauth2AuthAction.class.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
use wcf\system\user\authentication\oauth\User as OauthUser;
3131
use wcf\system\WCF;
3232
use wcf\util\HtmlString;
33-
use wcf\util\JSON;
3433

3534
/**
3635
* Generic implementation to handle the OAuth 2 flow.
@@ -163,7 +162,7 @@ protected function getAccessToken(OAuth2Success $auth2Success): array
163162
}
164163
}
165164

166-
$parsed = JSON::decode((string)$response->getBody());
165+
$parsed = \json_decode((string)$response->getBody(), true, flags: \JSON_THROW_ON_ERROR);
167166

168167
if (!empty($parsed['error'])) {
169168
throw new \Exception(

wcfsetup/install/files/lib/action/FacebookAuthAction.class.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use GuzzleHttp\Psr7\Request;
66
use wcf\system\request\LinkHandler;
77
use wcf\system\user\authentication\oauth\User as OauthUser;
8-
use wcf\util\JSON;
98
use wcf\util\StringUtil;
109

1110
/**
@@ -75,7 +74,7 @@ protected function getUser(array $accessToken): OauthUser
7574
'authorization' => \sprintf('Bearer %s', $accessToken['access_token']),
7675
]);
7776
$response = $this->getHttpClient()->send($request);
78-
$parsed = JSON::decode((string)$response->getBody());
77+
$parsed = \json_decode((string)$response->getBody(), true, flags: \JSON_THROW_ON_ERROR);
7978

8079
$parsed['__id'] = $parsed['id'];
8180
$parsed['__username'] = $parsed['name'];

0 commit comments

Comments
 (0)