MediaWiki REL1_37
MediaWiki\Rest\HeaderParser\HttpDate Class Reference

This is a parser for "HTTP-date" as defined by RFC 7231. More...

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

Static Public Member Functions

static format ( $unixTime)
 A convenience function to convert a UNIX timestamp to the preferred IMF-fixdate format for HTTP header output.
 
static parse ( $dateString)
 Parse an HTTP-date string.
 

Private Member Functions

 __construct ( $input)
 Private constructor.
 
 consumeAsctimeDate ()
 Execute the asctime-date rule.
 
 consumeDate1 ()
 Execute the date1 rule.
 
 consumeDate2 ()
 Execute the date2 rule.
 
 consumeDate3 ()
 Execute the date3 rule.
 
 consumeDay ()
 Execute the day rule, and capture the result.
 
 consumeDayName ()
 Execute the day-name rule, and capture the result.
 
 consumeDayNameLong ()
 Execute the day-name-l rule.
 
 consumeFixdate ()
 Execute the IMF-fixdate rule, or throw an exception.
 
 consumeMonth ()
 Execute the month rule, and capture the result.
 
 consumeRfc850Date ()
 Execute the rfc850-date rule.
 
 consumeTimeOfDay ()
 Execute the time-of-day rule.
 
 consumeYear ()
 Execute the year rule, and capture the result.
 
 execute ()
 Parse the input string.
 
 getUnixTime ()
 Convert the captured results to a UNIX timestamp.
 

Private Attributes

 $day
 
 $dayName
 
 $hour
 
 $minute
 
 $month
 
 $second
 
 $year
 

Static Private Attributes

static $dayNames
 
static $dayNamesLong
 
static $monthsByName
 

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.
 
 consumeFixedDigits ( $numDigits)
 Consume a specified number of digits, or throw an exception.
 
 consumeString ( $s)
 Consume a specified string, or throw an exception.
 
 error ( $message)
 Throw an exception to indicate a parse error.
 
 setInput ( $input)
 Set the input, and derived convenience properties.
 
 skipWhitespace ()
 Skip whitespace at the input position (OWS)
 
- Protected Attributes inherited from MediaWiki\Rest\HeaderParser\HeaderParserBase
string $input
 The input string being processed.
 
int $inputLength
 The length of $input.
 
int $pos
 The position within $input.
 

Detailed Description

This is a parser for "HTTP-date" as defined by RFC 7231.

Normally in MediaWiki, dates in HTTP headers are converted using ConvertibleTimestamp or strtotime(), and this is encouraged by RFC 7231:

"Recipients of timestamp values are encouraged to be robust in parsing timestamps unless otherwise restricted by the field definition."

In the case of If-Modified-Since, we are in fact otherwise restricted, since RFC 7232 says:

"A recipient MUST ignore the If-Modified-Since header field if the received field-value is not a valid HTTP-date"

So it is not correct to use strtotime() or ConvertibleTimestamp to parse If-Modified-Since.

Definition at line 23 of file HttpDate.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Rest\HeaderParser\HttpDate::__construct (   $input)
private

Private constructor.

Use the public static functions for public access.

Parameters
string$input

Definition at line 98 of file HttpDate.php.

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

Member Function Documentation

◆ consumeAsctimeDate()

◆ consumeDate1()

MediaWiki\Rest\HeaderParser\HttpDate::consumeDate1 ( )
private

◆ consumeDate2()

◆ consumeDate3()

◆ consumeDay()

MediaWiki\Rest\HeaderParser\HttpDate::consumeDay ( )
private

◆ consumeDayName()

MediaWiki\Rest\HeaderParser\HttpDate::consumeDayName ( )
private

Execute the day-name rule, and capture the result.

Exceptions
HeaderParserError

Definition at line 151 of file HttpDate.php.

References MediaWiki\Rest\HeaderParser\HttpDate\$month, and MediaWiki\Rest\HeaderParser\HeaderParserBase\error().

Referenced by MediaWiki\Rest\HeaderParser\HttpDate\consumeAsctimeDate(), and MediaWiki\Rest\HeaderParser\HttpDate\consumeFixdate().

