[779] | 1 | <?php
|
---|
| 2 |
|
---|
[817] | 3 | class ModelDef
|
---|
| 4 | {
|
---|
[949] | 5 | public string $Title;
|
---|
[887] | 6 | public array $OnChange;
|
---|
| 7 |
|
---|
[817] | 8 | function __construct()
|
---|
| 9 | {
|
---|
| 10 | $this->OnChange = array();
|
---|
| 11 | }
|
---|
[887] | 12 |
|
---|
| 13 | function DoOnChange(): void
|
---|
[817] | 14 | {
|
---|
[873] | 15 | foreach ($this->OnChange as $Callback)
|
---|
[817] | 16 | {
|
---|
| 17 | call_user_func($Callback);
|
---|
| 18 | }
|
---|
| 19 | }
|
---|
[887] | 20 |
|
---|
| 21 | function RegisterOnChange(string $SysName, callable $Callback): void
|
---|
[817] | 22 | {
|
---|
| 23 | $this->OnChange[$SysName] = $Callback;
|
---|
| 24 | }
|
---|
[887] | 25 |
|
---|
| 26 | function UnregisterOnChange(string $SysName): void
|
---|
[817] | 27 | {
|
---|
| 28 | unset($this->OnChange[$SysName]);
|
---|
| 29 | }
|
---|
| 30 | }
|
---|
| 31 |
|
---|
[887] | 32 | class Command
|
---|
| 33 | {
|
---|
| 34 | public string $Name;
|
---|
| 35 | public string $Description;
|
---|
| 36 | public $Callback;
|
---|
| 37 |
|
---|
| 38 | function __construct(string $Name, string $Description, callable $Callback)
|
---|
| 39 | {
|
---|
| 40 | $this->Name = $Name;
|
---|
| 41 | $this->Description = $Description;
|
---|
| 42 | $this->Callback = $Callback;
|
---|
| 43 | }
|
---|
| 44 | }
|
---|
| 45 |
|
---|
[899] | 46 | class System
|
---|
[779] | 47 | {
|
---|
[899] | 48 | public Database $Database;
|
---|
[887] | 49 | public string $Name;
|
---|
[899] | 50 | public ModuleManager $ModuleManager;
|
---|
[887] | 51 | public array $Models;
|
---|
| 52 | public array $CommandLine;
|
---|
| 53 | public array $Pages;
|
---|
| 54 |
|
---|
[779] | 55 | function __construct()
|
---|
| 56 | {
|
---|
[899] | 57 | $this->Database = new Database();
|
---|
| 58 | $this->Name = 'System';
|
---|
| 59 | $this->ModuleManager = new ModuleManager($this);
|
---|
[817] | 60 | $this->Models = array();
|
---|
[887] | 61 | $this->CommandLine = array();
|
---|
| 62 | $this->Pages = array();
|
---|
| 63 |
|
---|
| 64 | $this->RegisterCommandLine('list', 'Prints available commands', array($this, 'ListCommands'));
|
---|
[779] | 65 | }
|
---|
[887] | 66 |
|
---|
[899] | 67 | function GetModule(string $Name): Module
|
---|
[817] | 68 | {
|
---|
[895] | 69 | if (array_key_exists($Name, $this->ModuleManager->Modules))
|
---|
| 70 | return $this->ModuleManager->Modules[$Name];
|
---|
| 71 | else return null;
|
---|
[887] | 72 | }
|
---|
| 73 |
|
---|
| 74 | function RegisterModel(string $SysName, array $Model): void
|
---|
| 75 | {
|
---|
[817] | 76 | $NewModelDef = new ModelDef();
|
---|
| 77 | $NewModelDef->Title = $Model['Title'];
|
---|
| 78 | $this->Models[$SysName] = $NewModelDef;
|
---|
| 79 | }
|
---|
[779] | 80 |
|
---|
[887] | 81 | function UnregisterModel(string $SysName): void
|
---|
[817] | 82 | {
|
---|
| 83 | unset($this->Models[$SysName]);
|
---|
| 84 | }
|
---|
[887] | 85 |
|
---|
| 86 | function RegisterCommandLine(string $Name, string $Description, callable $Callback): void
|
---|
[779] | 87 | {
|
---|
[887] | 88 | $this->CommandLine[$Name] = new Command($Name, $Description, $Callback);
|
---|
| 89 | }
|
---|
[779] | 90 |
|
---|
[899] | 91 | function UnregisterCommandLine(string $Name): void
|
---|
[887] | 92 | {
|
---|
| 93 | unset($this->CommandLine[$Name]);
|
---|
[779] | 94 | }
|
---|
[887] | 95 |
|
---|
| 96 | function ListCommands(array $Parameters)
|
---|
| 97 | {
|
---|
| 98 | $Output = 'Available commands:'."\n";
|
---|
| 99 | foreach ($this->CommandLine as $Command)
|
---|
| 100 | {
|
---|
| 101 | $Output .= ' '.$Command->Name.' - '.$Command->Description."\n";
|
---|
| 102 | }
|
---|
| 103 | echo($Output."\n");
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | function RegisterPage(array $Path, string $Handler): void
|
---|
| 107 | {
|
---|
| 108 | $Page = &$this->Pages;
|
---|
| 109 | $LastKey = array_pop($Path);
|
---|
| 110 | foreach ($Path as $PathItem)
|
---|
| 111 | {
|
---|
| 112 | $Page = &$Page[$PathItem];
|
---|
| 113 | }
|
---|
| 114 | if (!is_array($Page)) $Page = array('' => $Page);
|
---|
| 115 | $Page[$LastKey] = $Handler;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | function UnregisterPage(array $Path): void
|
---|
| 119 | {
|
---|
| 120 | $Page = &$this->Pages;
|
---|
| 121 | $LastKey = array_pop($Path);
|
---|
| 122 | foreach ($Path as $PathItem)
|
---|
| 123 | {
|
---|
| 124 | $Page = &$Page[$PathItem];
|
---|
| 125 | }
|
---|
| 126 | unset($Page[$LastKey]);
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | function Run(): void
|
---|
| 130 | {
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | function Link(string $Target): string
|
---|
| 134 | {
|
---|
| 135 | return $Target;
|
---|
| 136 | }
|
---|
[912] | 137 |
|
---|
| 138 | function AbsoluteLink(string $Target): string
|
---|
| 139 | {
|
---|
| 140 | return $Target;
|
---|
| 141 | }
|
---|
[873] | 142 | }
|
---|