1
0
mirror of https://github.com/mrclay/minify.git synced 2025-08-10 16:14:18 +02:00

Big style cleanup

This commit is contained in:
Steve Clay
2016-10-16 15:13:38 -04:00
parent 5fb7ea1ed1
commit 16c811cd93
23 changed files with 257 additions and 266 deletions

View File

@@ -45,12 +45,14 @@ class Minify_Controller_Groups extends Minify_Controller_Files
$server = $this->env->server();
// mod_fcgid places PATH_INFO in ORIG_PATH_INFO
$pathInfo = isset($server['ORIG_PATH_INFO'])
? substr($server['ORIG_PATH_INFO'], 1)
: (isset($server['PATH_INFO'])
? substr($server['PATH_INFO'], 1)
: false
);
if (isset($server['ORIG_PATH_INFO'])) {
$pathInfo = substr($server['ORIG_PATH_INFO'], 1);
} elseif (isset($server['PATH_INFO'])) {
$pathInfo = substr($server['PATH_INFO'], 1)
} else {
$pathInfo = false;
}
if (false === $pathInfo || ! isset($groups[$pathInfo])) {
// no PATH_INFO or not a valid group
$this->logger->info("Missing PATH_INFO or no group set for \"$pathInfo\"");

View File

@@ -31,14 +31,14 @@ class Minify_Controller_MinApp extends Minify_Controller_Base
}
// filter controller options
$localOptions = array_merge(
array(
'groupsOnly' => false,
'groups' => array(),
'symlinks' => array(),
)
,(isset($options['minApp']) ? $options['minApp'] : array())
$defaults = array(
'groupsOnly' => false,
'groups' => array(),
'symlinks' => array(),
);
$minApp = isset($options['minApp']) ? $options['minApp'] : array();
$localOptions = array_merge($defaults, $minApp);
unset($options['minApp']);
// normalize $symlinks in order to map to target
@@ -53,7 +53,7 @@ class Minify_Controller_MinApp extends Minify_Controller_Base
$sources = array();
$selectionId = '';
$firstMissingResource = null;
$firstMissing = null;
if (isset($get['g'])) {
// add group(s)
@@ -83,12 +83,12 @@ class Minify_Controller_MinApp extends Minify_Controller_Base
$sources[] = $source;
} catch (Minify_Source_FactoryException $e) {
$this->logger->error($e->getMessage());
if (null === $firstMissingResource) {
$firstMissingResource = basename($file);
if (null === $firstMissing) {
$firstMissing = basename($file);
continue;
} else {
$secondMissingResource = basename($file);
$this->logger->info("More than one file was missing: '$firstMissingResource', '$secondMissingResource'");
$secondMissing = basename($file);
$this->logger->info("More than one file was missing: '$firstMissing', '$secondMissing'");
return new Minify_ServeConfiguration($options);
}
@@ -100,18 +100,18 @@ class Minify_Controller_MinApp extends Minify_Controller_Base
// try user files
// The following restrictions are to limit the URLs that minify will
// respond to.
if (// verify at least one file, files are single comma separated,
// and are all same extension
! preg_match('/^[^,]+\\.(css|less|js)(?:,[^,]+\\.\\1)*$/', $get['f'], $m)
// no "//"
|| strpos($get['f'], '//') !== false
// no "\"
|| strpos($get['f'], '\\') !== false
) {
// verify at least one file, files are single comma separated, and are all same extension
$validPattern = preg_match('/^[^,]+\\.(css|less|js)(?:,[^,]+\\.\\1)*$/', $get['f'], $m);
$hasComment = strpos($get['f'], '//') !== false;
$hasEscape = strpos($get['f'], '\\') !== false;
if (!$validPattern || $hasComment || $hasEscape) {
$this->logger->info("GET param 'f' was invalid");
return new Minify_ServeConfiguration($options);
}
$ext = ".{$m[1]}";
$files = explode(',', $get['f']);
if ($files != array_unique($files)) {
@@ -119,11 +119,14 @@ class Minify_Controller_MinApp extends Minify_Controller_Base
return new Minify_ServeConfiguration($options);
}
if (isset($get['b'])) {
// check for validity
if (preg_match('@^[^/]+(?:/[^/]+)*$@', $get['b'])
&& false === strpos($get['b'], '..')
&& $get['b'] !== '.') {
$isValidBase = preg_match('@^[^/]+(?:/[^/]+)*$@', $get['b']);
$hasDots = false !== strpos($get['b'], '..');
$isDot = $get['b'] === '.';
if ($isValidBase && !$hasDots && !$isDot) {
// valid base
$base = "/{$get['b']}/";
} else {
@@ -154,12 +157,12 @@ class Minify_Controller_MinApp extends Minify_Controller_Base
$basenames[] = basename($path, $ext);
} catch (Minify_Source_FactoryException $e) {
$this->logger->error($e->getMessage());
if (null === $firstMissingResource) {
$firstMissingResource = $uri;
if (null === $firstMissing) {
$firstMissing = $uri;
continue;
} else {
$secondMissingResource = $uri;
$this->logger->info("More than one file was missing: '$firstMissingResource', '$secondMissingResource`'");
$secondMissing = $uri;
$this->logger->info("More than one file was missing: '$firstMissing', '$secondMissing`'");
return new Minify_ServeConfiguration($options);
}
@@ -177,14 +180,14 @@ class Minify_Controller_MinApp extends Minify_Controller_Base
return new Minify_ServeConfiguration($options);
}
if (null !== $firstMissingResource) {
if (null !== $firstMissing) {
array_unshift($sources, new Minify_Source(array(
'id' => 'missingFile'
'id' => 'missingFile',
// should not cause cache invalidation
,'lastModified' => 0
'lastModified' => 0,
// due to caching, filename is unreliable.
,'content' => "/* Minify: at least one missing file. See " . Minify::URL_DEBUG . " */\n"
,'minifier' => 'Minify::nullMinifier'
'content' => "/* Minify: at least one missing file. See " . Minify::URL_DEBUG . " */\n",
'minifier' => 'Minify::nullMinifier',
)));
}

View File

@@ -42,8 +42,8 @@ class Minify_Controller_Page extends Minify_Controller_Base
} else {
// strip controller options
$sourceSpec = array(
'content' => $options['content']
,'id' => $options['id']
'content' => $options['content'],
'id' => $options['id'],
);
$f = $options['id'];
unset($options['content'], $options['id']);
@@ -54,8 +54,8 @@ class Minify_Controller_Page extends Minify_Controller_Base
if (isset($options['minifyAll'])) {
// this will be the 2nd argument passed to Minify_HTML::minify()
$sourceSpec['minifyOptions'] = array(
'cssMinifier' => array('Minify_CSSmin', 'minify')
,'jsMinifier' => array('JSMin\\JSMin', 'minify')
'cssMinifier' => array('Minify_CSSmin', 'minify'),
'jsMinifier' => array('JSMin\\JSMin', 'minify'),
);
unset($options['minifyAll']);
}