Beispiel #1
0
 public function setMethod(array $server) : self
 {
     if (array_key_exists('REQUEST_METHOD', $server)) {
         $this->method = Http::getMethod($server['REQUEST_METHOD']);
     }
     return $this;
 }
Beispiel #2
0
 public function compare(string $url, string $prefix, int $method) : MatchRoute
 {
     $find = new MatchRoute();
     if (!Http::allowMethod($method, $this->methods)) {
         return $find;
     }
     if ($prefix != "") {
         $prefix .= '\\/';
     }
     if (preg_match("#^" . $prefix . str_replace('/', '\\/', $this->regex) . "\$#", $url)) {
         $find->find();
         $find->setRoute($this);
         $ord = $this->orderParams;
         $params = [];
         preg_replace_callback("#^" . $this->regex . "\$#", function ($matches) use($ord, &$params) {
             foreach ($matches as $k => $v) {
                 if ($k != 0) {
                     $params[$ord[$k - 1]] = $v;
                 }
             }
         }, $url);
         $find->setParams($params);
     }
     return $find;
 }