◆ consumeDayNameLong()

MediaWiki\Rest\HeaderParser\HttpDate::consumeDayNameLong ( )
private

◆ consumeFixdate()

MediaWiki\Rest\HeaderParser\HttpDate::consumeFixdate ( )
private

◆ consumeMonth()

MediaWiki\Rest\HeaderParser\HttpDate::consumeMonth ( )
private

◆ consumeRfc850Date()

MediaWiki\Rest\HeaderParser\HttpDate::consumeRfc850Date ( )
private

◆ consumeTimeOfDay()

◆ consumeYear()

MediaWiki\Rest\HeaderParser\HttpDate::consumeYear ( )
private

◆ execute()

◆ format()

static MediaWiki\Rest\HeaderParser\HttpDate::format (   $unixTime)
static

A convenience function to convert a UNIX timestamp to the preferred IMF-fixdate format for HTTP header output.

Parameters
int$unixTime
Returns
false|string

Definition at line 89 of file HttpDate.php.

References MediaWiki\Rest\HeaderParser\HttpDate\$month.

Referenced by MediaWiki\Rest\ConditionalHeaderUtil\applyResponseHeaders().

◆ getUnixTime()

MediaWiki\Rest\HeaderParser\HttpDate::getUnixTime ( )
private

Convert the captured results to a UNIX timestamp.

This should only be called after parsing succeeds.

Returns
int

Definition at line 307 of file HttpDate.php.

References MediaWiki\Rest\HeaderParser\HttpDate\$month.

◆ parse()

static MediaWiki\Rest\HeaderParser\HttpDate::parse (   $dateString)
static

Parse an HTTP-date string.

Parameters
string$dateString
Returns
int|null The UNIX timestamp, or null if the date was invalid

Definition at line 73 of file HttpDate.php.

References MediaWiki\Rest\HeaderParser\HttpDate\$month.

Referenced by MediaWiki\Rest\ConditionalHeaderUtil\checkPreconditions().

Member Data Documentation

◆ $day

MediaWiki\Rest\HeaderParser\HttpDate::$day
private

Definition at line 60 of file HttpDate.php.

◆ $dayName

MediaWiki\Rest\HeaderParser\HttpDate::$dayName
private

◆ $dayNames

MediaWiki\Rest\HeaderParser\HttpDate::$dayNames
staticprivate
Initial value:
= [
'Mon' => true,
'Tue' => true,
'Wed' => true,
'Thu' => true,
'Fri' => true,
'Sat' => true,
'Sun' => true
]
return true
Definition router.php:92

Definition at line 24 of file HttpDate.php.

◆ $dayNamesLong

MediaWiki\Rest\HeaderParser\HttpDate::$dayNamesLong
staticprivate
Initial value:
= [
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
'Sunday',
]

Definition at line 49 of file HttpDate.php.

◆ $hour

MediaWiki\Rest\HeaderParser\HttpDate::$hour
private

Definition at line 63 of file HttpDate.php.

◆ $minute

MediaWiki\Rest\HeaderParser\HttpDate::$minute
private

Definition at line 64 of file HttpDate.php.

◆ $month

◆ $monthsByName

MediaWiki\Rest\HeaderParser\HttpDate::$monthsByName
staticprivate
Initial value:
= [
'Jan' => 1,
'Feb' => 2,
'Mar' => 3,
'Apr' => 4,
'May' => 5,
'Jun' => 6,
'Jul' => 7,
'Aug' => 8,
'Sep' => 9,
'Oct' => 10,
'Nov' => 11,
'Dec' => 12,
]

Definition at line 34 of file HttpDate.php.

◆ $second

MediaWiki\Rest\HeaderParser\HttpDate::$second
private

Definition at line 65 of file HttpDate.php.

◆ $year

MediaWiki\Rest\HeaderParser\HttpDate::$year
private

Definition at line 62 of file HttpDate.php.

Referenced by MediaWiki\Rest\HeaderParser\HttpDate\consumeDate2().


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