wikimedia/minify
Minification of JavaScript code and CSS stylesheets
Loading...
Searching...
No Matches
Wikimedia\Minify\CSSMin Class Reference

Transforms CSS data. More...

Static Public Member Functions

static getLocalFileReferences ( $source, $path)
 Get a list of local files referenced in a stylesheet (includes non-existent files).
 
static encodeImageAsDataURI ( $file, $type=null)
 Encode an image file as a data URI.
 
static encodeStringAsDataURI ( $contents, $type)
 Encode file contents as a data URI with chosen MIME type.
 
static serializeStringValue ( $value)
 Serialize a string (escape and quote) for use as a CSS string value.
 
static getMimeType ( $file)
 
static buildUrlValue ( $url)
 Build a CSS 'url()' value for the given URL, quoting parentheses (and other funny characters) and escaping quotes as necessary.
 
static remap ( $source, $local, $remote, $embedData=true)
 Remaps CSS URL paths and automatically embeds data URIs for CSS rules or url() values preceded by an / * @embed * / comment.
 
static remapOne ( $file, $query, $local, $remote, $embed)
 Remap or embed a CSS URL path.
 
static minify ( $css)
 Removes whitespace from CSS data.
 

Static Protected Member Functions

static isRemoteUrl ( $maybeUrl)
 Is this CSS rule referencing a remote URL?
 
static isLocalUrl ( $maybeUrl)
 Is this CSS rule referencing a local URL?
 

Detailed Description

Transforms CSS data.

This class provides minification, URL remapping, URL extracting, and data-URL embedding.

Member Function Documentation

◆ buildUrlValue()

static Wikimedia\Minify\CSSMin::buildUrlValue ( $url)
static

Build a CSS 'url()' value for the given URL, quoting parentheses (and other funny characters) and escaping quotes as necessary.

See http://www.w3.org/TR/css-syntax-3/#consume-a-url-token

Parameters
string$urlURL to process
Returns
string 'url()' value, usually just "url($url)", quoted/escaped if necessary

◆ encodeImageAsDataURI()

static Wikimedia\Minify\CSSMin::encodeImageAsDataURI ( $file,
$type = null )
static

Encode an image file as a data URI.

If the image file has a suitable MIME type and size, encode it as a data URI, base64-encoded for binary files or just percent-encoded otherwise. Return false if the image type is unfamiliar or the file exceeds the size limit.

Parameters
string$fileImage file to encode.
string | null$typeFile's MIME type or null. If null, CSSMin will try to autodetect the type.
Returns
string|false Image contents encoded as a data URI or false.

◆ encodeStringAsDataURI()

static Wikimedia\Minify\CSSMin::encodeStringAsDataURI ( $contents,
$type )
static

Encode file contents as a data URI with chosen MIME type.

The URI will be base64-encoded for binary files or just percent-encoded otherwise.

Since
2.0.0
Parameters
string$contentsFile contents to encode.
string$typeFile's MIME type.
Returns
string Image contents encoded as a data URI or false.

◆ getLocalFileReferences()

static Wikimedia\Minify\CSSMin::getLocalFileReferences ( $source,
$path )
static

Get a list of local files referenced in a stylesheet (includes non-existent files).

Parameters
string$sourceCSS stylesheet source to process
string$pathFile path where the source was read from
Returns
string[] List of local file references

◆ getMimeType()

static Wikimedia\Minify\CSSMin::getMimeType ( $file)
static
Parameters
string$file
Returns
bool|string

◆ isLocalUrl()

static Wikimedia\Minify\CSSMin::isLocalUrl ( $maybeUrl)
staticprotected

Is this CSS rule referencing a local URL?

Parameters
string$maybeUrl
Returns
bool

◆ isRemoteUrl()

static Wikimedia\Minify\CSSMin::isRemoteUrl ( $maybeUrl)
staticprotected

Is this CSS rule referencing a remote URL?

Parameters
string$maybeUrl
Returns
bool

◆ minify()

static Wikimedia\Minify\CSSMin::minify ( $css)
static

Removes whitespace from CSS data.

Parameters
string$cssCSS data to minify
Returns
string Minified CSS data

◆ remap()

static Wikimedia\Minify\CSSMin::remap ( $source,
$local,
$remote,
$embedData = true )
static

Remaps CSS URL paths and automatically embeds data URIs for CSS rules or url() values preceded by an / * @embed * / comment.

Parameters
string$sourceCSS data to remap
string$localFile path where the source was read from
string$remoteFull URL to the file's directory (may be protocol-relative, trailing slash is optional)
bool$embedDataIf false, never do any data URI embedding, even if / * @embed * / is found.
Returns
string Remapped CSS data

◆ remapOne()

static Wikimedia\Minify\CSSMin::remapOne ( $file,
$query,
$local,
$remote,
$embed )
static

Remap or embed a CSS URL path.

Parameters
string$fileURL to remap/embed
string$query
string$localFile path where the source was read from
string$remoteFull URL to the file's directory (may be protocol-relative, trailing slash is optional)
bool$embedWhether to do any data URI embedding
Returns
string Remapped/embedded URL data

◆ serializeStringValue()

static Wikimedia\Minify\CSSMin::serializeStringValue ( $value)
static

Serialize a string (escape and quote) for use as a CSS string value.

https://drafts.csswg.org/cssom/#serialize-a-string

Parameters
string$value
Returns
string

The documentation for this class was generated from the following file: