Example #1
0
File: sacy.php Project: fjg/sacy
 private function generate_file_cache($work_units, CacheRenderHandler $rh)
 {
     if (!is_dir(ASSET_COMPILE_OUTPUT_DIR)) {
         if (!@mkdir(ASSET_COMPILE_OUTPUT_DIR, 0755, true)) {
             throw new Exception("Failed to create output directory");
         }
     }
     $f = function ($f) {
         return pathinfo($f['file'], PATHINFO_FILENAME);
     };
     $ident = implode('-', array_map($f, $work_units));
     if (strlen($ident) > 120) {
         $ident = 'many-files-' . md5($ident);
     }
     $max = 0;
     $idents = array();
     foreach ($work_units as &$f) {
         $idents[] = array($f['group'], $f['file'], $f['type'], $f['tag']);
         $f['additional_files'] = $rh->getAdditionalFiles($f);
         $max = max($max, filemtime($f['file']));
         foreach ($f['additional_files'] as $af) {
             $max = max($max, filemtime($af));
         }
         unset($f);
     }
     // not using the actual content for quicker access
     $key = md5($max . serialize($idents) . $rh->getConfig()->getDebugMode());
     $key = $this->content_key_for_mtime_key($key, $work_units);
     $cfile = ASSET_COMPILE_OUTPUT_DIR . DIRECTORY_SEPARATOR . "{$ident}-{$key}" . $rh->getFileExtension();
     $pub = ASSET_COMPILE_URL_ROOT . "/{$ident}-{$key}" . $rh->getFileExtension();
     if (file_exists($cfile) && $rh->getConfig()->getDebugMode() != 2) {
         return $pub;
     }
     $this->write_cache($cfile, $work_units, $rh);
     return $pub;
 }
Example #2
0
 private function generate_file_cache($work_units, CacheRenderHandler $rh)
 {
     if (!is_dir(ASSET_COMPILE_OUTPUT_DIR)) {
         if (!@mkdir(ASSET_COMPILE_OUTPUT_DIR, 0755, true)) {
             throw new Exception("Failed to create output directory");
         }
     }
     $f = function ($f) {
         return pathinfo($f['file'], PATHINFO_FILENAME);
     };
     $ident = implode('-', array_map($f, $work_units));
     if (strlen($ident) > 120) {
         $ident = 'many-files-' . md5($ident);
     }
     $max = 0;
     $idents = array();
     foreach ($work_units as &$f) {
         $idents[] = array($f['group'], $f['file'], $f['type'], $f['tag']);
         $f['additional_files'] = $rh->getAdditionalFiles($f);
         $max = max($max, filemtime($f['file']));
         foreach ($f['additional_files'] as $af) {
             $max = max($max, filemtime($af));
         }
         unset($f);
     }
     // not using the actual content for quicker access
     $key = md5($max . serialize($idents) . $rh->getConfig()->getDebugMode());
     $key = $this->content_key_for_mtime_key($key, $work_units);
     $cfile = ASSET_COMPILE_OUTPUT_DIR . DIRECTORY_SEPARATOR . "{$ident}-{$key}" . $rh->getFileExtension();
     $pub = ASSET_COMPILE_URL_ROOT . "/{$ident}-{$key}" . $rh->getFileExtension();
     if (file_exists($cfile) && $rh->getConfig()->getDebugMode() != 2) {
         return $pub;
     }
     if (!$this->write_cache($cfile, $work_units, $rh)) {
         /* If something went wrong in here we delete the cache file
         
                        This ensures that on reload, sacy would see that no cached file exists and
                        will retry the process.
         
                        This is helpful for example if you define() one of the external utilities
                        and screw something up in the process.
                     */
         if (file_exists($cfile)) {
             @unlink($cfile);
         }
         return false;
     }
     return $pub;
 }