Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/http-foundation/RequestMatcher.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 1fec387a4317 |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
29 private $host; | 29 private $host; |
30 | 30 |
31 /** | 31 /** |
32 * @var string[] | 32 * @var string[] |
33 */ | 33 */ |
34 private $methods = array(); | 34 private $methods = []; |
35 | 35 |
36 /** | 36 /** |
37 * @var string[] | 37 * @var string[] |
38 */ | 38 */ |
39 private $ips = array(); | 39 private $ips = []; |
40 | 40 |
41 /** | 41 /** |
42 * @var array | 42 * @var array |
43 */ | 43 */ |
44 private $attributes = array(); | 44 private $attributes = []; |
45 | 45 |
46 /** | 46 /** |
47 * @var string[] | 47 * @var string[] |
48 */ | 48 */ |
49 private $schemes = array(); | 49 private $schemes = []; |
50 | 50 |
51 /** | 51 /** |
52 * @param string|null $path | 52 * @param string|null $path |
53 * @param string|null $host | 53 * @param string|null $host |
54 * @param string|string[]|null $methods | 54 * @param string|string[]|null $methods |
55 * @param string|string[]|null $ips | 55 * @param string|string[]|null $ips |
56 * @param array $attributes | 56 * @param array $attributes |
57 * @param string|string[]|null $schemes | 57 * @param string|string[]|null $schemes |
58 */ | 58 */ |
59 public function __construct($path = null, $host = null, $methods = null, $ips = null, array $attributes = array(), $schemes = null) | 59 public function __construct($path = null, $host = null, $methods = null, $ips = null, array $attributes = [], $schemes = null) |
60 { | 60 { |
61 $this->matchPath($path); | 61 $this->matchPath($path); |
62 $this->matchHost($host); | 62 $this->matchHost($host); |
63 $this->matchMethod($methods); | 63 $this->matchMethod($methods); |
64 $this->matchIps($ips); | 64 $this->matchIps($ips); |
74 * | 74 * |
75 * @param string|string[]|null $scheme An HTTP scheme or an array of HTTP schemes | 75 * @param string|string[]|null $scheme An HTTP scheme or an array of HTTP schemes |
76 */ | 76 */ |
77 public function matchScheme($scheme) | 77 public function matchScheme($scheme) |
78 { | 78 { |
79 $this->schemes = null !== $scheme ? array_map('strtolower', (array) $scheme) : array(); | 79 $this->schemes = null !== $scheme ? array_map('strtolower', (array) $scheme) : []; |
80 } | 80 } |
81 | 81 |
82 /** | 82 /** |
83 * Adds a check for the URL host name. | 83 * Adds a check for the URL host name. |
84 * | 84 * |
114 * | 114 * |
115 * @param string|string[]|null $ips A specific IP address or a range specified using IP/netmask like 192.168.1.0/24 | 115 * @param string|string[]|null $ips A specific IP address or a range specified using IP/netmask like 192.168.1.0/24 |
116 */ | 116 */ |
117 public function matchIps($ips) | 117 public function matchIps($ips) |
118 { | 118 { |
119 $this->ips = null !== $ips ? (array) $ips : array(); | 119 $this->ips = null !== $ips ? (array) $ips : []; |
120 } | 120 } |
121 | 121 |
122 /** | 122 /** |
123 * Adds a check for the HTTP method. | 123 * Adds a check for the HTTP method. |
124 * | 124 * |
125 * @param string|string[]|null $method An HTTP method or an array of HTTP methods | 125 * @param string|string[]|null $method An HTTP method or an array of HTTP methods |
126 */ | 126 */ |
127 public function matchMethod($method) | 127 public function matchMethod($method) |
128 { | 128 { |
129 $this->methods = null !== $method ? array_map('strtoupper', (array) $method) : array(); | 129 $this->methods = null !== $method ? array_map('strtoupper', (array) $method) : []; |
130 } | 130 } |
131 | 131 |
132 /** | 132 /** |
133 * Adds a check for request attribute. | 133 * Adds a check for request attribute. |
134 * | 134 * |
143 /** | 143 /** |
144 * {@inheritdoc} | 144 * {@inheritdoc} |
145 */ | 145 */ |
146 public function matches(Request $request) | 146 public function matches(Request $request) |
147 { | 147 { |
148 if ($this->schemes && !in_array($request->getScheme(), $this->schemes, true)) { | 148 if ($this->schemes && !\in_array($request->getScheme(), $this->schemes, true)) { |
149 return false; | 149 return false; |
150 } | 150 } |
151 | 151 |
152 if ($this->methods && !in_array($request->getMethod(), $this->methods, true)) { | 152 if ($this->methods && !\in_array($request->getMethod(), $this->methods, true)) { |
153 return false; | 153 return false; |
154 } | 154 } |
155 | 155 |
156 foreach ($this->attributes as $key => $pattern) { | 156 foreach ($this->attributes as $key => $pattern) { |
157 if (!preg_match('{'.$pattern.'}', $request->attributes->get($key))) { | 157 if (!preg_match('{'.$pattern.'}', $request->attributes->get($key))) { |
171 return true; | 171 return true; |
172 } | 172 } |
173 | 173 |
174 // Note to future implementors: add additional checks above the | 174 // Note to future implementors: add additional checks above the |
175 // foreach above or else your check might not be run! | 175 // foreach above or else your check might not be run! |
176 return 0 === count($this->ips); | 176 return 0 === \count($this->ips); |
177 } | 177 } |
178 } | 178 } |