Changeset 738 for trunk/Common/AppModule.php
- Timestamp:
- Apr 14, 2015, 10:20:16 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Common/AppModule.php
r731 r738 1 1 <?php 2 2 3 /* This implementation will not support installation from remote source. Just 3 /* This implementation will not support installation from remote source. Just 4 4 * installation of already presented modules mainly to persistence preparation. 5 5 */ … … 7 7 class ModuleType 8 8 { 9 10 11 9 const System = 0; 10 const Normal = 1; 11 const Application = 2; 12 12 } 13 13 … … 40 40 var $Title; 41 41 var $Version; 42 var $License; 42 var $License; 43 43 var $Creator; 44 44 var $HomePage; … … 58 58 var $Manager; 59 59 var $OnChange; 60 60 61 61 function __construct(System $System) 62 62 { … … 74 74 $this->Type = ModuleType::Normal; 75 75 } 76 76 77 77 function Install() 78 78 { … … 82 82 $this->Manager->Perform($List, array(ModuleAction::Install), array(ModuleCondition::NotInstalled)); 83 83 $this->DoInstall(); 84 85 86 87 } 88 84 $this->Installed = true; 85 $this->InstalledVersion = $this->Version; 86 $this->Manager->Modules[$this->Name] = $this; 87 } 88 89 89 function Uninstall() 90 90 { … … 97 97 $this->DoUninstall(); 98 98 } 99 99 100 100 function Upgrade() 101 101 { … … 106 106 $this->DoUpgrade(); 107 107 } 108 108 109 109 function Reinstall() 110 110 { … … 113 113 $this->Install(); 114 114 } 115 115 116 116 function Start() 117 117 { 118 118 if($this->Running) return; 119 if(!$this->Installed) return; 119 if(!$this->Installed) return; 120 120 $List = array(); 121 121 $this->Manager->EnumDependenciesCascade($this, $List, array(ModuleCondition::NotRunning)); 122 122 $this->Manager->Perform($List, array(ModuleAction::Start), array(ModuleCondition::NotRunning)); 123 123 $this->DoStart(); 124 125 } 126 124 $this->Running = true; 125 } 126 127 127 function Stop() 128 128 { 129 if(!$this->Running) return;129 if(!$this->Running) return; 130 130 $this->Running = false; 131 132 131 $List = array(); 132 $this->Manager->EnumSuperiorDependenciesCascade($this, $List, array(ModuleCondition::Running)); 133 133 $this->Manager->Perform($List, array(ModuleAction::Stop), array(ModuleCondition::Running)); 134 $this->DoStop();135 } 136 134 $this->DoStop(); 135 } 136 137 137 function Restart() 138 138 { … … 140 140 $this->Start(); 141 141 } 142 142 143 143 function Enable() 144 144 { … … 150 150 $this->Enabled = true; 151 151 } 152 152 153 153 function Disable() 154 154 { … … 160 160 $this->Manager->Perform($List, array(ModuleAction::Disable), array(ModuleCondition::Enabled)); 161 161 } 162 162 163 163 protected function DoStart() 164 164 { 165 165 } 166 166 167 167 protected function DoStop() 168 { 168 { 169 169 } 170 170 … … 172 172 { 173 173 } 174 174 175 175 protected function DoUninstall() 176 176 { … … 179 179 180 180 /* Manage installed modules */ 181 class AppModuleManager 181 class AppModuleManager 182 182 { 183 183 var $Modules; … … 185 185 var $FileName; 186 186 var $OnLoadModules; 187 187 188 188 function __construct(System $System) 189 189 { 190 190 $this->Modules = array(); 191 191 $this->System = &$System; 192 $this->FileName = 'Config/Modules.php'; 193 } 194 192 $this->FileName = 'Config/Modules.php'; 193 } 194 195 195 function Perform($List, $Actions, $Conditions = array(ModuleCondition::All)) 196 196 { … … 217 217 } 218 218 } 219 219 220 220 function EnumDependenciesCascade($Module, &$List, $Conditions = array(ModuleCondition::All)) 221 221 { … … 236 236 } 237 237 } 238 238 239 239 function EnumSuperiorDependenciesCascade($Module, &$List, $Conditions = array(ModuleCondition::All)) 240 240 { 241 241 foreach($this->Modules as $RefModule) 242 242 { 243 if(in_array($Module->Name, $RefModule->Dependencies) and 243 if(in_array($Module->Name, $RefModule->Dependencies) and 244 244 (in_array(ModuleCondition::All, $Conditions) or 245 245 ($Module->Running and in_array(ModuleCondition::Running, $Conditions)) or … … 255 255 } 256 256 } 257 257 258 258 function Start() 259 259 { … … 262 262 $this->StartEnabled(); 263 263 } 264 264 265 265 function StartAll() 266 266 { 267 267 $this->Perform($this->Modules, array(ModuleAction::Start)); 268 268 } 269 269 270 270 function StartEnabled() 271 271 { … … 277 277 $this->Perform($this->Modules, array(ModuleAction::Stop)); 278 278 } 279 279 280 280 function UninstallAll() 281 281 { … … 283 283 $this->SaveState(); 284 284 } 285 285 286 286 function ModulePresent($Name) 287 287 { 288 288 return(array_key_exists($Name, $this->Modules)); 289 289 } 290 290 291 291 /* @return Module */ 292 292 function SearchModuleById($Id) … … 299 299 return(''); 300 300 } 301 301 302 302 function LoadState() 303 303 { 304 304 $ConfigModules = array(); 305 305 include($this->FileName); 306 306 foreach($ConfigModules as $Mod) … … 312 312 $this->Modules[$Mod['Name']]->Installed = $Mod['Installed']; 313 313 $this->Modules[$Mod['Name']]->InstalledVersion = $Mod['Version']; 314 } 315 } 316 } 317 314 } 315 } 316 } 317 318 318 function SaveState() 319 319 { … … 321 321 foreach($this->Modules as $Module) 322 322 { 323 $Data[] = array('Name' => $Module->Name, 'Enabled' => $Module->Enabled, 323 $Data[] = array('Name' => $Module->Name, 'Enabled' => $Module->Enabled, 324 324 'Version' => $Module->Version, 'Installed' => $Module->Installed); 325 325 } 326 326 file_put_contents($this->FileName, "<?php \n\n\$ConfigModules = ".var_export($Data, true).";\n"); 327 327 } 328 328 329 329 function RegisterModule(AppModule $Module) 330 330 { … … 333 333 $Module->OnChange = &$this->OnModuleChange; 334 334 } 335 335 336 336 function UnregisterModule(AppModule $Module) 337 337 { 338 338 unset($this->Modules[array_search($Module, $this->Modules)]); 339 339 } 340 340 341 341 function LoadModulesFromDir($Directory) 342 342 { 343 $List = scandir($Directory);343 $List = scandir($Directory); 344 344 foreach($List as $Item) 345 345 { … … 352 352 } 353 353 } 354 354 355 355 function LoadModules() 356 356 { 357 357 if(method_exists($this->OnLoadModules[0], $this->OnLoadModules[1])) 358 358 $this->OnLoadModules(); 359 359 else $this->LoadModulesFromDir(dirname(__FILE__).'/../Modules');
Note:
See TracChangeset
for help on using the changeset viewer.