class_ApplicationSelector.php
Go to the documentation of this file.00001 <?php
00024 class ApplicationSelector extends BaseFrameworkSystem {
00028 private $foundApps = null;
00029
00033 private $loadedTemplates = null;
00034
00038 private $dirIgnoreList = array(
00039 ".",
00040 "..",
00041 ".htaccess",
00042 ".svn"
00043 );
00044
00050 protected function __construct() {
00051
00052 parent::__construct(__CLASS__);
00053
00054
00055 $this->removeSystemArray();
00056 $this->removeNumberFormaters();
00057
00058
00059 $this->initializeAppsList();
00060 $this->initializeTemplatesList();
00061 }
00062
00070 public final static function createApplicationSelector (ManageableLanguage $langInstance, FileIoHandler $fileIOInstance) {
00071
00072 $selInstance = new ApplicationSelector();
00073
00074
00075 $selInstance->readApplicationDirectory();
00076
00077
00078 $selInstance->setLanguageInstance($langInstance);
00079 $selInstance->setFileIoInstance($fileIOInstance);
00080
00081
00082 return $selInstance;
00083 }
00084
00090 private function initializeAppsList () {
00091 $this->foundApps = new FrameworkArrayObject("FakedFoundApplications");
00092 }
00093
00099 private function initializeTemplatesList () {
00100 $this->loadedTemplates = new FrameworkArrayObject("FakedLoadedTemplates");
00101 }
00102
00111 private function loadApplicationData ($appData, $appName) {
00112
00113 if ((is_file($appData)) && (is_readable($appData))) {
00114
00115 include ($appData);
00116
00117
00118 $this->foundApps->append($app);
00119 }
00120 }
00121
00128 private final function getLoadedTemplates () {
00129 return $this->loadedTemplates;
00130 }
00131
00137 public function getAppShortName() {
00138 $shortName = $this->getConfigInstance()->readConfig('selector_path');
00139 return $shortName;
00140 }
00141
00148 public function addDirIgnoreList ($ignoreItem) {
00149
00150 $this->dirIgnoreList[] = (string) $ignoreItem;
00151 }
00152
00159 public function readApplicationDirectory () {
00160
00161 $appBasePath = $this->getConfigInstance()->readConfig('application_path');
00162
00163
00164 $this->addDirIgnoreList($this->getConfigInstance()->readConfig('selector_path'));
00165
00166
00167 $dirInstance = FrameworkDirectoryPointer::createFrameworkDirectoryPointer($appBasePath);
00168
00169
00170 while ($appName = $dirInstance->readDirectoryExcept($this->dirIgnoreList)) {
00171
00172 $fqfn = sprintf("%s%s", $appBasePath, $appName);
00173
00174
00175 if ((is_dir($fqfn)) && (is_readable($fqfn))) {
00176
00177 $appData = sprintf("%s/data.php", $fqfn);
00178
00179
00180
00181 $this->loadApplicationData($appData, $appName);
00182 }
00183 }
00184
00185
00186 $dirInstance->closeDirectory();
00187 }
00188
00194 public function loadApplicationTemplates () {
00195
00196 for ($idx = $this->foundApps->getIterator(); $idx->valid(); $idx->next()) {
00197
00198 $appInstance = $idx->current();
00199
00200
00201 $templateInstance = $this->prepareTemplateInstance($appInstance);
00202
00203
00204 $templateInstance->loadWebTemplate(sprintf("%s_%s",
00205 $this->getConfigInstance()->readConfig('tpl_selector_prefix'),
00206 strtolower($appInstance->getAppShortName())
00207 ));
00208
00209
00210 $this->loadedTemplates->append(array(
00211 'template_class' => $templateInstance,
00212 'app_instance' => $appInstance
00213 ));
00214 }
00215
00216
00217 $this->initializeAppsList();
00218 }
00219
00225 public final function removeDirIgnoreList () {
00226 unset($this->dirIgnoreList);
00227 }
00228
00235 public function loadSelectorTemplate () {
00236
00237 $templateInstance = $this->prepareTemplateInstance($this);
00238
00239
00240 $templateInstance->loadCodeTemplate($this->getConfigInstance()->readConfig('selector_main_tpl'));
00241
00242
00243 $this->setTemplateInstance($templateInstance);
00244 }
00245
00258 public function insertApplicationTemplates () {
00259
00260 $templateInstance = $this->prepareTemplateInstance($this);
00261
00262
00263 $templateInstance->loadCodeTemplate($this->getConfigInstance()->readConfig('selector_apps_tpl'));
00264
00265
00266 $dummy = "";
00267 for ($idx = $this->getLoadedTemplates()->getIterator(); $idx->valid(); $idx->next()) {
00268
00269 $curr = $idx->current();
00270
00271
00272 if (is_null($curr)) {
00273
00274 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
00275 } elseif (!is_array($curr)) {
00276
00277 throw new NoArrayException($curr, self::EXCEPTION_IS_NO_ARRAY);
00278 } elseif (count($curr) != 2) {
00279
00280 throw new InvalidArrayCountException(array($this, "curr", count($curr), 2), self::EXCEPTION_ARRAY_HAS_INVALID_COUNT);
00281 } elseif (!isset($curr['template_class']) || (!isset($curr['app_instance']))) {
00282
00283 throw new MissingArrayElementsException(array($this, "curr", array("template_class", "app_instance")), self::EXCEPTION_ARRAY_ELEMENTS_MISSING);
00284 }
00285
00286
00287 die(__METHOD__."()<pre>".print_r($curr, true)."</pre>");
00288 }
00289 }
00290 }
00291
00292
00293 ?>