Changeset 95 for trunk/Application/Core.php
- Timestamp:
- Dec 6, 2021, 11:33:48 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Application/Core.php
r92 r95 6 6 include_once(dirname(__FILE__).'/../Global.php'); 7 7 include_once(dirname(__FILE__).'/Version.php'); 8 include_once(dirname(__FILE__).'/ View.php');8 include_once(dirname(__FILE__).'/BaseView.php'); 9 9 include_once(dirname(__FILE__).'/UpdateTrace.php'); 10 10 include_once(dirname(__FILE__).'/DefaultConfig.php'); 11 11 12 class Core extends Application12 class Core extends System 13 13 { 14 var$Pages;15 var$ShowPage;16 var$BaseURL;17 var$UseSession;14 public array $Pages; 15 public bool $ShowPage; 16 public string $BaseURL; 17 public bool $UseSession; 18 18 19 19 function __construct() … … 28 28 } 29 29 30 function RunCommon() 30 function RunCommon(): void 31 31 { 32 32 global $Config, $DatabaseRevision, $WithoutSessionStart; … … 38 38 //$ErrorHandler->Start(); 39 39 40 try { 40 try 41 { 41 42 $this->Database = new Database(); 42 43 $this->Database->Connect($Config['Database']['Host'], $Config['Database']['User'], … … 55 56 $this->Config = &$Config; 56 57 57 // Register and start existing modules 58 $this->Setup = new Setup($this); 59 $this->Setup->Start(); 60 if ($this->Setup->CheckState()) 58 $this->StartModules(); 59 } 60 61 function StartModules(): void 62 { 63 $ModuleSetup = $this->ModuleManager->LoadModule(dirname(__FILE__).'/../Packages/Common/Modules/Setup.php'); 64 $ModuleSetup->Install(); 65 $ModuleSetup->Start(); 66 $this->ModuleManager->LoadModules(); 67 $this->ModuleManager->LoadModule(dirname(__FILE__).'/../Packages/Common/Modules/ModuleManager.php'); 68 if (file_exists($this->ModuleManager->FileName)) $this->ModuleManager->LoadState(); 69 if (ModuleSetup::Cast($ModuleSetup)->CheckState()) 61 70 { 62 $this->ModuleManager->Start ();71 $this->ModuleManager->StartAll(array(ModuleCondition::Enabled)); 63 72 } 64 73 } 65 74 66 function Run() 75 function Run(): void 67 76 { 68 77 $this->RunCommon(); … … 74 83 } 75 84 76 function ShowPage() 85 static function Cast(System $System): Core 86 { 87 if ($System instanceof Core) 88 { 89 return $System; 90 } 91 throw new Exception('Expected Core type but '.gettype($System)); 92 } 93 94 function ShowPage(): void 77 95 { 78 96 $this->BaseView = new BaseView($this); … … 89 107 } 90 108 91 function RegisterPage($Path, $Handler) 92 { 93 if (is_array($Path)) 94 { 95 $Page = &$this->Pages; 96 $LastKey = array_pop($Path); 97 foreach ($Path as $PathItem) 98 { 99 $Page = &$Page[$PathItem]; 100 } 101 if (!is_array($Page)) $Page = array('' => $Page); 102 $Page[$LastKey] = $Handler; 103 } else $this->Pages[$Path] = $Handler; 104 } 105 106 function UnregisterPage($Path) 107 { 108 unset($this->Pages[$Path]); 109 } 110 111 function SearchPage($PathItems, $Pages) 109 function SearchPage(array $PathItems, array $Pages): string 112 110 { 113 111 if (count($PathItems) > 0) $PathItem = $PathItems[0]; … … 123 121 } 124 122 125 function Link( $Target)123 function Link(string $Target): string 126 124 { 127 125 return $this->BaseURL.$Target; … … 138 136 } 139 137 140 function Show() 138 function Show(): string 141 139 { 142 140 Header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found');
Note:
See TracChangeset
for help on using the changeset viewer.