parser.php 802 B

12345678910111213141516171819202122232425262728293031323334
  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. // Extract all of the parameters out of the URI. Any route
  17. // segment wrapped in parentheses is considered a parameter.
  18. // --------------------------------------------------------------
  19. for ($i = 0; $i < count($route_segments); $i++)
  20. {
  21. if (strpos($route_segments[$i], '(') === 0)
  22. {
  23. $parameters[] = $uri_segments[$i];
  24. }
  25. }
  26. return $parameters;
  27. }
  28. }