Example #1
0
 /**
  * Combines and returns the contents of all files that have been added with
  * addFile() or via this class's constructor.
  *
  * If MINIFY_USE_CACHE is true, the content will be returned from the server's
  * cache if the cache is up to date; otherwise the new content will be saved
  * to the cache for future use.
  *
  * @param bool $minify minify the combined contents before returning them
  * @return string combined file contents
  */
 function combine($minify = true)
 {
     // Return contents from server cache if possible.
     if (MINIFY_USE_CACHE) {
         if ($cacheResult = $this->serverCache(true)) {
             return $cacheResult;
         }
     }
     // Combine contents.
     $combined = array();
     foreach ($this->files as $file) {
         if ($this->type === TYPE_CSS && MINIFY_REWRITE_CSS_URLS) {
             // Rewrite relative CSS URLs.
             $combined[] = Minify::rewriteCSSUrls(file_get_contents($file), dirname($file));
         } else {
             $combined[] = file_get_contents($file);
         }
     }
     $combined = $minify ? Minify::_minify(implode("\n", $combined), $this->type) : implode("\n", $combined);
     // Save combined contents to the cache.
     if (MINIFY_USE_CACHE) {
         $cacheFile = MINIFY_CACHE_DIR . '/minify_' . $this->getHash();
         file_put_contents($cacheFile, $combined, LOCK_EX);
     }
     return $combined;
 }