/core/loader.php
PHP | 984 lines | 608 code | 138 blank | 238 comment | 96 complexity | ba673f2b04bf2773cd189e386f604613 MD5 | raw file
- <?php
- include_once(Loader::getDirectPath('{core}/{classes}/{framework}/cache/cache.{class_ext}'));
- class Loader {
-
- /**
- *
- * Are used for straight lookup files
- *
- * @var array
- */
- private static $_lookupDirs = array();
-
- /**
- *
- * @var CacheInterface
- */
- private static $_cache = null;
- /**
- *
- * @var array
- */
- private static $_cacheData = array();
-
- /**
- * @var int $pathsKey is unique identifier for paths combination
- */
- private static $_pathsKey = 0;
-
- /**
- *
- * Used for directories for recursive searching
- *
- * @var array
- */
- private static $_paths = array();
-
- /**
- *
- * Store replacement data for main configuration
- *
- * @var array
- */
- private static $_replacement = array();
-
- /**
- *
- * Returns absolute path from given related
- *
- * @param string|array $filepath relative path as string or array parts
- * @param array $options set of options if needed
- * @return string
- */
- public static function getDirectPath($filePath, $options = array())
- {
- if (is_array($filePath))
- {
- $filePath = self::arrayToPath($filePath);
- }
- $filePath = self::replaceCfgPlaceholders($filePath, $options);
-
- return Cfg_App::$DOCUMENT_ROOT . $filePath;
- }
-
- public static function getPackTplFilePath($template, $options = array())
- {
- $packName = App::getCurrentRoute()->getPackName();
-
- extract($options, EXTR_IF_EXISTS | EXTR_OVERWRITE);
-
- return self::getDirectPath("{packs}/{pack_name}/{media}/{tpl}/{$template}.{tpl_ext}", array('packName' => $packName));
- }
-
- public static function getComponentTplFilePath($template, $options = array())
- {
- $packName = App::getCurrentRoute()->getPackName();
-
- $componentName = App::getCurrentRoute()->getComponentName();
-
- extract($options, EXTR_IF_EXISTS | EXTR_OVERWRITE);
-
- return self::getDirectPath("{packs}/{pack_name}/{components}/{component_name}/{media}/{tpl}/{$template}.{tpl_ext}",
- array('packName' => $packName, 'componentName' => $componentName));
- }
-
- public static function getSystemTplFilePath($template)
- {
- return self::getDirectPath("{media}/{tpl}/{$template}.{tpl_ext}");
- }
-
- /**
- *
- * Returns file path of the pack controller
- *
- * @param string $packName
- * @param array $options
- * @return string
- */
- public static function getPackControllerFilePath($packName, $options = array())
- {
- $controllerName = Cfg_App::getPackOption(Cfg_App::KEY_DEFAULT_CONTROLLER_NAME, $packName);
-
- extract($options, EXTR_IF_EXISTS | EXTR_OVERWRITE);
-
- return self::getDirectPath("{packs}/{pack_name}/{controllers}/{$controllerName}.{class_ext}", array('packName' => $packName));
- }
-
- /**
- *
- * Returns file path of the component controller
- *
- * @param string $componentName
- * @param array $options
- * @return string
- */
- public static function getComponentControllerFilePath($componentName, $options = array())
- {
- $packName = App::getCurrentRoute()->getPackName();
- $controllerName = Cfg_App::getPackOption(Cfg_App::KEY_DEFAULT_CONTROLLER_NAME, $packName);
-
- extract($options, EXTR_IF_EXISTS | EXTR_OVERWRITE);
- return self::getDirectPath("{packs}/{pack_name}/{components}/{component_name}/{controllers}/{$controllerName}.{class_ext}",
- array('packName' => $packName, 'componentName' => $componentName));
- }
-
- /**
- *
- * Returns file path of the module controller
- *
- * @param string $moduleName
- * @param array $options
- * @return string
- */
- public static function getModuleControllerFilePath($moduleName, $options = array())
- {
- $packName = App::getCurrentRoute()->getPackName();
-
- $controllerName = Cfg_App::getPackOption(Cfg_App::KEY_DEFAULT_CONTROLLER_NAME, $packName);
-
- extract($options, EXTR_IF_EXISTS | EXTR_OVERWRITE);
-
- return self::getDirectPath("{packs}/{pack_name}/{modules}/{module_name}/{controllers}/{$controllerName}.{class_ext}",
- array('packName' => $packName, 'moduleName' => $moduleName));
- }
-
- public static function getCacheDirectoryPath($subDirectory = "")
- {
- if (!$subDirectory)
- $subDirectory = Cfg_App::_(Cfg_App::KEY_APP_SUBDIR);
-
- return self::getDirectPath("{core}/{cache}/{$subDirectory}");
- }
-
- public static function loadConfigurationFromFile($configFileName)
- {
- if (is_file($configFileName) && is_readable($configFileName))
- {
- $cfgData = include($configFileName);
-
- if (is_array($cfgData))
- {
- return $cfgData;
- }
- else
- {
- trigger_error("File \"{$configFileName}\" should return array as configuration settings!", E_USER_WARNING);
- }
- }
- else
- {
- return array();
- }
- }
-
- /**
- *
- * Returns configuration file path for the pack
- *
- * @param stirng $packName
- * @return string
- */
- public static function getPackConfigurationFilePath($packName)
- {
- return self::getDirectPath("packs/{$packName}/{cfg_dir}/{cfg_pack_file}");
- }
-
- /**
- *
- * Returns db configuration file path for the pack
- *
- * @param stirng $packName
- * @return string
- */
- public static function getPackDbConfigurationFilePath($packName)
- {
- return self::getDirectPath("packs/{$packName}/{cfg_dir}/{cfg_db_file}");
- }
-
- /**
- *
- * Returns data from pack config
- *
- * @param string $packName
- * @return array
- */
- public static function getPackConfiguration($packName)
- {
- $configFileName = self::getPackConfigurationFilePath($packName);
- return self::loadConfigurationFromFile($configFileName);
- }
-
- /**
- *
- * Returns data from pack db config
- *
- * @param string $packName
- * @return array
- */
- public static function getPackDbConfiguration($packName)
- {
- $configFileName = self::getPackDbConfigurationFilePath($packName);
- return self::loadConfigurationFromFile($configFileName);
- }
-
- /**
- *
- * @param string $className class name to be loaded
- * @param string $options
- *
- * @return bool
- */
- public static function loadClass($className, $options = array())
- {
- $fileToInclude = "";
-
- $packName = App::getCurrentRoute() ? App::getCurrentRoute()->getPackName() : "";
-
- $componentName = App::getCurrentRoute() ? App::getCurrentRoute()->getComponentName() : "";
- $searchInPackOnly = false;
-
- $searchInComponentOnly = false;
-
- extract($options, EXTR_IF_EXISTS | EXTR_OVERWRITE);
-
- $options['packName'] = $packName;
- $options['componentName'] = $componentName;
- if (Cfg_App::$AUTOLOADER_CACHE_ENABLED)
- {
- $fileToInclude = self::classFileCacheLookup($className, array('pathsKey' => self::_getCustomPathsKey($options)));
-
- $options['fromCache'] = (bool)$fileToInclude;
- }
- if (!$fileToInclude)
- {
- if (false == ($fileToInclude = self::classFileStraightLookupTest($className,
- self::_getFilePathPartByClassName($className, $packName),
- $options)))
- {
- if (!($searchInPackOnly || $searchInComponentOnly))
- {
- $fileToInclude = self::classFileRecursiveLookup(self::_getFilePathPartByClassName($className),
- $options);
- }
- }
- }
- return self::checkIncludeClassFile($className, $fileToInclude, $options);
- }
-
- /**
- *
- * @param string $className
- * @param string $packName
- * @param bool $throws
- * @return bool
- */
- public static function loadPackClass($className, $packName, $throws = false)
- {
- return self::loadClass($className, array(
- 'packName' => $packName,
- 'searchInPackOnly' => true,
- 'throws' => $throws
- ));
- }
-
- /**
- *
- * @param string $className
- * @param string $packName
- * @param bool $throws
- * @return bool
- */
- public static function loadComponentClass($className, $componentName, $packName, $throws = false)
- {
- return self::loadClass($className, array(
- 'packName' => $packName,
- 'componentName' => $componentName,
- 'searchInComponentOnly' => true,
- 'throws' => $throws
- ));
- }
-
- /**
- *
- * @param Cache_Interface $cache instance of your caching object for autoloader
- */
- public static function setCache(Cache_Interface $cache)
- {
- self::$_cache = $cache;
-
- self::$_cacheData = $cache->get(Cfg_App::_(Cfg_App::KEY_AUTOLOADER_CACHE));
- }
-
- /**
- *
- * @param string $className
- * @param string $fileToInclude
- * @param string $pathsKey practically unique identifier
- */
- public static function cacheFilePath($className, $fileToInclude, $pathsKey = "")
- {
- if (!$pathsKey)
- $pathsKey = self::$_pathsKey;
- if (Cfg_App::$AUTOLOADER_CACHE_ENABLED && self::$_cache)
- {
- if (!isset(self::$_cacheData[$className]) || !is_array(self::$_cacheData[$className]))
- {
- self::$_cacheData[$className] = array();
- }
-
- self::$_cacheData[$className][$pathsKey] = $fileToInclude;
- self::flushCache();
- }
- }
-
- private static function _getCustomPathsKey($options)
- {
- $componentName = "";
-
- $packName = "";
-
- $searchInPackOnly = false;
-
- $searchInComponentOnly = false;
-
- extract($options, EXTR_IF_EXISTS | EXTR_OVERWRITE);
-
- if ($searchInComponentOnly)
- {
- return self::_getStringIdentifier(self::$_pathsKey . $componentName);
- }
- elseif($searchInPackOnly)
- {
- return self::_getStringIdentifier(self::$_pathsKey . $packName);
- }
- else
- {
- return self::$_pathsKey;
- }
- }
-
- /**
- *
- * Saves cache data
- *
- * @return bool true on success, false otherwise
- */
- public static function flushCache()
- {
- if (self::$_cache)
- {
- $data = self::_arrayMergeRecursiveDistinct((array)self::$_cache->get(Cfg_App::_(Cfg_App::KEY_AUTOLOADER_CACHE)), (array)self::$_cacheData);
-
- return self::$_cache->set(Cfg_App::_(Cfg_App::KEY_AUTOLOADER_CACHE), $data);
- }
- }
-
- /**
- *
- * Adds a path to the path collection to perform searching in
- *
- * @param string|array $paths realtive paths to directory
- */
- public static function setIncludePaths($paths)
- {
- if (!is_array($paths))
- $paths = (array)$paths;
-
- foreach($paths as $path)
- {
- array_push(self::$_paths, self::getDirectPath($path));
- }
-
- $tmpPaths = self::$_paths;
- sort($tmpPaths, SORT_STRING);
- self::$_pathsKey = self::_getStringIdentifier(implode(",", $tmpPaths));
- }
-
- public static function getIncludePaths()
- {
- return self::$_paths;
- }
-
- public static function clearIncludePaths()
- {
- self::$_paths = array();
- self::$_pathsKey = self::_getStringIdentifier("");
- }
-
- /**
- *
- * Performs lookup of file to include in the file cache
- *
- * @param string $className Class name to look for
- * @param array $options Some options to perform searching. 'pathsKey' - define this key
- * as unique identifier for current class
- *
- * @return string path to included file
- */
- public static function classFileCacheLookup($className, $options = array())
- {
- $pathsKey = self::$_pathsKey;
-
- extract($options, EXTR_IF_EXISTS | EXTR_OVERWRITE);
-
- if (self::$_cache && self::$_cacheData)
- {
- return isset(self::$_cacheData[$className][$pathsKey]) ? self::$_cacheData[$className][$pathsKey] : "";
- }
- else
- {
- return "";
- }
- }
-
- /**
- *
- * @param string $className File name to be look for
- * @param string $classFile
- * @param array $options
- * @return string
- */
- public static function classFileStraightLookup($className, $classFile, $options = array())
- {
- $packName = "";
- $componentName = "";
-
- $searchInPackOnly = "";
- $searchInComponentOnly = "";
- extract($options, EXTR_IF_EXISTS | EXTR_OVERWRITE);
-
- if (!preg_match('/table$/i', $className))
- {
- $classesPath = Cfg_App::_(Cfg_App::KEY_CLASSES_PATH);
- $packClassesPath = Cfg_Pack::_(Cfg_App::KEY_CLASSES_PATH);
- }
- else
- {
- $classesPath = Cfg_App::_(Cfg_App::KEY_DATA_CLASSES_PATH);
- $packClassesPath = Cfg_Pack::_(Cfg_App::KEY_DATA_CLASSES_PATH);
- }
- $toRequire = "";
-
- if($searchInComponentOnly && !$searchInPackOnly)
- {
- if ($componentName && $packName)
- {
- $componentClassNameFile = self::getDirectPath(array(
- Cfg_App::_(Cfg_App::KEY_PACKS_PATH),
- $packName,
- Cfg_App::_(Cfg_App::KEY_COMPONENTS),
- $componentName,
- $packClassesPath,
- $classFile
- ));
- }
- if (isset($componentClassNameFile) && is_file($componentClassNameFile) && is_readable($componentClassNameFile))
- {
- $toRequire = $componentClassNameFile;
- }
- }
- elseif($searchInPackOnly && !$searchInComponentOnly)
- {
- if ($packName)
- {
- $packClassNameFile = self::getDirectPath(array(
- Cfg_App::_(Cfg_App::KEY_PACKS_PATH),
- $packName,
- $packClassesPath,
- $classFile
- ));
- }
- if (isset($packClassNameFile) && is_file($packClassNameFile) && is_readable($packClassNameFile))
- {
- $toRequire = $packClassNameFile;
- }
- }
- else
- {
- if ($componentName && $packName)
- {
- $componentClassNameFile = self::getDirectPath(array(
- Cfg_App::_(Cfg_App::KEY_PACKS_PATH),
- $packName,
- Cfg_App::_(Cfg_App::KEY_COMPONENTS),
- $componentName,
- $packClassesPath,
- $classFile
- ));
- }
- if(isset($componentClassNameFile) && is_file($componentClassNameFile) && is_readable($componentClassNameFile))
- {
- $toRequire = $componentClassNameFile;
- }
- else
- {
- if ($packName)
- {
- $packClassNameFile = self::getDirectPath(array(
- Cfg_App::_(Cfg_App::KEY_PACKS_PATH),
- $packName,
- $packClassesPath,
- $classFile
- ));
- }
- if (isset($packClassNameFile) && is_file($packClassNameFile) && is_readable($packClassNameFile))
- {
- $toRequire = $packClassNameFile;
- }
- else
- {
- $customClassNameFile = self::getDirectPath(array(
- Cfg_App::_(Cfg_App::KEY_CORE_PATH),
- $classesPath,
- Cfg_App::_(Cfg_App::KEY_USER_CLASSES),
- $classFile));
- if (is_file($customClassNameFile) && is_readable($customClassNameFile))
- {
- $toRequire = $customClassNameFile;
- }
- else
- {
- $classNameFile = self::getDirectPath(array(
- Cfg_App::_(Cfg_App::KEY_CORE_PATH),
- $classesPath,
- Cfg_App::_(Cfg_App::KEY_FRAMEWORK_CLASSES),
- $classFile));
- if(is_file($classNameFile) && is_readable($classNameFile))
- {
- $toRequire = $classNameFile;
- }
- }
- }
- }
- }
- return $toRequire;
- }
-
- /**
- *
- * @param string $className File name to be look for
- * @param string $classFile
- * @param array $options
- * @return string
- */
- public static function classFileStraightLookupTest($className, $classFile, $options = array())
- {
- // $packName = "";
- // $componentName = "";
- //
- $searchInPackOnly = "";
- $searchInComponentOnly = "";
- extract($options, EXTR_IF_EXISTS | EXTR_OVERWRITE);
-
- $options['classDirType'] = self::_getClassDirType($className);
-
- $toRequire = "";
-
- $dirs = array();
-
- if($searchInComponentOnly && !$searchInPackOnly)
- {
- $dirs = array_merge($dirs, array_values(self::$_lookupDirs[Cfg_App::COMPONENT_LOOKUP_PATHS]));
- }
- elseif($searchInPackOnly && !$searchInComponentOnly)
- {
- $dirs = array_merge($dirs, array_values(self::$_lookupDirs[Cfg_App::PACK_LOOKUP_PATHS]));
- }
- else
- {
- $dirs = array_merge($dirs, array_values(self::$_lookupDirs[Cfg_App::COMPONENT_LOOKUP_PATHS]),
- array_values(self::$_lookupDirs[Cfg_App::PACK_LOOKUP_PATHS]),
- array_values(self::$_lookupDirs[Cfg_App::SYSTEM_LOOKUP_PATHS]));
- }
- foreach($dirs as $dir)
- {
- $classNameFile = self::getDirectPath(array($dir, $classFile), $options);
-
- if(is_file($classNameFile))
- {
- $toRequire = $classNameFile;
- break;
- }
- }
- return $toRequire;
- }
-
- public static function classFileRecursiveLookup($className, $options)
- {
- foreach(self::$_paths as $path) {
- if (true == ($toInclude = self::_fileRecursiveLookup($className, $path)))
- {
- return $toInclude;
- }
- }
- }
-
- private static function _fileRecursiveLookup($searchFilePath, $directory)
- {
- if (is_dir($directory) && is_readable($directory))
- {
- if (true == ($handle = opendir($directory))) {
- while (false !== ($entry = readdir($handle))) {
-
- if ($entry !== "." && $entry !== "..")
- {
- $subPath = $directory . Cfg_App::DS . $entry;
-
- if (is_dir($subPath))
- {
- $filePath = $subPath . Cfg_App::DS . $searchFilePath;
- if (is_readable($filePath))
- {
- return $filePath;
- }
- else
- {
- if(true == ($filePath = self::_fileRecursiveLookup($searchFilePath, $subPath)))
- {
- return $filePath;
- }
- }
- }
- }
- }
-
- closedir($handle);
- }
- }
- else
- {
- return false;
- }
- }
-
- public static function checkIncludeClassFile($className, $fileToInclude, $options)
- {
- $fromCache = false;
-
- $throws = false;
- extract($options, EXTR_IF_EXISTS | EXTR_OVERWRITE);
- if ($fileToInclude && is_readable($fileToInclude) && include_once($fileToInclude))
- {
- if (!class_exists($className, false)
- && !interface_exists($className, false)
- && (!function_exists('trait_exists') || !trait_exists($className, false)))
- {
- if ($throws)
- {
- throw new Exception(
- sprintf('The autoloader expected class "%s" to be
- defined in file "%s". The file was found but
- the class was not in it.', $className, $fileToInclude));
- }
- else
- {
- trigger_error(
- sprintf('The autoloader expected class "%s" to be
- defined in file "%s". The file was found but
- the class was not in it.', $className, $fileToInclude), E_USER_ERROR);
- }
- }
- else
- {
- if (!$fromCache)
- {
- self::cacheFilePath($className, $fileToInclude, self::_getCustomPathsKey($options));
- }
- }
- }
- else
- {
- if ($throws)
- {
- throw new Exception(
- sprintf('The autoloader could not find class "%s"', $className));
- }
- else
- {
- trigger_error(
- sprintf('The autoloader could not find class "%s"', $className), E_USER_ERROR);
- }
- }
- }
-
- public static function registerAutoloader()
- {
- if (Cfg_App::$AUTOLOADER_CACHE_ENABLED){
- self::setCache(Cache::getFileBasedCache());
- }
-
- return spl_autoload_register(array('Loader', 'loadClass'), true);
- }
-
- /**
- *
- * @param array $parts
- * @return string concatenated with directory separator path parts
- */
- public static function arrayToPath($parts)
- {
- return implode(Cfg_App::DS, $parts);
- }
-
- /**
- *
- * Replaces config placeholders in the string
- * available placeholders are:
- * '/' => ,
- * '{core}' => ,
- * '{classes}' => ,
- * '{dataclasses}' => ,
- * '{interfaces}' => ,
- * '{framework}' => ,
- * '{custom}' => ,
- * '{controllers}' => ,
- * '{components}' => ,
- * '{packs}' => ,
- * '{modules}' => ,
- * '{router_file}' => ,
- * '{cfg_dir}' => ,
- * '{cfg_pack_file}' => ,
- * '{cfg_app_file}' => ,
- * '{cfg_db_file}' => ,
- * '{class_ext}' => ,
- * '{media}' => ,
- * '{tpl}' => ,
- * '{tpl_ext}' => ,
- * '{pack_name}' => ,
- * '{component_name}' => ,
- * '{module_name}' => ,
- * '{class_dir_type}' => ,
- * '{owner}' =>
- *
- * @param string $str string to find placeholders in it
- * @param array $options provide options if you want to use specific behavior
- *
- * @return string string with replaced values
- */
- public static function replaceCfgPlaceholders($str, $options = array())
- {
- $packName = "";
- extract($options, EXTR_IF_EXISTS | EXTR_OVERWRITE);
- if ($packName || (!self::$_replacement))
- {
- $cfg = Cfg_App::getPackOptions($packName);
- $replacement = array(
- '/' => Cfg_App::DS,
- '{core}' => $cfg[Cfg_App::KEY_CORE_PATH],
- '{cache}' => $cfg[Cfg_App::KEY_CACHE],
- '{classes}' => $cfg[Cfg_App::KEY_CLASSES_PATH],
- '{dataclasses}' => $cfg[Cfg_App::KEY_DATA_CLASSES_PATH],
- '{interfaces}' => $cfg[Cfg_App::KEY_INTERFACES_PATH],
- '{framework}' => $cfg[Cfg_App::KEY_FRAMEWORK_CLASSES],
- '{user}' => $cfg[Cfg_App::KEY_USER_CLASSES],
- '{controllers}' => $cfg[Cfg_App::KEY_CONTROLLERS],
- '{components}' => $cfg[Cfg_App::KEY_COMPONENTS],
- '{packs}' => $cfg[Cfg_App::KEY_PACKS_PATH],
- '{modules}' => $cfg[Cfg_App::KEY_MODULES],
- '{router_file}' => $cfg[Cfg_App::KEY_ROUTER_FILE_NAME],
- '{cfg_dir}' => $cfg[Cfg_App::KEY_CONFIG],
- '{cfg_pack_file}' => $cfg[Cfg_App::KEY_CONFIG_PACK],
- '{cfg_app_file}' => $cfg[Cfg_App::KEY_CONFIG_APP],
- '{cfg_db_file}' => $cfg[Cfg_App::KEY_CONFIG_DB],
- '{class_ext}' => $cfg[Cfg_App::KEY_CLASS_FILE_EXT],
- '{media}' => $cfg[Cfg_App::KEY_MEDIA_PATH],
- '{tpl}' => $cfg[Cfg_App::KEY_TEMPLATES],
- '{tpl_ext}' => $cfg[Cfg_App::KEY_TEMPLATE_EXT]
- );
-
- if (!self::$_replacement && !$packName)
- {
- self::$_replacement = $replacement;
- }
- }
- elseif (self::$_replacement)
- {
- $replacement = self::$_replacement;
- }
-
- if (($packName && count($options) > 1) || $options)
- {
- $packName = "";
- $componentName = "";
- $moduleName = "";
- $classDirType = "";
- $owner = "";
-
- extract($options, EXTR_IF_EXISTS | EXTR_OVERWRITE);
- $additionalReplacements = array(
- '{pack_name}' => $packName,
- '{component_name}' => $componentName,
- '{module_name}' => $moduleName,
- '{class_dir_type}' => Cfg_App::getPackOption($classDirType, $packName),
- '{owner}' => $owner
- );
-
- $replacement = array_merge($replacement, $additionalReplacements);
- }
-
- return str_replace(array_keys($replacement), array_values($replacement), $str);
- }
-
- /**
- *
- * Sets directories for lookup purposes of autoloader
- * use SYSTEM_LOOKUP_PATHS, PACK_LOOKUP_PATHS, COMPONENT_LOOKUP_PATHS constants of Loader
- * as $dirs array keys
- * If $merge is set to 'true', new directories will be merged with previous,
- * they will be replaced otherwise
- *
- * @param array $dirs
- * @param bool $merge
- */
- public static function setLookupDirectories($dirs, $merge = true)
- {
- $keys = array_keys($dirs);
-
- foreach($keys as $dirKey)
- {
- if (in_array($dirKey, Cfg_App::getLookupDirKeys()))
- {
- if ($merge)
- {
- if (!isset(self::$_lookupDirs[$dirKey]))
- self::$_lookupDirs[$dirKey] = array();
-
- self::$_lookupDirs[$dirKey] =
- array_merge(self::$_lookupDirs[$dirKey],
- $dirs[$dirKey]);
- }
- else
- {
- self::$_lookupDirs[$dirKey] = $dirs[$dirKey];
- }
- }
- }
- }
-
- /**
- *
- * Calculates simple numeric identifier for string
- *
- * @param string $string
- * @return string
- */
- private static function _getStringIdentifier($string)
- {
- return sprintf("%u", crc32($string));
- }
-
- /**
- *
- * Returns string key of the value from the configuration array
- *
- * @param string $className
- * @return string string key from the configuration array
- */
- private static function _getClassDirType($className)
- {
- $dirType = Cfg_App::KEY_CLASSES_PATH;
- if (preg_match('/(table|interface|plugin|view)$/', strtolower($className), $matches))
- {
- switch($matches[0]){
- case "table" :
- $dirType = Cfg_App::KEY_DATA_CLASSES_PATH;
- break;
- case "interface" :
- $dirType = Cfg_App::KEY_INTERFACES_PATH;
- break;
- case "plugin":
- $dirType = Cfg_App::KEY_PLUGINS_PATH;
- break;
- // case "view":
- // $dirType = Cfg_App::KEY_VIEWS_PATH;
- }
- }
-
- return $dirType;
- }
-
- /**
- *
- * @param string $className
- * @param string $packName
- * @return string
- */
- private static function _getFilePathPartByClassName($className, $packName = "")
- {
- $className = strtolower($className);
-
- $classFileExt = Cfg_App::_(Cfg_App::KEY_CLASS_FILE_EXT);
-
- if ($packName)
- {
- $classFileExt = Cfg_App::getPackOption(Cfg_App::KEY_CLASS_FILE_EXT, $packName);
- }
-
- return (!strpos($className, '_') ?
- $className . Cfg_App::DS . $className :
- str_replace('_', Cfg_App::DS, $className)) . '.' . $classFileExt;
- }
-
- /**
- *
- * @param array $array1
- * @param array $array2
- * @return array
- */
- private static function _arrayMergeRecursiveDistinct(array $array1, array $array2)
- {
- $merged = $array1;
- foreach ($array2 as $key => $value)
- {
- if (is_array($value) && isset($merged[$key]) && is_array($merged[$key]))
- {
- $merged[$key] = self::_arrayMergeRecursiveDistinct($merged[$key], $value);
- }
- else
- {
- $merged[$key] = $value;
- }
- }
- return $merged;
- }
-
- }