Scss compiler

Compiler extends BaseObject
in package

Table of Contents

$aliases  : array<string|int, mixed>
$cacheCheckImportResolutions  : bool
$cacheFolder  : string
$cacheLifetime  : int
$cleanDestination  : bool
$disableCache  : bool
$fileName  : string
$forceCacheRefresh  : bool
$hashMethod  : string
$importPaths  : array<string|int, mixed>
$publicFolder  : string
$sourcemapOptions  : array<string|int, mixed>
$sourcemaps  : string
$style  : string
$assets  : Assets
$compiler  : Compiler
$definedEvents  : mixed
$destFile  : string
$events  : Events
$fs  : Filesystem
$logger  : LoggerInterface
$plugins  : array<string|int, mixed>
$relativeDestFile  : string
$relativeDestFolder  : string
$sourcemapsMap  : mixed
$srcFile  : string
$srcFolder  : string
__construct()  : mixed
Constructor, configure this object's options
addAlias()  : Compiler
Add an alias
addAsset()  : Compiler
Add an asset
addPlugin()  : mixed
Add a plugin
appendImportPaths()  : self
Add one or several import paths
compile()  : Compiler
Compile some files, files parameter like so [ 'relative/to/srcFolder/app.scss' => 'relative/to/publicFolder/app.css' ]
debug()  : Compiler
Logs a debug message
getAssets()  : Assets
Get the asset manager
getCurrentFile()  : string
Get the current file being compiled
getCurrentFolder()  : string
Get the directory of the file being compiled
getDestFile()  : string
get the destination file of the source file currently compiling
getDestFolder()  : string
Get the destination folder of the source file currently compiling
getEvents()  : Events
Get the event manager
getFilesystem()  : Filesystem
Get the filesystem helper
getHash()  : string
Get a hash for some data
getLineNumber()  : int
Get the line number currently compiled
getRelativeCurrentFolder()  : string
Get the current folder, relative to src folder
getRelativeDestFile()  : string
Get the destination file, relative to the public folder
getRelativeDestFolder()  : string
Get the destination folder, relative to the public folder
getSrcFolder()  : string
Get the source folder (working directory)
on()  : self
Register a callable to an event
prependImportPaths()  : self
Prepend one or several import paths
removeAlias()  : Compiler
Remove an alias
setLogger()  : self
Set the logger
trigger()  : mixed
Triggers an event
warn()  : Compiler
Logs a warn message
_compile()  : mixed
Compile a file
checkOptions()  : mixed
Checks the validity of compiler options
cleanFolder()  : mixed
Clean a folder
extractAssets()  : mixed
Parse css and extract assets
getCompiler()  : Compiler
Get the Scss Compiler
import()  : string|null
Custom import function, resolve aliases and look into all import paths
optimize()  : mixed
sanitizePath()  : string
Sanitize a path, remove beginning and ending quotes and double quotes
utf8_byte_offset_to_unit()  : int|null
Transform a byte offset to a position in the string
writeAssets()  : mixed
Write assets on disk
writeSourcemaps()  : Asset|null

Properties

$aliases

public array<string|int, mixed> $aliases = []

$cacheCheckImportResolutions

public bool $cacheCheckImportResolutions = true

Cache checks import resolutions

$cacheFolder

public string $cacheFolder = __DIR__ . '/cache'

Cache directory

$cacheLifetime

public int $cacheLifetime = 604800

Cache lifetime

$cleanDestination

public bool $cleanDestination = true

Clean destination directory before compiling

$disableCache

public bool $disableCache = false

Disables compiler cache

$fileName

public string $fileName = '[name].[hash]'

Destination file name format

$forceCacheRefresh

public bool $forceCacheRefresh = false

Force cache refresh

$importPaths

public array<string|int, mixed> $importPaths = []

Import paths to resolve imports

$publicFolder

public string $publicFolder

Absolute public path

$sourcemapOptions

public array<string|int, mixed> $sourcemapOptions = ['sourceMapRootpath' => '/']

as defined by ScssPhp\ScssPhp\SourceMap\SourceMapGenerator::defaultOptions

$sourcemaps

public string $sourcemaps = 'file'

Sourcemaps : 'none', 'inline' or 'file'

$style

public string $style = 'expanded'

Css output style, 'expanded' or 'minified' Minifying the css will make the sitemaps innaccurate

$definedEvents

protected mixed $definedEvents = ['beforeCompile', 'afterCompile', 'beforeCompileFile', 'afterCompileFile', 'beforeWriteAssets', 'afterWriteAssets', 'beforeAddAsset', 'afterAddAsset', 'extractAsset', 'beforeExtractAssets', 'afterExtractAssets', 'beforeOptimize', 'afterOptimize', 'beforeWriteSourcemaps', 'afterWriteSourcemaps', 'importNotFound']

$destFile

protected string $destFile

Absolute destination file

$logger

protected LoggerInterface $logger

$plugins

protected array<string|int, mixed> $plugins = []

$relativeDestFile

protected string $relativeDestFile

Relative destination file path

$relativeDestFolder

protected string $relativeDestFolder

Relative destination folder

$sourcemapsMap

