added is method, improved comments.

This commit is contained in:
Taylor Otwell 2011-06-18 10:26:04 -05:00
parent c972fe198b
commit 396d148720
1 changed files with 27 additions and 11 deletions

View File

@ -2,6 +2,13 @@
class Request { class Request {
/**
* The request URI.
*
* @var string
*/
private static $uri;
/** /**
* Get the request URI. * Get the request URI.
* *
@ -9,8 +16,13 @@ class Request {
*/ */
public static function uri() public static function uri()
{ {
if ( ! is_null(static::$uri))
{
return static::$uri;
}
// ------------------------------------------------------- // -------------------------------------------------------
// If the PATH_INFO is available, use it. // Use the PATH_INFO variable if it is available.
// ------------------------------------------------------- // -------------------------------------------------------
if (isset($_SERVER['PATH_INFO'])) if (isset($_SERVER['PATH_INFO']))
{ {
@ -28,9 +40,6 @@ public static function uri()
throw new \Exception("Malformed request URI. Request terminated."); throw new \Exception("Malformed request URI. Request terminated.");
} }
} }
// -------------------------------------------------------
// Neither PATH_INFO or REQUEST_URI are available.
// -------------------------------------------------------
else else
{ {
throw new \Exception('Unable to determine the request URI.'); throw new \Exception('Unable to determine the request URI.');
@ -59,21 +68,28 @@ public static function uri()
} }
/** /**
* Check the request URI. * Check the URI against a string or set of strings.
* *
* @param mixed $uri
* @return bool * @return bool
*/ */
public static function is($uri) public static function is()
{ {
if (is_array($uri)) $parameters = func_get_args();
// -------------------------------------------------------
// If any of the parameters match the URI, return true.
// -------------------------------------------------------
if (count($parameters) > 1)
{ {
return (in_array(static::uri(), $uri)) ? true : false; return in_array(static::uri(), $parameters);
} }
else
if (count($parameters) === 1)
{ {
return (static::uri() == $uri) ? true : false; return static::uri() == $parameters[0];
} }
return false;
} }
/** /**