/** * 列出文件列表 */ public static function ls($paramArr) { $options = array('__dir' => './', '__pattern' => '*.*'); if (is_array($paramArr)) { $options = array_merge($options, $paramArr); } extract($options); return API_File::ls($__dir, $__pattern); }
public static function get($file, $intoAnArray = false) { self::$_file = self::exists($file); if (!self::$_file) { //throw new LJL_Exception('File does not exist or is not readable: '.$file); //trigger_error('File does not exist or is not readable: ' . $file); return false; } unset($file); if (false == $intoAnArray) { return file_get_contents(self::$_file); } else { return file(self::$_file); } }
/** * 获取 * * @param mixed $key 配置地址 * @param mixed $arrKeyName 配置子键,可多维,用.号分隔 * @param enum $type PHP|INI|EVAL * @return array|false */ public static function get($key, $arrKeyName = '', $type = 'PHP') { $fileExt = array('ini' => 'ini', 'php' => 'php', 'eval' => 'php'); $path = LJL_API_ROOT . '/Config/' . str_replace('_', '/', $key) . '.' . $fileExt[strtolower($type)]; if (isset(self::$_cache[$path])) { $config = self::$_cache[$path]; } else { if (!API_File::exists($path)) { self::$_cache[$path] = false; return false; } $type = strtoupper($type); switch ($type) { case 'INI': $config = parse_ini_file($path); break; case 'EVAL': #config中可以有变量,这样可以将变量传入到config中 if (is_array($arrKeyName)) { extract($arrKeyName); } $config = (include $path); break; default: case 'PHP': $config = (include $path); break; } self::$_cache[$path] = $config; } if ($arrKeyName && $type != 'EVAL') { if (strpos('.', $arrKeyName)) { $keyArr = explode('.', $arrKeyName); foreach ($keyArr as $key) { if (!$config) { break; } $config = empty($config[$key]) ? false : $config[$key]; } } else { $config = empty($config[$arrKeyName]) ? false : $config[$arrKeyName]; } } return $config; }
public static function write($message, $type, $hasMark = true) { if (empty($message)) { trigger_error('$message dose not empty! '); return false; } if (empty($type)) { trigger_error('$type dose not empty! '); return false; } if (!isset(self::$type[$type])) { trigger_error('Unknow log type: ' . $type); return false; } $var = defined('LJL_API_LOG') ? LJL_API_LOG : SYSTEM_VAR; //var_dump($var);die; $path = $var . '/log/' . self::$type[$type] . '/' . date('Y/m/d') . '.log'; if ($hasMark) { $mark = "\n\n===========================================================================\n"; $mark .= 'time:' . date('Y/m/d H:i:s') . "\n"; $message = $mark . $message; } return API_File::write($message, $path, FILE_APPEND | LOCK_EX); }