wikimedia/less.php
PHP port of the LESS processor
Loading...
Searching...
No Matches
Less_Parser Class Reference

Parse and compile Less files into CSS. More...

Public Member Functions

 __construct ( $env=null)
 
 Reset ( $options=null)
 Reset the parser state completely.
 
 SetOptions ( $options)
 Set one or more compiler options options: import_dirs, cache_dir, cache_method.
 
 SetOption ( $option, $value)
 Set one compiler option.
 
 registerFunction ( $name, $callback)
 Registers a new custom function.
 
 unregisterFunction ( $name)
 Removed an already registered function.
 
 getCss ()
 Get the current css buffer.
 
 findValueOf ( $varName)
 
 getVariables ()
 Gets the private rules variable and returns an array of the found variables it uses a helper method getVariableValue() that contains the logic ot fetch the value from the rule object.
 
 findVarByName ( $var_name)
 
 parse ( $str, $file_uri=null)
 Parse a Less string.
 
 parseFile ( $filename, $uri_root='', $returnRoot=false)
 Parse a Less string from a given file.
 
 ModifyVars ( $vars)
 Allows a user to set variables values.
 
 SetFileInfo ( $filename, $uri_root='')
 
 SetCacheDir ( $dir)
 
 SetImportDirs ( $dirs)
 Set a list of directories or callbacks the parser should use for determining import paths.
 
 SetInput ( $file_path)
 
 UnsetInput ()
 
 CacheFile ( $file_path)
 
 getParsedFiles ()
 
 save ()
 
 Error ( $msg)
 
 CacheEnabled ()
 

Static Public Member Functions

static AllParsedFiles ()
 
static serializeVars ( $vars)
 
static is_method ( $a, $b)
 Some versions of PHP have trouble with method_exists($a,$b) if $a is not an object.
 
static round ( $input, $precision=0)
 Round numbers similarly to javascript eg: 1.499999 to 1 instead of 2.
 
static WinPath ( $path)
 
static AbsPath ( $path, $winPath=false)
 

Static Public Attributes

static $default_options
 
static $options = []
 
static $has_extends = false
 
static $next_id = 0
 
static $contentsMap = []
 

Protected Attributes

 $rules = []
 

Detailed Description

Parse and compile Less files into CSS.

Constructor & Destructor Documentation

◆ __construct()

Less_Parser::__construct ( $env = null)
Parameters
Less_Environment | array | null$env

Member Function Documentation

◆ AllParsedFiles()

static Less_Parser::AllParsedFiles ( )
static
Deprecated
since 4.3.0 Use $parser->getParsedFiles() instead.
Returns
string[]

◆ Error()

Less_Parser::Error ( $msg)
Returns
never

◆ getCss()

Less_Parser::getCss ( )

Get the current css buffer.

Returns
string

◆ getParsedFiles()

Less_Parser::getParsedFiles ( )
Since
4.3.0
Returns
string[]

◆ getVariables()

Less_Parser::getVariables ( )

Gets the private rules variable and returns an array of the found variables it uses a helper method getVariableValue() that contains the logic ot fetch the value from the rule object.

Returns
array

◆ is_method()

static Less_Parser::is_method ( $a,
$b )
static

Some versions of PHP have trouble with method_exists($a,$b) if $a is not an object.

Parameters
mixed$a
string$b

◆ ModifyVars()

Less_Parser::ModifyVars ( $vars)

Allows a user to set variables values.

Parameters
array$vars
Returns
$this

◆ parse()

Less_Parser::parse ( $str,
$file_uri = null )

Parse a Less string.

Exceptions
Less_Exception_ParserIf the compiler encounters invalid syntax
Parameters
string$strThe string to convert
string | null$file_uriThe url of the file
Returns
$this

◆ parseFile()

Less_Parser::parseFile ( $filename,
$uri_root = '',
$returnRoot = false )

Parse a Less string from a given file.

Exceptions
Less_Exception_ParserIf the compiler encounters invalid syntax
Parameters
string$filenameThe file to parse
string$uri_rootThe url of the file
bool$returnRootIndicates whether the return value should be a css string a root node
Returns
Less_Tree_Ruleset|$this

◆ registerFunction()

Less_Parser::registerFunction ( $name,
$callback )

Registers a new custom function.

Parameters
string$namefunction name
callable$callbackcallback

◆ SetCacheDir()

Less_Parser::SetCacheDir ( $dir)
Deprecated
1.5.1.2

◆ SetFileInfo()

Less_Parser::SetFileInfo ( $filename,
$uri_root = '' )
Parameters
string$filename
string$uri_root

◆ SetImportDirs()

Less_Parser::SetImportDirs ( $dirs)

Set a list of directories or callbacks the parser should use for determining import paths.

Import closures are called with a single $path argument containing the unquoted @import string an input LESS file. The string is unchanged, except for a statically appended ".less" suffix if the basename does not yet contain a dot. If a dot is present in the filename, you are responsible for choosing whether to expand "foo.bar" to "foo.bar.less". If your callback can handle this import statement, return an array with an absolute file path and an optional URI path, or return void/null to indicate that your callback does not handle this import statement.

Example:

function ( $path ) {
    if ( $path === 'virtual/something.less' ) {
        return [ '/srv/elsewhere/thing.less', null ];
    }
}
Parameters
array<string|callable>$dirs The key should be a server directory from which LESS files may be imported. The value is an optional public URL or URL base path that corresponds to the same directory (use empty string otherwise). The value may also be a closure, in which case the key is ignored.

◆ unregisterFunction()

Less_Parser::unregisterFunction ( $name)

Removed an already registered function.

Parameters
string$namefunction name

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