mirror of
https://github.com/mrclay/minify.git
synced 2025-01-29 11:18:30 +01:00
Created "min" = new default implementation as specified in Issue 45.
Minify: fixed default value in useServerCache(), + doc for 'contentType' serve() option Minify_Controller_Base: added todo item Minify_Controller_Version1: fixed default cache to '' (instead of null)
This commit is contained in:
parent
1e04e2c68e
commit
961e04ca30
@ -55,7 +55,7 @@ class Minify {
|
||||
* @return null
|
||||
* @deprecated
|
||||
*/
|
||||
public static function useServerCache($path = null)
|
||||
public static function useServerCache($path = '')
|
||||
{
|
||||
self::setCache($path);
|
||||
}
|
||||
@ -133,6 +133,11 @@ class Minify {
|
||||
* $options['minifierOptions'][Minify::TYPE_CSS]['optionName'] = 'optionValue';
|
||||
* </code>
|
||||
*
|
||||
* 'contentType' : (optional) this is only needed if your file extension is not
|
||||
* js/css/html. The given content-type will be sent regardless of source file
|
||||
* extension, so this should not be used in a Groups config with other
|
||||
* Javascript/CSS files.
|
||||
*
|
||||
* Any controller options are documented in that controller's setupSources() method.
|
||||
*
|
||||
* @param mixed instance of subclass of Minify_Controller_Base or string name of
|
||||
@ -143,6 +148,8 @@ class Minify {
|
||||
* @return mixed null, or, if the 'quiet' option is set to true, an array
|
||||
* with keys "success" (bool), "statusCode" (int), "content" (string), and
|
||||
* "headers" (array).
|
||||
*
|
||||
* @todo add option to auto-fix relative URIs in CSS (default = true)
|
||||
*/
|
||||
public static function serve($controller, $options = array()) {
|
||||
if (is_string($controller)) {
|
||||
|
@ -13,6 +13,9 @@
|
||||
*
|
||||
* @package Minify
|
||||
* @author Stephen Clay <steve@mrclay.org>
|
||||
*
|
||||
* @todo add static function to ease setting currentPath for CSS files
|
||||
* (see line 83 of Version1.php)
|
||||
*/
|
||||
abstract class Minify_Controller_Base {
|
||||
|
||||
|
@ -30,7 +30,7 @@ class Minify_Controller_Version1 extends Minify_Controller_Base {
|
||||
if (MINIFY_USE_CACHE) {
|
||||
$cacheDir = defined('MINIFY_CACHE_DIR')
|
||||
? MINIFY_CACHE_DIR
|
||||
: null;
|
||||
: '';
|
||||
Minify::setCache($cacheDir);
|
||||
}
|
||||
$options['badRequestHeader'] = 'HTTP/1.0 404 Not Found';
|
||||
|
48
min/config.php
Normal file
48
min/config.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* Configuration for default Minify implementation
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* For best performance, specify your temp directory here.
|
||||
* Otherwise Minify will have to load extra code to guess.
|
||||
*/
|
||||
$minifyCachePath = 'c:\\xampp\\tmp';
|
||||
//$minifyCachePath = 'c:\\WINDOWS\Temp';
|
||||
//$minifyCachePath = '/tmp';
|
||||
|
||||
|
||||
/**
|
||||
* Manually set the path to Minify's lib folder
|
||||
*/
|
||||
$minifyLibPath = '../lib';
|
||||
|
||||
|
||||
/**
|
||||
* Set to true to disable the "f" GET parameter for specifying files.
|
||||
* Only the "g" parameter will be considered.
|
||||
*/
|
||||
$minifyGroupsOnly = false;
|
||||
|
||||
|
||||
/**
|
||||
* Allows specification of base directory via the "b" GET parameter.
|
||||
* E.g. these are the same:
|
||||
* ?f=jsFiles/file1.js,jsFiles/file2.js
|
||||
* ?b=jsFiles&f=file1.js,file2.js
|
||||
*/
|
||||
$minifyAllowBase = false;
|
||||
|
||||
|
||||
/**
|
||||
* If you'd like to restrict the "f" option to files within/below
|
||||
* a particular directory below DOCUMENT_ROOT, set this here.
|
||||
* You will still need to include this directory in the
|
||||
* f or b GET parameters.
|
||||
*
|
||||
* // = DOCUMENT_ROOT
|
||||
*/
|
||||
$minifyRestrictDir = '//js/transition';
|
||||
|
11
min/groupsConfig.php
Normal file
11
min/groupsConfig.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* Groups configuration for default Minify implementation
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
return array(
|
||||
// 'js' => array('//js/file1.js', '//js/file2.js'),
|
||||
// 'css' => array('//css/file1.css', '//css/file2.css'),
|
||||
'js' => array('//js/Class.js', '//js/email.js')
|
||||
);
|
68
min/index.php
Normal file
68
min/index.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* Front controller for default Minify implementation
|
||||
*
|
||||
* DO NOT EDIT! Configure this utility via config.php and groupsConfig.php
|
||||
*
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
define('MINIFY_MIN_DIR', dirname(__FILE__));
|
||||
|
||||
// load config
|
||||
require MINIFY_MIN_DIR . '/config.php';
|
||||
|
||||
// setup include path
|
||||
if (!isset($minifyLibPath)) {
|
||||
// default lib path is inside this directory
|
||||
$minifyLibPath = MINIFY_MIN_DIR . '/lib';
|
||||
}
|
||||
set_include_path($minifyLibPath . PATH_SEPARATOR . get_include_path());
|
||||
|
||||
// friendly error if lib wasn't in the include_path
|
||||
if (! (include 'Minify.php')) {
|
||||
trigger_error(
|
||||
'Minify: You must add Minify/lib to the include_path or set $minifyLibPath in config.php'
|
||||
,E_USER_ERROR
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($_GET['g'])) {
|
||||
|
||||
Minify::setCache(isset($minifyCachePath) ? $minifyCachePath : null);
|
||||
// Groups expects the group key as PATH_INFO
|
||||
// we want to allow ?g=groupKey
|
||||
$_SERVER['PATH_INFO'] = '/' . $_GET['g'];
|
||||
Minify::serve('Groups', array(
|
||||
'groups' => (require MINIFY_MIN_DIR . '/groupsConfig.php')
|
||||
));
|
||||
|
||||
} elseif (!$minifyGroupsOnly && isset($_GET['f'])) {
|
||||
|
||||
/**
|
||||
* crude initial implementation hacked onto on Version1 controller
|
||||
* @todo encapsulate this in a new controller
|
||||
*/
|
||||
|
||||
if (isset($minifyCachePath)) {
|
||||
define('MINIFY_CACHE_DIR', $minifyCachePath);
|
||||
}
|
||||
if (isset($minifyRestrictDir)) {
|
||||
define('MINIFY_BASE_DIR', realpath(
|
||||
$_SERVER['DOCUMENT_ROOT'] . substr($minifyRestrictDir, 1)
|
||||
));
|
||||
}
|
||||
// Version1 already does validation. All we want is to prepend "b"
|
||||
// to each file if it looks right.
|
||||
$base = ($minifyAllowBase
|
||||
&& isset($_GET['b'])
|
||||
&& preg_match('@^[^/.]+(?:/[^/.]+)*$@', $_GET['b']))
|
||||
? '/' . $_GET['b'] . '/'
|
||||
: '/';
|
||||
// Version1 expects ?files=/js/file1.js,/js/file2.js,/js/file3.js
|
||||
// we want to allow ?f=js/file1.js,js/file2.js,js/file3.js
|
||||
// or ?b=js&f=file1.js,file2.js,file3.js
|
||||
$_GET['files'] = $base . str_replace(',', ',' . $base, $_GET['f']);
|
||||
|
||||
Minify::serve('Version1');
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user