public static function setRoot($path) { self::$ROOT_PATH = $path; if (!file_exists($path)) { mkdir($path); } }
function testAll() { $file = new SimpleFile('filename.txt', 'contents', 'text/plain'); $this->assertEquals('filename.txt', $file->getName()); $this->assertEquals('contents', $file->get()); $this->assertEquals(8, $file->getSize()); $this->assertEquals('"' . sha1('contents') . '"', $file->getETag()); $this->assertEquals('text/plain', $file->getContentType()); }
function __construct($filename) { $this->jsonData = json(SimpleFile::read("./site/" . $filename)); }
function F($name, $value = '', $path = false) { static $_cache = array(); require_cache(ADDON_PATH . "/libs/Multi/SimpleFile.php"); if (!$path) { $path = SITE_PATH . '/_runtime/_cache/'; } $name = C('DATA_CACHE_PREFIX') . $name; SimpleFile::setRoot($path); $file = new SimpleFile($name); if ('' !== $value) { if (is_null($value)) { // 删除缓存 return $file->rm(); } else { $value = serialize($value); return $file->save($value); } } if (isset($_cache[$name])) { return $_cache[$name]; } // 获取缓存数据 $value = unserialize($file->read()); if ($value) { $_cache[$name] = $value; } return $value; }