ISGArchiveDelegate.php
3 years ago
SGBGArchive.php
3 years ago
SGBGArchiveCdr.php
3 years ago
SGBGArchiveHelper.php
3 years ago
SGBGCache.php
3 years ago
SGBGCacheableFile.php
3 years ago
SGBGDirectoryTreeFile.php
3 years ago
SGBGFile.php
3 years ago
SGBGFileHelper.php
3 years ago
SGBGJsonFile.php
3 years ago
SGBGLog.php
3 years ago
SGBGReloader.php
3 years ago
SGBGStateFile.php
3 years ago
SGBGTask.php
3 years ago
SGBGJsonFile.php
44 lines
| 1 | <?php |
| 2 | /* |
| 3 | @ trait SGBGJsonFile |
| 4 | @ version 1.0.1 |
| 5 | @ updated 23/01/2021 |
| 6 | */ |
| 7 | |
| 8 | require_once(__DIR__.'/SGBGFile.php'); |
| 9 | |
| 10 | trait SGBGJsonFile |
| 11 | { |
| 12 | /** |
| 13 | * |
| 14 | * Get decoded JSON file contents. |
| 15 | * |
| 16 | * @return mixed decoded JSON contents |
| 17 | */ |
| 18 | public function getDecodedContents() |
| 19 | { |
| 20 | $contents = parent::read(); |
| 21 | |
| 22 | if (!empty($contents)) { |
| 23 | $contents = json_decode($contents, true); |
| 24 | if (json_last_error() == JSON_ERROR_NONE) { |
| 25 | return $contents; |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | return null; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * |
| 34 | * JSON encode the contents and save to file. |
| 35 | * |
| 36 | * @param string $contents data to encode and save |
| 37 | * @return string the number of bytes written to file, or false in case of an error |
| 38 | */ |
| 39 | public function encodeAndSetContents($contents) |
| 40 | { |
| 41 | return parent::write(json_encode($contents)); |
| 42 | } |
| 43 | } |
| 44 |