Modified:
trunk/Lux/Controller/Rest.php
Log:
Updated comments.
Modified: trunk/Lux/Controller/Rest.php
==============================================================================
--- trunk/Lux/Controller/Rest.php (original)
+++ trunk/Lux/Controller/Rest.php Wed Oct 1 07:07:20 2008
@@ -18,27 +18,19 @@
{
/**
*
- * HTTP request method.
- *
- * @var string
- *
- */
- protected $_request_method;
-
- /**
- *
- * A list of supported HTTP request methods for each action,
- * keyed by the dashed action name. Example:
+ * A list of supported HTTP request methods for each action, keyed by
the
+ * action name in "dashes" format. All public actions **must** be
+ * explicitly listed here to be accessible. Example:
*
* {{code: php
*
- * $_action_http = array(
- * // actionList supports only GET
+ * protected $_action_http = array(
+ * // actionList() supports only GET
* 'list' => 'GET',
- * // actionItem suppports four methods
+ * // actionItem() suppports all methods
* 'item' => array('GET', 'POST', 'PUT', 'DELETE'),
* );
- *
+ *
* }}
*
* @var array
@@ -49,17 +41,20 @@
/**
*
* A list of actions to be mapped based on the HTTP request method,
- * keyed by the dashed action name. Example:
+ * keyed by the action name in "dashes" format. Example:
*
* {{code: php
*
- * $_action_map = array(
+ * // Normally 'actionItem()' is executed
when '/my-controller/item'
+ * // is requested, but here we override this explicitly defining
+ * // actions for different request methods:
+ * protected $_action_map = array(
* 'item' => array(
- * // change action to 'actionItemUpdate' for POST
- * 'POST' => 'item-update',
- * // change action to 'actionItemInsert' for PUT
- * 'PUT' => 'item-insert',
- * // change action to 'actionItemDelete' for DELETE
+ * // execute 'actionItemInsert()' if request method is
POST
+ * 'POST' => 'item-insert',
+ * // execute 'actionItemUpdate()' if request method is PUT
+ * 'PUT' => 'item-update',
+ * // execute 'actionItemDelete()' if request method is
DELETE
* 'DELETE' => 'item-delete',
* ),
* );
@@ -73,7 +68,16 @@
/**
*
- * Content data to be converted depending on the current format
+ * HTTP request method: 'GET', 'POST', 'PUT' or 'DELETE'.
+ *
+ * @var string
+ *
+ */
+ protected $_request_method;
+
+ /**
+ *
+ * Content data to be converted based on the current format.
*
* @var array
*
@@ -110,6 +114,8 @@
* Sets the response content for JSON.
*
* @return void
+ *
+ * @todo make this method abstract?
*
*/
protected function _renderJson()
@@ -124,12 +130,13 @@
* Sets the response content for XML.
*
* @return void
+ *
+ * @todo convert content to XML? make this method abstract?
*
*/
protected function _renderXml()
{
- // @todo: convert content to XML
- $this->_response->content = '';
+ $this->_response->content = $this->_content;
}
/**
@@ -253,18 +260,16 @@
*/
protected function _preRun()
{
- // convert first requested action name to dashes, to match
- // keys in $_action_map and $_action_http. the "dashes" format
must be
- // the standard internally, e.g., for actions passed to _forward()
etc
+ // convert first requested action name to dashes, to match keys in
+ // $_action_map and $_action_http. the "dashes" format must be the
+ // standard internally, e.g. for action names passed to _forward()
etc
// (code from Solar_Inflect::camelToDashes())
$action = preg_replace('/([a-z])([A-Z])/', '$1 $2',
$this->_action);
$this->_action = str_replace(' ', '-', strtolower($action));
- // get some shortcuts
+ // change action based on the request method, if defined
$action = $this->_action;
$method = $this->_request_method;
-
- // rename action according to the request method, if defined
if (isset($this->_action_map[$action][$method])) {
$this->_action = $this->_action_map[$action][$method];
}