protected mixed $sourcemapsMap = ['none' => \ScssPhp\ScssPhp\Compiler::SOURCE_MAP_NONE, 'inline' => \ScssPhp\ScssPhp\Compiler::SOURCE_MAP_INLINE, 'file' => \ScssPhp\ScssPhp\Compiler::SOURCE_MAP_FILE]

$srcFile

protected string $srcFile

Current source file

$srcFolder

protected string $srcFolder

Current source folder

Methods

__construct()

Constructor, configure this object's options

public __construct([array<string|int, mixed> $options = [] ][, array<string|int, mixed> $plugins = [] ][, LoggerInterface|null $logger = null ]) : mixed
Parameters
$options : array<string|int, mixed> = []
$plugins : array<string|int, mixed> = []
$logger : LoggerInterface|null = null
Return values
mixed

addAlias()

Add an alias

public addAlias(string $alias, string $subFolder) : Compiler
Parameters
$alias : string
$subFolder : string
Return values
Compiler

appendImportPaths()

Add one or several import paths

public appendImportPaths(string|array<string|int, mixed> $path) : self
Parameters
$path : string|array<string|int, mixed>
Return values
self

compile()

Compile some files, files parameter like so [ 'relative/to/srcFolder/app.scss' => 'relative/to/publicFolder/app.css' ]

public compile(array<string|int, mixed> $files, string $srcFolder[, string $srcFile = null ]) : Compiler
Parameters
$files : array<string|int, mixed>
$srcFolder : string
$srcFile : string = null

override the source file to resolve import. This is used when the scss imports scss or assets that are in a different folder altogether

Return values
Compiler

debug()

Logs a debug message

public debug(mixed $message) : Compiler
Parameters
$message : mixed
Return values
Compiler

getCurrentFile()

Get the current file being compiled

public getCurrentFile() : string
Return values
string

getCurrentFolder()

Get the directory of the file being compiled

public getCurrentFolder() : string
Return values
string

getDestFile()

get the destination file of the source file currently compiling

public getDestFile() : string
Return values
string

getDestFolder()

Get the destination folder of the source file currently compiling

public getDestFolder() : string
Return values
string

getFilesystem()

Get the filesystem helper

public getFilesystem() : Filesystem
Return values
Filesystem

getHash()

Get a hash for some data

public getHash(string $data) : string
Parameters
$data : string
Return values
string

getLineNumber()

Get the line number currently compiled

public getLineNumber() : int
Return values
int

getRelativeCurrentFolder()

Get the current folder, relative to src folder

public getRelativeCurrentFolder() : string
Return values
string

getRelativeDestFile()

Get the destination file, relative to the public folder

public getRelativeDestFile() : string
Return values
string

getRelativeDestFolder()

Get the destination folder, relative to the public folder

public getRelativeDestFolder() : string
Return values
string

getSrcFolder()

Get the source folder (working directory)

public getSrcFolder() : string
Return values
string

on()

Register a callable to an event

public on(string $event, array<string|int, mixed>|function $callable[, int $order = 10 ]) : self
Parameters
$event : string
$callable : array<string|int, mixed>|function
$order : int = 10
Return values
self

prependImportPaths()

Prepend one or several import paths

public prependImportPaths(string|array<string|int, mixed> $path) : self
Parameters
$path : string|array<string|int, mixed>
Return values
self

removeAlias()

Remove an alias

public removeAlias(string $alias) : Compiler
Parameters
$alias : string
Return values
Compiler

setLogger()

Set the logger

public setLogger(LoggerInterface|null $logger) : self
Parameters
$logger : LoggerInterface|null
Return values
self

trigger()

Triggers an event

public trigger(string $event[, array<string|int, mixed> $params = [] ][, mixed $returnValue = null ][, bool $stopOnValue = false ]) : mixed
Parameters
$event : string
$params : array<string|int, mixed> = []
$returnValue : mixed = null

The value that should be returned at the end (if not modified)

$stopOnValue : bool = false

Should the event stop when it gets a value (not null) from a callback

Return values
mixed

warn()

Logs a warn message

public warn(mixed $message[, bool $deprecation = false ]) : Compiler
Parameters
$message : mixed
$deprecation : bool = false
Return values
Compiler

_compile()

Compile a file

protected _compile(string $scssFile) : mixed
Parameters
$scssFile : string
Return values
mixed

cleanFolder()

Clean a folder

protected cleanFolder(string $folder) : mixed
Parameters
$folder : string
Return values
mixed

getCompiler()

Get the Scss Compiler

protected getCompiler() : Compiler
Return values
Compiler

import()

Custom import function, resolve aliases and look into all import paths

protected import(string $path) : string|null
Parameters
$path : string
Return values
string|null

sanitizePath()

Sanitize a path, remove beginning and ending quotes and double quotes

protected sanitizePath(string $path) : string
Parameters
$path : string
Return values
string

utf8_byte_offset_to_unit()

Transform a byte offset to a position in the string

protected utf8_byte_offset_to_unit(string $string, int $boff) : int|null
Parameters
$string : string
$boff : int
Return values
int|null

writeAssets()

Write assets on disk

protected writeAssets() : mixed
Return values
mixed

Search results