/** * @param string $type type to load * @param array $paths paths where to search * @param array $prefixes explicit file prefixes * @return LBoxLoader * @throws LBoxExceptionLoader */ public static function getInstance($paths = array(), $pathsIgnore = array(), $prefixes = array()) { $className = __CLASS__; try { if (!isset(self::$instance)) { self::$instance = new $className($paths, $pathsIgnore, $prefixes); } return self::$instance; } catch (Exception $e) { throw $e; } }
function __autoload($className) { try { $debug = false; $slash = SLASH; $dirArr = explode($slash, dirname(__FILE__)); unset($dirArr[count($dirArr) - 1]); $lBoxDirName = end($dirArr); $projectRootArr = $dirArr; unset($projectRootArr[count($projectRootArr) - 1]); $projectRootPath = implode($slash, $projectRootArr); $paths = array($projectRootPath . $slash . $lBoxDirName, $projectRootPath . $slash . LBOX_DIRNAME_PROJECT, $projectRootPath . $slash . LBOX_DIRNAME_PLUGINS); $pathsIgnore = array($projectRootPath . $slash . "{$lBoxDirName}" . $slash . "TAL", $projectRootPath . $slash . "{$lBoxDirName}" . $slash . "dev", $projectRootPath . $slash . LBOX_DIRNAME_PROJECT . $slash . "dev", $projectRootPath . $slash . LBOX_DIRNAME_PROJECT . $slash . "css", $projectRootPath . $slash . LBOX_DIRNAME_PROJECT . $slash . "js", $projectRootPath . $slash . LBOX_DIRNAME_PROJECT . $slash . "documents", $projectRootPath . $slash . LBOX_DIRNAME_PROJECT . $slash . "img", $projectRootPath . $slash . LBOX_DIRNAME_PROJECT . $slash . "filespace", $projectRootPath . $slash . LBOX_DIRNAME_PROJECT . $slash . ".cache", $projectRootPath . $slash . LBOX_DIRNAME_PROJECT . $slash . ".tal_compiled", $projectRootPath . $slash . LBOX_DIRNAME_PROJECT . $slash . "wsw"); $pathsConfig = array($projectRootPath . $slash . "{$lBoxDirName}" . $slash . "config", $projectRootPath . $slash . LBOX_DIRNAME_PROJECT . $slash . "config"); /*$lime_output = new lime_output(); $lime_output->info('looking for '. $className);*/ LBoxLoader::getInstance($paths, $pathsIgnore)->debug = $debug ? 'terminal' : false; LBoxLoader::getInstance()->load($className); } catch (Exception $e) { $lime = new lime_output(); $lime->error($e->getMessage(), $e->getFile(), $e->getLine(), $e->getTrace()); } }
/** * zkopiruje zdrojovy kod tridy do tridy nove, pokud uz neexistuje * @param string $sourceClassName * @param string $targetClassName */ public static function copyClassTo($sourceClassName = "", $targetClassName = "") { try { if (strlen($sourceClassName) < 1) { throw new LBoxExceptionClasses("\$sourceClassName: " . LBoxExceptionClasses::MSG_PARAM_STRING_NOTNULL, LBoxExceptionClasses::CODE_BAD_PARAM); } if (strlen($targetClassName) < 1) { throw new LBoxExceptionClasses("\$targetClassName: " . LBoxExceptionClasses::MSG_PARAM_STRING_NOTNULL, LBoxExceptionClasses::CODE_BAD_PARAM); } if (class_exists($targetClassName)) { throw new LBoxExceptionClasses("{$targetClassName}: " . LBoxExceptionClasses::MSG_TARGET_CLASS_EXISTS, LBoxExceptionClasses::CODE_TARGET_CLASS_EXISTS); } if (!class_exists($sourceClassName)) { throw new LBoxExceptionClasses("{$sourceClassName}: " . LBoxExceptionClasses::MSG_SOURCE_CLASS_NOT_EXISTS, LBoxExceptionClasses::CODE_SOURCE_CLASS_NOT_EXISTS); } $srcClassPath = LBoxLoader::getInstance()->getFoundTypePath($sourceClassName); $trgtClassPath = str_replace($sourceClassName, $targetClassName, $srcClassPath); if (file_exists($trgtClassPath)) { throw new LBoxExceptionClasses("{$trgtClassPath}: " . LBoxExceptionFilesystem::MSG_FILE_ALREADY_EXISTS, LBoxExceptionFilesystem::CODE_FILE_ALREADY_EXISTS); } $sourceSRCClass = fread($fs = fopen($srcClassPath, "r"), filesize($srcClassPath)); $sourceTRGTClass = $sourceSRCClass; $sourceTRGTClass = preg_replace("/class(\\s+){$sourceClassName}/i", "class {$targetClassName}", $sourceTRGTClass); $sourceTRGTClass = preg_replace("/\\@since(\\s+)(\\d{4}-\\d{2}-\\d{2})/i", "@since " . date("Y-m-d"), $sourceTRGTClass); $sourceTRGTClass = preg_replace("/\\/\\*\\*(\\s*)\n(\\s*)\\*(\\s*)([\\w ]+)/", "/**\n * Automaticaly duplicated class from {$sourceClassName}", $sourceTRGTClass); if (!($ft = fopen($trgtClassPath, "w+"))) { throw new LBoxExceptionFilesystem("{$trgtClassPath}: " . LBoxExceptionFilesystem::MSG_FILE_CANNOT_OPEN, LBoxExceptionFilesystem::CODE_FILE_CANNOT_OPEN); } if (!fwrite($ft, $sourceTRGTClass)) { throw new LBoxExceptionFilesystem("{$trgtClassPath}: " . LBoxExceptionFilesystem::MSG_FILE_CANNOT_WRITE, LBoxExceptionFilesystem::CODE_FILE_CANNOT_WRITE); } @fclose($fs); @fclose($ft); include $trgtClassPath; } catch (Exception $e) { throw $e; } }