MediaWiki  master
MagicWordArray Class Reference

Class for handling an array of magic words. More...

Collaboration diagram for MagicWordArray:

Public Member Functions

 __construct ( $names=[], MagicWordFactory $factory=null)
 
 add ( $name)
 Add a magic word by name. More...
 
 addArray ( $names)
 Add a number of magic words by name. More...
 
 getBaseRegex (bool $capture=true, string $delimiter='/')
 Get the base regex. More...
 
 getHash ()
 Get a 2-d hashtable for this array. More...
 
 getNames ()
 
 getRegex ()
 Get an unanchored regex that does not match parameters. More...
 
 getRegexStart ()
 Get a regex anchored to the start of the string that does not match parameters. More...
 
 getVariableRegex ()
 Get a regex for matching variables with parameters. More...
 
 getVariableStartToEndRegex ()
 Get an anchored regex for matching variables with parameters. More...
 
 matchAndRemove (&$text)
 Returns an associative array, ID => param value, for all items that match Removes the matched items from the input string (passed by reference) More...
 
 matchStartAndRemove (&$text)
 Return the ID of the magic word at the start of $text, and remove the prefix from $text. More...
 
 matchStartToEnd ( $text)
 Match some text, without parameter capture Returns the magic word name, or false if there was no capture. More...
 
 matchVariableStartToEnd ( $text)
 Match some text, with parameter capture Returns an array with the magic word name in the first element and the parameter in the second element. More...
 
 parseMatch ( $m)
 Parse a match array from preg_match Returns array(magic word ID, parameter value) If there is no parameter value, that element will be false. More...
 

Public Attributes

string[] $names = []
 

Private Attributes

string[] null $baseRegex
 
MagicWordFactory $factory
 
array null $hash
 
string[] null $regex
 

Detailed Description

Class for handling an array of magic words.

Definition at line 32 of file MagicWordArray.php.

Constructor & Destructor Documentation

◆ __construct()

MagicWordArray::__construct (   $names = [],
MagicWordFactory  $factory = null 
)
Parameters
string[]$names
MagicWordFactory | null$factory

Definition at line 52 of file MagicWordArray.php.

References $factory, and $names.

Member Function Documentation

◆ add()

MagicWordArray::add (   $name)

Add a magic word by name.

Parameters
string$name

Definition at line 62 of file MagicWordArray.php.

◆ addArray()

MagicWordArray::addArray (   $names)

Add a number of magic words by name.

Parameters
string[]$names

Definition at line 72 of file MagicWordArray.php.

References $names.

◆ getBaseRegex()

MagicWordArray::getBaseRegex ( bool  $capture = true,
string  $delimiter = '/' 
)

Get the base regex.

Parameters
bool$captureSet to false to suppress the capture groups, which can cause unexpected conflicts when this regexp is embedded in other regexps with similar constructs.
string$delimiterThe delimiter which will be used for the eventual regexp.
Returns
string[]
Access: internal

Definition at line 108 of file MagicWordArray.php.

References $baseRegex.

◆ getHash()

MagicWordArray::getHash ( )

Get a 2-d hashtable for this array.

Returns
array

Definition at line 81 of file MagicWordArray.php.

References $hash.

◆ getNames()

MagicWordArray::getNames ( )
Since
1.20
Returns
string[]

Definition at line 221 of file MagicWordArray.php.

◆ getRegex()

MagicWordArray::getRegex ( )

Get an unanchored regex that does not match parameters.

Returns
string[]
Access: internal

Definition at line 156 of file MagicWordArray.php.

References $base.

◆ getRegexStart()

MagicWordArray::getRegexStart ( )

Get a regex anchored to the start of the string that does not match parameters.

Returns
string[]
Access: internal

Definition at line 187 of file MagicWordArray.php.

References $base.

◆ getVariableRegex()

MagicWordArray::getVariableRegex ( )

Get a regex for matching variables with parameters.

Returns
string[]
Access: internal
Deprecated:
since 1.36 Appears to have no uses.

Definition at line 177 of file MagicWordArray.php.

◆ getVariableStartToEndRegex()

MagicWordArray::getVariableStartToEndRegex ( )

Get an anchored regex for matching variables with parameters.

Returns
string[]
Access: internal

Definition at line 205 of file MagicWordArray.php.

References $base.

◆ matchAndRemove()

MagicWordArray::matchAndRemove ( $text)

Returns an associative array, ID => param value, for all items that match Removes the matched items from the input string (passed by reference)

Parameters
string&$text
Returns
array

Definition at line 303 of file MagicWordArray.php.

References $matches, and $res.

◆ matchStartAndRemove()

MagicWordArray::matchStartAndRemove ( $text)

Return the ID of the magic word at the start of $text, and remove the prefix from $text.

Return false if no match found and $text is not modified. Does not match parameters.

Parameters
string&$text
Returns
int|bool False on failure

Definition at line 344 of file MagicWordArray.php.

◆ matchStartToEnd()

MagicWordArray::matchStartToEnd (   $text)

Match some text, without parameter capture Returns the magic word name, or false if there was no capture.

Parameters
string$text
Returns
string|bool False on failure

Definition at line 286 of file MagicWordArray.php.

◆ matchVariableStartToEnd()

MagicWordArray::matchVariableStartToEnd (   $text)

Match some text, with parameter capture Returns an array with the magic word name in the first element and the parameter in the second element.

Both elements are false if there was no match.

Parameters
string$text
Returns
array

Definition at line 267 of file MagicWordArray.php.

◆ parseMatch()

MagicWordArray::parseMatch (   $m)

Parse a match array from preg_match Returns array(magic word ID, parameter value) If there is no parameter value, that element will be false.

Parameters
array$m
Exceptions
MWException
Returns
array

Definition at line 235 of file MagicWordArray.php.

Member Data Documentation

◆ $baseRegex

string [] null MagicWordArray::$baseRegex
private

Definition at line 43 of file MagicWordArray.php.

Referenced by getBaseRegex().

◆ $factory

MagicWordFactory MagicWordArray::$factory
private

Definition at line 37 of file MagicWordArray.php.

Referenced by __construct().

◆ $hash

array null MagicWordArray::$hash
private

Definition at line 40 of file MagicWordArray.php.

Referenced by getHash().

◆ $names

string [] MagicWordArray::$names = []

Definition at line 34 of file MagicWordArray.php.

Referenced by __construct(), and addArray().

◆ $regex

string [] null MagicWordArray::$regex
private

Definition at line 46 of file MagicWordArray.php.


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