mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-02-01 09:39:58 +09:00
Update composer dependencies
This commit is contained in:
parent
866a33fd39
commit
ab195fbf3b
463 changed files with 14839 additions and 11927 deletions
114
vendor/matthiasmullie/minify/src/CSS.php
vendored
114
vendor/matthiasmullie/minify/src/CSS.php
vendored
|
|
@ -1,4 +1,13 @@
|
|||
<?php
|
||||
/**
|
||||
* CSS Minifier
|
||||
*
|
||||
* Please report bugs on https://github.com/matthiasmullie/minify/issues
|
||||
*
|
||||
* @author Matthias Mullie <minify@mullie.eu>
|
||||
* @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved
|
||||
* @license MIT License
|
||||
*/
|
||||
|
||||
namespace MatthiasMullie\Minify;
|
||||
|
||||
|
|
@ -7,10 +16,11 @@ use MatthiasMullie\PathConverter\ConverterInterface;
|
|||
use MatthiasMullie\PathConverter\Converter;
|
||||
|
||||
/**
|
||||
* CSS minifier.
|
||||
* CSS minifier
|
||||
*
|
||||
* Please report bugs on https://github.com/matthiasmullie/minify/issues
|
||||
*
|
||||
* @package Minify
|
||||
* @author Matthias Mullie <minify@mullie.eu>
|
||||
* @author Tijs Verkoyen <minify@verkoyen.eu>
|
||||
* @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved
|
||||
|
|
@ -19,12 +29,12 @@ use MatthiasMullie\PathConverter\Converter;
|
|||
class CSS extends Minify
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
* @var int maximum inport size in kB
|
||||
*/
|
||||
protected $maxImportSize = 5;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
* @var string[] valid import extensions
|
||||
*/
|
||||
protected $importExtensions = array(
|
||||
'gif' => 'data:image/gif',
|
||||
|
|
@ -76,14 +86,14 @@ class CSS extends Minify
|
|||
*/
|
||||
protected function moveImportsToTop($content)
|
||||
{
|
||||
if (preg_match_all('/@import[^;]+;/', $content, $matches)) {
|
||||
if (preg_match_all('/(;?)(@import (?<url>url\()?(?P<quotes>["\']?).+?(?P=quotes)(?(url)\)));?/', $content, $matches)) {
|
||||
// remove from content
|
||||
foreach ($matches[0] as $import) {
|
||||
$content = str_replace($import, '', $content);
|
||||
}
|
||||
|
||||
// add to top
|
||||
$content = implode('', $matches[0]).$content;
|
||||
$content = implode(';', $matches[2]).';'.trim($content, ';');
|
||||
}
|
||||
|
||||
return $content;
|
||||
|
|
@ -437,12 +447,14 @@ class CSS extends Minify
|
|||
* Urls with `)` (as could happen with data: uris) should also be
|
||||
* quoted to avoid being confused for the url() closing parentheses.
|
||||
* And urls with a # have also been reported to cause issues.
|
||||
* Urls with quotes inside should also remain escaped.
|
||||
*
|
||||
* @see https://developer.mozilla.org/nl/docs/Web/CSS/url#The_url()_functional_notation
|
||||
* @see https://hg.mozilla.org/mozilla-central/rev/14abca4e7378
|
||||
* @see https://github.com/matthiasmullie/minify/issues/193
|
||||
*/
|
||||
$url = trim($url);
|
||||
if (preg_match('/[\s\)#\x{7f}-\x{9f}]/u', $url)) {
|
||||
if (preg_match('/[\s\)\'"#\x{7f}-\x{9f}]/u', $url)) {
|
||||
$url = $match['quotes'] . $url . $match['quotes'];
|
||||
}
|
||||
|
||||
|
|
@ -541,6 +553,16 @@ class CSS extends Minify
|
|||
*/
|
||||
protected function shortenZeroes($content)
|
||||
{
|
||||
// we don't want to strip units in `calc()` expressions:
|
||||
// `5px - 0px` is valid, but `5px - 0` is not
|
||||
// `10px * 0` is valid (equates to 0), and so is `10 * 0px`, but
|
||||
// `10 * 0` is invalid
|
||||
// best to just leave `calc()`s alone, even if they could be optimized
|
||||
// (which is a whole other undertaking, where units & order of
|
||||
// operations all need to be considered...)
|
||||
$calcs = $this->findCalcs($content);
|
||||
$content = str_replace($calcs, array_keys($calcs), $content);
|
||||
|
||||
// reusable bits of code throughout these regexes:
|
||||
// before & after are used to make sure we don't match lose unintended
|
||||
// 0-like values (e.g. in #000, or in http://url/1.0)
|
||||
|
|
@ -569,35 +591,21 @@ class CSS extends Minify
|
|||
// strip negative zeroes (-0 -> 0) & truncate zeroes (00 -> 0)
|
||||
$content = preg_replace('/'.$before.'-?0+'.$units.'?'.$after.'/', '0\\1', $content);
|
||||
|
||||
// remove zeroes where they make no sense in calc: e.g. calc(100px - 0)
|
||||
// the 0 doesn't have any effect, and this isn't even valid without unit
|
||||
// strip all `+ 0` or `- 0` occurrences: calc(10% + 0) -> calc(10%)
|
||||
// looped because there may be multiple 0s inside 1 group of parentheses
|
||||
do {
|
||||
$previous = $content;
|
||||
$content = preg_replace('/\(([^\(\)]+) [\+\-] 0( [^\(\)]+)?\)/', '(\\1\\2)', $content);
|
||||
} while ($content !== $previous);
|
||||
// strip all `0 +` occurrences: calc(0 + 10%) -> calc(10%)
|
||||
$content = preg_replace('/\(0 \+ ([^\(\)]+)\)/', '(\\1)', $content);
|
||||
// strip all `0 -` occurrences: calc(0 - 10%) -> calc(-10%)
|
||||
$content = preg_replace('/\(0 \- ([^\(\)]+)\)/', '(-\\1)', $content);
|
||||
// I'm not going to attempt to optimize away `x * 0` instances:
|
||||
// it's dumb enough code already that it likely won't occur, and it's
|
||||
// too complex to do right (order of operations would have to be
|
||||
// respected etc)
|
||||
// what I cared about most here was fixing incorrectly truncated units
|
||||
|
||||
// IE doesn't seem to understand a unitless flex-basis value, so let's
|
||||
// add it in again (make it `%`, which is only 1 char: 0%, 0px, 0
|
||||
// anything, it's all just the same)
|
||||
$content = preg_replace('/flex:([^ ]+ [^ ]+ )0([;\}])/', 'flex:${1}0%${2}', $content);
|
||||
// IE doesn't seem to understand a unitless flex-basis value (correct -
|
||||
// it goes against the spec), so let's add it in again (make it `%`,
|
||||
// which is only 1 char: 0%, 0px, 0 anything, it's all just the same)
|
||||
// @see https://developer.mozilla.org/nl/docs/Web/CSS/flex
|
||||
$content = preg_replace('/flex:([0-9]+\s[0-9]+\s)0([;\}])/', 'flex:${1}0%${2}', $content);
|
||||
$content = preg_replace('/flex-basis:0([;\}])/', 'flex-basis:0%${1}', $content);
|
||||
|
||||
// restore `calc()` expressions
|
||||
$content = str_replace(array_keys($calcs), $calcs, $content);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip comments from source code.
|
||||
* Strip empty tags from source code.
|
||||
*
|
||||
* @param string $content
|
||||
*
|
||||
|
|
@ -605,7 +613,10 @@ class CSS extends Minify
|
|||
*/
|
||||
protected function stripEmptyTags($content)
|
||||
{
|
||||
return preg_replace('/(^|\}|;)[^\{\};]+\{\s*\}/', '\\1', $content);
|
||||
$content = preg_replace('/(?<=^)[^\{\};]+\{\s*\}/', '', $content);
|
||||
$content = preg_replace('/(?<=(\}|;))[^\{\};]+\{\s*\}/', '', $content);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -639,10 +650,12 @@ class CSS extends Minify
|
|||
$content = preg_replace('/\s+([\]\)])/', '$1', $content);
|
||||
$content = preg_replace('/\s+(:)(?![^\}]*\{)/', '$1', $content);
|
||||
|
||||
// whitespace around + and - can only be stripped in selectors, like
|
||||
// :nth-child(3+2n), not in things like calc(3px + 2px) or shorthands
|
||||
// like 3px -2px
|
||||
$content = preg_replace('/\s*([+-])\s*(?=[^}]*{)/', '$1', $content);
|
||||
// whitespace around + and - can only be stripped inside some pseudo-
|
||||
// classes, like `:nth-child(3+2n)`
|
||||
// not in things like `calc(3px + 2px)`, shorthands like `3px -2px`, or
|
||||
// selectors like `div.weird- p`
|
||||
$pseudos = array('nth-child', 'nth-last-child', 'nth-last-of-type', 'nth-of-type');
|
||||
$content = preg_replace('/:('.implode('|', $pseudos).')\(\s*([+-]?)\s*(.+?)\s*([+-]?)\s*(.*?)\s*\)/', ':$1($2$3$4$5)', $content);
|
||||
|
||||
// remove semicolon/whitespace followed by closing bracket
|
||||
$content = str_replace(';}', '}', $content);
|
||||
|
|
@ -650,6 +663,39 @@ class CSS extends Minify
|
|||
return trim($content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find all `calc()` occurrences.
|
||||
*
|
||||
* @param string $content The CSS content to find `calc()`s in.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
protected function findCalcs($content)
|
||||
{
|
||||
$results = array();
|
||||
preg_match_all('/calc(\(.+?)(?=$|;|calc\()/', $content, $matches, PREG_SET_ORDER);
|
||||
|
||||
foreach ($matches as $match) {
|
||||
$length = strlen($match[1]);
|
||||
$expr = '';
|
||||
$opened = 0;
|
||||
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$char = $match[1][$i];
|
||||
$expr .= $char;
|
||||
if ($char === '(') {
|
||||
$opened++;
|
||||
} elseif ($char === ')' && --$opened === 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$results['calc('.count($results).')'] = 'calc'.$expr;
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if file is small enough to be imported.
|
||||
*
|
||||
|
|
|
|||
10
vendor/matthiasmullie/minify/src/Exception.php
vendored
10
vendor/matthiasmullie/minify/src/Exception.php
vendored
|
|
@ -1,10 +1,18 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Base Exception
|
||||
*
|
||||
* @deprecated Use Exceptions\BasicException instead
|
||||
*
|
||||
* @author Matthias Mullie <minify@mullie.eu>
|
||||
*/
|
||||
namespace MatthiasMullie\Minify;
|
||||
|
||||
/**
|
||||
* Base Exception Class
|
||||
* @deprecated Use Exceptions\BasicException instead
|
||||
*
|
||||
* @package Minify
|
||||
* @author Matthias Mullie <minify@mullie.eu>
|
||||
*/
|
||||
abstract class Exception extends \Exception
|
||||
|
|
|
|||
|
|
@ -1,10 +1,21 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Basic exception
|
||||
*
|
||||
* Please report bugs on https://github.com/matthiasmullie/minify/issues
|
||||
*
|
||||
* @author Matthias Mullie <minify@mullie.eu>
|
||||
* @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved
|
||||
* @license MIT License
|
||||
*/
|
||||
namespace MatthiasMullie\Minify\Exceptions;
|
||||
|
||||
use MatthiasMullie\Minify\Exception;
|
||||
|
||||
/**
|
||||
* Basic Exception Class
|
||||
*
|
||||
* @package Minify\Exception
|
||||
* @author Matthias Mullie <minify@mullie.eu>
|
||||
*/
|
||||
abstract class BasicException extends Exception
|
||||
|
|
|
|||
|
|
@ -1,8 +1,19 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* File Import Exception
|
||||
*
|
||||
* Please report bugs on https://github.com/matthiasmullie/minify/issues
|
||||
*
|
||||
* @author Matthias Mullie <minify@mullie.eu>
|
||||
* @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved
|
||||
* @license MIT License
|
||||
*/
|
||||
namespace MatthiasMullie\Minify\Exceptions;
|
||||
|
||||
/**
|
||||
* File Import Exception Class
|
||||
*
|
||||
* @package Minify\Exception
|
||||
* @author Matthias Mullie <minify@mullie.eu>
|
||||
*/
|
||||
class FileImportException extends BasicException
|
||||
|
|
|
|||
|
|
@ -1,8 +1,19 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* IO Exception
|
||||
*
|
||||
* Please report bugs on https://github.com/matthiasmullie/minify/issues
|
||||
*
|
||||
* @author Matthias Mullie <minify@mullie.eu>
|
||||
* @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved
|
||||
* @license MIT License
|
||||
*/
|
||||
namespace MatthiasMullie\Minify\Exceptions;
|
||||
|
||||
/**
|
||||
* IO Exception Class
|
||||
*
|
||||
* @package Minify\Exception
|
||||
* @author Matthias Mullie <minify@mullie.eu>
|
||||
*/
|
||||
class IOException extends BasicException
|
||||
|
|
|
|||
131
vendor/matthiasmullie/minify/src/JS.php
vendored
131
vendor/matthiasmullie/minify/src/JS.php
vendored
|
|
@ -1,13 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace MatthiasMullie\Minify;
|
||||
|
||||
/**
|
||||
* JavaScript minifier.
|
||||
* JavaScript minifier
|
||||
*
|
||||
* Please report bugs on https://github.com/matthiasmullie/minify/issues
|
||||
*
|
||||
* @author Matthias Mullie <minify@mullie.eu>
|
||||
* @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved
|
||||
* @license MIT License
|
||||
*/
|
||||
namespace MatthiasMullie\Minify;
|
||||
|
||||
/**
|
||||
* JavaScript Minifier Class
|
||||
*
|
||||
* Please report bugs on https://github.com/matthiasmullie/minify/issues
|
||||
*
|
||||
* @package Minify
|
||||
* @author Matthias Mullie <minify@mullie.eu>
|
||||
* @author Tijs Verkoyen <minify@verkoyen.eu>
|
||||
* @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved
|
||||
* @license MIT License
|
||||
|
|
@ -80,8 +89,7 @@ class JS extends Minify
|
|||
* them. Some end of lines are not the end of a statement, like with these
|
||||
* operators.
|
||||
*
|
||||
* Note: Most operators are fine, we've only removed !, ++ and --.
|
||||
* There can't be a newline separating ! and whatever it is negating.
|
||||
* Note: Most operators are fine, we've only removed ++ and --.
|
||||
* ++ & -- have to be joined with the value they're in-/decrementing.
|
||||
*
|
||||
* Will be loaded from /data/js/operators_before.txt
|
||||
|
|
@ -97,7 +105,8 @@ class JS extends Minify
|
|||
* them. Some end of lines are not the end of a statement, like when
|
||||
* continued by one of these operators on the newline.
|
||||
*
|
||||
* Note: Most operators are fine, we've only removed ), ], ++ and --.
|
||||
* Note: Most operators are fine, we've only removed ), ], ++, --, ! and ~.
|
||||
* There can't be a newline separating ! or ~ and whatever it is negating.
|
||||
* ++ & -- have to be joined with the value they're in-/decrementing.
|
||||
* ) & ] are "special" in that they have lots or usecases. () for example
|
||||
* is used for function calls, for grouping, in if () and for (), ...
|
||||
|
|
@ -139,19 +148,6 @@ class JS extends Minify
|
|||
{
|
||||
$content = '';
|
||||
|
||||
// loop files
|
||||
foreach ($this->data as $source => $js) {
|
||||
/*
|
||||
* Combine js: separating the scripts by a ;
|
||||
* I'm also adding a newline: it will be eaten when whitespace is
|
||||
* stripped, but we need to make sure we're not just appending
|
||||
* a new script right after a previous script that ended with a
|
||||
* singe-line comment on the last line (in which case it would also
|
||||
* be seen as part of that comment)
|
||||
*/
|
||||
$content .= $js."\n;";
|
||||
}
|
||||
|
||||
/*
|
||||
* Let's first take out strings, comments and regular expressions.
|
||||
* All of these can contain JS code-like characters, and we should make
|
||||
|
|
@ -166,11 +162,24 @@ class JS extends Minify
|
|||
$this->extractStrings('\'"`');
|
||||
$this->stripComments();
|
||||
$this->extractRegex();
|
||||
$content = $this->replace($content);
|
||||
|
||||
$content = $this->propertyNotation($content);
|
||||
$content = $this->shortenBools($content);
|
||||
$content = $this->stripWhitespace($content);
|
||||
// loop files
|
||||
foreach ($this->data as $source => $js) {
|
||||
// take out strings, comments & regex (for which we've registered
|
||||
// the regexes just a few lines earlier)
|
||||
$js = $this->replace($js);
|
||||
|
||||
$js = $this->propertyNotation($js);
|
||||
$js = $this->shortenBools($js);
|
||||
$js = $this->stripWhitespace($js);
|
||||
|
||||
// combine js: separating the scripts by a ;
|
||||
$content .= $js.";";
|
||||
}
|
||||
|
||||
// clean up leftover `;`s from the combination of multiple scripts
|
||||
$content = ltrim($content, ';');
|
||||
$content = (string) substr($content, 0, -1);
|
||||
|
||||
/*
|
||||
* Earlier, we extracted strings & regular expressions and replaced them
|
||||
|
|
@ -216,20 +225,62 @@ class JS extends Minify
|
|||
$minifier = $this;
|
||||
$callback = function ($match) use ($minifier) {
|
||||
$count = count($minifier->extracted);
|
||||
$placeholder = '/'.$count.'/';
|
||||
$placeholder = '"'.$count.'"';
|
||||
$minifier->extracted[$placeholder] = $match[0];
|
||||
|
||||
return $placeholder;
|
||||
};
|
||||
|
||||
$pattern = '\/.*?(?<!\\\\)(\\\\\\\\)*\/[gimy]*(?![0-9a-zA-Z\/])';
|
||||
// match all chars except `/` and `\`
|
||||
// `\` is allowed though, along with whatever char follows (which is the
|
||||
// one being escaped)
|
||||
// this should allow all chars, except for an unescaped `/` (= the one
|
||||
// closing the regex)
|
||||
// then also ignore bare `/` inside `[]`, where they don't need to be
|
||||
// escaped: anything inside `[]` can be ignored safely
|
||||
$pattern = '\\/(?:[^\\[\\/\\\\\n\r]+|(?:\\\\.)+|(?:\\[(?:[^\\]\\\\\n\r]+|(?:\\\\.)+)+\\])+)++\\/[gimuy]*';
|
||||
|
||||
// a regular expression can only be followed by a few operators or some
|
||||
// of the RegExp methods (a `\` followed by a variable or value is
|
||||
// likely part of a division, not a regex)
|
||||
$after = '[\.,;\)\}]';
|
||||
$methods = '\.(exec|test|match|search|replace|split)\(';
|
||||
$this->registerPattern('/'.$pattern.'(?=\s*('.$after.'|'.$methods.'))/', $callback);
|
||||
$keywords = array('do', 'in', 'new', 'else', 'throw', 'yield', 'delete', 'return', 'typeof');
|
||||
$before = '([=:,;\+\-\*\/\}\(\{\[&\|!]|^|'.implode('|', $keywords).')\s*';
|
||||
$propertiesAndMethods = array(
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#Properties_2
|
||||
'constructor',
|
||||
'flags',
|
||||
'global',
|
||||
'ignoreCase',
|
||||
'multiline',
|
||||
'source',
|
||||
'sticky',
|
||||
'unicode',
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#Methods_2
|
||||
'compile(',
|
||||
'exec(',
|
||||
'test(',
|
||||
'toSource(',
|
||||
'toString(',
|
||||
);
|
||||
$delimiters = array_fill(0, count($propertiesAndMethods), '/');
|
||||
$propertiesAndMethods = array_map('preg_quote', $propertiesAndMethods, $delimiters);
|
||||
$after = '(?=\s*([\.,;\)\}&\|+]|\/\/|$|\.('.implode('|', $propertiesAndMethods).')))';
|
||||
$this->registerPattern('/'.$before.'\K'.$pattern.$after.'/', $callback);
|
||||
|
||||
// regular expressions following a `)` are rather annoying to detect...
|
||||
// quite often, `/` after `)` is a division operator & if it happens to
|
||||
// be followed by another one (or a comment), it is likely to be
|
||||
// confused for a regular expression
|
||||
// however, it's perfectly possible for a regex to follow a `)`: after
|
||||
// a single-line `if()`, `while()`, ... statement, for example
|
||||
// since, when they occur like that, they're always the start of a
|
||||
// statement, there's only a limited amount of ways they can be useful:
|
||||
// by calling the regex methods directly
|
||||
// if a regex following `)` is not followed by `.<property or method>`,
|
||||
// it's quite likely not a regex
|
||||
$before = '\)\s*';
|
||||
$after = '(?=\s*\.('.implode('|', $propertiesAndMethods).'))';
|
||||
$this->registerPattern('/'.$before.'\K'.$pattern.$after.'/', $callback);
|
||||
|
||||
// 1 more edge case: a regex can be followed by a lot more operators or
|
||||
// keywords if there's a newline (ASI) in between, where the operator
|
||||
|
|
@ -237,7 +288,8 @@ class JS extends Minify
|
|||
// (https://github.com/matthiasmullie/minify/issues/56)
|
||||
$operators = $this->getOperatorsForRegex($this->operatorsBefore, '/');
|
||||
$operators += $this->getOperatorsForRegex($this->keywordsReserved, '/');
|
||||
$this->registerPattern('/'.$pattern.'\s*\n(?=\s*('.implode('|', $operators).'))/', $callback);
|
||||
$after = '(?=\s*\n\s*('.implode('|', $operators).'))';
|
||||
$this->registerPattern('/'.$pattern.$after.'/', $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -309,6 +361,16 @@ class JS extends Minify
|
|||
$content = preg_replace('/('.implode('|', $operatorsDiffBefore).')[^\S\n]+/', '\\1', $content);
|
||||
$content = preg_replace('/[^\S\n]+('.implode('|', $operatorsDiffAfter).')/', '\\1', $content);
|
||||
|
||||
/*
|
||||
* Whitespace after `return` can be omitted in a few occasions
|
||||
* (such as when followed by a string or regex)
|
||||
* Same for whitespace in between `)` and `{`, or between `{` and some
|
||||
* keywords.
|
||||
*/
|
||||
$content = preg_replace('/\breturn\s+(["\'\/\+\-])/', 'return$1', $content);
|
||||
$content = preg_replace('/\)\s+\{/', '){', $content);
|
||||
$content = preg_replace('/}\n(else|catch|finally)\b/', '}$1', $content);
|
||||
|
||||
/*
|
||||
* Get rid of double semicolons, except where they can be used like:
|
||||
* "for(v=1,_=b;;)", "for(v=1;;v++)" or "for(;;ja||(ja=true))".
|
||||
|
|
@ -326,12 +388,19 @@ class JS extends Minify
|
|||
* semicolon), like: `for(i=1;i<3;i++);`, of `for(i in list);`
|
||||
* Here, nothing happens during the loop; it's just used to keep
|
||||
* increasing `i`. With that ; omitted, the next line would be expected
|
||||
* to be the for-loop's body...
|
||||
* to be the for-loop's body... Same goes for while loops.
|
||||
* I'm going to double that semicolon (if any) so after the next line,
|
||||
* which strips semicolons here & there, we're still left with this one.
|
||||
*/
|
||||
$content = preg_replace('/(for\([^;\{]*;[^;\{]*;[^;\{]*\));(\}|$)/s', '\\1;;\\2', $content);
|
||||
$content = preg_replace('/(for\([^;\{]+\s+in\s+[^;\{]+\));(\}|$)/s', '\\1;;\\2', $content);
|
||||
/*
|
||||
* Below will also keep `;` after a `do{}while();` along with `while();`
|
||||
* While these could be stripped after do-while, detecting this
|
||||
* distinction is cumbersome, so I'll play it safe and make sure `;`
|
||||
* after any kind of `while` is kept.
|
||||
*/
|
||||
$content = preg_replace('/(while\([^;\{]+\));(\}|$)/s', '\\1;;\\2', $content);
|
||||
|
||||
/*
|
||||
* We also can't strip empty else-statements. Even though they're
|
||||
|
|
|
|||
45
vendor/matthiasmullie/minify/src/Minify.php
vendored
45
vendor/matthiasmullie/minify/src/Minify.php
vendored
|
|
@ -1,5 +1,13 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Abstract minifier class
|
||||
*
|
||||
* Please report bugs on https://github.com/matthiasmullie/minify/issues
|
||||
*
|
||||
* @author Matthias Mullie <minify@mullie.eu>
|
||||
* @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved
|
||||
* @license MIT License
|
||||
*/
|
||||
namespace MatthiasMullie\Minify;
|
||||
|
||||
use MatthiasMullie\Minify\Exceptions\IOException;
|
||||
|
|
@ -10,6 +18,7 @@ use Psr\Cache\CacheItemInterface;
|
|||
*
|
||||
* Please report bugs on https://github.com/matthiasmullie/minify/issues
|
||||
*
|
||||
* @package Minify
|
||||
* @author Matthias Mullie <minify@mullie.eu>
|
||||
* @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved
|
||||
* @license MIT License
|
||||
|
|
@ -230,6 +239,12 @@ abstract class Minify
|
|||
foreach ($this->patterns as $i => $pattern) {
|
||||
list($pattern, $replacement) = $pattern;
|
||||
|
||||
// we can safely ignore patterns for positions we've unset earlier,
|
||||
// because we know these won't show up anymore
|
||||
if (!isset($positions[$i])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// no need to re-run matches that are still in the part of the
|
||||
// content that hasn't been processed
|
||||
if ($positions[$i] >= 0) {
|
||||
|
|
@ -237,19 +252,18 @@ abstract class Minify
|
|||
}
|
||||
|
||||
$match = null;
|
||||
if (preg_match($pattern, $content, $match)) {
|
||||
if (preg_match($pattern, $content, $match, PREG_OFFSET_CAPTURE)) {
|
||||
$matches[$i] = $match;
|
||||
|
||||
// we'll store the match position as well; that way, we
|
||||
// don't have to redo all preg_matches after changing only
|
||||
// the first (we'll still know where those others are)
|
||||
$positions[$i] = strpos($content, $match[0]);
|
||||
$positions[$i] = $match[0][1];
|
||||
} else {
|
||||
// if the pattern couldn't be matched, there's no point in
|
||||
// executing it again in later runs on this same content;
|
||||
// ignore this one until we reach end of content
|
||||
unset($matches[$i]);
|
||||
$positions[$i] = strlen($content);
|
||||
unset($matches[$i], $positions[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -264,7 +278,7 @@ abstract class Minify
|
|||
// other found was not inside what the first found)
|
||||
$discardLength = min($positions);
|
||||
$firstPattern = array_search($discardLength, $positions);
|
||||
$match = $matches[$firstPattern][0];
|
||||
$match = $matches[$firstPattern][0][0];
|
||||
|
||||
// execute the pattern that matches earliest in the content string
|
||||
list($pattern, $replacement) = $this->patterns[$firstPattern];
|
||||
|
|
@ -272,7 +286,7 @@ abstract class Minify
|
|||
|
||||
// figure out which part of the string was unmatched; that's the
|
||||
// part we'll execute the patterns on again next
|
||||
$content = substr($content, $discardLength);
|
||||
$content = (string) substr($content, $discardLength);
|
||||
$unmatched = (string) substr($content, strpos($content, $match) + strlen($match));
|
||||
|
||||
// move the replaced part to $processed and prepare $content to
|
||||
|
|
@ -324,12 +338,13 @@ abstract class Minify
|
|||
* via restoreStrings().
|
||||
*
|
||||
* @param string[optional] $chars
|
||||
* @param string[optional] $placeholderPrefix
|
||||
*/
|
||||
protected function extractStrings($chars = '\'"')
|
||||
protected function extractStrings($chars = '\'"', $placeholderPrefix = '')
|
||||
{
|
||||
// PHP only supports $this inside anonymous functions since 5.4
|
||||
$minifier = $this;
|
||||
$callback = function ($match) use ($minifier) {
|
||||
$callback = function ($match) use ($minifier, $placeholderPrefix) {
|
||||
// check the second index here, because the first always contains a quote
|
||||
if ($match[2] === '') {
|
||||
/*
|
||||
|
|
@ -342,7 +357,7 @@ abstract class Minify
|
|||
}
|
||||
|
||||
$count = count($minifier->extracted);
|
||||
$placeholder = $match[1].$count.$match[1];
|
||||
$placeholder = $match[1].$placeholderPrefix.$count.$match[1];
|
||||
$minifier->extracted[$placeholder] = $match[1].$match[2].$match[1];
|
||||
|
||||
return $placeholder;
|
||||
|
|
@ -395,6 +410,16 @@ abstract class Minify
|
|||
*/
|
||||
protected function canImportFile($path)
|
||||
{
|
||||
$parsed = parse_url($path);
|
||||
if (
|
||||
// file is elsewhere
|
||||
isset($parsed['host']) ||
|
||||
// file responds to queries (may change, or need to bypass cache)
|
||||
isset($parsed['query'])
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return strlen($path) < PHP_MAXPATHLEN && @is_file($path) && is_readable($path);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue