Skip to content
Permalink
Browse files

Merge branch 'master' into static

  • Loading branch information...
mrclay committed Jan 19, 2017
2 parents 59d4c97 + a07991c commit 5f15af469de0810fbd4fb90f5b4ac4d181da2778
Showing with 1,124 additions and 471 deletions.
  1. +1 −0 .gitignore
  2. +2 −1 .php_cs
  3. +7 −2 .travis.yml
  4. +6 −3 composer.json
  5. +1 −1 docs/UserGuide.wiki.md
  6. +4 −2 lib/HTTP/ConditionalGet.php
  7. +5 −7 lib/HTTP/Encoder.php
  8. +17 −14 lib/Minify.php
  9. +20 −6 lib/Minify/App.php
  10. +6 −6 lib/Minify/Build.php
  11. +12 −16 lib/Minify/CSS.php
  12. +38 −29 lib/Minify/CSS/Compressor.php
  13. +41 −29 lib/Minify/CSS/UriRewriter.php
  14. +2 −1 lib/Minify/CSSmin.php
  15. +10 −11 lib/Minify/Cache/APC.php
  16. +29 −24 lib/Minify/Cache/File.php
  17. +13 −12 lib/Minify/Cache/Memcache.php
  18. +2 −1 lib/Minify/Cache/Null.php
  19. +12 −6 lib/Minify/Cache/WinCache.php
  20. +11 −10 lib/Minify/Cache/XCache.php
  21. +8 −13 lib/Minify/Cache/ZendPlatform.php
  22. +2 −1 lib/Minify/CacheInterface.php
  23. +17 −23 lib/Minify/ClosureCompiler.php
  24. +9 −13 lib/Minify/CommentPreserver.php
  25. +2 −1 lib/Minify/Controller/Base.php
  26. +4 −3 lib/Minify/Controller/Files.php
  27. +12 −8 lib/Minify/Controller/Groups.php
  28. +39 −34 lib/Minify/Controller/MinApp.php
  29. +8 −6 lib/Minify/Controller/Page.php
  30. +2 −2 lib/Minify/ControllerInterface.php
  31. +3 −1 lib/Minify/DebugDetector.php
  32. +9 −9 lib/Minify/Env.php
  33. +4 −2 lib/Minify/HTML.php
  34. +10 −8 lib/Minify/HTML/Helper.php
  35. +22 −27 lib/Minify/ImportProcessor.php
  36. +5 −2 lib/Minify/JS/ClosureCompiler.php
  37. +48 −0 lib/Minify/JS/JShrink.php
  38. +33 −15 lib/Minify/LessCssSource.php
  39. +104 −39 lib/Minify/Lines.php
  40. +0 −1 lib/Minify/Logger/LegacyHandler.php
  41. +2 −1 lib/Minify/Packer.php
  42. +176 −0 lib/Minify/ScssCssSource.php
  43. +2 −1 lib/Minify/ServeConfiguration.php
  44. +16 −15 lib/Minify/Source.php
  45. +9 −4 lib/Minify/Source/Factory.php
  46. +3 −1 lib/Minify/Source/FactoryException.php
  47. +2 −1 lib/Minify/SourceInterface.php
  48. +2 −1 lib/Minify/SourceSet.php
  49. +15 −16 lib/Minify/YUICompressor.php
  50. +2 −1 lib/MrClay/Cli.php
  51. +2 −1 lib/MrClay/Cli/Arg.php
  52. +1 −1 min_extras/tools/minifyTextarea.php
  53. +1 −1 server-info.php
  54. +0 −2 tests/LessSourceTest.php
  55. +26 −2 tests/MinifyClosureCompilerTest.php
  56. +21 −11 tests/MinifyLinesTest.php
  57. +3 −1 tests/MinifyNailgunClosureCompilerTest.php
  58. +42 −0 tests/ScssSourceTest.php
  59. +19 −0 tests/TestCase.php
  60. +8 −0 tests/_test_files/_included.scss
  61. +2 −0 tests/_test_files/css_uriRewriter/exp.css
  62. +2 −0 tests/_test_files/css_uriRewriter/exp_prepend.css
  63. +2 −0 tests/_test_files/css_uriRewriter/exp_prepend2.css
  64. +2 −0 tests/_test_files/css_uriRewriter/in.css
  65. +4 −0 tests/_test_files/htmlHelper_groupsConfig.php
  66. +7 −0 tests/_test_files/js/jscomp.polyfill.js
  67. +1 −0 tests/_test_files/js/jscomp.polyfill.min.js
  68. +3 −0 tests/_test_files/js/jscomp.polyfilled.min.js
  69. +66 −0 tests/_test_files/lines/basic.in.js
  70. +12 −12 tests/_test_files/{minify/lines_output.js → lines/basic.out.js}
  71. +14 −10 tests/_test_files/{minify/lines_bugs.js → lines/misc.in.js}
  72. +18 −0 tests/_test_files/lines/misc.out.js
  73. +13 −0 tests/_test_files/lines/url.in.js
  74. +17 −0 tests/_test_files/lines/url.out.js
  75. +29 −0 tests/_test_files/main.scss
