Uri.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Pimf
  4. *
  5. * @copyright Copyright (c) Gjero Krsteski (http://krsteski.de)
  6. * @license http://krsteski.de/new-bsd-license New BSD License
  7. */
  8. namespace Pimf;
  9. use Pimf\Util\String as Str;
  10. /**
  11. * URI
  12. *
  13. * @package Pimf
  14. * @author Gjero Krsteski <[email protected]>
  15. */
  16. class Uri
  17. {
  18. /**
  19. * The URI for the current request.
  20. *
  21. * @var string
  22. */
  23. public static $uri;
  24. /**
  25. * The URI segments for the current request.
  26. *
  27. * @var array
  28. */
  29. public static $segments = array();
  30. /**
  31. * Get the full URI including the query string.
  32. *
  33. * @return string
  34. */
  35. public static function full()
  36. {
  37. return Registry::get('env')->REQUEST_URI;
  38. }
  39. /**
  40. * Get the URI for the current request.
  41. *
  42. * @return string
  43. */
  44. public static function current()
  45. {
  46. if (!is_null(static::$uri)) {
  47. return static::$uri;
  48. }
  49. //Format a given URI.
  50. $uri = trim(Registry::get('env')->PATH_INFO, '/') ? : '/';
  51. //Set the URI segments for the request.
  52. $segments = explode('/', trim($uri, '/'));
  53. static::$segments = array_diff($segments, array(''));
  54. return static::$uri = $uri;
  55. }
  56. /**
  57. * Determine if the current URI matches a given pattern.
  58. *
  59. * @param string $pattern
  60. *
  61. * @return bool
  62. */
  63. public static function is($pattern)
  64. {
  65. return Str::is($pattern, static::current());
  66. }
  67. }