public function testGet() { $this->assertNull(File::get(TESTFILE)); $this->assertEquals('default', File::get(TESTFILE, 'default')); file_put_contents(TESTFILE, 'Hello World'); $this->assertEquals('Hello World', File::get(TESTFILE)); $this->assertNull(File::get(__DIR__)); // cannot get directory }
/** * Packing all js files in one * if $_compression is true the pack will be compressed * * @param boolean $save * @param boolean $compress - if this is set to FALSE it will not compress the file even if we had added file with compress option (good for debuging) * @return string if $save is TRUE result will be the js filename otherwise js string */ public function pack($save = true, $compress = true) { // Generates a hash of all the files $hash = $this->hash(array($this->_files, $this->_lastmtime)); // Check there is a packed version $filename = $compress ? "_{$hash}.js" : "__{$hash}.js"; $output = $this->_output_path . $filename; if (File::exists($output)) { return $save ? $filename : File::get($output); } // The output file does not exists $buffer = ''; foreach ($this->_files as $file) { // if we don't want compression at all or the file is already minifed if (!$compress or strpos($file, '.min.') !== false) { $buffer .= File::get($file) . "\n"; } else { $buffer .= $this->compress(File::get($file)) . "\n"; } } // Save combined file if ($save) { file_put_contents($output, $buffer); return $filename; } return $buffer; }
protected function _read($id) { return (string) \Sugi\File::get($this->path . "sess_" . $id); }
/** * 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; }
/** * 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; } } } }