<?php
/**
* @package phprouter
*/
namespace phprouter;
/**
* Class containing information about the HTTP request done by client
* @package phprouter
*/
abstract class Request
{
/**
* HTTP request URI
* @see uri()
* @var string
* @access private
*/
static protected $uri;
/**
* HTTP request method
* @see method()
* @see Http::$methods
* @var string
* @access private
*/
static protected $method;
/**
* Server HTTP protocol version
* @see server_protocol()
* @var string
* @access private
*/
static protected $server_protocol;
/**
* Returns HTTP request URI
* @see $uri
* @return string The relative HTTP request URI
*/
static function uri()
{
if ( isset( self::$uri ) )
{
return self::$uri;
}
if ( isset( $_SERVER['PATH_INFO'] ) )
{
self::$uri = $_SERVER['PATH_INFO'];
}
// if Apache's mod_php5 isn't enabled
else
{
$get_keys = array_keys( $_GET );
$first_key = reset( $get_keys );
if ( $first_key[0] == '/' )
{
self::$uri = $first_key;
}
else
{
self::$uri = '/';
}
}
return self::$uri;
}
/**
* Returns HTTP request method
* @see $method
* @see Http::$methods
* @return string The capitalized HTTP method used, GET if not found
*/
static function method()
{
if ( isset( self::$method ) )
{
return self::$method;
}
if ( isset( $_SERVER['REQUEST_METHOD'] ) )
{
self::$method = strtoupper( $_SERVER['REQUEST_METHOD'] );
}
else
{
self::$method = 'GET';
}
return self::$method;
}
/**
* Returns server HTTP protocol version
* @see $server_protocol
* @return string Server HTTP protocol version, HTTP/1.1 if not found
*/
static function server_protocol()
{
if ( isset( self::$server_protocol ) )
{
return self::$server_protocol;
}
if ( isset( $_SERVER['SERVER_PROTOCOL'] ) )
{
self::$server_protocol = strtoupper( $_SERVER['SERVER_PROTOCOL'] );
}
else
{
self::$server_protocol = 'HTTP/1.1';
}
return self::$server_protocol;
}
}
/* EOF */