PHP Class MatthiasMullie\Minify\CSS

Please report bugs on https://github.com/matthiasmullie/minify/issues
Author: Matthias Mullie ([email protected])
Author: Tijs Verkoyen ([email protected])
Inheritance: extends Minify
Show file Open project: matthiasmullie/minify Class Usage Examples

Protected Properties

Property Type Description
$importExtensions string[]
$maxImportSize integer

Public Methods

Method Description
execute ( string[optional] $path = null, string[] $parents = [] ) : string Minify the data.
setImportExtensions ( array $extensions ) Set the type of extensions to be imported into the CSS (to save network connections).
setMaxImportSize ( integer $size ) Set the maximum size if files to be imported.

Protected Methods

Method Description
canImportBySize ( string $path ) : boolean Check if file is small enough to be imported.
combineImports ( string $source, string $content, string[] $parents ) : string Combine CSS from import statements.
importFiles ( string $source, string $content ) : string Import files into the CSS, base64-ized.
move ( MatthiasMullie\PathConverter\Converter $converter, string $content ) : string Moving a css file should update all relative urls.
moveImportsToTop ( string $content ) : string Move any import statements to the top.
shortenFontWeights ( string $content ) : string Shorten CSS font weights.
shortenHex ( string $content ) : string Shorthand hex color codes.
shortenZeroes ( string $content ) : string Shorthand 0 values to plain 0, instead of e.g. -0em.
stripComments ( ) Strip comments from source code.
stripEmptyTags ( string $content ) : string Strip comments from source code.
stripWhitespace ( string $content ) : string Strip whitespace.

Method Details

canImportBySize() protected method

Check if file is small enough to be imported.
protected canImportBySize ( string $path ) : boolean
$path string The path to the file
return boolean

combineImports() protected method

Combine CSS from import statements.
protected combineImports ( string $source, string $content, string[] $parents ) : string
$source string The file to combine imports for
$content string The CSS content to combine imports for
$parents string[] Parent paths, for circular reference checks
return string

execute() public method

Perform CSS optimizations.
public execute ( string[optional] $path = null, string[] $parents = [] ) : string
$path string[optional]
$parents string[] Parent paths, for circular reference checks
return string The minified data

importFiles() protected method

Import files into the CSS, base64-ized.
protected importFiles ( string $source, string $content ) : string
$source string The file to import files for
$content string The CSS content to import files for
return string

move() protected method

Relative references (e.g. ../images/image.gif) in a certain css file, will have to be updated when a file is being saved at another location (e.g. ../../images/image.gif, if the new CSS file is 1 folder deeper).
protected move ( MatthiasMullie\PathConverter\Converter $converter, string $content ) : string
$converter MatthiasMullie\PathConverter\Converter Relative path converter
$content string The CSS content to update relative urls for
return string

moveImportsToTop() protected method

Move any import statements to the top.
protected moveImportsToTop ( string $content ) : string
$content string Nearly finished CSS content
return string

setImportExtensions() public method

Keys of the array should be the file extensions & respective values should be the data type.
public setImportExtensions ( array $extensions )
$extensions array Array of file extensions

setMaxImportSize() public method

Files larger than this size (in kB) will not be imported into the CSS. Importing files into the CSS as data-uri will save you some connections, but we should only import relatively small decorative images so that our CSS file doesn't get too bulky.
public setMaxImportSize ( integer $size )
$size integer Size in kB

shortenFontWeights() protected method

Shorten CSS font weights.
protected shortenFontWeights ( string $content ) : string
$content string The CSS content to shorten the font weights for
return string

shortenHex() protected method

#FF0000 -> #F00.
protected shortenHex ( string $content ) : string
$content string The CSS content to shorten the hex color codes for
return string

shortenZeroes() protected method

Shorthand 0 values to plain 0, instead of e.g. -0em.
protected shortenZeroes ( string $content ) : string
$content string The CSS content to shorten the zero values for
return string

stripComments() protected method

Strip comments from source code.
protected stripComments ( )

stripEmptyTags() protected method

Strip comments from source code.
protected stripEmptyTags ( string $content ) : string
$content string
return string

stripWhitespace() protected method

Strip whitespace.
protected stripWhitespace ( string $content ) : string
$content string The CSS content to strip the whitespace for
return string

Property Details

$importExtensions protected property

protected string[] $importExtensions
return string[]

$maxImportSize protected property

protected int $maxImportSize
return integer