Abstract minifier class.
More...
|
| __construct () |
| Init the minify class - optionally, code may be passed along already.
|
|
| add ($data) |
| Add a file or straight-up code to be minified.
|
|
| addFile ($data) |
| Add a file to be minified.
|
|
| cache (CacheItemInterface $item) |
| Minify the data & write it to a CacheItemInterface object.
|
|
| execute ($path=null) |
| Minify the data.
|
|
| gzip ($path=null, $level=9) |
| Minify & gzip the data & (optionally) saves it to a file.
|
|
| minify ($path=null) |
| Minify the data & (optionally) saves it to a file.
|
|
|
string[] | $extracted = array() |
| This array will hold content of strings and regular expressions that have been extracted from the JS source code, so we can reliably match "code", without having to worry about potential "code-like" characters inside.
|
|
|
| canImportFile ($path) |
| Check if the path is a regular file and can be read.
|
|
| executeReplacement ($replacement, $match) |
| If $replacement is a callback, execute it, passing in the match data.
|
|
| extractStrings ($chars='\'"', $placeholderPrefix = '') |
| Strings are a pattern we need to match, in order to ignore potential code-like content inside them, but we just want all of the string content to remain untouched.
|
|
| load ($data) |
| Load data.
|
|
| openFileForWriting ($path) |
| Attempts to open file specified by $path for writing.
|
|
| registerPattern ($pattern, $replacement='') |
| Register a pattern to execute against the source content.
|
|
| replace ($content) |
| We can't "just" run some regular expressions against JavaScript: it's a complex language.
|
|
| restoreExtractedData ($content) |
| This method will restore all extracted data (strings, regexes) that were replaced with placeholder text in extract*().
|
|
| save ($content, $path) |
| Save to file.
|
|
| stripMultilineComments () |
| Both JS and CSS use the same form of multi-line comment, so putting the common code here.
|
|
| writeToFile ($handler, $content, $path='') |
| Attempts to write $content to the file specified by $handler.
|
|
|
static | str_replace_first ($search, $replace, $subject) |
|
|
string[] | $data = array() |
| The data to be minified.
|
|
string[] | $patterns = array() |
| Array of patterns to match.
|
|
Abstract minifier class.
Please report bugs on https://github.com/matthiasmullie/minify/issues
- Author
- Matthias Mullie minif.nosp@m.y@mu.nosp@m.llie..nosp@m.eu
- Copyright
- Copyright (c) 2012, Matthias Mullie. All rights reserved
- License
- MIT License
◆ add()
MatthiasMullie\Minify\Minify::add |
( |
| $data | ) |
|
Add a file or straight-up code to be minified.
- Parameters
-
- Return values
-
◆ addFile()
MatthiasMullie\Minify\Minify::addFile |
( |
| $data | ) |
|
Add a file to be minified.
- Parameters
-
- Return values
-
- Exceptions
-
◆ cache()
MatthiasMullie\Minify\Minify::cache |
( |
CacheItemInterface | $item | ) |
|
Minify the data & write it to a CacheItemInterface object.
- Parameters
-
CacheItemInterface | $item | Cache item to write the data to |
- Return values
-
CacheItemInterface | Cache item with the minifier data |
◆ canImportFile()
MatthiasMullie\Minify\Minify::canImportFile |
( |
| $path | ) |
|
|
protected |
Check if the path is a regular file and can be read.
- Parameters
-
- Return values
-
◆ execute()
MatthiasMullie\Minify\Minify::execute |
( |
| $path = null | ) |
|
|
abstract |
Minify the data.
- Parameters
-
string[optional] | $path Path to write the data to |
- Return values
-
◆ executeReplacement()
MatthiasMullie\Minify\Minify::executeReplacement |
( |
| $replacement, |
|
|
| $match ) |
|
protected |
If $replacement is a callback, execute it, passing in the match data.
If it's a string, just pass it through.
- Parameters
-
string | callable | $replacement | Replacement value |
array | $match | Match data, in PREG_OFFSET_CAPTURE form |
- Return values
-
◆ extractStrings()
MatthiasMullie\Minify\Minify::extractStrings |
( |
| ) |
|
|
protected |
Strings are a pattern we need to match, in order to ignore potential code-like content inside them, but we just want all of the string content to remain untouched.
This method will replace all string content with simple STRING# placeholder text, so we've rid all strings from characters that may be misinterpreted. Original string content will be saved in $this->extracted and after doing all other minifying, we can restore the original content via restoreStrings().
- Parameters
-
string[optional] | $chars |
string[optional] | $placeholderPrefix |
◆ gzip()
MatthiasMullie\Minify\Minify::gzip |
( |
| $path = null, |
|
|
| $level = 9 ) |
Minify & gzip the data & (optionally) saves it to a file.
- Parameters
-
string[optional] | $path Path to write the data to |
int[optional] | $level Compression level, from 0 to 9 |
- Return values
-
string | The minified & gzipped data |
◆ load()
MatthiasMullie\Minify\Minify::load |
( |
| $data | ) |
|
|
protected |
Load data.
- Parameters
-
string | $data | Either a path to a file or the content itself |
- Return values
-
◆ minify()
MatthiasMullie\Minify\Minify::minify |
( |
| $path = null | ) |
|
Minify the data & (optionally) saves it to a file.
- Parameters
-
string[optional] | $path Path to write the data to |
- Return values
-
◆ openFileForWriting()
MatthiasMullie\Minify\Minify::openFileForWriting |
( |
| $path | ) |
|
|
protected |
Attempts to open file specified by $path for writing.
- Parameters
-
string | $path | The path to the file |
- Return values
-
resource | Specifier for the target file |
- Exceptions
-
◆ registerPattern()
MatthiasMullie\Minify\Minify::registerPattern |
( |
| $pattern, |
|
|
| $replacement = '' ) |
|
protected |
Register a pattern to execute against the source content.
If $replacement is a string, it must be plain text. Placeholders like $1 or 2 don't work. If you need that functionality, use a callback instead.
- Parameters
-
string | $pattern | PCRE pattern |
string | callable | $replacement | Replacement value for matched pattern |
◆ replace()
MatthiasMullie\Minify\Minify::replace |
( |
| $content | ) |
|
|
protected |
We can't "just" run some regular expressions against JavaScript: it's a complex language.
E.g. having an occurrence of // xyz would be a comment, unless it's used within a string. Of you could have something that looks like a 'string', but inside a comment. The only way to accurately replace these pieces is to traverse the JS one character at a time and try to find whatever starts first.
- Parameters
-
string | $content | The content to replace patterns in |
- Return values
-
string | The (manipulated) content |
◆ restoreExtractedData()
MatthiasMullie\Minify\Minify::restoreExtractedData |
( |
| $content | ) |
|
|
protected |
This method will restore all extracted data (strings, regexes) that were replaced with placeholder text in extract*().
The original content was saved in $this->extracted.
- Parameters
-
- Return values
-
◆ save()
MatthiasMullie\Minify\Minify::save |
( |
| $content, |
|
|
| $path ) |
|
protected |
Save to file.
- Parameters
-
string | $content | The minified data |
string | $path | The path to save the minified data to |
- Exceptions
-
◆ writeToFile()
MatthiasMullie\Minify\Minify::writeToFile |
( |
| $handler, |
|
|
| $content, |
|
|
| $path = '' ) |
|
protected |
Attempts to write $content to the file specified by $handler.
$path is used for printing exceptions.
- Parameters
-
resource | $handler | The resource to write to |
string | $content | The content to write |
string | $path | The path to the file (for exception printing only) |
- Exceptions
-
The documentation for this class was generated from the following file:
- lib/minify/matthiasmullie-minify/src/Minify.php