PHP 클래스 MatthiasMullie\Minify\Minify

Please report bugs on https://github.com/matthiasmullie/minify/issues
저자: Matthias Mullie ([email protected])
파일 보기 프로젝트 열기: matthiasmullie/minify

공개 프로퍼티들

프로퍼티 타입 설명
$extracted string[] 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.

보호된 프로퍼티들

프로퍼티 타입 설명
$data string[] The data to be minified.
$patterns string[] Array of patterns to match.

공개 메소드들

메소드 설명
__construct ( ) Init the minify class - optionally, code may be passed along already.
add ( string | string[] $data ) Add a file or straight-up code to be minified.
cache ( Psr\Cache\CacheItemInterface $item ) : Psr\Cache\CacheItemInterface Minify the data & write it to a CacheItemInterface object.
execute ( string[optional] $path = null ) : string Minify the data.
gzip ( string[optional] $path = null, int[optional] $level = 9 ) : string Minify & gzip the data & (optionally) saves it to a file.
minify ( string[optional] $path = null ) : string Minify the data & (optionally) saves it to a file.

보호된 메소드들

메소드 설명
canImportFile ( string $path ) : boolean Check if the path is a regular file and can be read.
extractStrings ( string[optional] $chars = ''"' ) 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 ( string $data ) : string Load data.
openFileForWriting ( string $path ) : resource Attempts to open file specified by $path for writing.
registerPattern ( string $pattern, string | callable $replacement = '' ) Register a pattern to execute against the source content.
replace ( string $content ) : string 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.
replacePattern ( string $pattern, string | callable $replacement, string $content ) : string This is where a pattern is matched against $content and the matches are replaced by their respective value.
restoreExtractedData ( string $content ) : string 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.
save ( string $content, string $path ) Save to file.
writeToFile ( resource $handler, string $content, string $path = '' ) Attempts to write $content to the file specified by $handler. $path is used for printing exceptions.

메소드 상세

__construct() 공개 메소드

Init the minify class - optionally, code may be passed along already.
public __construct ( )

add() 공개 메소드

Add a file or straight-up code to be minified.
public add ( string | string[] $data )
$data string | string[]

cache() 공개 메소드

Minify the data & write it to a CacheItemInterface object.
public cache ( Psr\Cache\CacheItemInterface $item ) : Psr\Cache\CacheItemInterface
$item Psr\Cache\CacheItemInterface Cache item to write the data to
리턴 Psr\Cache\CacheItemInterface Cache item with the minifier data

canImportFile() 보호된 메소드

Check if the path is a regular file and can be read.
protected canImportFile ( string $path ) : boolean
$path string
리턴 boolean

execute() 추상적인 공개 메소드

Minify the data.
abstract public execute ( string[optional] $path = null ) : string
$path string[optional]
리턴 string The minified data

extractStrings() 보호된 메소드

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().
protected extractStrings ( string[optional] $chars = ''"' )
$chars string[optional]

gzip() 공개 메소드

Minify & gzip the data & (optionally) saves it to a file.
public gzip ( string[optional] $path = null, int[optional] $level = 9 ) : string
$path string[optional]
$level int[optional]
리턴 string The minified & gzipped data

load() 보호된 메소드

Load data.
protected load ( string $data ) : string
$data string Either a path to a file or the content itself
리턴 string

minify() 공개 메소드

Minify the data & (optionally) saves it to a file.
public minify ( string[optional] $path = null ) : string
$path string[optional]
리턴 string The minified data

openFileForWriting() 보호된 메소드

Attempts to open file specified by $path for writing.
protected openFileForWriting ( string $path ) : resource
$path string The path to the file
리턴 resource Specifier for the target file

registerPattern() 보호된 메소드

Register a pattern to execute against the source content.
protected registerPattern ( string $pattern, string | callable $replacement = '' )
$pattern string PCRE pattern
$replacement string | callable Replacement value for matched pattern

replace() 보호된 메소드

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.
protected replace ( string $content ) : string
$content string The content to replace patterns in
리턴 string The (manipulated) content

replacePattern() 보호된 메소드

This function will be called plenty of times, where $content will always move up 1 character.
protected replacePattern ( string $pattern, string | callable $replacement, string $content ) : string
$pattern string Pattern to match
$replacement string | callable Replacement value
$content string Content to match pattern against
리턴 string

restoreExtractedData() 보호된 메소드

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.
protected restoreExtractedData ( string $content ) : string
$content string
리턴 string

save() 보호된 메소드

Save to file.
protected save ( string $content, string $path )
$content string The minified data
$path string The path to save the minified data to

writeToFile() 보호된 메소드

Attempts to write $content to the file specified by $handler. $path is used for printing exceptions.
protected writeToFile ( resource $handler, string $content, string $path = '' )
$handler resource The resource to write to
$content string The content to write
$path string The path to the file (for exception printing only)

프로퍼티 상세

$data 보호되어 있는 프로퍼티

The data to be minified.
protected string[] $data
리턴 string[]

$extracted 공개적으로 프로퍼티

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.
public string[] $extracted
리턴 string[]

$patterns 보호되어 있는 프로퍼티

Array of patterns to match.
protected string[] $patterns
리턴 string[]