See Release Notes
Long Term Support Release
Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 and 402] [Versions 401 and 403]
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 |
File Size: | 505 lines (16 kb) |
Included or required: | 0 times |
Referenced: | 0 times |
Includes or requires: | 0 files |
Minify:: (17 methods):
__construct()
add()
addFile()
minify()
gzip()
cache()
load()
save()
registerPattern()
replace()
executeReplacement()
extractStrings()
restoreExtractedData()
canImportFile()
openFileForWriting()
writeToFile()
str_replace_first()
__construct() X-Ref |
Init the minify class - optionally, code may be passed along already. |
add($data ) X-Ref |
Add a file or straight-up code to be minified. param: string|string[] $data return: static |
addFile($data ) X-Ref |
Add a file to be minified. param: string|string[] $data return: static |
minify($path = null) X-Ref |
Minify the data & (optionally) saves it to a file. param: string[optional] $path Path to write the data to return: string The minified data |
gzip($path = null, $level = 9) X-Ref |
Minify & gzip the data & (optionally) saves it to a file. param: string[optional] $path Path to write the data to param: int[optional] $level Compression level, from 0 to 9 return: string The minified & gzipped data |
cache(CacheItemInterface $item) X-Ref |
Minify the data & write it to a CacheItemInterface object. param: CacheItemInterface $item Cache item to write the data to return: CacheItemInterface Cache item with the minifier data |
load($data) X-Ref |
Load data. param: string $data Either a path to a file or the content itself return: string |
save($content, $path) X-Ref |
Save to file. param: string $content The minified data param: string $path The path to save the minified data to |
registerPattern($pattern, $replacement = '') X-Ref |
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. param: string $pattern PCRE pattern param: string|callable $replacement Replacement value for matched pattern |
replace($content) X-Ref |
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. param: string $content The content to replace patterns in return: string The (manipulated) content |
executeReplacement($replacement, $match) X-Ref |
If $replacement is a callback, execute it, passing in the match data. If it's a string, just pass it through. param: string|callable $replacement Replacement value param: array $match Match data, in PREG_OFFSET_CAPTURE form return: string |
extractStrings($chars = '\'"', $placeholderPrefix = '') X-Ref |
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(). param: string[optional] $chars param: string[optional] $placeholderPrefix |
restoreExtractedData($content) X-Ref |
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. param: string $content return: string |
canImportFile($path) X-Ref |
Check if the path is a regular file and can be read. param: string $path return: bool |
openFileForWriting($path) X-Ref |
Attempts to open file specified by $path for writing. param: string $path The path to the file return: resource Specifier for the target file |
writeToFile($handler, $content, $path = '') X-Ref |
Attempts to write $content to the file specified by $handler. $path is used for printing exceptions. param: resource $handler The resource to write to param: string $content The content to write param: string $path The path to the file (for exception printing only) |
str_replace_first($search, $replace, $subject) X-Ref |
No description |