protected function _gc($maxlifetime) { foreach (glob("{$this->path}sess_*") as $filename) { if (\Sugi\File::modified($filename) + $maxlifetime < time()) { \Sugi\File::delete($filename); } } return true; }
public function testFileJson() { $json = '{ "key1": "value1", "key2": { "subkey1": "subvalue1" }, "key3": "value3" }'; File::put(__DIR__ . "/test2.json", $json); $this->assertNull(Config::get('test2.key99')); $this->assertEquals('foo', Config::get('test2.key99', 'foo')); $this->assertEquals('value1', Config::get('test2.key1')); $this->assertEquals('value1', Config::get('test2.key1', 'foo')); $this->assertInternalType('array', Config::get('test2.key2')); $this->assertEquals('subvalue1', Config::get('test2.key2.subkey1')); $this->assertNull(Config::get('test2.key2.subkey1.subsubkey')); File::delete(__DIR__ . "/test2.json"); }
/** * Add one file in the pack * * @param string $file * @return boolean - FALSE if the file is not found */ public function appendFile($file) { // Check the file is within default input path if ($mtime = File::modified($this->_input_path . $file)) { $file = $this->_input_path . $file; } elseif (!($mtime = File::exists($file))) { trigger_error("file {$file} does not exists"); return false; } // add a file to the pack $this->_files[] = $file; // last modified time of the pack will be the latest time $this->_lastmtime = max($mtime, $this->_lastmtime); return true; }
/** * Combines all added files in a string * * @param array $files * @param boolean $level1 * @return string */ protected function _combine($files, $level1 = true) { $buffer = ''; $less = false; foreach ($files as $file) { if (is_array($file)) { $buffer .= $this->_combine($file, false); continue; } if (substr($file, -5) === '.less') { // if one .less file is added as a single file // we will compress it immediately if ($level1) { $lessc = new \lessc(); $buffer .= $lessc->compileFile($file); continue; } $less = true; } $buffer .= File::get($file) . "\n"; } if ($less) { $lessc = new \lessc(); $buffer = $lessc->compile($buffer) . "\n"; } return $buffer; }
/** * @expectedException PHPUnit_Framework_Error */ public function testPutWithChmod() { $this->assertEquals(11, File::put(TESTFILE, 'Hello World', 0444)); $this->assertEquals('Hello World', file_get_contents(TESTFILE)); file_put_contents(TESTFILE, 'foo'); }
/** * Loads the binary .mo translation file * * @param str $file - binary .mo file to load * @return boolean */ protected static function loadMo($file) { $data = File::get($file); if ($data) { $header = substr($data, 0, 20); $header = unpack("L1magic/L1version/L1count/L1o_msg/L1o_trn", $header); extract($header); if ((dechex($magic) == '950412de' || dechex($magic) == 'ffffffff950412de') && $version == 0) { for ($n = 0; $n < $count; $n++) { $r = unpack("L1len/L1offs", substr($data, $o_msg + $n * 8, 8)); $msgid = substr($data, $r["offs"], $r["len"]); $r = unpack("L1len/L1offs", substr($data, $o_trn + $n * 8, 8)); $msgstr = substr($data, $r["offs"], $r["len"]); if (strpos($msgstr, "")) { $msgstr = explode("", $msgstr); } static::$lines[$msgid] = $msgstr; } } } }