Changeset 887 for trunk/Packages/Common/AppModule.php
- Timestamp:
- Nov 20, 2020, 12:08:12 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/AppModule.php
r880 r887 36 36 class AppModule 37 37 { 38 var $Id; 39 var $Name; 40 var $Title; 41 var $Version; 42 var $License; 43 var $Creator; 44 var $HomePage; 45 var $Description; 46 var $Running; 47 var $Enabled; 48 var $Installed; 49 var $InstalledVersion; 50 /** @var ModuleType */ 51 var $Type; 52 var $Dependencies; 53 /** @var Database */ 54 var $Database; 55 /** @var System */ 56 var $System; 57 /** @var AppModuleManager */ 58 var $Manager; 59 var $OnChange; 60 61 function __construct(System $System) 38 public int $Id; 39 public string $Name; 40 public string $Title; 41 public string $Version; 42 public string $License; 43 public string $Creator; 44 public string $HomePage; 45 public string $Description; 46 public bool $Running; 47 public bool $Enabled; 48 public bool $Installed; 49 public string $InstalledVersion; 50 public int $Type; 51 public array $Dependencies; 52 public Database $Database; 53 public Application $System; 54 public AppModuleManager $Manager; 55 public $OnChange; 56 public array $Models; 57 58 function __construct(Application $System) 62 59 { 63 60 $this->System = &$System; … … 73 70 $this->Dependencies = array(); 74 71 $this->Type = ModuleType::Normal; 75 } 76 77 function Install() 72 $this->Models = array(); 73 } 74 75 function Install(): void 78 76 { 79 77 if ($this->Installed) return; … … 87 85 } 88 86 89 function Uninstall() 87 function Uninstall(): void 90 88 { 91 89 if (!$this->Installed) return; … … 98 96 } 99 97 100 function Upgrade() 98 function Upgrade(): void 101 99 { 102 100 if (!$this->Installed) return; … … 108 106 } 109 107 110 function Reinstall() 108 function Reinstall(): void 111 109 { 112 110 $this->Uninstall(); … … 115 113 } 116 114 117 function Start() 115 function Start(): void 118 116 { 119 117 if ($this->Running) return; … … 126 124 } 127 125 128 function Stop() 126 function Stop(): void 129 127 { 130 128 if (!$this->Running) return; … … 136 134 } 137 135 138 function Restart() 136 function Restart(): void 139 137 { 140 138 $this->Stop(); … … 142 140 } 143 141 144 function Enable() 142 function Enable(): void 145 143 { 146 144 if ($this->Enabled) return; … … 152 150 } 153 151 154 function Disable() 152 function Disable(): void 155 153 { 156 154 if (!$this->Enabled) return; … … 162 160 } 163 161 164 protected function DoStart() 165 { 166 } 167 168 protected function DoStop() 169 { 170 } 171 172 protected function DoInstall() 173 { 174 } 175 176 protected function DoUninstall() 177 { 178 } 179 180 protected function DoUpgrade() 181 { 182 162 protected function DoStart(): void 163 { 164 } 165 166 protected function DoStop(): void 167 { 168 } 169 170 protected function DoInstall(): void 171 { 172 } 173 174 protected function DoUninstall(): void 175 { 176 } 177 178 protected function DoUpgrade(): void 179 { 180 } 181 182 function AddModel(Model $Model): void 183 { 184 $this->Models[get_class($Model)] = $Model; 183 185 } 184 186 } … … 187 189 class AppModuleManager 188 190 { 189 var$Modules;190 var$System;191 var$FileName;192 var$ModulesDir;193 var$OnLoadModules;191 public array $Modules; 192 public System $System; 193 public string $FileName; 194 public string $ModulesDir; 195 public $OnLoadModules; 194 196 195 197 function __construct(System $System) … … 201 203 } 202 204 203 function Perform( $List, $Actions, $Conditions = array(ModuleCondition::All))205 function Perform(array $List, array $Actions, array $Conditions = array(ModuleCondition::All)): void 204 206 { 205 207 foreach ($List as $Index => $Module) … … 227 229 } 228 230 229 function EnumDependenciesCascade( $Module, &$List,$Conditions = array(ModuleCondition::All))231 function EnumDependenciesCascade(AppModule $Module, array &$List, array $Conditions = array(ModuleCondition::All)) 230 232 { 231 233 foreach ($Module->Dependencies as $Dependency) … … 248 250 } 249 251 250 function EnumSuperiorDependenciesCascade( $Module, &$List,$Conditions = array(ModuleCondition::All))252 function EnumSuperiorDependenciesCascade(AppModule $Module, array &$List, array $Conditions = array(ModuleCondition::All)) 251 253 { 252 254 foreach ($this->Modules as $RefModule) … … 267 269 } 268 270 269 function Start() 271 function Start(): void 270 272 { 271 273 $this->LoadModules(); … … 274 276 } 275 277 276 function StartAll() 278 function StartAll(): void 277 279 { 278 280 $this->Perform($this->Modules, array(ModuleAction::Start)); 279 281 } 280 282 281 function StartEnabled() 283 function StartEnabled(): void 282 284 { 283 285 $this->Perform($this->Modules, array(ModuleAction::Start), array(ModuleCondition::Enabled)); 284 286 } 285 287 286 function StopAll() 288 function StopAll(): void 287 289 { 288 290 $this->Perform($this->Modules, array(ModuleAction::Stop)); 289 291 } 290 292 291 function InstallAll() 293 function InstallAll(): void 292 294 { 293 295 $this->Perform($this->Modules, array(ModuleAction::Install)); … … 295 297 } 296 298 297 function UninstallAll() 299 function UninstallAll(): void 298 300 { 299 301 $this->Perform($this->Modules, array(ModuleAction::Uninstall)); … … 301 303 } 302 304 303 function EnableAll() 305 function EnableAll(): void 304 306 { 305 307 $this->Perform($this->Modules, array(ModuleAction::Enable)); … … 307 309 } 308 310 309 function DisableAll() 311 function DisableAll(): void 310 312 { 311 313 $this->Perform($this->Modules, array(ModuleAction::Disable)); … … 313 315 } 314 316 315 function ModulePresent( $Name)317 function ModulePresent(string $Name): bool 316 318 { 317 319 return array_key_exists($Name, $this->Modules); 318 320 } 319 321 320 function ModuleEnabled( $Name)322 function ModuleEnabled(string $Name): bool 321 323 { 322 324 return array_key_exists($Name, $this->Modules) and $this->Modules[$Name]->Enabled; 323 325 } 324 326 325 function ModuleRunning( $Name)327 function ModuleRunning(string $Name): bool 326 328 { 327 329 return array_key_exists($Name, $this->Modules) and $this->Modules[$Name]->Running; 328 330 } 329 331 330 /* @return Module */ 331 function SearchModuleById($Id) 332 function GetModule(string $Name): AppModule 333 { 334 return $this->Modules[$Name]; 335 } 336 337 function SearchModuleById(int $Id): string 332 338 { 333 339 foreach ($this->Modules as $Module) … … 339 345 } 340 346 341 function LoadState() 347 function LoadState(): void 342 348 { 343 349 $ConfigModules = array(); … … 355 361 } 356 362 357 function SaveState() 363 function SaveState(): void 358 364 { 359 365 $Data = array(); … … 369 375 } 370 376 371 function RegisterModule(AppModule $Module) 377 function RegisterModule(AppModule $Module): void 372 378 { 373 379 $this->Modules[$Module->Name] = &$Module; … … 376 382 } 377 383 378 function UnregisterModule(AppModule $Module) 384 function UnregisterModule(AppModule $Module): void 379 385 { 380 386 unset($this->Modules[array_search($Module, $this->Modules)]); 381 387 } 382 388 383 function LoadModulesFromDir( $Directory)389 function LoadModulesFromDir(string $Directory): void 384 390 { 385 391 $List = scandir($Directory); … … 395 401 } 396 402 397 function LoadModules() 403 function LoadModules(): void 398 404 { 399 405 if (is_array($this->OnLoadModules) and (count($this->OnLoadModules) == 2) and method_exists($this->OnLoadModules[0], $this->OnLoadModules[1])) 400 $this->OnLoadModules();406 call_user_func($this->OnLoadModules); 401 407 else $this->LoadModulesFromDir($this->ModulesDir); 402 408 }
Note:
See TracChangeset
for help on using the changeset viewer.