1
0
mirror of https://github.com/mrclay/minify.git synced 2025-08-22 13:42:48 +02:00

Large restructuring

Moves all dependency building into App
bootstrap.php returns an App instance
The app loads config files as necessary
Moves logging to Monolog
Moves HTTP digest auth to packagist component
Rely on sys_get_temp_dir
Env hosts $_POST and allows defaults when reading
HTML helper uses the App and can handle less files
Source factory assumes strings are filenames
Fixes JsClosureCompilerTest::test6 (API now handles ES5 by default)
Exclude JsClosureCompilerTest due to API limitations
config.php can now return a Minify\Config object
Variables set in config.php are now moved to a `Minify\Config` object,
allowing better static analysis.
The `zlib.output_compression` set is moved into `Minify::serve`.
This commit is contained in:
Steve Clay
2016-02-27 01:13:28 -05:00
parent 0b466c0892
commit 4710509c68
30 changed files with 629 additions and 637 deletions

View File

@@ -4,6 +4,9 @@
* @package Minify
*/
use Psr\Log\LoggerInterface;
use Monolog\Logger;
/**
* Base class for Minify controller
*
@@ -24,14 +27,24 @@ abstract class Minify_Controller_Base implements Minify_ControllerInterface {
*/
protected $sourceFactory;
/**
* @var LoggerInterface
*/
protected $logger;
/**
* @param Minify_Env $env
* @param Minify_Source_Factory $sourceFactory
* @param LoggerInterface $logger
*/
public function __construct(Minify_Env $env, Minify_Source_Factory $sourceFactory)
public function __construct(Minify_Env $env, Minify_Source_Factory $sourceFactory, LoggerInterface $logger = null)
{
$this->env = $env;
$this->sourceFactory = $sourceFactory;
if (!$logger) {
$logger = new Logger('minify');
}
$this->logger = $logger;
}
/**
@@ -49,9 +62,11 @@ abstract class Minify_Controller_Base implements Minify_ControllerInterface {
* @param string $msg
*
* @return null
* @deprecated use $this->logger
*/
public function log($msg)
{
Minify_Logger::log($msg);
trigger_error(__METHOD__ . ' is deprecated in Minify 3.0.', E_USER_DEPRECATED);
$this->logger->info($msg);
}
}

View File

@@ -4,6 +4,9 @@
* @package Minify
*/
use Psr\Log\LoggerInterface;
use Monolog\Logger;
/**
* Controller class for minifying a set of files
*
@@ -28,16 +31,6 @@
*/
class Minify_Controller_Files extends Minify_Controller_Base {
/**
* @param Minify_Env $env Environment
* @param Minify_Source_Factory $sourceFactory Source factory. If you need to serve files from any path, this
* component must have its "checkAllowDirs" option set to false.
*/
public function __construct(Minify_Env $env, Minify_Source_Factory $sourceFactory)
{
parent::__construct($env, $sourceFactory);
}
/**
* Set up file sources
*
@@ -62,16 +55,10 @@ class Minify_Controller_Files extends Minify_Controller_Base {
$sources = array();
foreach ($files as $file) {
if ($file instanceof Minify_SourceInterface) {
$sources[] = $file;
continue;
}
try {
$sources[] = $this->sourceFactory->makeSource(array(
'filepath' => $file,
));
$sources[] = $this->sourceFactory->makeSource($file);
} catch (Minify_Source_FactoryException $e) {
$this->log($e->getMessage());
$this->logger->error($e->getMessage());
return new Minify_ServeConfiguration($options);
}

View File

@@ -51,7 +51,7 @@ class Minify_Controller_Groups extends Minify_Controller_Files {
);
if (false === $pathInfo || ! isset($groups[$pathInfo])) {
// no PATH_INFO or not a valid group
$this->log("Missing PATH_INFO or no group set for \"$pathInfo\"");
$this->logger->info("Missing PATH_INFO or no group set for \"$pathInfo\"");
return new Minify_ServeConfiguration($options);
}

View File

@@ -58,13 +58,13 @@ class Minify_Controller_MinApp extends Minify_Controller_Base {
$selectionId .= 'g=' . $get['g'];
$keys = explode(',', $get['g']);
if ($keys != array_unique($keys)) {
$this->log("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])) {
$this->log("A group configuration for \"{$key}\" was not found");
$this->logger->info("A group configuration for \"{$key}\" was not found");
return new Minify_ServeConfiguration($options);
}
@@ -76,23 +76,17 @@ class Minify_Controller_MinApp extends Minify_Controller_Base {
$files = (array)$files;
}
foreach ($files as $file) {
if ($file instanceof Minify_SourceInterface) {
$sources[] = $file;
continue;
}
try {
$source = $this->sourceFactory->makeSource(array(
'filepath' => $file,
));
$source = $this->sourceFactory->makeSource($file);
$sources[] = $source;
} catch (Minify_Source_FactoryException $e) {
$this->log($e->getMessage());
$this->logger->error($e->getMessage());
if (null === $firstMissingResource) {
$firstMissingResource = basename($file);
continue;
} else {
$secondMissingResource = basename($file);
$this->log("More than one file was missing: '$firstMissingResource', '$secondMissingResource'");
$this->logger->info("More than one file was missing: '$firstMissingResource', '$secondMissingResource'");
return new Minify_ServeConfiguration($options);
}
@@ -112,14 +106,14 @@ class Minify_Controller_MinApp extends Minify_Controller_Base {
// no "\"
|| strpos($get['f'], '\\') !== false
) {
$this->log("GET param 'f' was invalid");
$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)) {
$this->log("Duplicate files were specified");
$this->logger->info("Duplicate files were specified");
return new Minify_ServeConfiguration($options);
}
@@ -131,7 +125,7 @@ class Minify_Controller_MinApp extends Minify_Controller_Base {
// valid base
$base = "/{$get['b']}/";
} else {
$this->log("GET param 'b' was invalid");
$this->logger->info("GET param 'b' was invalid");
return new Minify_ServeConfiguration($options);
}
@@ -153,19 +147,17 @@ class Minify_Controller_MinApp extends Minify_Controller_Base {
}
try {
$source = $this->sourceFactory->makeSource(array(
'filepath' => $path,
));
$source = $this->sourceFactory->makeSource($path);
$sources[] = $source;
$basenames[] = basename($path, $ext);
} catch (Minify_Source_FactoryException $e) {
$this->log($e->getMessage());
$this->logger->error($e->getMessage());
if (null === $firstMissingResource) {
$firstMissingResource = $uri;
continue;
} else {
$secondMissingResource = $uri;
$this->log("More than one file was missing: '$firstMissingResource', '$secondMissingResource`'");
$this->logger->info("More than one file was missing: '$firstMissingResource', '$secondMissingResource`'");
return new Minify_ServeConfiguration($options);
}
@@ -178,7 +170,7 @@ class Minify_Controller_MinApp extends Minify_Controller_Base {
}
if (!$sources) {
$this->log("No sources to serve");
$this->logger->info("No sources to serve");
return new Minify_ServeConfiguration($options);
}