Route.php 921 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace FastRoute;
  3. class Route
  4. {
  5. /** @var string */
  6. public $httpMethod;
  7. /** @var string */
  8. public $regex;
  9. /** @var array */
  10. public $variables;
  11. /** @var mixed */
  12. public $handler;
  13. /**
  14. * Constructs a route (value object).
  15. *
  16. * @param string $httpMethod
  17. * @param mixed $handler
  18. * @param string $regex
  19. * @param array $variables
  20. */
  21. public function __construct($httpMethod, $handler, $regex, $variables)
  22. {
  23. $this->httpMethod = $httpMethod;
  24. $this->handler = $handler;
  25. $this->regex = $regex;
  26. $this->variables = $variables;
  27. }
  28. /**
  29. * Tests whether this route matches the given string.
  30. *
  31. * @param string $str
  32. *
  33. * @return bool
  34. */
  35. public function matches($str)
  36. {
  37. $regex = '~^' . $this->regex . '$~';
  38. return (bool) preg_match($regex, $str);
  39. }
  40. }