38 lines
821 B
PHP
38 lines
821 B
PHP
<?php
|
|
|
|
namespace FastRoute;
|
|
|
|
class Route {
|
|
public $httpMethod;
|
|
public $regex;
|
|
public $variables;
|
|
public $handler;
|
|
|
|
/**
|
|
* Constructs a route (value object).
|
|
*
|
|
* @param string $httpMethod
|
|
* @param mixed $handler
|
|
* @param string $regex
|
|
* @param array $variables
|
|
*/
|
|
public function __construct($httpMethod, $handler, $regex, $variables) {
|
|
$this->httpMethod = $httpMethod;
|
|
$this->handler = $handler;
|
|
$this->regex = $regex;
|
|
$this->variables = $variables;
|
|
}
|
|
|
|
/**
|
|
* Tests whether this route matches the given string.
|
|
*
|
|
* @param string $str
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function matches($str) {
|
|
$regex = '~^' . $this->regex . '$~';
|
|
return (bool) preg_match($regex, $str);
|
|
}
|
|
}
|
|
|