CssLoader
in package
Table of Contents
Properties
Methods
- __construct() : mixed
- extractExternalStylesheetUrls() : array<string|int, mixed>
- Extract external stylesheet URLs from HTML.
- loadStylesheet() : string
- Fetch and return the CSS from $path
- processDataUriImages() : string
- Process data URI images in CSS.
- processExternalCssImports() : string
- Locate embedded @import stylesheets in other stylesheets and fix url paths (including background-images) relative to stylesheet
- resolveBackgroundUrls() : string
- Resolve background image URLs in CSS.
Properties
$assetFetcher
private
AssetFetcher
$assetFetcher
$cache
private
Cache
$cache
$mpdf
private
Mpdf
$mpdf
Methods
__construct()
public
__construct(Mpdf $mpdf, AssetFetcher $assetFetcher, Cache $cache) : mixed
Parameters
- $mpdf : Mpdf
- $assetFetcher : AssetFetcher
- $cache : Cache
extractExternalStylesheetUrls()
Extract external stylesheet URLs from HTML.
public
extractExternalStylesheetUrls(string $html) : array<string|int, mixed>
Finds all external CSS file references including:
- @import url(...)
- @import "..."
Parameters
- $html : string
-
HTML content to scan
Return values
array<string|int, mixed> —Array of CSS file URLs
loadStylesheet()
Fetch and return the CSS from $path
public
loadStylesheet(string $path) : string
Parameters
- $path : string
Tags
Return values
stringprocessDataUriImages()
Process data URI images in CSS.
public
processDataUriImages(string $cssStr) : string
Converts data URI images to temporary files for processing. Example: url(data:image/png;base64,...) becomes url("tempfile.png")
Parameters
- $cssStr : string
-
CSS string potentially containing data URIs
Tags
Return values
string —CSS string with data URIs replaced by temp file references
processExternalCssImports()
Locate embedded @import stylesheets in other stylesheets and fix url paths (including background-images) relative to stylesheet
public
processExternalCssImports(string $stylesheetCss, string $path, array<string|int, mixed> &$externalCss, int &$externalCssCount) : string
Parameters
- $stylesheetCss : string
- $path : string
- $externalCss : array<string|int, mixed>
- $externalCssCount : int
Return values
stringresolveBackgroundUrls()
Resolve background image URLs in CSS.
public
resolveBackgroundUrls(string $cssStr[, string|null $basePath = null ]) : string
Converts relative URLs to absolute paths using Path::relativeToAbsolute. Skips data URIs which are already absolute.
Parameters
- $cssStr : string
-
CSS string potentially containing background URLs
- $basePath : string|null = null
-
Optional base path for resolving relative URLs
Return values
string —CSS string with resolved URLs