Esempio n. 1
0
 /**
  * @return LBoxCacheLoader
  * @throws LBoxExceptionCache
  */
 public static function getInstance($fileName = "")
 {
     $className = __CLASS__;
     try {
         if (!self::$instance instanceof $className) {
             self::$instance = new $className();
         }
         return self::$instance;
     } catch (Exception $e) {
         throw $e;
     }
 }
Esempio n. 2
0
 /**
  * nacte pozadovany typ
  * @param string 	$type type to load
  * @throws LBoxExceptionLoader
  */
 public function load($type = "")
 {
     try {
         if (array_key_exists($type, self::$typesPaths)) {
             return;
         }
         if ($this->debug == 'terminal') {
             $lime_output = new lime_output();
         }
         // nalezeno v cachi
         if ($value = LBoxCacheLoader::getInstance()->{$type}) {
             if ($this->debug == 'terminal') {
                 $lime_output->echoln("'{$type}' found in cache as '{$value}'", $parameters = array('fg' => 'magenta'));
             } else {
                 if ($this->debug) {
                     echo __CLASS__ . "(" . __LINE__ . "):: <font style='color:fuchsia;'>'<b>{$type}</b>' found in cache as '<i>{$value}</i>'<br /></font>\n";
                 }
             }
             // zkontrolovat, ze se jedna o path v ramci projektu (opatreni, ze cache neni nakopirovana spolu s puvodnim projektem)
             if (substr($value, 0, strlen(LBOX_PATH_INSTANCE_ROOT)) == LBOX_PATH_INSTANCE_ROOT) {
                 if (!@(include "{$value}")) {
                     LBoxCacheLoader::getInstance()->resetValue($type);
                     // throw new LBoxExceptionLoader("'$type' ". LBoxExceptionLoader::MSG_TYPE_LOAD_ERROR ." Path '$value'", LBoxExceptionLoader::CODE_TYPE_LOAD_ERROR);
                 } else {
                     self::$typesPaths[$type] = $value;
                     return;
                 }
             } else {
                 if ($this->debug == 'terminal') {
                     $lime_output->echoln("'{$type}' Was found in cache under other project. Returned: '{$value}' - RESETING cache", $parameters = array('bg' => 'cyan', 'fg' => 'white'));
                 } else {
                     if ($this->debug) {
                         echo __CLASS__ . "(" . __LINE__ . "):: <font style='color:#C0C0C0;'>'<b>{$type}</b>' Was found in cache under other project. Returned: '<i>{$value}</i>' - RESETING cache<br /></font>\n";
                     }
                 }
                 LBoxCacheLoader::getInstance()->reset();
             }
         } else {
             if ($this->debug == 'terminal') {
                 $lime_output->echoln("'{$type}' NOT found in cache. Returned: '{$value}'", $parameters = array('bg' => 'grey', 'fg' => 'black'));
             } else {
                 if ($this->debug) {
                     echo __CLASS__ . "(" . __LINE__ . "):: <font style='color:orange;'>'<b>{$type}</b>' NOT found in cache. Returned: '<i>{$value}</i>'<br /></font>\n";
                 }
             }
         }
         foreach ($this->paths as $path) {
             if (!is_dir($path)) {
                 throw new LBoxExceptionLoader("Error in defined paths. Element " . LBoxExceptionLoader::MSG_INVALID_DIRPATH . " ('{$path}')", LBoxExceptionLoader::CODE_INVALID_DIRPATH);
             }
             $pathSearched = false;
             if (array_key_exists($type, $this->searchedPathsByTypes)) {
                 if (is_array($this->searchedPathsByTypes[$type])) {
                     foreach ($this->searchedPathsByTypes[$type] as $searchedPath) {
                         if (strstr("{$path}" . SLASH, $searchedPath)) {
                             $pathSearched = true;
                         }
                     }
                 }
             }
             if ($pathSearched) {
                 continue;
             }
             if (strlen($foundPath = $this->getPathOfType($type, $path)) > 0) {
                 if (!(include "{$foundPath}")) {
                     throw new LBoxExceptionLoader("'{$type}' " . LBoxExceptionLoader::MSG_TYPE_LOAD_ERROR . " Path '{$foundPath}'", LBoxExceptionLoader::CODE_TYPE_LOAD_ERROR);
                 } else {
                     LBoxCacheLoader::getInstance()->{$type} = $foundPath;
                     self::$typesPaths[$type] = $foundPath;
                     return;
                 }
             }
             $this->searchedPathsByTypes[$type][] = "{$path}" . SLASH;
         }
     } catch (Exception $e) {
         throw $e;
     }
 }