mirror of
https://github.com/mrclay/minify.git
synced 2025-08-08 07:06:49 +02:00
+ FirePHP error logging in Files, Groups, and MinApp controllers
This commit is contained in:
@@ -17,7 +17,7 @@ $min_libPath = dirname(__FILE__) . '/lib';
|
||||
* Minify will have to load extra code to guess. Commented out below
|
||||
* are a few possible choices.
|
||||
*/
|
||||
//$min_cachePath = 'c:\\WINDOWS\Temp';
|
||||
//$min_cachePath = 'c:\\WINDOWS\\Temp';
|
||||
//$min_cachePath = '/tmp';
|
||||
//$min_cachePath = preg_replace('/^\\d+;/', '', session_save_path());
|
||||
|
||||
@@ -36,10 +36,12 @@ $min_enableBuilder = true;
|
||||
|
||||
|
||||
/**
|
||||
* In 'debug' mode, Minify can combine files with no minification and
|
||||
* add comments to indicate line #s of the original files.
|
||||
* Enable logging of errors to FirePHP and setting of the 'debug' flag.
|
||||
*
|
||||
* When enabled and "&debug=1" is added to the URI, Minify will combine files with no
|
||||
* minification and add comments to indicate line #s of the original files.
|
||||
*
|
||||
* To allow debugging, set this option to true and add "&debug=1" to
|
||||
* To allow debugging, set this option to true and add "&debug=1" to
|
||||
* a URI. E.g. /min/?f=script1.js,script2.js&debug=1
|
||||
*/
|
||||
$min_allowDebugFlag = false;
|
||||
|
@@ -26,8 +26,12 @@ Minify::setCache(
|
||||
if (0 === stripos(PHP_OS, 'win')) {
|
||||
Minify::setDocRoot(); // we may be on IIS
|
||||
}
|
||||
if ($min_allowDebugFlag && isset($_GET['debug'])) {
|
||||
$min_serveOptions['debug'] = true;
|
||||
if ($min_allowDebugFlag) {
|
||||
require_once 'FirePHP.php';
|
||||
Minify::setLogger(FirePHP::getInstance(true));
|
||||
if (isset($_GET['debug'])) {
|
||||
$min_serveOptions['debug'] = true;
|
||||
}
|
||||
}
|
||||
// check for URI versioning
|
||||
if (preg_match('/&\\d/', $_SERVER['QUERY_STRING'])) {
|
||||
|
1370
min/lib/FirePHP.php
Normal file
1370
min/lib/FirePHP.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -358,9 +358,34 @@ class Minify {
|
||||
if ($unsetPathInfo) {
|
||||
unset($_SERVER['PATH_INFO']);
|
||||
}
|
||||
Minify::logError("setDocRoot() set DOCUMENT_ROOT to \"{$_SERVER['DOCUMENT_ROOT']}\"");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set error logger object.
|
||||
*
|
||||
* The object should have a method "log" that accepts a value as 1st argument and
|
||||
* an optional string label as the 2nd.
|
||||
*
|
||||
* @param mixed $obj or a "falsey" value to disable
|
||||
*/
|
||||
public static function setLogger($obj = null) {
|
||||
self::$_logger = $obj
|
||||
? $obj
|
||||
: null;
|
||||
}
|
||||
|
||||
public static function logError($msg) {
|
||||
if (! self::$_logger) return;
|
||||
self::$_logger->log($msg, 'Minify');
|
||||
}
|
||||
|
||||
/**
|
||||
* @var mixed logger object (like FirePHP) or null (i.e. no logging enabled)
|
||||
*/
|
||||
private static $_logger = null;
|
||||
|
||||
/**
|
||||
* @var mixed Minify_Cache_* object or null (i.e. no server cache is used)
|
||||
*/
|
||||
|
@@ -52,13 +52,13 @@ class Minify_Controller_Files extends Minify_Controller_Base {
|
||||
if (0 === strpos($file, '//')) {
|
||||
$file = $_SERVER['DOCUMENT_ROOT'] . substr($file, 1);
|
||||
}
|
||||
$file = realpath($file);
|
||||
if (file_exists($file)) {
|
||||
$realPath = realpath($file);
|
||||
if (is_file($realPath)) {
|
||||
$sources[] = new Minify_Source(array(
|
||||
'filepath' => $file
|
||||
'filepath' => $realPath
|
||||
));
|
||||
} else {
|
||||
// file not found
|
||||
Minify::logError("The path \"{$file}\" could not be found (or was not a file)");
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
|
@@ -55,6 +55,7 @@ class Minify_Controller_Groups extends Minify_Controller_Base {
|
||||
);
|
||||
if (false === $pi || ! isset($groups[$pi])) {
|
||||
// no PATH_INFO or not a valid group
|
||||
Minify::logError("Missing PATH_INFO or no group set for \"$pi\"");
|
||||
return $options;
|
||||
}
|
||||
$sources = array();
|
||||
@@ -66,13 +67,13 @@ class Minify_Controller_Groups extends Minify_Controller_Base {
|
||||
if (0 === strpos($file, '//')) {
|
||||
$file = $_SERVER['DOCUMENT_ROOT'] . substr($file, 1);
|
||||
}
|
||||
$file = realpath($file);
|
||||
if (file_exists($file)) {
|
||||
$realPath = realpath($file);
|
||||
if (is_file($realPath)) {
|
||||
$sources[] = new Minify_Source(array(
|
||||
'filepath' => $file
|
||||
'filepath' => $realPath
|
||||
));
|
||||
} else {
|
||||
// file doesn't exist
|
||||
Minify::logError("The path \"{$file}\" could not be found (or was not a file)");
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
|
@@ -37,6 +37,7 @@ class Minify_Controller_MinApp extends Minify_Controller_Base {
|
||||
if (isset($_GET['g'])) {
|
||||
// try groups
|
||||
if (! isset($cOptions['groups'][$_GET['g']])) {
|
||||
Minify::logError("A group configuration for \"{$_GET['g']}\" was not set");
|
||||
return $options;
|
||||
}
|
||||
foreach ((array)$cOptions['groups'][$_GET['g']] as $file) {
|
||||
@@ -53,7 +54,7 @@ class Minify_Controller_MinApp extends Minify_Controller_Base {
|
||||
'filepath' => $file
|
||||
));
|
||||
} else {
|
||||
// file doesn't exist
|
||||
Minify::logError("The path \"{$file}\" could not be found (or was not a file)");
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
@@ -71,11 +72,12 @@ class Minify_Controller_MinApp extends Minify_Controller_Base {
|
||||
// no "./"
|
||||
|| preg_match('/(?:^|[^\\.])\\.\\//', $_GET['f'])
|
||||
) {
|
||||
Minify::logError("GET param 'f' invalid (see MinApp.php line 63)");
|
||||
return $options;
|
||||
}
|
||||
$files = explode(',', $_GET['f']);
|
||||
if (count($files) > $cOptions['maxFiles'] || $files != array_unique($files)) {
|
||||
// too many or duplicate files
|
||||
Minify::logError("Too many or duplicate files specified");
|
||||
return $options;
|
||||
}
|
||||
if (isset($_GET['b'])) {
|
||||
@@ -86,6 +88,7 @@ class Minify_Controller_MinApp extends Minify_Controller_Base {
|
||||
// valid base
|
||||
$base = "/{$_GET['b']}/";
|
||||
} else {
|
||||
Minify::logError("GET param 'b' invalid (see MinApp.php line 84)");
|
||||
return $options;
|
||||
}
|
||||
} else {
|
||||
@@ -96,20 +99,25 @@ class Minify_Controller_MinApp extends Minify_Controller_Base {
|
||||
$allowDirs[] = realpath(str_replace('//', $_SERVER['DOCUMENT_ROOT'] . '/', $allowDir));
|
||||
}
|
||||
foreach ($files as $file) {
|
||||
$file = realpath($_SERVER['DOCUMENT_ROOT'] . $base . $file);
|
||||
// don't allow unsafe or duplicate files
|
||||
if (parent::_fileIsSafe($file, $allowDirs)) {
|
||||
$path = $_SERVER['DOCUMENT_ROOT'] . $base . $file;
|
||||
$file = realpath($path);
|
||||
if (false === $file) {
|
||||
Minify::logError("Path \"{$path}\" failed realpath()");
|
||||
return $options;
|
||||
} elseif (! parent::_fileIsSafe($file, $allowDirs)) {
|
||||
Minify::logError("Path \"{$path}\" failed Minify_Controller_Base::_fileIsSafe()");
|
||||
return $options;
|
||||
} else {
|
||||
$sources[] = new Minify_Source(array(
|
||||
'filepath' => $file
|
||||
));
|
||||
} else {
|
||||
// unsafe file
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($sources) {
|
||||
$this->sources = $sources;
|
||||
} else {
|
||||
Minify::logError("No sources to serve");
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
Reference in New Issue
Block a user