Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

RequestMatcher.php

Zuletzt modifiziert: 09.10.2024, 12:54 - Dateigröße: 4.35 KiB


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