css-sanitizer
Classes to parse and sanitize CSS
Wikimedia\CSS\Objects\Token Class Reference

Represent a CSS token. More...

+ Inheritance diagram for Wikimedia\CSS\Objects\Token:
+ Collaboration diagram for Wikimedia\CSS\Objects\Token:

Public Member Functions

 __construct ( $type, $value=[])
 
 type ()
 Get the type of this token. More...
 
 value ()
 Get the value of this token. More...
 
 typeFlag ()
 Get the type flag for this T_HASH or numeric token. More...
 
 representation ()
 Get the representation for this numeric token. More...
 
 unit ()
 Get the unit for this T_DIMENSION token. More...
 
 range ()
 Get the unicode range for this T_UNICODE_RANGE token. More...
 
 significant ()
 Whether this token is considered "significant". More...
 
 copyWithSignificance ( $significant)
 Make a copy of this token with altered "significant" flag. More...
 
 toTokenArray ()
 @inheritDoc
 
 toComponentValueArray ()
 @inheritDoc
 
 __toString ()
 
- Public Member Functions inherited from Wikimedia\CSS\Objects\ComponentValue
 getPosition ()
 Get the position of this ComponentValue in the input stream. More...
 

Static Public Member Functions

static separate (Token $firstToken, Token $secondToken)
 Indicate whether the two tokens need to be separated. More...
 

Public Attributes

const T_IDENT = "ident"
 
const T_FUNCTION = "function"
 
const T_AT_KEYWORD = "at-keyword"
 
const T_HASH = "hash"
 
const T_STRING = "string"
 
const T_BAD_STRING = "bad-string"
 
const T_URL = "url"
 
const T_BAD_URL = "bad-url"
 
const T_DELIM = "delim"
 
const T_NUMBER = "number"
 
const T_PERCENTAGE = "percentage"
 
const T_DIMENSION = "dimension"
 
const T_UNICODE_RANGE = "unicode-range"
 
const T_INCLUDE_MATCH = "include-match"
 
const T_DASH_MATCH = "dash-match"
 
const T_PREFIX_MATCH = "prefix-match"
 
const T_SUFFIX_MATCH = "suffix-match"
 
const T_SUBSTRING_MATCH = "substring-match"
 
const T_COLUMN = "column"
 
const T_WHITESPACE = "whitespace"
 
const T_CDO = "CDO"
 
const T_CDC = "CDC"
 
const T_COLON = "colon"
 
const T_SEMICOLON = "semicolon"
 
const T_COMMA = "comma"
 
const T_LEFT_BRACKET = "["
 
const T_RIGHT_BRACKET = "]"
 
const T_LEFT_PAREN = "("
 
const T_RIGHT_PAREN = ")"
 
const T_LEFT_BRACE = "{"
 
const T_RIGHT_BRACE = "}"
 
const T_EOF = "EOF"
 
 $end = 0
 
- Public Attributes inherited from Wikimedia\CSS\Objects\ComponentValue
 $pos = -1
 

Protected Attributes

 $type
 
 $value = ''
 
 $typeFlag = ''
 
 $representation = null
 
 $unit = ''
 
 $start = 0
 
 $significant = true
 
- Protected Attributes inherited from Wikimedia\CSS\Objects\ComponentValue
 $line = -1
 

Detailed Description

Represent a CSS token.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\CSS\Objects\Token::__construct (   $type,
  $value = [] 
)
Parameters
string$typeOne of the T_* constants
string | array$valueValue of the token, or an array with the following keys. Depending on the type, some keys may be required and some may be ignored.
  • value: (string|int|float) Value of the token
  • position: (array) Token position in the input stream. Same format as returned by self::getPosition().
  • typeFlag: (string) Flag for various token types. For T_HASH, 'id' or 'unrestricted'. For T_NUMBER, T_PERCENTAGE, and T_DIMENSION, 'integer' or 'number'.
  • representation: (string) String representation of the value for T_NUMBER, T_PERCENTAGE, and T_DIMENSION.
  • unit: (string) Unit for T_DIMENSION.
  • start: (int) Start code point for T_UNICODE_RANGE.
  • end: (int) End code point for T_UNICODE_RANGE.
  • significant: (bool) Whether the token is considered "significant"

Member Function Documentation

◆ copyWithSignificance()

Wikimedia\CSS\Objects\Token::copyWithSignificance (   $significant)

Make a copy of this token with altered "significant" flag.

Parameters
bool$significantWhether the new token is considered "significant"
Returns
Token May be the same as the current token

◆ range()

Wikimedia\CSS\Objects\Token::range ( )

Get the unicode range for this T_UNICODE_RANGE token.

Returns
array [ int $start, int $end ]

◆ representation()

Wikimedia\CSS\Objects\Token::representation ( )

Get the representation for this numeric token.

Returns
string|null

◆ separate()

static Wikimedia\CSS\Objects\Token::separate ( Token  $firstToken,
Token  $secondToken 
)
static

Indicate whether the two tokens need to be separated.

See also
https://www.w3.org/TR/2014/CR-css-syntax-3-20140220/#serialization
Parameters
Token$firstToken
Token$secondToken
Returns
bool

◆ significant()

bool Whether this token is considered Wikimedia\CSS\Objects\Token::significant ( )

Whether this token is considered "significant".

A token that isn't "significant" may be removed for minification of CSS. For example, most whitespace is entirely optional, as is the semicolon after the last declaration in a block.

Returns
bool

◆ type()

Wikimedia\CSS\Objects\Token::type ( )

Get the type of this token.

Returns
string One of the Token::T_* constants

◆ typeFlag()

Wikimedia\CSS\Objects\Token::typeFlag ( )

Get the type flag for this T_HASH or numeric token.

Returns
string

◆ unit()

Wikimedia\CSS\Objects\Token::unit ( )

Get the unit for this T_DIMENSION token.

Returns
string

◆ value()

Wikimedia\CSS\Objects\Token::value ( )

Get the value of this token.

Returns
string|int|float $value

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