Commit | Line | Data |
---|---|---|
a9396478 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
a9396478 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
a9396478 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
a9396478 TO |
11 | |
12 | /** | |
13 | * Work-around for CRM-13120 - The "create" action incorrectly returns string literal "null" | |
14 | * when the actual value is NULL or "". Rewrite the output. | |
15 | * | |
16 | * @package CRM | |
ca5cec67 | 17 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
a9396478 TO |
18 | */ |
19 | ||
20 | require_once 'api/Wrapper.php'; | |
5bc392e6 EM |
21 | |
22 | /** | |
23 | * Class CRM_Utils_API_NullOutputCoder | |
24 | */ | |
a9396478 TO |
25 | class CRM_Utils_API_NullOutputCoder extends CRM_Utils_API_AbstractFieldCoder { |
26 | ||
27 | /** | |
28 | * @var CRM_Utils_API_NullOutputCoder | |
29 | */ | |
30 | private static $_singleton = NULL; | |
31 | ||
32 | /** | |
33 | * @return CRM_Utils_API_NullOutputCoder | |
34 | */ | |
35 | public static function singleton() { | |
36 | if (self::$_singleton === NULL) { | |
37 | self::$_singleton = new CRM_Utils_API_NullOutputCoder(); | |
38 | } | |
39 | return self::$_singleton; | |
40 | } | |
41 | ||
42 | /** | |
e8e8f3ad | 43 | * Going to filter the submitted values across XSS vulnerability. |
a9396478 TO |
44 | * |
45 | * @param array|string $values | |
a9396478 TO |
46 | */ |
47 | public function encodeInput(&$values) { | |
48 | } | |
49 | ||
5bc392e6 | 50 | /** |
e8e8f3ad | 51 | * Decode output. |
52 | * | |
53 | * @param array $values | |
5bc392e6 EM |
54 | * @param bool $castToString |
55 | */ | |
a9396478 TO |
56 | public function decodeOutput(&$values, $castToString = FALSE) { |
57 | if (is_array($values)) { | |
58 | foreach ($values as &$value) { | |
59 | $this->decodeOutput($value, TRUE); | |
60 | } | |
61 | } | |
62 | elseif ($castToString || is_string($values)) { | |
63 | if ($values === 'null') { | |
64 | $values = ''; | |
65 | } | |
66 | } | |
67 | } | |
68 | ||
5bc392e6 | 69 | /** |
e8e8f3ad | 70 | * To api output. |
71 | * | |
72 | * @param array $apiRequest | |
73 | * @param array $result | |
5bc392e6 | 74 | * |
e8e8f3ad | 75 | * @return array |
5bc392e6 | 76 | */ |
a9396478 TO |
77 | public function toApiOutput($apiRequest, $result) { |
78 | $lowerAction = strtolower($apiRequest['action']); | |
79 | if ($lowerAction === 'create') { | |
80 | return parent::toApiOutput($apiRequest, $result); | |
0db6c3e1 TO |
81 | } |
82 | else { | |
a9396478 TO |
83 | return $result; |
84 | } | |
85 | } | |
96025800 | 86 | |
a9396478 | 87 | } |