Beispiel #1
0
 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');
 }
Beispiel #2
0
function s3_upload_asset($file, $path)
{
    $mime = \IO\Helpers::mimetype($path);
    $bucket = \Labourer\Config::get('s3_bucket');
    \Labourer\AS3::put_object_file($file, $bucket, $path, S3::ACL_PUBLIC_READ, array(), $mime);
}