| @@ -32,9 +32,10 @@ | ||
| 32 | 32 | public static function get_providers(): array |
| 33 | 33 | { |
| 34 | 34 | /** |
| 35 | 35 | * Register cache providers. |
| 36 | - * @param array $providers The list of cache providers. Each provider should have `id`, `name`, `description`, and `callback` keys. | |
| 36 | + * Each provider should have `id`, `name`, `description`, and `callback` keys. | |
| 37 | + * Providers supporting stable source identities opt in with `source_index` => 1. | |
| 37 | 38 | */ |
| 38 | 39 | return apply_filters('f!windpress/core/cache:compile.providers', []); |
| 39 | 40 | } |
| 40 | 41 | public static function get_cache_path(string $file_path = ''): string |
| @@ -87,9 +88,15 @@ | ||
| 87 | 88 | throw new Exception(__('The callback should return an array', 'windpress')); |
| 88 | 89 | } |
| 89 | 90 | $_metadata = array_key_exists('metadata', $result) ? $result['metadata'] : []; |
| 90 | 91 | $_contents = array_key_exists('contents', $result) ? $result['contents'] : $result; |
| 92 | + if (!is_array($_metadata) || !is_array($_contents)) { | |
| 93 | + throw new Exception(__('The provider metadata and contents must be arrays.', 'windpress')); | |
| 94 | + } | |
| 91 | 95 | $_contents = array_map(static function ($content) { |
| 96 | + if (!is_array($content) || !array_key_exists('content', $content)) { | |
| 97 | + throw new Exception(__('A scan source is missing its content.', 'windpress')); | |
| 98 | + } | |
| 92 | 99 | $content_type = $content['type'] ?? null; |
| 93 | 100 | if (is_array($content['content']) || is_object($content['content'])) { |
| 94 | 101 | $content['content'] = wp_json_encode($content['content']); |
| 95 | 102 | $content['type'] = 'json'; |
| @@ -99,9 +106,12 @@ | ||
| 99 | 106 | if (json_last_error() === \JSON_ERROR_NONE && ($decoded !== null || $content['content'] === 'null')) { |
| 100 | 107 | $content['type'] = 'json'; |
| 101 | 108 | } |
| 102 | 109 | } |
| 103 | - $content['content'] = is_string($content['content']) ? base64_encode($content['content']) : null; | |
| 110 | + if (!is_string($content['content'])) { | |
| 111 | + throw new Exception(__('A scan source could not be encoded as text.', 'windpress')); | |
| 112 | + } | |
| 113 | + $content['content'] = base64_encode($content['content']); | |
| 104 | 114 | return $content; |
| 105 | 115 | }, $_contents); |
| 106 | 116 | } catch (\Throwable $throwable) { |
| 107 | 117 | throw $throwable; |