CSS
extends PHP
in package
Table of Contents
- $endScopeTokens : array<string|int, mixed>
- A list of tokens that end the scope.
- $ignoredLines : array<string|int, mixed>
- A list of lines being ignored due to error suppression comments.
- $knownLengths : array<int, int>
- Known lengths of tokens.
- $scopeOpeners : array<string|int, mixed>
- A list of tokens that are allowed to open a scope.
- $config : Config
- The config data for the run.
- $eolChar : string
- The EOL char used in the content.
- $numTokens : int
- The number of tokens in the tokens array.
- $tokens : array<string|int, mixed>
- A token-based representation of the content.
- $tstringContexts : array<string|int, mixed>
- Contexts in which keywords should always be tokenized as T_STRING.
- $resolveTokenCache : array<string|int, mixed>
- A cache of different token types, resolved into arrays.
- __construct() : void
- Initialise the tokenizer.
- getTokens() : array<string|int, mixed>
- Gets the array of tokens.
- processAdditional() : void
- Performs additional processing after main tokenizing.
- replaceTabsInToken() : void
- Replaces tabs in original token content with spaces.
- resolveSimpleToken() : array<string|int, mixed>
- Converts simple tokens into a format that conforms to complex tokens produced by token_get_all().
- standardiseToken() : array<string|int, mixed>
- Takes a token produced from <code>token_get_all()</code> and produces a more uniform token.
- tokenize() : array<string|int, mixed>
- Creates an array of tokens when given some CSS code.
- isMinifiedContent() : bool
- Checks the content to see if it looks minified.
- createAttributesNestingMap() : void
- Creates a map for the attributes tokens that surround other tokens.
- createLevelMap() : void
- Constructs the level map.
- createParenthesisNestingMap() : void
- Creates a map for the parenthesis tokens that surround other tokens.
- createPositionMap() : void
- Sets token position information.
- createScopeMap() : void
- Creates a scope map of tokens that open scopes.
- createTokenMap() : void
- Creates a map of brackets positions.
- findCloser() : int|null
- Finds a "closer" token (closing parenthesis or square bracket for example) Handle parenthesis balancing while searching for closing token
- parsePhpAttribute() : array<string|int, mixed>|null
- PHP 8 attributes parser for PHP < 8 Handles single-line and multiline attributes.
- recurseScopeMap() : int
- Recurses though the scope openers to build a scope map.
Properties
$endScopeTokens
A list of tokens that end the scope.
public
array<string|int, mixed>
$endScopeTokens
= []
$ignoredLines
A list of lines being ignored due to error suppression comments.
public
array<string|int, mixed>
$ignoredLines
= []
$knownLengths
Known lengths of tokens.
public
array<int, int>
$knownLengths
= []
$scopeOpeners
A list of tokens that are allowed to open a scope.
public
array<string|int, mixed>
$scopeOpeners
= []
$config
The config data for the run.
protected
Config
$config
= null
$eolChar
The EOL char used in the content.
protected
string
$eolChar
= []
$numTokens
The number of tokens in the tokens array.
protected
int
$numTokens
= 0
$tokens
A token-based representation of the content.
protected
array<string|int, mixed>
$tokens
= []
$tstringContexts
Contexts in which keywords should always be tokenized as T_STRING.
protected
array<string|int, mixed>
$tstringContexts
= [T_OBJECT_OPERATOR => true, T_NULLSAFE_OBJECT_OPERATOR => true, T_FUNCTION => true, T_CLASS => true, T_INTERFACE => true, T_TRAIT => true, T_EXTENDS => true, T_IMPLEMENTS => true, T_ATTRIBUTE => true, T_NEW => true, T_CONST => true, T_NS_SEPARATOR => true, T_USE => true, T_NAMESPACE => true, T_PAAMAYIM_NEKUDOTAYIM => true]
$resolveTokenCache
A cache of different token types, resolved into arrays.
private
static array<string|int, mixed>
$resolveTokenCache
= []
Tags
Methods
__construct()
Initialise the tokenizer.
public
__construct(string $content, Config $config[, string $eolChar = '\n' ]) : void
Pre-checks the content to see if it looks minified.
Parameters
- $content : string
-
The content to tokenize,
- $config : Config
-
The config data for the run.
- $eolChar : string = '\n'
-
The EOL char used in the content.
Tags
Return values
void —getTokens()
Gets the array of tokens.
public
getTokens() : array<string|int, mixed>
Return values
array<string|int, mixed> —processAdditional()
Performs additional processing after main tokenizing.
public
processAdditional() : void
Return values
void —replaceTabsInToken()
Replaces tabs in original token content with spaces.
public
replaceTabsInToken(array<string|int, mixed> &$token[, string $prefix = ' ' ][, string $padding = ' ' ][, int $tabWidth = null ]) : void
Each tab can represent between 1 and $config->tabWidth spaces, so this cannot be a straight string replace. The original content is placed into an orig_content index and the new token length is also set in the length index.
Parameters
- $token : array<string|int, mixed>
-
The token to replace tabs inside.
- $prefix : string = ' '
-
The character to use to represent the start of a tab.
- $padding : string = ' '
-
The character to use to represent the end of a tab.
- $tabWidth : int = null
-
The number of spaces each tab represents.
Return values
void —resolveSimpleToken()
Converts simple tokens into a format that conforms to complex tokens produced by token_get_all().
public
static resolveSimpleToken(string $token) : array<string|int, mixed>
Simple tokens are tokens that are not in array form when produced from token_get_all().
Parameters
- $token : string
-
The simple token to convert.
Return values
array<string|int, mixed> —The new token in array format.
standardiseToken()
Takes a token produced from <code>token_get_all()</code> and produces a more uniform token.
public
static standardiseToken(string|array<string|int, mixed> $token) : array<string|int, mixed>
Parameters
- $token : string|array<string|int, mixed>
-
The token to convert.
Return values
array<string|int, mixed> —The new token.
tokenize()
Creates an array of tokens when given some CSS code.
public
tokenize(string $string) : array<string|int, mixed>
Uses the PHP tokenizer to do all the tricky work
Parameters
- $string : string
-
The string to tokenize.
Return values
array<string|int, mixed> —isMinifiedContent()
Checks the content to see if it looks minified.
protected
isMinifiedContent(string $content[, string $eolChar = '\n' ]) : bool
Parameters
- $content : string
-
The content to tokenize.
- $eolChar : string = '\n'
-
The EOL char used in the content.
Return values
bool —createAttributesNestingMap()
Creates a map for the attributes tokens that surround other tokens.
private
createAttributesNestingMap() : void
Return values
void —createLevelMap()
Constructs the level map.
private
createLevelMap() : void
The level map adds a 'level' index to each token which indicates the depth that a token within a set of scope blocks. It also adds a 'conditions' index which is an array of the scope conditions that opened each of the scopes - position 0 being the first scope opener.
Return values
void —createParenthesisNestingMap()
Creates a map for the parenthesis tokens that surround other tokens.
private
createParenthesisNestingMap() : void
Return values
void —createPositionMap()
Sets token position information.
private
createPositionMap() : void
Can also convert tabs into spaces. Each tab can represent between 1 and $width spaces, so this cannot be a straight string replace.
Return values
void —createScopeMap()
Creates a scope map of tokens that open scopes.
private
createScopeMap() : void
Tags
Return values
void —createTokenMap()
Creates a map of brackets positions.
private
createTokenMap() : void
Return values
void —findCloser()
Finds a "closer" token (closing parenthesis or square bracket for example) Handle parenthesis balancing while searching for closing token
private
findCloser(array<string|int, mixed> &$tokens, int $start, string|array<string|int, string> $openerTokens, string $closerChar) : int|null
Parameters
- $tokens : array<string|int, mixed>
-
The list of tokens to iterate searching the closing token (as returned by token_get_all)
- $start : int
-
The starting position
- $openerTokens : string|array<string|int, string>
-
The opening character
- $closerChar : string
-
The closing character
Return values
int|null —The position of the closing token, if found. NULL otherwise.
parsePhpAttribute()
PHP 8 attributes parser for PHP < 8 Handles single-line and multiline attributes.
private
parsePhpAttribute(array<string|int, mixed> &$tokens, int $stackPtr) : array<string|int, mixed>|null
Parameters
- $tokens : array<string|int, mixed>
-
The original array of tokens (as returned by token_get_all)
- $stackPtr : int
-
The current position in token array
Return values
array<string|int, mixed>|null —The array of parsed attribute tokens
recurseScopeMap()
Recurses though the scope openers to build a scope map.
private
recurseScopeMap(int $stackPtr[, int $depth = 1 ], int &$ignore) : int
Parameters
- $stackPtr : int
-
The position in the stack of the token that opened the scope (eg. an IF token or FOR token).
- $depth : int = 1
-
How many scope levels down we are.
- $ignore : int
-
How many curly braces we are ignoring.
Tags
Return values
int —The position in the stack that closed the scope.