parser.php 740 B

123456789101112131415161718192021222324252627282930313233
  1. <?php namespace System\Route;
  2. class Parser {
  3. /**
  4. * Get the parameters that should be passed to the route callback.
  5. *
  6. * @param string $uri
  7. * @param string $route
  8. * @return array
  9. */
  10. public static function parameters($uri, $route)
  11. {
  12. $parameters = array();
  13. $uri_segments = explode('/', $uri);
  14. $route_segments = explode('/', $route);
  15. // --------------------------------------------------------------
  16. // Any route segment wrapped in parentheses is a parameter.
  17. // --------------------------------------------------------------
  18. for ($i = 0; $i < count($route_segments); $i++)
  19. {
  20. if (strpos($route_segments[$i], '(') === 0)
  21. {
  22. $parameters[] = $uri_segments[$i];
  23. }
  24. }
  25. return $parameters;
  26. }
  27. }