Changeset 887 for trunk/Packages/Common/Application.php
- Timestamp:
- Nov 20, 2020, 12:08:12 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/Application.php
r873 r887 3 3 class ModelDef 4 4 { 5 var$OnChange;6 5 public array $OnChange; 6 7 7 function __construct() 8 8 { 9 9 $this->OnChange = array(); 10 10 } 11 12 function DoOnChange() 11 12 function DoOnChange(): void 13 13 { 14 14 foreach ($this->OnChange as $Callback) … … 17 17 } 18 18 } 19 20 function RegisterOnChange( $SysName, $Callback)19 20 function RegisterOnChange(string $SysName, callable $Callback): void 21 21 { 22 22 $this->OnChange[$SysName] = $Callback; 23 23 } 24 25 function UnregisterOnChange( $SysName)24 25 function UnregisterOnChange(string $SysName): void 26 26 { 27 27 unset($this->OnChange[$SysName]); … … 29 29 } 30 30 31 class Command 32 { 33 public string $Name; 34 public string $Description; 35 public $Callback; 36 37 function __construct(string $Name, string $Description, callable $Callback) 38 { 39 $this->Name = $Name; 40 $this->Description = $Description; 41 $this->Callback = $Callback; 42 } 43 } 44 31 45 class Application extends System 32 46 { 33 var$Name;34 /** @var AppModuleManager */35 var $ModuleManager;36 var $Modules;37 var $Models;38 47 public string $Name; 48 public AppModuleManager $ModuleManager; 49 public array $Models; 50 public array $CommandLine; 51 public array $Pages; 52 39 53 function __construct() 40 54 { … … 42 56 $this->Name = 'Application'; 43 57 $this->ModuleManager = new AppModuleManager($this); 44 $this->Modules = array();45 58 $this->Models = array(); 59 $this->CommandLine = array(); 60 $this->Pages = array(); 61 62 $this->RegisterCommandLine('list', 'Prints available commands', array($this, 'ListCommands')); 46 63 } 47 48 function RegisterModel($SysName, $Model) 64 65 function GetModule(string $Name): AppModule 66 { 67 return $this->ModuleManager->Modules[$Name]; 68 } 69 70 function RegisterModel(string $SysName, array $Model): void 49 71 { 50 72 $NewModelDef = new ModelDef(); … … 53 75 } 54 76 55 function UnregisterModel( $SysName)77 function UnregisterModel(string $SysName): void 56 78 { 57 79 unset($this->Models[$SysName]); 58 80 } 59 60 function R un()81 82 function RegisterCommandLine(string $Name, string $Description, callable $Callback): void 61 83 { 84 $this->CommandLine[$Name] = new Command($Name, $Description, $Callback); 85 } 62 86 87 function UnrgisterCommandLine(string $Name): void 88 { 89 unset($this->CommandLine[$Name]); 90 } 91 92 function ListCommands(array $Parameters) 93 { 94 $Output = 'Available commands:'."\n"; 95 foreach ($this->CommandLine as $Command) 96 { 97 $Output .= ' '.$Command->Name.' - '.$Command->Description."\n"; 98 } 99 echo($Output."\n"); 100 } 101 102 function RegisterPage(array $Path, string $Handler): void 103 { 104 $Page = &$this->Pages; 105 $LastKey = array_pop($Path); 106 foreach ($Path as $PathItem) 107 { 108 $Page = &$Page[$PathItem]; 109 } 110 if (!is_array($Page)) $Page = array('' => $Page); 111 $Page[$LastKey] = $Handler; 112 } 113 114 function UnregisterPage(array $Path): void 115 { 116 $Page = &$this->Pages; 117 $LastKey = array_pop($Path); 118 foreach ($Path as $PathItem) 119 { 120 $Page = &$Page[$PathItem]; 121 } 122 unset($Page[$LastKey]); 123 } 124 125 function Run(): void 126 { 127 } 128 129 function Link(string $Target): string 130 { 131 return $Target; 63 132 } 64 133 }
Note:
See TracChangeset
for help on using the changeset viewer.