MediaWiki
master
IfNoneMatch.php
Go to the documentation of this file.
1
<?php
2
3
namespace
MediaWiki\Rest\HeaderParser
;
4
8
class
IfNoneMatch
extends
HeaderParserBase
{
10
private
$results = [];
11
13
private
$lastError;
14
38
public
function
parseHeaderList
( $headerList ) {
39
$this->lastError =
null
;
40
if
( count( $headerList ) === 1 && $headerList[0] ===
'*'
) {
41
return
[ [
42
'weak'
=>
true
,
43
'contents'
=>
null
,
44
'whole'
=>
'*'
45
] ];
46
}
47
$this->results = [];
48
try
{
49
foreach
( $headerList as
$header
) {
50
$this->parseHeader(
$header
);
51
}
52
return
$this->results;
53
}
catch
(
HeaderParserError
$e ) {
54
$this->lastError = $e->getMessage();
55
return
[];
56
}
57
}
58
69
public
function
parseETag
( $eTag ) {
70
$this->
setInput
( $eTag );
71
$this->results = [];
72
73
try
{
74
$this->consumeTag();
75
$this->
assertEnd
();
76
}
catch
(
HeaderParserError
$e ) {
77
$this->lastError = $e->getMessage();
78
return
null
;
79
}
80
/* @phan-suppress-next-line PhanTypeInvalidDimOffset */
81
return
$this->results[0];
82
}
83
89
public
function
getLastError
() {
90
return
$this->lastError;
91
}
92
99
private
function
parseHeader(
$header
) {
100
$this->
setInput
(
$header
);
101
$this->consumeTagList();
102
$this->
assertEnd
();
103
}
104
110
private
function
consumeTagList() {
111
while
(
true
) {
112
$this->
skipWhitespace
();
113
$this->consumeTag();
114
$this->
skipWhitespace
();
115
if
( $this->pos === $this->inputLength ) {
116
break
;
117
}
else
{
118
$this->
consumeString
(
','
);
119
}
120
}
121
}
122
128
private
function
consumeTag() {
129
$weak =
false
;
130
$whole =
''
;
131
if
( substr( $this->input, $this->pos, 2 ) ===
'W/'
) {
132
$weak =
true
;
133
$whole .=
'W/'
;
134
$this->pos += 2;
135
}
136
$this->
consumeString
(
'"'
);
137
if
( !preg_match(
'/[!#-~\x80-\xff]*/A'
, $this->input, $m, 0, $this->pos ) ) {
138
$this->
error
(
'unexpected regex failure'
);
139
}
140
$contents = $m[0];
141
$this->pos += strlen( $contents );
142
$this->
consumeString
(
'"'
);
143
$whole .=
'"'
. $contents .
'"'
;
144
$this->results[] = [
145
'weak'
=> $weak,
146
'contents'
=> $contents,
147
'whole'
=> $whole
148
];
149
}
150
}
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:93
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:56
MediaWiki\Rest\HeaderParser\HeaderParserBase\error
error( $message)
Throw an exception to indicate a parse error.
Definition
HeaderParserBase.php:67
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:89
MediaWiki\Rest\HeaderParser\IfNoneMatch\parseETag
parseETag( $eTag)
Parse an entity-tag such as might be found in an ETag response header.
Definition
IfNoneMatch.php:69
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:38
MediaWiki\Rest\HeaderParser
Definition
HeaderParserBase.php:3
$header
$header
Definition
updateCredits.php:37
includes
Rest
HeaderParser
IfNoneMatch.php
Generated on Sun Oct 6 2024 09:25:22 for MediaWiki by
1.10.0