Shrink
in package
Shrink class
This class is responsible for shrinking CSS and JS files.
It provides methods to add CSS and JS files, and to shrink them.
Tags
Table of Contents
Properties
- $CSS : CSS
- $cssPaths : array<string|int, mixed>
- $JS : JS
- $jsPaths : array<string|int, mixed>
- $logger : T4LOG
- $option : array<string|int, mixed>
Methods
- __construct() : mixed
- Shrink constructor.
- __destruct() : mixed
- Destructs the object and removes all the CSS and JavaScript paths from memory.
- addCss() : void
- Adds a CSS file to be shrunk.
- addJs() : void
- Adds a JavaScript file to be shrunk.
- autoScanCssDir() : void
- Automatically scans a directory for CSS files and adds them to be shrunk.
- autoScanJsDir() : void
- Automatically scans a directory for JavaScript files and adds them to be shrunk.
- css() : string
- Returns the minified CSS content from the given file path.
- cssWithSave() : string
- Returns the minified CSS content from the given file path and saves it to a target path.
- js() : string
- Shrink a JavaScript file.
- jsWithSave() : string
- Shrink a JavaScript file with save.
- save() : void
- Saves the shrunk CSS and JavaScript files.
Properties
$CSS
private
static CSS
$CSS
$cssPaths
private
array<string|int, mixed>
$cssPaths
= []
$JS
private
static JS
$JS
$jsPaths
private
array<string|int, mixed>
$jsPaths
= []
$logger
private
T4LOG
$logger
$option
private
array<string|int, mixed>
$option
Methods
__construct()
Shrink constructor.
public
__construct(T4LOG $logger, array<string|int, mixed> $option) : mixed
Parameters
- $logger : T4LOG
-
logger instance
- $option : array<string|int, mixed>
-
options for shrink
__destruct()
Destructs the object and removes all the CSS and JavaScript paths from memory.
public
__destruct() : mixed
This method is called when the object is destroyed. It will remove all the CSS and JavaScript paths from memory.
addCss()
Adds a CSS file to be shrunk.
public
addCss(string $path) : void
Parameters
- $path : string
-
The path to the CSS file.
Tags
addJs()
Adds a JavaScript file to be shrunk.
public
addJs(string $path) : void
Parameters
- $path : string
-
The path to the JavaScript file.
Tags
autoScanCssDir()
Automatically scans a directory for CSS files and adds them to be shrunk.
public
autoScanCssDir(string $dirPath) : void
Parameters
- $dirPath : string
-
The path to the directory to be scanned.
Tags
autoScanJsDir()
Automatically scans a directory for JavaScript files and adds them to be shrunk.
public
autoScanJsDir(string $dirPath) : void
This method scans a given directory for JavaScript files and adds them to be shrunk.
Parameters
- $dirPath : string
-
The path to the directory to be scanned.
Tags
css()
Returns the minified CSS content from the given file path.
public
css(string $path) : string
Parameters
- $path : string
-
The path to the CSS file.
Tags
Return values
string —The minified CSS content.
cssWithSave()
Returns the minified CSS content from the given file path and saves it to a target path.
public
cssWithSave(string $path, string $targetPath) : string
Parameters
- $path : string
-
The path to the CSS file.
- $targetPath : string
-
The path where the minified CSS content will be saved.
Tags
Return values
string —The minified CSS content.
js()
Shrink a JavaScript file.
public
js(string $path) : string
This method shrinks a given JavaScript file.
Parameters
- $path : string
-
The path to the JavaScript file.
Tags
Return values
string —The shrunk JavaScript code.
jsWithSave()
Shrink a JavaScript file with save.
public
jsWithSave(string $path, string $targetPath) : string
This method shrinks a given JavaScript file and saves the result to a target path.
Parameters
- $path : string
-
The path to the JavaScript file.
- $targetPath : string
-
The path where the shrunk JavaScript content will be saved.
Tags
Return values
string —The shrunk JavaScript code.
save()
Saves the shrunk CSS and JavaScript files.
public
save() : void
This method saves the shrunk CSS and JavaScript files to the designated paths.