Permalink
Browse files

quality fixes and expansion of docblocks, minor code changes for cons…

…istency and readability.

also relocated constructor properties for `\net\http\Request` which had no business inside `\net\http\Message`.
  • Loading branch information...
1 parent e99dea1 commit b752ffd4426342382bce7b4f455039985297ce65 @mikegreiling mikegreiling committed Apr 18, 2013
Showing with 225 additions and 177 deletions.
  1. +47 −53 action/Request.php
  2. +37 −11 action/Response.php
  3. +17 −17 net/Message.php
  4. +9 −4 net/http/Auth.php
  5. +29 −30 net/http/Message.php
  6. +60 −57 net/http/Request.php
  7. +25 −4 net/http/Response.php
  8. +1 −1 security/auth/adapter/Http.php
View
@@ -50,16 +50,16 @@ class Request extends \lithium\net\http\Request {
public $persist = array();
/**
- * POST data.
+ * Data found in the HTTP request body, most often populated by `$_POST` and `$_FILES`.
*
- * @var data
+ * @var array
*/
public $data = array();
/**
- * GET data.
+ * Key/value pairs found encoded in the request URL after '?', populated by `$_GET`.
*
- * @var string
+ * @var array
*/
public $query = array();
@@ -86,13 +86,6 @@ class Request extends \lithium\net\http\Request {
protected $_env = array();
/**
- * Classes used by `Request`.
- *
- * @var array
- */
- protected $_classes = array('media' => 'lithium\net\http\Media');
-
- /**
* If POST / PUT data is coming from an input stream (rather than `$_POST`), this specified
* where to read it from.
*
@@ -144,37 +137,40 @@ class Request extends \lithium\net\http\Request {
protected $_locale = null;
/**
- * Adds config values to the public properties when a new object is created.
- * Pulling request data from superglobals if `globals` is set to `true`.
+ * Adds config values to the public properties when a new object is created, pulling
+ * request data from superglobals if `globals` is set to `true`.
*
* @param array $config Configuration options : default values are:
- * - `url`: ''
- * - `base`: ''
- * - `data`: array
- * - `scheme`: http
- * - `host`: localhost
- * - `port`: null
- * - `username`: null
- * - `password`: null
- * - `path`: null
- * - `query`: array - after the question mark ?
- * - `headers`: array
- * - `body`: null
- * - `auth` - the Authorization method (Basic|Digest)
- * - `method` - GET
- * - `protocol`: null
- * - `version`: 1.1
- * - `globals` : true. If true build the Request from superglobals.
+ * - `'base'` _string_: null
+ * - `'url'` _string_: null
+ * - `'protocol'` _string_: null
+ * - `'version'` _string_: '1.1'
+ * - `'method'` _string_: 'GET'
+ * - `'scheme'` _string_: 'http'
+ * - `'host'` _string_: 'localhost'
+ * - `'port'` _integer_: null
+ * - `'username'` _string_: null
+ * - `'password'` _string_: null
+ * - `'path'` _string_: null
+ * - `'query'` _array_: array()
+ * - `'headers'` _array_: array()
+ * - `'type'` _string_: null
+ * - `'auth'` _mixed_: null
+ * - `'body'` _mixed_: null
+ * - `'data'` _array_: array()
+ * - `'env'` _array_: array()
+ * - `'globals'` _boolean_: true
*/
public function __construct(array $config = array()) {
- $config += array(
+ $defaults = array(
'base' => null,
'url' => null,
'env' => array(),
'query' => array(),
'data' => array(),
'globals' => true
);
+ $config += $defaults;
if ($config['globals'] === true) {
if (isset($_SERVER)) {
@@ -222,9 +218,8 @@ public function __construct(array $config = array()) {
/**
* Initialize request object
*
- * Defines an artificial `'PLATFORM'` environment variable as either
- * `'IIS'`, `'CGI'` or `null` to allow checking for the SAPI in a
- * normalized way.
+ * Defines an artificial `'PLATFORM'` environment variable as either `'IIS'`, `'CGI'` or `null`
+ * to allow checking for the SAPI in a normalized way.
*/
protected function _init() {
parent::_init();
@@ -400,10 +395,10 @@ public function env($key) {
*
* @see lithium\net\http\Media::negotiate()
* @param $type mixed If not specified, returns the media type name that the client prefers,
- * using content negotiation. If a media type name (string) is passed, returns
- * `true` or `false`, indicating whether or not that type is accepted by the client
- * at all. If `true`, returns the raw content types from the `Accept` header,
- * parsed into an array and sorted by client preference.
+ * using content negotiation. If a media type name (string) is passed, returns `true` or
+ * `false`, indicating whether or not that type is accepted by the client at all.
+ * If `true`, returns the raw content types from the `Accept` header, parsed into an array
+ * and sorted by client preference.
* @return string Returns a simple type name if the type is registered (i.e. `'json'`), or
* a fully-qualified content-type if not (i.e. `'image/jpeg'`), or a boolean or array,
* depending on the value of `$type`.
@@ -522,7 +517,7 @@ public function get($key) {
* @see lithium\action\Request::detect()
* @see lithium\net\http\Media::type()
* @param string $flag The name of the flag to check, which should be the name of a valid
- * detector (that is either built-in or defined with `detect()`).
+ * detector (that is either built-in or defined with `detect()`).
* @return boolean Returns `true` if the detector check succeeds (see the details for the
* built-in detectors above, or `detect()`), otherwise `false`.
*/
@@ -581,19 +576,18 @@ public function type($type = null) {
* {{{ embed:lithium\tests\cases\action\RequestTest::testDetect(11-12) }}}
*
* @see lithium\action\Request::is()
- * @param string $flag The name of the detector check. Used in subsequent calls to
- * `Request::is()`.
+ * @param string $flag The name of the detector check. Used in subsequent calls to `Request::is()`.
* @param mixed $detector Detectors can be specified in four different ways:
- * - The name of an HTTP header or environment variable. If a string, calling the
- * detector will check that the header or environment variable exists and is set
- * to a non-empty value.
- * - A two-element array containing a header/environment variable name, and a value
- * to match against. The second element of the array must be an exact match to
- * the header or variable value.
- * - A two-element array containing a header/environment variable name, and a
- * regular expression that matches against the value, as in the example above.
- * - A closure which accepts an instance of the `Request` object and returns a
- * boolean value.
+ * - The name of an HTTP header or environment variable. If a string, calling the detector
+ * will check that the header or environment variable exists and is set to a non-empty
+ * value.
+ * - A two-element array containing a header/environment variable name, and a value to match
+ * against. The second element of the array must be an exact match to the header or
+ * variable value.
+ * - A two-element array containing a header/environment variable name, and a regular
+ * expression that matches against the value, as in the example above.
+ * - A closure which accepts an instance of the `Request` object and returns a boolean
+ * value.
* @return void
*/
public function detect($flag, $detector = null) {
@@ -652,7 +646,7 @@ public function to($format, array $options = array()) {
* "[Globalization](http://lithify.me/docs/manual/07_globalization)" in the manual.
*
* @param string $locale An optional locale string like `'en'`, `'en_US'` or `'de_DE'`. If
- * specified, will overwrite the existing locale.
+ * specified, will overwrite the existing locale.
* @return Returns the currently set locale string.
*/
public function locale($locale = null) {
@@ -714,7 +708,7 @@ protected function _url($url = null) {
* @return array
*/
protected function _parseFiles() {
- if (isset($_FILES) && $_FILES) {
+ if (!empty($_FILES)) {
$result = array();
$normalize = function($key, $value) use ($result, &$normalize){
View
@@ -28,31 +28,57 @@ class Response extends \lithium\net\http\Response {
*/
protected $_classes = array(
'router' => 'lithium\net\http\Router',
- 'media' => 'lithium\net\http\Media'
+ 'media' => 'lithium\net\http\Media',
+ 'auth' => 'lithium\net\http\Auth'
);
+ /**
+ * Auto configuration properties.
+ *
+ * @var array
+ */
protected $_autoConfig = array('classes' => 'merge');
+ /**
+ * Adds config values to the public properties when a new object is created. Config options
+ * also include default values for `Response::body()` when called from `Response::render()`.
+ *
+ * @see lithium\net\http\Message::body()
+ * @param array $config Configuration options : default value
+ * - `'protocol'` _string_: null
+ * - `'version'` _string_: '1.1'
+ * - `'headers'` _array_: array()
+ * - `'body'` _mixed_: null
+ * - `'message'` _string_: null
+ * - `'status'` _mixed_: null
+ * - `'type'` _string_: null
+ * - `'buffer'` _integer_: null
+ * - `'decode'` _boolean_: null
+ * - `'location'` _mixed_: null
+ * - `'request'` _object_: null
+ */
public function __construct(array $config = array()) {
$defaults = array(
'buffer' => 8192,
'location' => null,
- 'status' => 0,
'request' => null,
'decode' => false
);
parent::__construct($config + $defaults);
}
+ /**
+ * Sets the Location header using `$config['location']` and `$config['request']` passed in
+ * through the constructor if provided.
+ *
+ * @return void
+ */
protected function _init() {
parent::_init();
- $config = $this->_config;
- $this->status($config['status']);
- unset($this->_config['status']);
- if ($config['location']) {
- $classes = $this->_classes;
- $location = $classes['router']::match($config['location'], $config['request']);
+ if ($this->_config['location']) {
+ $router = $this->_classes['router'];
+ $location = $router::match($this->_config['location'], $this->_config['request']);
$this->headers('Location', $location);
}
}
@@ -61,9 +87,9 @@ protected function _init() {
* Controls how or whether the client browser and web proxies should cache this response.
*
* @param mixed $expires This can be a Unix timestamp indicating when the page expires, or a
- * string indicating the relative time offset that a page should expire, i.e.
- * `"+5 hours". Finally, `$expires` can be set to `false` to completely disable
- * browser or proxy caching.
+ * string indicating the relative time offset that a page should expire, i.e. `"+5 hours".
+ * Finally, `$expires` can be set to `false` to completely disable browser or proxy
+ * caching.
* @return void
*/
public function cache($expires) {
View
@@ -41,44 +41,44 @@ class Message extends \lithium\core\Object {
public $port = null;
/**
- * Absolute path of the request.
+ * The username for this endpoint.
*
* @var string
*/
- public $path = null;
+ public $username = null;
/**
- * The username for this endpoint.
+ * The password for this endpoint.
*
* @var string
*/
- public $username = null;
+ public $password = null;
/**
- * The password for this endpoint.
+ * Absolute path of the request.
*
* @var string
*/
- public $password = null;
+ public $path = null;
/**
* The body of the message.
*
- * @var array
+ * @var mixed
*/
- public $body = array();
+ public $body = null;
/**
* Adds config values to the public properties when a new object is created.
*
* @param array $config Configuration options : default value
- * - `scheme`: tcp
- * - `host`: localhost
- * - `port`: null
- * - `username`: null
- * - `password`: null
- * - `path`: null
- * - `body`: null
+ * - `'scheme'` _string_: 'tcp'
+ * - `'host'` _string_: 'localhost'
+ * - `'port'` _integer_: null
+ * - `'username'` _string_: null
+ * - `'password'` _string_: null
+ * - `'path'` _string_: null
+ * - `'body'` _mixed_: null
*/
public function __construct(array $config = array()) {
$defaults = array(
@@ -99,11 +99,11 @@ public function __construct(array $config = array()) {
}
/**
- * Add body parts.
+ * Add body parts and compile the message body.
*
* @param mixed $data
* @param array $options
- * - `'buffer'`: split the body string
+ * - `'buffer'` _integer_: split the body string
* @return array
*/
public function body($data = null, $options = array()) {
View
@@ -9,8 +9,13 @@
namespace lithium\net\http;
/**
- * The `Auth` class handles HTTP Authentication encoding and decode. Typically, this class is not
- * used directly, but is a utility of `action\Request` and `security\auth\adapter\Http`
+ * The `Auth` class handles HTTP Authentication encoding and decoding. Typically, this class is
+ * not used directly, but is a utility of `net\http\Request`, `net\http\Response`, and
+ * `security\auth\adapter\Http`
+ *
+ * @see lithium\net\http\Request::to()
+ * @see lithium\net\http\Response::digest()
+ * @see lithium\security\auth\adapter\Http
*/
class Auth extends \lithium\core\StaticObject {
@@ -30,7 +35,7 @@ public static function header($data) {
if (empty($data['response'])) {
return null;
}
- if (!empty($data['opaque'])) {
+ if (isset($data['nonce'])) {
$defaults = array(
'realm' => 'app', 'method' => 'GET', 'uri' => '/',
'username' => null, 'qop' => 'auth',
@@ -48,7 +53,7 @@ public static function header($data) {
}
/**
- * Encoded the data with username and password to create the proper response. Returns an array
+ * Encodes the data with username and password to create the proper response. Returns an array
* containing the username and encoded response.
*
* @param string $username Username to authenticate with
Oops, something went wrong.

0 comments on commit b752ffd

Please sign in to comment.