MediaWiki  master
MediaWiki\Rest\HeaderParser\Origin Class Reference

A class to assist with the parsing of Origin header according to the RFC 6454 https://tools.ietf.org/html/rfc6454#section-7. More...

Inheritance diagram for MediaWiki\Rest\HeaderParser\Origin:
Collaboration diagram for MediaWiki\Rest\HeaderParser\Origin:

Public Member Functions

 getOriginList ()
 Get the list of origins. More...
 
 getSingleOrigin ()
 
 isMultiOrigin ()
 Whether the Origin header contains multiple origins. More...
 
 isNullOrigin ()
 Whether the Origin header was explicitly set to null. More...
 
 match (array $allowList, array $excludeList)
 Check whether all the origins match at least one of the rules in $allowList. More...
 

Static Public Member Functions

static parseHeaderList (array $headerList)
 Parse an Origin header list as returned by RequestInterface::getHeader(). More...
 

Public Attributes

const HEADER_NAME = 'Origin'
 

Private Member Functions

 __construct (array $input)
 Private constructor. More...
 
 execute ()
 

Static Private Member Functions

static matchSingleOrigin (string $origin, array $allowList, array $excludeList)
 Checks whether the origin matches at list one of the provided rules in $allowList. More...
 
static wildcardToRegex ( $wildcard)
 Helper function to convert wildcard string into a regex '*' => '. More...
 

Private Attributes

bool $isNullOrigin
 whether the origin was set to null More...
 
array $origins = []
 List of specified origins. More...
 

Additional Inherited Members

- Protected Member Functions inherited from MediaWiki\Rest\HeaderParser\HeaderParserBase
 assertEnd ()
 If the position is not at the end of the input string, raise an error, complaining of trailing characters. More...
 
 consumeFixedDigits ( $numDigits)
 Consume a specified number of digits, or throw an exception. More...
 
 consumeString ( $s)
 Consume a specified string, or throw an exception. More...
 
 error ( $message)
 Throw an exception to indicate a parse error. More...
 
 setInput ( $input)
 Set the input, and derived convenience properties. More...
 
 skipWhitespace ()
 Skip whitespace at the input position (OWS) More...
 
- Protected Attributes inherited from MediaWiki\Rest\HeaderParser\HeaderParserBase
string $input
 The input string being processed. More...
 
int $inputLength
 The length of $input. More...
 
int $pos
 The position within $input. More...
 

Detailed Description

A class to assist with the parsing of Origin header according to the RFC 6454 https://tools.ietf.org/html/rfc6454#section-7.

Since
1.36

Definition at line 12 of file Origin.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Rest\HeaderParser\Origin::__construct ( array  $input)
private

Private constructor.

Use the public static functions for public access.

Parameters
string[]$input

Definition at line 120 of file Origin.php.

References MediaWiki\Rest\HeaderParser\HeaderParserBase\$input, MediaWiki\Rest\HeaderParser\HeaderParserBase\error(), and MediaWiki\Rest\HeaderParser\HeaderParserBase\setInput().

Member Function Documentation

◆ execute()

MediaWiki\Rest\HeaderParser\Origin::execute ( )
private

◆ getOriginList()

MediaWiki\Rest\HeaderParser\Origin::getOriginList ( )

◆ getSingleOrigin()

MediaWiki\Rest\HeaderParser\Origin::getSingleOrigin ( )

◆ isMultiOrigin()

MediaWiki\Rest\HeaderParser\Origin::isMultiOrigin ( )

Whether the Origin header contains multiple origins.

Returns
bool

Definition at line 48 of file Origin.php.

References MediaWiki\Rest\HeaderParser\Origin\getOriginList().

Referenced by MediaWiki\Rest\HeaderParser\Origin\getSingleOrigin().

◆ isNullOrigin()

MediaWiki\Rest\HeaderParser\Origin::isNullOrigin ( )

Whether the Origin header was explicitly set to null.

Returns
bool

Definition at line 39 of file Origin.php.

References MediaWiki\Rest\HeaderParser\Origin\$isNullOrigin.

Referenced by MediaWiki\Rest\HeaderParser\Origin\execute(), and MediaWiki\Rest\HeaderParser\Origin\match().

◆ match()

MediaWiki\Rest\HeaderParser\Origin::match ( array  $allowList,
array  $excludeList 
)

Check whether all the origins match at least one of the rules in $allowList.

Parameters
string[]$allowList
string[]$excludeList
Returns
bool

Definition at line 77 of file Origin.php.

References MediaWiki\Rest\HeaderParser\Origin\getOriginList(), and MediaWiki\Rest\HeaderParser\Origin\isNullOrigin().

Referenced by MediaWiki\Rest\CorsUtils\allowOrigin().

◆ matchSingleOrigin()

static MediaWiki\Rest\HeaderParser\Origin::matchSingleOrigin ( string  $origin,
array  $allowList,
array  $excludeList 
)
staticprivate

Checks whether the origin matches at list one of the provided rules in $allowList.

Parameters
string$origin
array$allowList
array$excludeList
Returns
bool

Definition at line 98 of file Origin.php.

◆ parseHeaderList()

static MediaWiki\Rest\HeaderParser\Origin::parseHeaderList ( array  $headerList)
static

Parse an Origin header list as returned by RequestInterface::getHeader().

Parameters
string[]$headerList
Returns
self

Definition at line 28 of file Origin.php.

Referenced by MediaWiki\Rest\CorsUtils\authorize(), and MediaWiki\Rest\CorsUtils\modifyResponse().

◆ wildcardToRegex()

static MediaWiki\Rest\HeaderParser\Origin::wildcardToRegex (   $wildcard)
staticprivate

Helper function to convert wildcard string into a regex '*' => '.

*?' '?' => '.'

Parameters
string$wildcardString with wildcards
Returns
string Regular expression

Definition at line 147 of file Origin.php.

Member Data Documentation

◆ $isNullOrigin

bool MediaWiki\Rest\HeaderParser\Origin::$isNullOrigin
private

whether the origin was set to null

Definition at line 17 of file Origin.php.

Referenced by MediaWiki\Rest\HeaderParser\Origin\isNullOrigin().

◆ $origins

array MediaWiki\Rest\HeaderParser\Origin::$origins = []
private

List of specified origins.

Definition at line 20 of file Origin.php.

Referenced by MediaWiki\Rest\HeaderParser\Origin\getOriginList().

◆ HEADER_NAME

const MediaWiki\Rest\HeaderParser\Origin::HEADER_NAME = 'Origin'

Definition at line 14 of file Origin.php.


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