[lux commit] r139 - trunk/Lux/Controller

0 views
Skip to first unread message

codesite...@google.com

unread,
Sep 30, 2008, 7:04:26 PM9/30/08
to lux...@googlegroups.com
Author: rodrigo.moraes
Date: Tue Sep 30 16:03:25 2008
New Revision: 139

Modified:
trunk/Lux/Controller/Rest.php

Log:
* Converted initial action name to dashes format, to match keys in
$_action_map and $_action_http even if the url uses CamelCase.
* Casted $this->_action_http[$this->_action] to array so that a string can
also be used, as in the phpdoc example.
* Updated comments.

Modified: trunk/Lux/Controller/Rest.php
==============================================================================
--- trunk/Lux/Controller/Rest.php (original)
+++ trunk/Lux/Controller/Rest.php Tue Sep 30 16:03:25 2008
@@ -35,10 +35,8 @@
* $_action_http = array(
* // actionList supports only GET
* 'list' => 'GET',
- * // actionItem suppports GET, POST and PUT
- * 'item' => array(
- * 'GET', 'POST', 'PUT'
- * ),
+ * // actionItem suppports four methods
+ * 'item' => array('GET', 'POST', 'PUT', 'DELETE'),
* );
*
* }}
@@ -57,10 +55,12 @@
*
* $_action_map = array(
* 'item' => array(
- * // if HTTP method is POST, use 'actionItemUpdate'
instead
- * 'POST' => 'item-update',
- * // if HTTP method is PUT, use 'actionItemInsert' instead
- * 'PUT' => 'item-insert',
+ * // change action to 'actionItemUpdate' for POST
+ * 'POST' => 'item-update',
+ * // change action to 'actionItemInsert' for PUT
+ * 'PUT' => 'item-insert',
+ * // change action to 'actionItemDelete' for DELETE
+ * 'DELETE' => 'item-delete',
* ),
* );
*
@@ -170,7 +170,7 @@
$method = $this->_request_method;

if (isset($this->_action_http[$action]) &&
- in_array($method, $this->_action_http[$action])) {
+ in_array($method, (array) $this->_action_http[$action])) {
return true;
}

@@ -253,6 +253,14 @@
*/
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
+ // (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
$action = $this->_action;
$method = $this->_request_method;

Reply all
Reply to author
Forward
0 new messages