| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Standalone field-schema registry. |
| 5 |
* |
| 6 |
* The config classes (src/Admin/Views/*.php) keep registering their field |
| 7 |
* sections through the framework's `createSection()` API exactly as before — |
| 8 |
* those files are unchanged. That API now forwards each section into this |
| 9 |
* lightweight registry instead of into a rendering framework. The REST layer |
| 10 |
* (AbstractRestController and its SettingsRest subclass) reads from here to |
| 11 |
* build the schema served to the React admin, so no PHP rendering is involved. |
| 12 |
* |
| 13 |
* This is what keeps the migration backward compatible: the field ids, defaults, |
| 14 |
* dependencies and the option key are still the ones the Views declared, so |
| 15 |
* existing saved settings load and save unchanged. |
| 16 |
* |
| 17 |
* @package darkify |
| 18 |
* @subpackage darkify/src/Admin/Schema |
| 19 |
* @author ThemeAtelier<themeatelierbd@gmail.com> |
| 20 |
*/ |
| 21 |
|
| 22 |
namespace ThemeAtelier\Darkify\Admin\Schema; |
| 23 |
|
| 24 |
if (! defined('ABSPATH')) { |
| 25 |
die; |
| 26 |
} |
| 27 |
|
| 28 |
class SchemaRegistry |
| 29 |
{ |
| 30 |
/** |
| 31 |
* Registered sections keyed by option id. Darkify stores everything under a |
| 32 |
* single option, so in practice this holds one key: 'darkify'. |
| 33 |
* |
| 34 |
* @var array<string,array<int,array>> |
| 35 |
*/ |
| 36 |
public static $sections = array(); |
| 37 |
|
| 38 |
/** |
| 39 |
* Page-level args from createOptions() (menu title, slug, icon, position). |
| 40 |
* The admin menu is registered from these so the menu keeps its existing |
| 41 |
* slug, icon and position — an existing bookmark to `?page=darkify` and the |
| 42 |
* menu's place in the sidebar both survive the migration. |
| 43 |
* |
| 44 |
* @var array<string,array> |
| 45 |
*/ |
| 46 |
public static $options = array(); |
| 47 |
|
| 48 |
/** |
| 49 |
* Register one section config under an option key. |
| 50 |
* |
| 51 |
* @param string $id The option key the section belongs to. |
| 52 |
* @param array $section The section config (title, icon, fields, …). |
| 53 |
* @return void |
| 54 |
*/ |
| 55 |
public static function createSection($id, $section) |
| 56 |
{ |
| 57 |
if (! isset(self::$sections[$id])) { |
| 58 |
self::$sections[$id] = array(); |
| 59 |
} |
| 60 |
self::$sections[$id][] = $section; |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Record an option page's args. |
| 65 |
* |
| 66 |
* @param string $id The option key. |
| 67 |
* @param array $args Page args (menu_title, menu_slug, menu_icon, …). |
| 68 |
* @return void |
| 69 |
*/ |
| 70 |
public static function createOptions($id, $args = array()) |
| 71 |
{ |
| 72 |
self::$options[$id] = is_array($args) ? $args : array(); |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Page args for an option key, with sane fallbacks. |
| 77 |
* |
| 78 |
* @param string $id The option key. |
| 79 |
* @return array |
| 80 |
*/ |
| 81 |
public static function options($id) |
| 82 |
{ |
| 83 |
return isset(self::$options[$id]) ? self::$options[$id] : array(); |
| 84 |
} |
| 85 |
} |
| 86 |
|