MediaWiki  master
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. More...
 
static parse ( $dateString)
 Parse an HTTP-date string. More...
 

Private Member Functions

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

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. 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

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()

◆ consumeDate2()

◆ consumeDate3()

◆ consumeDay()

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

◆ consumeDayName()

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

◆ consumeDayNameLong()

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

◆ consumeFixdate()

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

◆ consumeMonth()

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

◆ consumeRfc850Date()

◆ consumeTimeOfDay()

◆ consumeYear()

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

◆ execute()

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

◆ 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.

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.

◆ 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.

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
]

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

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

Definition at line 61 of file HttpDate.php.

◆ $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:
true
return true
Definition: router.php:90