source: trunk/www/Base/AppModule.php

Last change on this file was 95, checked in by chronos, 10 years ago
  • Upraveno: Soubory různých logických částí systému odděleny do aplikačních modulů.
File size: 2.5 KB
Line 
1<?php
2
3class ModuleType
4{
5 const System = 0;
6 const Normal = 1;
7 const Application = 2;
8}
9
10class AppModule
11{
12 var $Id;
13 var $Name;
14 var $Version;
15 var $License;
16 var $Creator;
17 var $Description;
18 var $Installed;
19 var $InstalledVersion;
20 var $Running;
21 /** @var ModuleType */
22 var $Type;
23 var $Enabled;
24 var $Dependencies;
25 /** @var Database */
26 var $Database;
27 /** @var System */
28 var $System;
29 /** @var ModularSystem */
30 var $Manager;
31 var $OnChange;
32
33 function __construct($System)
34 {
35 $this->System = &$System;
36 $this->Database = &$System->Database;
37 $this->Installed = false;
38 $this->Dependencies = array();
39 $this->Type = ModuleType::Normal;
40 }
41
42 function Install()
43 {
44 }
45
46 function Uninstall()
47 {
48 }
49
50 function Start()
51 {
52 }
53
54 function Stop()
55 {
56 }
57}
58
59class AppModuleManager
60{
61 var $Modules;
62 var $System;
63 var $OnLoadModules;
64
65 function __construct($System)
66 {
67 $this->Modules = array();
68 $this->System = &$System;
69 }
70
71 function StartAll()
72 {
73 foreach($this->Modules as $Index => $Module)
74 {
75 //DebugLog('Init module '.$Module->Name);
76 $this->Modules[$Index]->Start();
77 }
78 }
79
80 function StopAll()
81 {
82 foreach($this->Modules as $Index => $Module)
83 {
84 //DebugLog('Init module '.$Module->Name);
85 $this->Modules[$Index]->Stop();
86 }
87 }
88
89 function ModulePresent($Name)
90 {
91 return(array_key_exists($Name, $this->Modules));
92 }
93
94 function RegisterModule(AppModule $Module)
95 {
96 $this->Modules[$Module->Name] = &$Module;
97 $Module->Manager = &$this;
98 $Module->OnChange = &$this->OnModuleChange;
99 }
100
101 function UnregisterModule($Module)
102 {
103 unset($this->Modules[array_search($Module, $this->Modules)]);
104 }
105
106 /* @return Module */
107 function SearchModuleById($Id)
108 {
109 foreach($this->Modules as $Module)
110 {
111 //DebugLog($Module->Name.' '.$Module->Id);
112 if($Module->Id == $Id) return($Module->Name);
113 }
114 return('');
115 }
116
117 function LoadModulesFromDir($Directory)
118 {
119 $List = scandir($Directory);
120 foreach($List as $Item)
121 {
122 if(is_dir($Directory.'/'.$Item) and ($Item != '.') and ($Item != '..'))
123 {
124 include_once($Directory.'/'.$Item.'/'.$Item.'.php');
125 $ModuleName = 'Module'.$Item;
126 $this->RegisterModule(new $ModuleName($this->System));
127 }
128 }
129 }
130
131 function LoadModules()
132 {
133 if(method_exists($this->OnLoadModules[0], $this->OnLoadModules[1]))
134 $this->OnLoadModules();
135 else $this->LoadModulesFromDir(dirname(__FILE__).'/../Modules');
136 }
137}
Note: See TracBrowser for help on using the repository browser.