mirror of
https://github.com/mrclay/minify.git
synced 2025-08-22 21:52:58 +02:00
Apply php-cs-fixer new rules
This commit is contained in:
@@ -1,18 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Minify_Controller_MinApp
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
/**
|
||||
* Controller class for requests to /min/index.php
|
||||
*
|
||||
* @package Minify
|
||||
* @author Stephen Clay <steve@mrclay.org>
|
||||
*/
|
||||
class Minify_Controller_MinApp extends Minify_Controller_Base
|
||||
{
|
||||
|
||||
/**
|
||||
* Set up groups of files as sources
|
||||
*
|
||||
@@ -26,15 +21,15 @@ class Minify_Controller_MinApp extends Minify_Controller_Base
|
||||
$get = $this->env->get();
|
||||
foreach (array('g', 'b', 'f') as $key) {
|
||||
if (isset($get[$key])) {
|
||||
$get[$key] = str_replace("\x00", '', (string)$get[$key]);
|
||||
$get[$key] = str_replace("\x00", '', (string) $get[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
// filter controller options
|
||||
$defaults = array(
|
||||
'groupsOnly' => false,
|
||||
'groups' => array(),
|
||||
'symlinks' => array(),
|
||||
'groups' => array(),
|
||||
'symlinks' => array(),
|
||||
);
|
||||
$minApp = isset($options['minApp']) ? $options['minApp'] : array();
|
||||
$localOptions = array_merge($defaults, $minApp);
|
||||
@@ -44,7 +39,7 @@ class Minify_Controller_MinApp extends Minify_Controller_Base
|
||||
// normalize $symlinks in order to map to target
|
||||
$symlinks = array();
|
||||
foreach ($localOptions['symlinks'] as $link => $target) {
|
||||
if (0 === strpos($link, '//')) {
|
||||
if (strpos($link, '//') === 0) {
|
||||
$link = rtrim(substr($link, 1), '/') . '/';
|
||||
$target = rtrim($target, '/\\');
|
||||
$symlinks[$link] = $target;
|
||||
@@ -60,12 +55,12 @@ class Minify_Controller_MinApp extends Minify_Controller_Base
|
||||
$selectionId .= 'g=' . $get['g'];
|
||||
$keys = explode(',', $get['g']);
|
||||
if ($keys != array_unique($keys)) {
|
||||
$this->logger->info("Duplicate group key found.");
|
||||
$this->logger->info('Duplicate group key found.');
|
||||
|
||||
return new Minify_ServeConfiguration($options);
|
||||
}
|
||||
foreach ($keys as $key) {
|
||||
if (! isset($localOptions['groups'][$key])) {
|
||||
if (!isset($localOptions['groups'][$key])) {
|
||||
$this->logger->info("A group configuration for \"{$key}\" was not found");
|
||||
|
||||
return new Minify_ServeConfiguration($options);
|
||||
@@ -74,8 +69,8 @@ class Minify_Controller_MinApp extends Minify_Controller_Base
|
||||
// if $files is a single object, casting will break it
|
||||
if (is_object($files)) {
|
||||
$files = array($files);
|
||||
} elseif (! is_array($files)) {
|
||||
$files = (array)$files;
|
||||
} elseif (!is_array($files)) {
|
||||
$files = (array) $files;
|
||||
}
|
||||
foreach ($files as $file) {
|
||||
try {
|
||||
@@ -83,20 +78,20 @@ class Minify_Controller_MinApp extends Minify_Controller_Base
|
||||
$sources[] = $source;
|
||||
} catch (Minify_Source_FactoryException $e) {
|
||||
$this->logger->error($e->getMessage());
|
||||
if (null === $firstMissing) {
|
||||
if ($firstMissing === null) {
|
||||
$firstMissing = basename($file);
|
||||
continue;
|
||||
} else {
|
||||
$secondMissing = basename($file);
|
||||
$this->logger->info("More than one file was missing: '$firstMissing', '$secondMissing'");
|
||||
|
||||
return new Minify_ServeConfiguration($options);
|
||||
continue;
|
||||
}
|
||||
$secondMissing = basename($file);
|
||||
$this->logger->info("More than one file was missing: '${firstMissing}', '${secondMissing}'");
|
||||
|
||||
return new Minify_ServeConfiguration($options);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (! $localOptions['groupsOnly'] && isset($get['f'])) {
|
||||
if (!$localOptions['groupsOnly'] && isset($get['f'])) {
|
||||
// try user files
|
||||
// The following restrictions are to limit the URLs that minify will
|
||||
// respond to.
|
||||
@@ -115,7 +110,7 @@ class Minify_Controller_MinApp extends Minify_Controller_Base
|
||||
$ext = ".{$m[1]}";
|
||||
$files = explode(',', $get['f']);
|
||||
if ($files != array_unique($files)) {
|
||||
$this->logger->info("Duplicate files were specified");
|
||||
$this->logger->info('Duplicate files were specified');
|
||||
|
||||
return new Minify_ServeConfiguration($options);
|
||||
}
|
||||
@@ -123,7 +118,7 @@ class Minify_Controller_MinApp extends Minify_Controller_Base
|
||||
if (isset($get['b'])) {
|
||||
// check for validity
|
||||
$isValidBase = preg_match('@^[^/]+(?:/[^/]+)*$@', $get['b']);
|
||||
$hasDots = false !== strpos($get['b'], '..');
|
||||
$hasDots = strpos($get['b'], '..') !== false;
|
||||
$isDot = $get['b'] === '.';
|
||||
|
||||
if ($isValidBase && !$hasDots && !$isDot) {
|
||||
@@ -145,8 +140,9 @@ class Minify_Controller_MinApp extends Minify_Controller_Base
|
||||
|
||||
// try to rewrite path
|
||||
foreach ($symlinks as $link => $target) {
|
||||
if (0 === strpos($uri, $link)) {
|
||||
if (strpos($uri, $link) === 0) {
|
||||
$path = $target . DIRECTORY_SEPARATOR . substr($uri, strlen($link));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -157,15 +153,15 @@ class Minify_Controller_MinApp extends Minify_Controller_Base
|
||||
$basenames[] = basename($path, $ext);
|
||||
} catch (Minify_Source_FactoryException $e) {
|
||||
$this->logger->error($e->getMessage());
|
||||
if (null === $firstMissing) {
|
||||
if ($firstMissing === null) {
|
||||
$firstMissing = $uri;
|
||||
continue;
|
||||
} else {
|
||||
$secondMissing = $uri;
|
||||
$this->logger->info("More than one file was missing: '$firstMissing', '$secondMissing`'");
|
||||
|
||||
return new Minify_ServeConfiguration($options);
|
||||
continue;
|
||||
}
|
||||
$secondMissing = $uri;
|
||||
$this->logger->info("More than one file was missing: '${firstMissing}', '${secondMissing}`'");
|
||||
|
||||
return new Minify_ServeConfiguration($options);
|
||||
}
|
||||
}
|
||||
if ($selectionId) {
|
||||
@@ -175,18 +171,18 @@ class Minify_Controller_MinApp extends Minify_Controller_Base
|
||||
}
|
||||
|
||||
if (!$sources) {
|
||||
$this->logger->info("No sources to serve");
|
||||
$this->logger->info('No sources to serve');
|
||||
|
||||
return new Minify_ServeConfiguration($options);
|
||||
}
|
||||
|
||||
if (null !== $firstMissing) {
|
||||
if ($firstMissing !== null) {
|
||||
array_unshift($sources, new Minify_Source(array(
|
||||
'id' => 'missingFile',
|
||||
// should not cause cache invalidation
|
||||
'lastModified' => 0,
|
||||
// due to caching, filename is unreliable.
|
||||
'content' => "/* Minify: at least one missing file. See " . Minify::URL_DEBUG . " */\n",
|
||||
'content' => '/* Minify: at least one missing file. See ' . Minify::URL_DEBUG . " */\n",
|
||||
'minifier' => 'Minify::nullMinifier',
|
||||
)));
|
||||
}
|
||||
|
Reference in New Issue
Block a user