1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Aoe\Restler\System\RestApi; |
4
|
|
|
|
5
|
|
|
/*************************************************************** |
6
|
|
|
* Copyright notice |
7
|
|
|
* |
8
|
|
|
* (c) 2024 AOE GmbH <[email protected]> |
9
|
|
|
* |
10
|
|
|
* All rights reserved |
11
|
|
|
* |
12
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
13
|
|
|
* free software; you can redistribute it and/or modify |
14
|
|
|
* it under the terms of the GNU General Public License as published by |
15
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
16
|
|
|
* (at your option) any later version. |
17
|
|
|
* |
18
|
|
|
* The GNU General Public License can be found at |
19
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
20
|
|
|
* |
21
|
|
|
* This script is distributed in the hope that it will be useful, |
22
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
23
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24
|
|
|
* GNU General Public License for more details. |
25
|
|
|
* |
26
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
27
|
|
|
***************************************************************/ |
28
|
|
|
|
29
|
|
|
use Luracast\Restler\Format\JsonFormat; |
30
|
|
|
use Luracast\Restler\RestException; |
31
|
|
|
use TYPO3\CMS\Core\SingletonInterface; |
32
|
|
|
|
33
|
|
|
class RestApiJsonFormat extends JsonFormat implements SingletonInterface |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* @param string $data |
37
|
|
|
*/ |
38
|
|
|
public function decode($data) |
39
|
|
|
{ |
40
|
|
|
$options = 0; |
41
|
|
|
if (self::$bigIntAsString) { |
42
|
|
|
if ((PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 4) // PHP >= 5.4 |
43
|
|
|
|| PHP_MAJOR_VERSION > 5 // PHP >= 6.0 |
44
|
|
|
) { |
45
|
|
|
$options |= JSON_BIGINT_AS_STRING; |
46
|
|
|
} else { |
47
|
|
|
$data = preg_replace( |
48
|
|
|
'/:\s*(\-?\d+(\.\d+)?([e|E][\-|\+]\d+)?)/', |
49
|
|
|
': "$1"', |
50
|
|
|
$data |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
try { |
56
|
|
|
$decoded = json_decode((string) $data, false, 512, $options); |
57
|
|
|
$this->handleJsonError(); |
58
|
|
|
} catch (\RuntimeException $runtimeException) { |
59
|
|
|
throw new RestException('400', $runtimeException->getMessage()); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
if (strlen((string) $data) && $decoded === null || $decoded === $data) { |
|
|
|
|
63
|
|
|
throw new RestException('400', 'Error parsing JSON'); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return $decoded; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|