Navigation Menu

Skip to content

Commit

Permalink
adding Put functionality to Default router
Browse files Browse the repository at this point in the history
  • Loading branch information
kotfic committed Mar 27, 2012
1 parent 62ce2fe commit dbdd8ec
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion App/Assembla/Controller/Custom.php
Expand Up @@ -19,7 +19,7 @@ public function getActiveTickets(){
}

public function update_ticket() {
die();

}

}
Expand Down
35 changes: 29 additions & 6 deletions App/Assembla/Controller/Default.php
Expand Up @@ -14,14 +14,37 @@ protected function _camelize($name)
return $this->_uc_words($name, '');
}

protected function _processGet($service, $method, $args){
$method = "load" . $this->_camelize($method);
if( isset( $args[0] ) && is_array($args[0] ) ){
return $this->_api->$method( $args[0] )->toJSON();
} else {
return $this->_api->$method()->toJSON();
}
}

protected function _processPut( $service, $method, $args ){
if( count($this->getRequest()->getPut()) ){
if( isset($service['classname'] ) ){
$object = new $service['classname']();
$object->setData( $this->getRequest()->getParams() );
return '';
}
}
}


public function __call($method, $args){
if( ($service = $this->_api->getService($method) ) !== null ){
$method = "load" . $this->_camelize($method);
if( isset( $args[0] ) && is_array($args[0] ) ){
return $this->_api->$method( $args[0] )->toJSON();
} else {
return $this->_api->$method()->toJSON();
}
switch( $service['type'] ){
case 'GET':
return $this->_processGet( $service, $method, $args );
break;
case 'PUT':
return $this->_processPut( $service, $method, $args );
break;

}
} else {
throw new Exception( 'Service: ' . $method . ' is not defined in the api config!' );
}
Expand Down
2 changes: 1 addition & 1 deletion App/Assembla/etc/routes.json
Expand Up @@ -82,7 +82,7 @@
"action" : "update_space_by_id"},
"spaces/${space_wiki_name}" : { "controller" : "Assembla_Controller_Default",
"action" : "update_space_by_wiki"},
"spaces/${space_id}/tickets/${ticket_number}" : { "controller" : "Assembla_Controller_Custom",
"spaces/${space_id}/tickets/${ticket_number}" : { "controller" : "Assembla_Controller_Default",
"action" : "update_ticket"},
"user/time_entires/${task_id}" : { "controller" : "Assembla_Controller_Default",
"action" : "update_task"},
Expand Down
4 changes: 4 additions & 0 deletions App/Zend/Controller/Request/Rest.php
Expand Up @@ -6,6 +6,10 @@ class Zend_Controller_Request_Rest extends Zend_Controller_Request_Http
protected $_PUT = array();


public function getPut(){
return $this->_PUT;
}

public function __construct(){
if( isset( $_SERVER['REQUEST_METHOD'] ) ){
switch( $_SERVER['REQUEST_METHOD'] ){
Expand Down
2 changes: 1 addition & 1 deletion lib
Submodule lib updated 1 files
+1 −1 Core/API.php

0 comments on commit dbdd8ec

Please sign in to comment.