css-sanitizer
Classes to parse and sanitize CSS
Loading...
Searching...
No Matches
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.
 
 value ()
 Get the value of this token.
 
 typeFlag ()
 Get the type flag for this T_HASH or numeric token.
 
 representation ()
 Get the representation for this numeric token.
 
 unit ()
 Get the unit for this T_DIMENSION token.
 
 significant ()
 Whether this token is considered "significant".
 
 copyWithSignificance ( $significant)
 Make a copy of this token with altered "significant" flag.
 
 toTokenArray ()
 @inheritDoc
 
 toComponentValueArray ()
 @inheritDoc
 
 __toString ()
 
 urangeHack ( $hack=null)
 Allow for marking the 'U' T_IDENT beginning a <urange>, to later avoid serializing it with extraneous comments.
 
- Public Member Functions inherited from Wikimedia\CSS\Objects\ComponentValue
 getPosition ()
 Get the position of this ComponentValue in the input stream.
 

Static Public Member Functions

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

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_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"
 

Protected Attributes

 $type
 
 $value = ''
 
 $typeFlag = ''
 
 $representation = null
 
 $unit = ''
 
 $significant = true
 
- Protected Attributes inherited from Wikimedia\CSS\Objects\ComponentValue
 $line = -1
 
 $pos = -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.
  • 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

◆ 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/2019/CR-css-syntax-3-20190716/#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

◆ toComponentValueArray()

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

@inheritDoc

Reimplemented from Wikimedia\CSS\Objects\ComponentValue.

◆ toTokenArray()

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

@inheritDoc

Implements Wikimedia\CSS\Objects\CSSObject.

◆ 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: