public function load($debug_mode, $profile_name) { $config_file = "{$profile_name}.profile.ini"; try { // get profile directory path $profile_dir = Charcoal_ResourceLocator::getApplicationFile('config/profile'); // make config file object $config_file = new Charcoal_File($config_file, $profile_dir); // check if profile directory exists if (!$profile_dir->exists()) { if ($debug_mode) { echo "profile directory not exists: [{$profile_dir}]" . eol(); } log_error("debug,config,profile", "profile directory not exists: [{$profile_dir}]"); _throw(new Charcoal_ProfileDirectoryNotFoundException($profile_dir)); } // throw exception when config file is not found if (!$config_file->isFile() || !$config_file->canRead()) { if ($debug_mode) { echo "profile config file not exists or not readable: [{$config_file}]" . eol(); } log_error("debug,config,profile", "profile config file not exists or not readable: [{$config_file}]"); _throw(new Charcoal_ProfileConfigFileNotFoundException($config_file)); } // parse config file // log_debug( "debug,config,profile", "profile", "parsing config file: [$config_file]" ); $config_file = $config_file->getAbsolutePath(); if ($debug_mode) { echo "executing parse_ini_file: [{$config_file}]" . eol(); } $config = @parse_ini_file($config_file, FALSE); if ($config === FALSE) { if ($debug_mode) { echo "profile config file format error: [{$config_file}]" . eol(); } log_error("debug,config,profile", "profile config file format error: [{$config_file}]"); _throw(new Charcoal_ProfileConfigFileFormatException($config_file)); } if ($debug_mode) { echo "executed parse_ini_file: " . ad($config) . eol(); } // log_debug( "profile", "profile", "parse_ini_file: " . print_r($config,TRUE) ); // 設定を保存 parent::mergeArray($config); // log_debug( "debug,config,profile", "profile", "marged profile:" . print_r($config,TRUE) ); } catch (Exception $ex) { // log_debug( "system,error,debug", "catch $e" ); _catch($ex); _throw(new Charcoal_ProfileLoadingException($config_file, $profile_name, $ex)); } }
/** * get cache * * @param Charcoal_String $cache_key identify cache * @param Charcoal_File $source config file * * @return mixed configure data */ public function getCache(Charcoal_String $cache_key, Charcoal_File $source) { $cache_dir = $this->getSandbox()->getProfile()->getString('CACHE_DIR'); $cache_dir = new Charcoal_File(s($cache_dir)); $cache_file = new Charcoal_File(s($cache_key), $cache_dir); if (!$cache_file->isFile()) { return FALSE; } if ($source->isFile()) { $lm_cache = $cache_file->getLastModified(); $lm_source = $source->getLastModified(); if ($lm_cache === FALSE || $lm_source === FALSE) { return FALSE; } if ($lm_cache >= $lm_source) { return FALSE; } } return unserialize($cache_file->getContents()); }
public static function copyFile(Charcoal_File $src, Charcoal_File $dest) { // コピー元ファイルの確認 if (!$src->isFile()) { _throw(new Charcoal_FileSystemException('copy', $src->getAbsolutePath() . ' is not file')); } if (!$src->isReadable()) { _throw(new Charcoal_FileSystemException('copy', $src->getAbsolutePath() . ' is not readable')); } // コピー先の確認 $dir = $dest->getDir(); if (!$dir->isDir()) { _throw(new Charcoal_FileSystemException('copy', $dir->getAbsolutePath() . ' is not directory')); } $src = us($src->getPath()); $dest = us($dest->getPath()); $result = copy($src, $dest); if (false === $result) { _throw(new Charcoal_FileSystemException('copy', "[src]{$src} [dest]{$dest}")); } }
/** * クリーンアップ */ public function cleanUp($action, $context) { $action = us($action); switch ($action) { case "get_empty_data": case "get_integer_data": case "get_string_data": case "get_array_data": case "get_boolean_data": case "get_float_data": case "get_object_data": case "set_duration": case "delete": case "delete_wildcard": case "delete_regex": case "touch": case "touch_wildcard": case "touch_regex": $cache_files = glob($this->cache_root . '/*'); if ($cache_files && is_array($cache_files)) { foreach ($cache_files as $cache) { $file = new Charcoal_File(s($cache)); $name = $file->getName(); $ext = $file->getExtension(); if ($file->exists() && $file->isFile() && in_array($ext, array("meta", "data"))) { $file->delete(); echo "removed cache file: [{$cache}]" . eol(); } } } break; default: break; } }