MediaWiki REL1_33
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.
 
 addArray ( $names)
 Add a number of magic words by name.
 
 getBaseRegex ()
 Get the base regex.
 
 getHash ()
 Get a 2-d hashtable for this array.
 
 getNames ()
 
 getRegex ()
 Get an unanchored regex that does not match parameters.
 
 getRegexStart ()
 Get a regex anchored to the start of the string that does not match parameters.
 
 getVariableRegex ()
 Get a regex for matching variables with parameters.
 
 getVariableStartToEndRegex ()
 Get an anchored regex for matching variables with parameters.
 
 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)
 
 matchStartAndRemove (&$text)
 Return the ID of the magic word at the start of $text, and remove the prefix from $text.
 
 matchStartToEnd ( $text)
 Match some text, without parameter capture Returns the magic word name, or false if there was no capture.
 
 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.
 
 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.
 

Public Attributes

array $names = []
 

Private Attributes

 $baseRegex
 
MagicWordFactory $factory
 
array $hash
 
 $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
array$names
MagicWordFactory | null$factory

Definition at line 50 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 63 of file MagicWordArray.php.

References $name.

◆ addArray()

MagicWordArray::addArray ( $names)

Add a number of magic words by name.

Parameters
array$names

Definition at line 73 of file MagicWordArray.php.

References $names, and and().

◆ getBaseRegex()

MagicWordArray::getBaseRegex ( )

Get the base regex.

Returns
array

Definition at line 103 of file MagicWordArray.php.

References $baseRegex, $name, and and().

Referenced by getRegex(), getRegexStart(), and getVariableStartToEndRegex().

◆ getHash()

MagicWordArray::getHash ( )

Get a 2-d hashtable for this array.

Returns
array

Definition at line 82 of file MagicWordArray.php.

References $hash, $name, and and().

Referenced by matchStartToEnd().

◆ getNames()

MagicWordArray::getNames ( )
Since
1.20
Returns
array

Definition at line 198 of file MagicWordArray.php.

References $names.

◆ getRegex()

MagicWordArray::getRegex ( )

Get an unanchored regex that does not match parameters.

Returns
array

Definition at line 137 of file MagicWordArray.php.

References $base, $regex, and(), and getBaseRegex().

Referenced by getVariableRegex(), and matchAndRemove().

◆ getRegexStart()

MagicWordArray::getRegexStart ( )

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

Returns
array

Definition at line 165 of file MagicWordArray.php.

References $base, and(), and getBaseRegex().

Referenced by matchStartAndRemove().

◆ getVariableRegex()

MagicWordArray::getVariableRegex ( )

Get a regex for matching variables with parameters.

Returns
string

Definition at line 156 of file MagicWordArray.php.

References and(), and getRegex().

◆ getVariableStartToEndRegex()

MagicWordArray::getVariableStartToEndRegex ( )

Get an anchored regex for matching variables with parameters.

Returns
array

Definition at line 182 of file MagicWordArray.php.

References $base, and(), and getBaseRegex().

Referenced by matchVariableStartToEnd().

◆ 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 282 of file MagicWordArray.php.

References $matches, $name, $regex, $res, and(), getRegex(), list, and parseMatch().

◆ 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 326 of file MagicWordArray.php.

References $regex, and(), getRegexStart(), list, and parseMatch().

◆ 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 265 of file MagicWordArray.php.

References $hash, and(), and getHash().

◆ 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 244 of file MagicWordArray.php.

References $regex, and(), false, getVariableStartToEndRegex(), and parseMatch().

◆ 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 212 of file MagicWordArray.php.

References $value, and(), key, and list.

Referenced by matchAndRemove(), matchStartAndRemove(), and matchVariableStartToEnd().

Member Data Documentation

◆ $baseRegex

MagicWordArray::$baseRegex
private

Definition at line 42 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 MagicWordArray::$hash
private

Definition at line 40 of file MagicWordArray.php.

Referenced by getHash(), and matchStartToEnd().

◆ $names

array MagicWordArray::$names = []

Definition at line 34 of file MagicWordArray.php.

Referenced by __construct(), addArray(), and getNames().

◆ $regex

MagicWordArray::$regex
private

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