示例#1
0
 /**
  * Combines, minifies, and outputs the requested files.
  *
  * Inspects the $_GET array for a 'files' entry containing a comma-separated
  * list and uses this as the set of files to be combined and minified.
  */
 public static function handleRequest()
 {
     // 404 if no files were requested.
     if (!isset($_GET['files'])) {
         header('HTTP/1.0 404 Not Found');
         exit;
     }
     $files = array_map('trim', explode(',', $_GET['files'], MINIFY_MAX_FILES));
     // 404 if the $files array is empty for some weird reason.
     if (!count($files)) {
         header('HTTP/1.0 404 Not Found');
         exit;
     }
     // Determine the content type based on the extension of the first file
     // requested.
     $type = preg_match('/\\.js$/iD', $files[0]) ? self::TYPE_JS : self::TYPE_CSS;
     // Minify and spit out the result.
     try {
         $minify = new Minify($type, $files);
         header("Content-Type: {$type};charset=" . MINIFY_ENCODING);
         $minify->browserCache();
         echo $minify->combine();
         exit;
     } catch (MinifyException $e) {
         header('HTTP/1.0 404 Not Found');
         echo htmlentities($e->getMessage());
         exit;
     }
 }
示例#2
0
 /**
  * Combines, minifies, and outputs the requested files.
  *
  * Inspects the $_GET array for a 'files' entry containing a comma-separated
  * list and uses this as the set of files to be combined and minified.
  */
 function handleRequest()
 {
     // 404 if no files were requested.
     if (!isset($_GET['files'])) {
         header('HTTP/1.0 404 Not Found');
         exit;
     }
     $files = array_map('trim', explode(',', $_GET['files'], MINIFY_MAX_FILES));
     // 404 if the $files array is empty for some weird reason.
     if (!count($files)) {
         header('HTTP/1.0 404 Not Found');
         exit;
     }
     // Determine the content type based on the extension of the first file
     // requested.
     $type = preg_match('/\\.js$/iD', $files[0]) ? TYPE_JS : TYPE_CSS;
     // Minify and spit out the result.
     $minify = new Minify($type);
     $minify->addFile($files);
     ob_start("ob_gzhandler");
     header("Content-Type: {$type};charset=" . MINIFY_ENCODING);
     $minify->browserCache();
     echo $minify->combine();
 }