1
|
|
|
<?php |
2
|
|
|
// This file is part of Moodle - http://moodle.org/ |
3
|
|
|
// |
4
|
|
|
// Moodle is free software: you can redistribute it and/or modify |
5
|
|
|
// it under the terms of the GNU General Public License as published by |
6
|
|
|
// the Free Software Foundation, either version 3 of the License, or |
7
|
|
|
// (at your option) any later version. |
8
|
|
|
// |
9
|
|
|
// Moodle is distributed in the hope that it will be useful, |
10
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
11
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12
|
|
|
// GNU General Public License for more details. |
13
|
|
|
// |
14
|
|
|
// You should have received a copy of the GNU General Public License |
15
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The helper class for the assignsubmission_edulegit plugin. |
19
|
|
|
* |
20
|
|
|
* Provides utility methods for JSON encoding and decoding. |
21
|
|
|
* |
22
|
|
|
* @package assignsubmission_edulegit |
23
|
|
|
* @author Alex Crosby <[email protected]> |
24
|
|
|
* @copyright @2024 EduLegit.com |
25
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
namespace assignsubmission_edulegit; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Class edulegit_helper |
32
|
|
|
* |
33
|
|
|
* This class provides helper methods such as JSON encoding and decoding, which are used throughout the plugin. |
34
|
|
|
*/ |
35
|
|
|
class edulegit_helper { |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Decode a JSON string into a PHP variable. |
39
|
|
|
* |
40
|
|
|
* @param string $json The JSON string to decode. |
41
|
|
|
* @return mixed The decoded value, typically an object or an array. |
42
|
|
|
*/ |
43
|
|
|
public static function json_decode(string $json): mixed { |
44
|
|
|
return json_decode($json, false, 512, JSON_INVALID_UTF8_SUBSTITUTE); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Encode a PHP variable into a JSON string. |
49
|
|
|
* |
50
|
|
|
* @param mixed $data The data to encode as JSON. |
51
|
|
|
* @return string|false The JSON-encoded string, or false on failure. |
52
|
|
|
*/ |
53
|
|
|
public static function json_encode(mixed $data): string|false { |
54
|
|
|
return json_encode($data, JSON_INVALID_UTF8_SUBSTITUTE); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
} |
58
|
|
|
|