Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5955870
KeywordMatcher.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
KeywordMatcher.php
View Options
<?php
/**
* @file
* @license https://opensource.org/licenses/Apache-2.0 Apache-2.0
*/
namespace
Wikimedia\CSS\Grammar
;
use
Wikimedia\CSS\Objects\ComponentValueList
;
use
Wikimedia\CSS\Objects\Token
;
/**
* Matcher that matches one of a set of keywords, case-insensitively
*
* This is intended for matching specific <ident-token>s, but will work for
* other types (case-insensitively) too. For delimiter (or case-sensitive)
* matching, use DelimMatcher.
*
* @see https://www.w3.org/TR/2019/CR-css-values-3-20190606/#component-types
*/
class
KeywordMatcher
extends
Matcher
{
/** @var string One of the Token::T_* constants */
protected
$type
;
/** @var array Associative array with keys being the values to match */
protected
$values
;
/**
* @param string|string[] $values Token values to match
* @param array $options Options
* - type: (string) Token type to match. Default is Token::T_IDENT.
*/
public
function
__construct
(
$values
,
array
$options
=
[]
)
{
$options
+=
[
'type'
=>
Token
::
T_IDENT
,
];
$this
->
values
=
array_flip
(
array_map
(
'strtolower'
,
(
array
)
$values
)
);
$this
->
type
=
$options
[
'type'
];
}
/** @inheritDoc */
protected
function
generateMatches
(
ComponentValueList
$values
,
$start
,
array
$options
)
{
$cv
=
$values
[
$start
]
??
null
;
if
(
$cv
instanceof
Token
&&
$cv
->
type
()
===
$this
->
type
&&
isset
(
$this
->
values
[
strtolower
(
$cv
->
value
()
)]
)
)
{
yield
$this
->
makeMatch
(
$values
,
$start
,
$this
->
next
(
$values
,
$start
,
$options
)
);
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Oct 3, 04:02 (3 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
51/e6/1870aa542856a7a74602203478f6
Default Alt Text
KeywordMatcher.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment