Verzeichnisstruktur phpBB-3.1.0
- Veröffentlicht
- 27.10.2014
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 * @api
020 */
021 class RequestMatcher implements RequestMatcherInterface
022 {
023 /**
024 * @var string
025 */
026 private $path;
027
028 /**
029 * @var string
030 */
031 private $host;
032
033 /**
034 * @var array
035 */
036 private $methods = array();
037
038 /**
039 * @var string
040 */
041 private $ips = array();
042
043 /**
044 * @var array
045 */
046 private $attributes = array();
047
048 /**
049 * @param string|null $path
050 * @param string|null $host
051 * @param string|string[]|null $methods
052 * @param string|string[]|null $ips
053 * @param array $attributes
054 */
055 public function __construct($path = null, $host = null, $methods = null, $ips = null, array $attributes = array())
056 {
057 $this->matchPath($path);
058 $this->matchHost($host);
059 $this->matchMethod($methods);
060 $this->matchIps($ips);
061 foreach ($attributes as $k => $v) {
062 $this->matchAttribute($k, $v);
063 }
064 }
065
066 /**
067 * Adds a check for the URL host name.
068 *
069 * @param string $regexp A Regexp
070 */
071 public function matchHost($regexp)
072 {
073 $this->host = $regexp;
074 }
075
076 /**
077 * Adds a check for the URL path info.
078 *
079 * @param string $regexp A Regexp
080 */
081 public function matchPath($regexp)
082 {
083 $this->path = $regexp;
084 }
085
086 /**
087 * Adds a check for the client IP.
088 *
089 * @param string $ip A specific IP address or a range specified using IP/netmask like 192.168.1.0/24
090 */
091 public function matchIp($ip)
092 {
093 $this->matchIps($ip);
094 }
095
096 /**
097 * Adds a check for the client IP.
098 *
099 * @param string|string[] $ips A specific IP address or a range specified using IP/netmask like 192.168.1.0/24
100 */
101 public function matchIps($ips)
102 {
103 $this->ips = (array) $ips;
104 }
105
106 /**
107 * Adds a check for the HTTP method.
108 *
109 * @param string|string[]|null $method An HTTP method or an array of HTTP methods
110 */
111 public function matchMethod($method)
112 {
113 $this->methods = array_map('strtoupper', (array) $method);
114 }
115
116 /**
117 * Adds a check for request attribute.
118 *
119 * @param string $key The request attribute name
120 * @param string $regexp A Regexp
121 */
122 public function matchAttribute($key, $regexp)
123 {
124 $this->attributes[$key] = $regexp;
125 }
126
127 /**
128 * {@inheritdoc}
129 *
130 * @api
131 */
132 public function matches(Request $request)
133 {
134 if ($this->methods && !in_array($request->getMethod(), $this->methods)) {
135 return false;
136 }
137
138 foreach ($this->attributes as $key => $pattern) {
139 if (!preg_match('{'.$pattern.'}', $request->attributes->get($key))) {
140 return false;
141 }
142 }
143
144 if (null !== $this->path && !preg_match('{'.$this->path.'}', rawurldecode($request->getPathInfo()))) {
145 return false;
146 }
147
148 if (null !== $this->host && !preg_match('{'.$this->host.'}i', $request->getHost())) {
149 return false;
150 }
151
152 if (IpUtils::checkIp($request->getClientIp(), $this->ips)) {
153 return true;
154 }
155
156 // Note to future implementors: add additional checks above the
157 // foreach above or else your check might not be run!
158 return count($this->ips) === 0;
159 }
160 }
161