3 require_once("AOOSException.php");
4 require_once("AOOSModel.php");
5 require_once("AOOSStorageDevice.php");
11 * The core class of AOOS
13 * @author Sebastian Skejø
18 private $_exceptions = array();
19 private $_modules = null;
20 private $_settings = array();
21 private $_transStrings = array();
22 private $_log = array();
25 * During constructing a model is built with module names and properties
27 public function __construct()
30 require_once("config.php");
31 $this->_settings
= $settings; /* Set in config.php */
32 $l = $this->getSetting("lang");
35 require_once("lang.php");
36 if (!in_array($l, array_keys($lang))) /* $lang set in lang.php */
38 throw new AOOSException($this, "Language not found in lang.php. You will not be able to translate strings","",true, 1);
42 $this->_transStrings
= $lang[$l];
46 $s = $this->newStorageDevice();
47 $s->setTable("modules");
48 $this->_modules
= $s->selectModel("*");
49 $this->_modules
->setEscape(false);
51 $this->log("Created AOOSCore");
54 public function log($str)
56 $this->_log
[] = array(
58 "TIMESTAMP" => microtime()
64 * @param AOOSException $e The exception
66 public function setException($e)
68 $this->_exceptions
[$e->getName()] = $e;
69 if ($e->getEcode() == 0)
77 public function printExceptions()
79 $str = "<div class=\"Exceptions\">";
80 foreach ($this->_exceptions
as $e)
88 public function getSetting($name, $module = "no")
90 $a = $this->_settings
;
91 if ($module != "no" && $this->isLoaded($module))
95 if (!in_array($name, array_keys($a)))
97 throw new AOOSException($this, "Settingkey not found", "Key: ".$name, true, 2);
103 public function getTranslatedString($string, $module = "no")
105 $a = $this->_transStrings
;
106 if ($module != "no" && $this->isLoaded($module))
110 if (!in_array($string, array_keys($a)))
112 throw new AOOSException($this, "Translated string not found", "String name: ".$string, true, 2);
118 public function modules()
120 return $this->_modules
;
123 public function loadModule($name)
125 $this->log("Loading ".$name);
126 $m = $this->modules();
127 if (($r = $m->getRowFromValue("name", $name)) === false)
129 $this->log("Failed!");
130 throw new AOOSException($this, $this->getTranslatedString("module_not_loadable"), "", true, 1);
134 $row = $m->getRow($r);
135 $dir = $this->getSetting("module_dir")."/".$row["name"]."/";
136 $filename = $row["name"].$this->getSetting("extension");
138 $deps = explode(",", $row["deps"]);
139 if (!empty($deps[0]))
141 foreach($deps as $dep)
143 if (!$this->isLoaded($dep))
147 $this->loadModule($dep);
149 catch(AOOSException
$e)
151 throw new AOOSException($this, $this->getTranslatedString("deps_not_loadable"), $row["name"], true, 1);
158 if ($row["instance"])
161 return $row["instance"];
164 require_once($dir.$filename);
165 if (file_exists($dir."settings".$this->getSetting("extension")))
167 require_once($dir."settings".$this->getSetting("extension"));
168 $this->_settings
[$row["name"]] = $settings;
170 if (file_exists($dir."lang".$this->getSetting("extension")))
172 require_once($dir."lang".$this->getSetting("extension"));
173 $this->_transStrings
[$row["name"]] = $lang;
175 $i = new $row["name"]($this);
176 $m->setData($i, $r, "instance");
183 * Returns true if $module is loaded, otherwise return false.
184 * @param string $name Module name
187 public function isLoaded($name)
189 $m = $this->modules();
190 if (($row = $m->getRowFromValue("name", $name)) === false)
192 // TODO: throw exception
200 * Returns an instance to the given $module
201 * @param string $module The name of the module
202 * @return false|AOOSModule
204 public function getModule($module)
206 $m = $this->modules();
207 if (($row = $m->getRowFromValue("name", $module)) === false)
209 throw new AOOSException($this, $this->getTranslatedString("module_not_found"), "", true, 1);
212 return $this->loadModule($module);
215 public function __toString()
221 public function newStorageDevice() {
222 $obj = new AOOSStorageDevice($this);
223 $obj->setStorageType($this->getSetting("default_storage_type"));