/* Protected Static Members */
/** @var array List of common image files extensions and MIME-types */
- protected static $mimeTypes = array(
+ protected static $mimeTypes = [
'gif' => 'image/gif',
'jpe' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'tiff' => 'image/tiff',
'xbm' => 'image/x-xbitmap',
'svg' => 'image/svg+xml',
- );
+ ];
/* Static Methods */
*/
public static function getLocalFileReferences( $source, $path = null ) {
if ( $path === null ) {
- return array();
+ return [];
}
$files = self::getAllLocalFileReferences( $source, $path );
public static function getAllLocalFileReferences( $source, $path ) {
$stripped = preg_replace( '/' . self::COMMENT_REGEX . '/s', '', $source );
$path = rtrim( $path, '/' ) . '/';
- $files = array();
+ $files = [];
$rFlags = PREG_OFFSET_CAPTURE | PREG_SET_ORDER;
if ( preg_match_all( '/' . self::URL_REGEX . '/', $stripped, $matches, $rFlags ) ) {
if ( strstr( $value, "\0" ) ) {
throw new Exception( "Invalid character in CSS string" );
}
- $value = strtr( $value, array( '\\' => '\\\\', '"' => '\\"' ) );
+ $value = strtr( $value, [ '\\' => '\\\\', '"' => '\\"' ] );
$value = preg_replace_callback( '/[\x01-\x1f\x7f-\x9f]/', function ( $match ) {
return '\\' . base_convert( ord( $match[0] ), 10, 16 ) . ' ';
}, $value );
if ( preg_match( '!^[\w\d:@/~.%+;,?&=-]+$!', $url ) ) {
return "url($url)";
} else {
- return 'url("' . strtr( $url, array( '\\' => '\\\\', '"' => '\\"' ) ) . '")';
+ return 'url("' . strtr( $url, [ '\\' => '\\\\', '"' => '\\"' ] ) . '")';
}
}
// Replace all comments by a placeholder so they will not interfere with the remapping.
// Warning: This will also catch on anything looking like the start of a comment between
// quotation marks (e.g. "foo /* bar").
- $comments = array();
+ $comments = [];
$pattern = '/(?!' . CSSMin::EMBED_REGEX . ')(' . CSSMin::COMMENT_REGEX . ')/s';
if ( $embedData ) {
// Remember the occurring MIME types to avoid fallbacks when embedding some files.
- $mimeTypes = array();
+ $mimeTypes = [];
$ruleWithEmbedded = preg_replace_callback(
$pattern,
);
// Are all referenced images SVGs?
- $needsEmbedFallback = $mimeTypes !== array( 'image/svg+xml' => true );
+ $needsEmbedFallback = $mimeTypes !== [ 'image/svg+xml' => true ];
}
if ( !$embedData || $ruleWithEmbedded === $ruleWithRemapped ) {
public static function minify( $css ) {
return trim(
str_replace(
- array( '; ', ': ', ' {', '{ ', ', ', '} ', ';}' ),
- array( ';', ':', '{', '{', ',', '}', '}' ),
- preg_replace( array( '/\s+/', '/\/\*.*?\*\//s' ), array( ' ', '' ), $css )
+ [ '; ', ': ', ' {', '{ ', ', ', '} ', ';}' ],
+ [ ';', ':', '{', '{', ',', '}', '}' ],
+ preg_replace( [ '/\s+/', '/\/\*.*?\*\//s' ], [ ' ', '' ], $css )
)
);
}