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.
 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 ()
 Get an array of the found variables in the parsed input.
 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.
 getParsedFiles ()
 parseNode ( $str, array $parseList, $currentIndex, $fileInfo)
 Used after initial parsing to create nodes on the fly.
 parseConditionAnd ( $needsParens)
 negatedCondition ( $needsParens)
 parenthesisCondition ( $needsParens)
 atomicCondition ()
 Error ( $msg)
 CacheEnabled ()

Static Public Member Functions

static serializeVars ( $vars)
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

◆ atomicCondition()

Less_Parser::atomicCondition ( )
See also
less-3.13.1.js#Parser.atomicCondition

◆ 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 ( )

Get an array of the found variables in the parsed input.

Returns
array

◆ ModifyVars()

Less_Parser::ModifyVars ( $vars)

Allows a user to set variables values.

Parameters
array$vars
Returns
$this

◆ negatedCondition()

Less_Parser::negatedCondition ( $needsParens)
See also
less-3.13.1.js#Parser.negatedCondition

◆ parenthesisCondition()

Less_Parser::parenthesisCondition ( $needsParens)
See also
less-3.13.1.js#Parser.parenthesisCondition

◆ 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

◆ parseConditionAnd()

Less_Parser::parseConditionAnd ( $needsParens)
See also
less-3.13.1.js#Parser.conditionAnd

◆ 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

◆ parseNode()

Less_Parser::parseNode ( $str,
array $parseList,
$currentIndex,
$fileInfo )

Used after initial parsing to create nodes on the fly.

Parameters
string$strstring to parse
string[]$parseListarray of parsers to run input through e.g. ["value", "important"]
int$currentIndexstart number to begin indexing
array$fileInfofileInfo to attach to created nodes
Returns
array
See also
less-3.13.1.js#Parser.parseNode

◆ 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 Use Less_Cache::SetCacheDir instead.

◆ 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$dirsThe 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:
  • lib/Less/Parser.php