/** * Returns a file with a given source opened in the given mode * * @param string $source * @param string $mode One of the file open modes * @return io.File */ private function fileWith($source, $mode) { $file = new File($this->tempName()); $file->open($mode); $file->write($source); return $file; }
function write($file, $content, $append = FALSE) { return \IO\File::write($file, $content, $append); }
public static function read($path) { $ext = \IO\File::ext($path); $type = \IO\Helpers::mimetype($ext); $dir = \Tailor\Config::get(static::guess($path)); $path = trim(strtr($path, '\\/', '//'), '/'); $file = substr($path, strpos($path, '/') + 1); $base = path($dir, $file); $test = \Tailor\Helpers::findfile("{$base}*", 0); if (!is_file($test)) { throw new \Exception("File '{$base}' not found"); } switch ($ext) { case 'css': case 'js': if (\IO\File::ext($test) === $ext) { $output = \IO\File::read($test); } else { $tmp = path(\Tailor\Config::get('cache_dir'), strtr($file, '\\/', '__')); if (is_file($tmp)) { if (filemtime($test) > filemtime($tmp)) { unlink($tmp); } } if (!is_file($tmp)) { $tpl = \Tailor\Base::compile($test); $now = date('Y-m-d H:i:s', filemtime($test)); $output = "/* {$now} ./assets/{$ext}/{$file} */\n{$tpl}"; \IO\File::write($tmp, $output); } else { $output = \IO\File::read($tmp); } } break; default: $output = \IO\File::read($test); break; } return compact('output', 'type'); }