@@ -9,3 +9,4 @@
/vendor
/.php_cs.cache
/static/[0-9]*
/tests/compiler.jar
@@ -5,7 +5,7 @@ $finder = Symfony\CS\Finder\DefaultFinder::create()
;
return Symfony\CS\Config\Config::create()
->level(Symfony\CS\FixerInterface::NONE_LEVEL)
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
->setUsingCache(true)
->fixers(array(
'linefeed',
@@ -21,6 +21,7 @@ return Symfony\CS\Config\Config::create()
'controls_spaces',
'elseif',
'-eof_ending',
'-method_argument_space',
))
->finder($finder)
;
@@ -6,7 +6,6 @@ php:
- 5.6
- 5.5
- 5.4
- 5.3
- hhvm

matrix:
@@ -25,8 +24,14 @@ cache:
install:
- composer update --no-interaction --prefer-source

before_script:
- wget -c https://dl.google.com/closure-compiler/compiler-latest.zip -O vendor/compiler-latest.zip
- unzip -od vendor/closure-compiler vendor/compiler-latest.zip
- ln -sfn ../$(echo vendor/closure-compiler/closure-compiler-*.jar) tests/compiler.jar
- java -jar tests/compiler.jar --version

script:
- composer validate
- phpunit
- phpunit --verbose

# vim:ts=2:sw=2:et
@@ -23,21 +23,24 @@
"classmap": ["tests/TestCase.php"]
},
"require": {
"php": ">=5.3.0",
"ext-pcre": "*",
"firephp/firephp-core": "~0.4.0",
"intervention/httpauth": "~2.0",
"monolog/monolog": "~1.1",
"mrclay/jsmin-php": "~2",
"mrclay/props-dic": "^2.2",
"php": "^5.3.0 || ^7.0",
"tubalmartin/cssmin": "~2.4.8"
},
"require-dev": {
"firephp/firephp-core": "~0.4.0",
"leafo/lessphp": "~0.4.0",
"leafo/scssphp": "~0.6.6",
"meenie/javascript-packer": "~1.1",
"phpunit/phpunit": "4.8.*"
"phpunit/phpunit": "4.8.*",
"tedivm/jshrink": "~1.1.0"
},
"suggest": {
"firephp/firephp-core": "Use FirePHP for Log messages",
"leafo/lessphp": "LESS support",
"meenie/javascript-packer": "Keep track of the Packer PHP port using Composer"
},
@@ -10,7 +10,7 @@ In other words, the "f" argument is set to the file path from root without the i

To combine multiple files, separate the paths given to "f" with commas.

Let's say you have CSS files at these URLs:
Let's say you have JS files at these URLs:

