MediaWiki
REL1_40
IfNoneMatch.php
Go to the documentation of this file.
1
<?php
2
3
namespace
MediaWiki\Rest\HeaderParser
;
4
8
class
IfNoneMatch
extends
HeaderParserBase
{
9
private
$results = [];
10
12
private
$lastError;
13
37
public
function
parseHeaderList
( $headerList ) {
38
$this->lastError =
null
;
39
if
( count( $headerList ) === 1 && $headerList[0] ===
'*'
) {
40
return
[ [
41
'weak'
=>
true
,
42
'contents'
=>
null
,
43
'whole'
=>
'*'
44
] ];
45
}
46
$this->results = [];
47
try
{
48
foreach
( $headerList as
$header
) {
49
$this->parseHeader(
$header
);
50
}
51
return
$this->results;
52
}
catch
(
HeaderParserError
$e ) {
53
$this->lastError = $e->getMessage();
54
return
[];
55
}
56
}
57
68
public
function
parseETag
( $eTag ) {
69
$this->
setInput
( $eTag );
70
$this->results = [];
71
72
try
{
73
$this->consumeTag();
74
$this->
assertEnd
();
75
}
catch
(
HeaderParserError
$e ) {
76
$this->lastError = $e->getMessage();
77
return
null
;
78
}
79
/* @phan-suppress-next-line PhanTypeInvalidDimOffset */
80
return
$this->results[0];
81
}
82
88
public
function
getLastError
() {
89
return
$this->lastError;
90
}
91
98
private
function
parseHeader(
$header
) {
99
$this->
setInput
(
$header
);
100
$this->consumeTagList();
101
$this->
assertEnd
();
102
}
103
109
private
function
consumeTagList() {
110
while
(
true
) {
111
$this->
skipWhitespace
();
112
$this->consumeTag();
113
$this->
skipWhitespace
();
114
if
( $this->pos === $this->inputLength ) {
115
break
;
116
}
else
{
117
$this->
consumeString
(
','
);
118
}
119
}
120
}
121
127
private
function
consumeTag() {
128
$weak =
false
;
129
$whole =
''
;
130
if
( substr( $this->input, $this->pos, 2 ) ===
'W/'
) {
131
$weak =
true
;
132
$whole .=
'W/'
;
133
$this->pos += 2;
134
}
135
$this->
consumeString
(
'"'
);
136
if
( !preg_match(
'/[!#-~\x80-\xff]*/A'
, $this->input, $m, 0, $this->pos ) ) {
137
$this->
error
(
'unexpected regex failure'
);
138
}
139
$contents = $m[0];
140
$this->pos += strlen( $contents );
141
$this->
consumeString
(
'"'
);
142
$whole .=
'"'
. $contents .
'"'
;
143
$this->results[] = [
144
'weak'
=> $weak,
145
'contents'
=> $contents,
146
'whole'
=> $whole
147
];
148
}
149
}
MediaWiki\Rest\HeaderParser\HeaderParserBase
Definition
HeaderParserBase.php:8
MediaWiki\Rest\HeaderParser\HeaderParserBase\setInput
setInput( $input)
Set the input, and derived convenience properties.
Definition
HeaderParserBase.php:29
MediaWiki\Rest\HeaderParser\HeaderParserBase\assertEnd
assertEnd()
If the position is not at the end of the input string, raise an error, complaining of trailing charac...
Definition
HeaderParserBase.php:92
MediaWiki\Rest\HeaderParser\HeaderParserBase\consumeString
consumeString( $s)
Consume a specified string, or throw an exception.
Definition
HeaderParserBase.php:41
MediaWiki\Rest\HeaderParser\HeaderParserBase\skipWhitespace
skipWhitespace()
Skip whitespace at the input position (OWS)
Definition
HeaderParserBase.php:55
MediaWiki\Rest\HeaderParser\HeaderParserBase\error
error( $message)
Throw an exception to indicate a parse error.
Definition
HeaderParserBase.php:66
MediaWiki\Rest\HeaderParser\HeaderParserError
Definition
HeaderParserError.php:5
MediaWiki\Rest\HeaderParser\IfNoneMatch
A class to assist with the parsing of If-None-Match, If-Match and ETag headers.
Definition
IfNoneMatch.php:8
MediaWiki\Rest\HeaderParser\IfNoneMatch\getLastError
getLastError()
Get the last parse error message, or null if there was none.
Definition
IfNoneMatch.php:88
MediaWiki\Rest\HeaderParser\IfNoneMatch\parseETag
parseETag( $eTag)
Parse an entity-tag such as might be found in an ETag response header.
Definition
IfNoneMatch.php:68
MediaWiki\Rest\HeaderParser\IfNoneMatch\parseHeaderList
parseHeaderList( $headerList)
Parse an If-None-Match or If-Match header list as returned by RequestInterface::getHeader().
Definition
IfNoneMatch.php:37
MediaWiki\Rest\HeaderParser
Definition
HeaderParserBase.php:3
$header
$header
Definition
updateCredits.php:37
includes
Rest
HeaderParser
IfNoneMatch.php
Generated on Thu Jun 27 2024 14:03:57 for MediaWiki by
1.10.0