Changeset 18476 for plugins/dsExtDirectPlugin
- Timestamp:
- 05/19/09 20:11:23 (4 years ago)
- Files:
-
- plugins/dsExtDirectPlugin/trunk/README (modified) (2 diffs)
- plugins/dsExtDirectPlugin/trunk/lib/controller/dsExtDirectController.class.php (modified) (4 diffs)
- plugins/dsExtDirectPlugin/trunk/lib/task/dsExtDirectGenerateApiTask.class.php (modified) (1 diff)
- plugins/dsExtDirectPlugin/trunk/package.xml (modified) (1 prop)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/dsExtDirectPlugin/trunk/README
r18427 r18476 49 49 * 50 50 * @extdirect-enable 51 * @extdirect-len 1 51 52 * 52 53 */ … … 68 69 By simply adding `@extdirect-enable` to the comments above the action method the `extdirect:generate-api` task knows to include this method into the API spec. 69 70 70 ### Doc comment options include:71 ### Method-level doc comment options include: 71 72 72 73 * `@extdirect-enable` - flags the action method for inclusion in the API spec. 74 * `@extdirect-method` {string method name} - Optional. Allows you to set a custom method name. 73 75 * `@extdirect-len` {int length} - Optional. Tells Ext.Direct the number of parameters to expect when generating the request. (Omitting this parameter defaults to 0). 74 76 * `@extdirect-formhandler` - Optional. Flags the method as a formhandler method. This is important when dealing with how we handle the sfRequest parameters as discussed later. (Omitting this sets the formHandler to false in the API spec - this should be omitted unless you know what it means) 75 77 76 Now that we've added our doc comment, let's run the `extdirect:generate-api` task: 78 ### Action-level doc comment options include: 79 80 * `@extdirect-action` {string action name} - Optional. Allows you to set a custom action name. 81 82 Now that we've added our doc comments, let's run the `extdirect:generate-api` task: 77 83 78 84 > symfony extdirect:generate-api frontend extdirect plugins/dsExtDirectPlugin/trunk/lib/controller/dsExtDirectController.class.php
r18426 r18476 106 106 { 107 107 $apiAction = $api[$action]; 108 109 //Actual symfony name of action (if overridden by extdirect-action) 110 $realAction = isset($api[$action]['action']) ? $api[$action]['action'] : $action; 108 111 } 109 112 else 110 113 { 111 throw new Exception('Call to undefined action: ' . $ cdata->action);114 throw new Exception('Call to undefined action: ' . $action); 112 115 } 113 116 … … 117 120 { 118 121 $apiMethod = $apiAction['methods'][$method]; 122 123 //Actual symfony name of method (if overridden by extdirect-method) 124 $realMethod = isset($apiAction['method_map'][$method]) ? $apiAction['method_map'][$method] : $apiMethod; 119 125 } 120 126 else … … 145 151 if (sfConfig::get('sf_logging_enabled')) 146 152 { 147 $this->context->getEventDispatcher()->notify(new sfEvent($this, 'application.log', array(sprintf('Forwarding to "%s/%s".', $ action, $method))));148 } 149 $this->forward($ action, $method);153 $this->context->getEventDispatcher()->notify(new sfEvent($this, 'application.log', array(sprintf('Forwarding to "%s/%s".', $realAction, $realMethod)))); 154 } 155 $this->forward($realAction, $realMethod); 150 156 151 157 //Get the action … … 155 161 if($actionInstance->getModuleName() == sfConfig::get('sf_error_404_module') && $actionInstance->getActionName() == sfConfig::get('sf_error_404_action')) 156 162 { 157 throw new sfError404Exception("Call to undefined method: $ method on action: $action");163 throw new sfError404Exception("Call to undefined method: $realMethod on action: $realAction"); 158 164 } 159 165 plugins/dsExtDirectPlugin/trunk/lib/task/dsExtDirectGenerateApiTask.class.php
r18427 r18476 93 93 { 94 94 $class = new ReflectionClass($module.'Actions'); 95 $class_comments = $class->getDocComment(); 95 96 foreach($class->getMethods(ReflectionMethod::IS_PUBLIC) as $method) 96 97 { 97 $ comments = $method->getDocComment();98 $method_comments = $method->getDocComment(); 98 99 99 if(strpos($ comments, '@extdirect-enable') !== false)100 if(strpos($method_comments, '@extdirect-enable') !== false) 100 101 { 101 preg_match('/@extdirect-len (?P<len>\\d*)/', $comments, $method_len); 102 //Get custom action name, if any 103 preg_match('/@extdirect-action (?P<action>[_\\w]*)/', $class_comments, $action_name); 104 $action_name = isset($action_name['action']) && !empty($action_name['action']) ? $action_name['action'] : $module; 105 106 //Get custom method name, if any 107 $real_method_name = $this->getShortMethodName($method->getName()); 108 preg_match('/@extdirect-method (?P<method>[_\\w]*)/', $method_comments, $method_name); 109 $method_name = isset($method_name['method']) && !empty($method_name['method']) ? $method_name['method'] : $real_method_name; 110 111 preg_match('/@extdirect-len (?P<len>\\d*)/', $method_comments, $method_len); 102 112 $method_len = isset($method_len['len']) && !empty($method_len['len']) ? $method_len['len'] : 0; 103 $method_name = $this->getShortMethodName($method->getName()); 104 $method_fh = strpos($comments, '@extdirect-formhandler') !== false ? true : false; 113 114 $method_fh = strpos($method_comments, '@extdirect-formhandler') !== false ? true : false; 115 105 116 $method_def = array('len' => $method_len, 'formHandler' => $method_fh); 106 117 107 if(!isset($api[$ module]))118 if(!isset($api[$action_name])) 108 119 { 109 $api[$module] = array('methods' => array($method_name => $method_def)); 120 // 'action' value in array equals the real name of the action ($module) since $action_name can be custom 121 $api[$action_name] = array( 122 'action' => $module, 123 'methods' => array($method_name => $method_def), 124 'method_map' => array($method_name => $real_method_name));//Maps custom method name to real method name 110 125 } 111 126 else 112 127 { 113 $api[$module]['methods'][$method_name] = $method_def; 128 $api[$action_name]['methods'][$method_name] = $method_def; 129 $api[$action_name]['method_map'][$method_name] = $real_method_name; 114 130 } 115 131 } plugins/dsExtDirectPlugin/trunk/package.xml
- Property svn:mime-type set to text/plain