From 10273f5d10e20f56f29cbfa992c855aa49beaf9f Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 11 Jun 2011 10:47:15 -0400 Subject: [PATCH] Add the Request and Response objects copied from phalanx --- base/strict_object.php | 38 +++++++++++++++++ http/request.php | 35 ++++++++++++++++ http/response.php | 92 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 165 insertions(+) create mode 100644 base/strict_object.php create mode 100644 http/request.php create mode 100644 http/response.php diff --git a/base/strict_object.php b/base/strict_object.php new file mode 100644 index 0000000..5441c37 --- /dev/null +++ b/base/strict_object.php @@ -0,0 +1,38 @@ +. + +namespace hoplite\base; + +/*! + Objects that expose public properties without accessors |public $foo = NULL;| + should inherit from this class to prevent undefined property access. This + prevents subtle bugs caused by typos. For arbitrary key-value storage, use a + Dictionary. +*/ +class StrictObject +{ + public function __get($key) + { + throw new StrictObjectException('Cannot get ' . get_class($this) . '::' . $key); + } + + public function __set($key, $value) + { + throw new StrictObjectException('Cannot set ' . get_class($this) . '::' . $key); + } +} + +class StrictObjectException extends \Exception {} diff --git a/http/request.php b/http/request.php new file mode 100644 index 0000000..aaa7ac5 --- /dev/null +++ b/http/request.php @@ -0,0 +1,35 @@ +. + +namespace hoplite\http; + +require_once HOPLITE_ROOT . '/base/strict_object.php'; + +/*! + A Request represents a HTTP request and holds the data and contexte associated + with it. +*/ +class Request extends \hoplite\base\StrictObject +{ + /*! @var string The request method (upper case). */ + public $http_method = NULL; + + /*! @var string The URL, relataive to the RootController. */ + public $url = ''; + + /*! @var array HTTP request data. */ + public $data = NULL; +} diff --git a/http/response.php b/http/response.php new file mode 100644 index 0000000..ebebf13 --- /dev/null +++ b/http/response.php @@ -0,0 +1,92 @@ +. + +namespace hoplite\http; + +require_once HOPLITE_ROOT . 'base/strict_object.php'; + +/*! + A Response holds data processed by Action objects. When the RootController is + Run(), a Response object is created. This response is used for any subsequent + chained Actions. After processing, the OutputFilter will take the data and + formulate the actual HTTP response body. +*/ +class Response extends \hoplite\base\StrictObject +{ + /*! @var integer The HTTP response code to return. */ + public $response_code = ResponseCode::OK; + + /*! @var array A map of headers to values to be sent with the response. */ + public $headers = array(); + + /*! @var string Raw HTTP response body. */ + public $body = ''; + + /*! @var array Context data that is not sent to the output filter but is used + to store application-specific information between Actions. + */ + public $context = array(); + + /*! @var array Model data. */ + public $data = array(); +} + +/*! + An enumeration of all the HTTP status codes as constants. This is the complete + list of codes. Not all will be usable by an application. + @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html +*/ +class ResponseCode +{ + const 100 = CONTINUE; + const 101 = SWITCHING_PROTOCOLS; + const 200 = OK; + const 201 = CREATED; + const 202 = ACCEPTED; + const 204 = NO_CONTENT; + const 205 = RESET_CONTENT; + const 206 = PARTIAL_CONTENT; + const 300 = MULTIPLE_CHOICES; + const 301 = MOVED_PERMANENTLY; + const 302 = FOUND; + const 303 = SEE_OTHER; + const 304 = NOT_MODIFIED; + const 305 = USE_PROXY; + const 307 = TEMPORARY_REDIRECT; + const 400 = BAD_REQUEST; + const 401 = UNAUTHORIZED; + const 402 = PAYMENT_REQUIRED; + const 403 = FORBIDDEN; + const 404 = NOT_FOUND; + const 405 = METHOD_NOT_ALLOWED; + const 406 = NOT_ACCEPTABLE; + const 407 = PROXY_AUTHENTICATION_REQUIRED; + const 408 = REQUEST_TIMEOUT; + const 409 = CONFLICT; + const 410 = GONE; + const 411 = LENGTH_REQUIRED; + const 412 = PRECONDITION_FAILED; + const 413 = REQUEST_ENTITY_TOO_LARGE; + const 415 = UNSUPPORTED_MEDIA_TYPE; + const 416 = REQUESTED_RANGE_NOT_SATISFIABLE; + const 417 = EXPECTATION_FAILED; + const 500 = INTERNAL_SERVER_ERROR; + const 501 = NOT_IMPLEMENTED; + const 502 = BAD_GATEWAY; + const 503 = SERVICE_UNAVAILABLE; + const 504 = GATEWAY_TIMEOUT; + const 505 = HTTP_VERSION_NOT_SUPPORTED; +} -- 2.22.5