Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
RequestMatcher.php
001 <?php
002
003 /*
004 * This file is part of the Symfony package.
005 *
006 * (c) Fabien Potencier <fabien@symfony.com>
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 namespace Symfony\Component\HttpFoundation;
013
014 /**
015 * RequestMatcher compares a pre-defined set of checks against a Request instance.
016 *
017 * @author Fabien Potencier <fabien@symfony.com>
018 */
019 class RequestMatcher implements RequestMatcherInterface
020 {
021 /**
022 * @var string|null
023 */
024 private $path;
025
026 /**
027 * @var string|null
028 */
029 private $host;
030
031 /**
032 * @var string[]
033 */
034 private $methods = [];
035
036 /**
037 * @var string[]
038 */
039 private $ips = [];
040
041 /**
042 * @var array
043 */
044 private $attributes = [];
045
046 /**
047 * @var string[]
048 */
049 private $schemes = [];
050
051 /**
052 * @param string|null $path
053 * @param string|null $host
054 * @param string|string[]|null $methods
055 * @param string|string[]|null $ips
056 * @param string|string[]|null $schemes
057 */
058 public function __construct($path = null, $host = null, $methods = null, $ips = null, array $attributes = [], $schemes = null)
059 {
060 $this->matchPath($path);
061 $this->matchHost($host);
062 $this->matchMethod($methods);
063 $this->matchIps($ips);
064 $this->matchScheme($schemes);
065
066 foreach ($attributes as $k => $v) {
067 $this->matchAttribute($k, $v);
068 }
069 }
070
071 /**
072 * Adds a check for the HTTP scheme.
073 *
074 * @param string|string[]|null $scheme An HTTP scheme or an array of HTTP schemes
075 */
076 public function matchScheme($scheme)
077 {
078 $this->schemes = null !== $scheme ? array_map('strtolower', (array) $scheme) : [];
079 }
080
081 /**
082 * Adds a check for the URL host name.
083 *
084 * @param string|null $regexp A Regexp
085 */
086 public function matchHost($regexp)
087 {
088 $this->host = $regexp;
089 }
090
091 /**
092 * Adds a check for the URL path info.
093 *
094 * @param string|null $regexp A Regexp
095 */
096 public function matchPath($regexp)
097 {
098 $this->path = $regexp;
099 }
100
101 /**
102 * Adds a check for the client IP.
103 *
104 * @param string $ip A specific IP address or a range specified using IP/netmask like 192.168.1.0/24
105 */
106 public function matchIp($ip)
107 {
108 $this->matchIps($ip);
109 }
110
111 /**
112 * Adds a check for the client IP.
113 *
114 * @param string|string[]|null $ips A specific IP address or a range specified using IP/netmask like 192.168.1.0/24
115 */
116 public function matchIps($ips)
117 {
118 $this->ips = null !== $ips ? (array) $ips : [];
119 }
120
121 /**
122 * Adds a check for the HTTP method.
123 *
124 * @param string|string[]|null $method An HTTP method or an array of HTTP methods
125 */
126 public function matchMethod($method)
127 {
128 $this->methods = null !== $method ? array_map('strtoupper', (array) $method) : [];
129 }
130
131 /**
132 * Adds a check for request attribute.
133 *
134 * @param string $key The request attribute name
135 * @param string $regexp A Regexp
136 */
137 public function matchAttribute($key, $regexp)
138 {
139 $this->attributes[$key] = $regexp;
140 }
141
142 /**
143 * {@inheritdoc}
144 */
145 public function matches(Request $request)
146 {
147 if ($this->schemes && !\in_array($request->getScheme(), $this->schemes, true)) {
148 return false;
149 }
150
151 if ($this->methods && !\in_array($request->getMethod(), $this->methods, true)) {
152 return false;
153 }
154
155 foreach ($this->attributes as $key => $pattern) {
156 if (!preg_match('{'.$pattern.'}', $request->attributes->get($key))) {
157 return false;
158 }
159 }
160
161 if (null !== $this->path && !preg_match('{'.$this->path.'}', rawurldecode($request->getPathInfo()))) {
162 return false;
163 }
164
165 if (null !== $this->host && !preg_match('{'.$this->host.'}i', $request->getHost())) {
166 return false;
167 }
168
169 if (IpUtils::checkIp($request->getClientIp(), $this->ips)) {
170 return true;
171 }
172
173 // Note to future implementors: add additional checks above the
174 // foreach above or else your check might not be run!
175 return 0 === \count($this->ips);
176 }
177 }
178