* http://example.com/scripts/library-1.5.js
* http://example.com/scripts/site.js
@@ -60,7 +60,8 @@
* @subpackage HTTP
* @author Stephen Clay <steve@mrclay.org>
*/
class HTTP_ConditionalGet {
class HTTP_ConditionalGet
{
/**
* Does the client have a valid copy of the requested resource?
@@ -340,7 +341,8 @@ protected function resourceMatchedEtag()
*
* @return string
*/
protected function normalizeEtag($etag) {
protected function normalizeEtag($etag)
{
$etag = trim($etag);
return $this->_stripEtag
@@ -43,7 +43,8 @@
* @subpackage HTTP
* @author Stephen Clay <steve@mrclay.org>
*/
class HTTP_Encoder {
class HTTP_Encoder
{
/**
* Should the encoder allow HTTP encoding to IE6?
@@ -97,8 +98,7 @@ public function __construct($spec)
$this->_headers['Content-Type'] = $spec['type'];
}
if (isset($spec['method'])
&& in_array($spec['method'], array('gzip', 'deflate', 'compress', '')))
{
&& in_array($spec['method'], array('gzip', 'deflate', 'compress', ''))) {
$this->_encodeMethod = array($spec['method'], $spec['method']);
} else {
$this->_encodeMethod = self::getAcceptedEncoding();
@@ -192,8 +192,7 @@ public static function getAcceptedEncoding($allowCompress = true, $allowDeflate
// @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
if (! isset($_SERVER['HTTP_ACCEPT_ENCODING'])
|| self::isBuggyIe())
{
|| self::isBuggyIe()) {
return array('', '');
}
$ae = $_SERVER['HTTP_ACCEPT_ENCODING'];
@@ -259,8 +258,7 @@ public function encode($compressionLevel = null)
}
if ('' === $this->_encodeMethod[0]
|| ($compressionLevel == 0)
|| !extension_loaded('zlib'))
{
|| !extension_loaded('zlib')) {
return false;
}
if ($this->_encodeMethod[0] === 'deflate') {
@@ -24,7 +24,8 @@
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link https://github.com/mrclay/minify
*/
class Minify {
class Minify
{
/**
* API version
@@ -87,7 +88,8 @@ class Minify {
* @param Minify_CacheInterface $cache
* @param LoggerInterface $logger
*/
public function __construct(Minify_CacheInterface $cache, LoggerInterface $logger = null) {
public function __construct(Minify_CacheInterface $cache, LoggerInterface $logger = null)
{
$this->cache = $cache;
$this->logger = $logger;
}
@@ -272,7 +274,8 @@ public function serve(Minify_ControllerInterface $controller, $options = array()
// depending on what the client accepts, $contentEncoding may be
// 'x-gzip' while our internal encodeMethod is 'gzip'. Calling
// getAcceptedEncoding(false, false) leaves out compress and deflate as options.
list($this->options['encodeMethod'], $contentEncoding) = HTTP_Encoder::getAcceptedEncoding(false, false);
$list = HTTP_Encoder::getAcceptedEncoding(false, false);
list($this->options['encodeMethod'], $contentEncoding) = $list;
$sendVary = ! HTTP_Encoder::isBuggyIe();
}
} else {
@@ -492,11 +495,13 @@ public function errorExit($header, $url = '', $msgHtml = '')
* @param string $content
* @return string
*/
public static function nullMinifier($content) {
public static function nullMinifier($content)
{
if (isset($content[0]) && $content[0] === "\xef") {
$content = substr($content, 3);
}
$content = str_replace("\r\n", "\n", $content);
return trim($content);
}
@@ -505,14 +510,14 @@ public static function nullMinifier($content) {
*/
protected function setupUriRewrites()
{
foreach($this->sources as $key => $source) {
foreach ($this->sources as $key => $source) {
$file = $this->env->normalizePath($source->getFilePath());
$minifyOptions = $source->getMinifierOptions();
if ($file
&& !isset($minifyOptions['currentDir'])
&& !isset($minifyOptions['prependRelativePath'])
) {
&& !isset($minifyOptions['prependRelativePath'])) {
$minifyOptions['currentDir'] = dirname($file);
$source->setMinifierOptions($minifyOptions);
}
@@ -592,9 +597,7 @@ protected function combineMinify()
! $source // yes, we ran out of sources
|| $type === self::TYPE_CSS // yes, to process CSS individually (avoiding PCRE bugs/limits)
|| $minifier !== $lastMinifier // yes, minifier changed
|| $options !== $lastOptions) // yes, options changed
)
{
|| $options !== $lastOptions)) { // yes, options changed
// minify previous sources with last settings
$imploded = implode($implodeSeparator, $groupToProcessTogether);
$groupToProcessTogether = array();
@@ -717,10 +720,10 @@ protected function analyzeSources($options = array())
if (!empty($options['contentType'])) {
// just verify sources have null content type or match the options
if ($sourceType !== null && $sourceType !== $options['contentType']) {
$this->logger && $this->logger->warning('ContentType mismatch');
$this->logger && $this->logger->warning("ContentType mismatch: '{$sourceType}' != '{$options['contentType']}'");
$this->sources = array();
return $options;
}
@@ -730,10 +733,10 @@ protected function analyzeSources($options = array())
if ($type === null) {
$type = $sourceType;
} elseif ($sourceType !== $type) {
$this->logger && $this->logger->warning('ContentType mismatch');
$this->logger && $this->logger->warning("ContentType mismatch: '{$sourceType}' != '{$type}'");
$this->sources = array();
return $options;
}
}
@@ -3,7 +3,6 @@
namespace Minify;
use Props\Container;
use Psr\Log\LoggerInterface;
/**
* @property \Minify_CacheInterface $cache
@@ -22,7 +21,8 @@
* @property \Minify_Source_Factory $sourceFactory
* @property array $sourceFactoryOptions
*/
class App extends Container {
class App extends Container
{
/**
* Constructor
@@ -64,9 +64,10 @@ public function __construct($dir)
$propNames = array_keys(get_object_vars($config));
$varNames = array_map(function ($name) {
$prefixer = function ($name) {
return "min_$name";
}, $propNames);
};
$varNames = array_map($prefixer, $propNames);
$vars = compact($varNames);
@@ -104,19 +105,22 @@ public function __construct($dir)
if (empty($config->documentRoot)) {
return $app->env->getDocRoot();
}
return $app->env->normalizePath($config->documentRoot);
};
$this->env = function (App $app) {
$config = $app->config;
$envArgs = empty($config->envArgs) ? array() : $config->envArgs;
return new \Minify_Env($envArgs);
};
$this->errorLogHandler = function (App $app) {
$format = "%channel%.%level_name%: %message% %context% %extra%";
$handler = new \Monolog\Handler\ErrorLogHandler();
$handler->setFormatter(new \Monolog\Formatter\LineFormatter($format));
return $handler;
};
@@ -142,18 +146,21 @@ public function __construct($dir)
if ($value === true || $value instanceof \FirePHP) {
$logger->pushHandler($app->errorLogHandler);
$logger->pushHandler(new \Monolog\Handler\FirePHPHandler());
return $logger;
}
if ($value instanceof \Monolog\Handler\HandlerInterface) {
$logger->pushHandler($value);
return $logger;
}
// BC
if (is_object($value) && is_callable(array($value, 'log'))) {
$handler = new \Minify\Logger\LegacyHandler($value);
$logger->pushHandler($handler);
return $logger;
}
@@ -232,6 +239,10 @@ public function __construct($dir)
$ret['allowDirs'] = $serveOptions['minApp']['allowDirs'];
}
if (isset($serveOptions['checkAllowDirs'])) {
$ret['checkAllowDirs'] = $serveOptions['checkAllowDirs'];
}
if (is_numeric($app->config->uploaderHoursBehind)) {
$ret['uploaderHoursBehind'] = $app->config->uploaderHoursBehind;
}
@@ -240,7 +251,8 @@ public function __construct($dir)
};
}
public function runServer() {
public function runServer()
{
if (!$this->env->get('f') && $this->env->get('g') === null) {
// no spec given
$msg = '<p>No "f" or "g" parameters were detected.</p>';
@@ -256,8 +268,10 @@ public function runServer() {
* @param mixed $var
* @return string
*/
private function typeOf($var) {
private function typeOf($var)
{
$type = gettype($var);
return $type === 'object' ? get_class($var) : $type;
}
}
@@ -34,7 +34,8 @@
* @package Minify
* @author Stephen Clay <steve@mrclay.org>
*/
class Minify_Build {
class Minify_Build
{
/**
* Last modification time of all files in the build
@@ -67,15 +68,14 @@ class Minify_Build {
* append the timestamp to the URI.
* @return string
*/
public function uri($uri, $forceAmpersand = false) {
$sep = ($forceAmpersand || strpos($uri, '?') !== false)
? self::$ampersand
: '?';
public function uri($uri, $forceAmpersand = false)
{
$sep = ($forceAmpersand || strpos($uri, '?') !== false) ? self::$ampersand : '?';
return "{$uri}{$sep}{$this->lastModified}";
}
/**
/**
* Create a build object
*
* @param array $sources array of Minify_Source objects and/or file paths

0 comments on commit 5f15af4

Please sign in to comment.
You can’t perform that action at this time.