Development

Changeset 18476 for plugins/dsExtDirectPlugin

You must first sign up to be able to contribute.

Show
Ignore:
Timestamp:
05/19/09 20:11:23 (4 years ago)
Author:
dancablam
Message:

added support for custom action and method names to be set via doc comments

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/dsExtDirectPlugin/trunk/README

    r18427 r18476  
    4949     *  
    5050     * @extdirect-enable 
     51     * @extdirect-len 1 
    5152     * 
    5253     */ 
     
    6869By 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. 
    6970 
    70 ### Doc comment options include: 
     71### Method-level doc comment options include: 
    7172 
    7273*    `@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. 
    7375*    `@extdirect-len` {int length} - Optional. Tells Ext.Direct the number of parameters to expect when generating the request. (Omitting this parameter defaults to 0). 
    7476*    `@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) 
    7577 
    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 
     82Now that we've added our doc comments, let's run the `extdirect:generate-api` task: 
    7783 
    7884    > symfony extdirect:generate-api frontend extdirect 
  • plugins/dsExtDirectPlugin/trunk/lib/controller/dsExtDirectController.class.php

    r18426 r18476  
    106106      { 
    107107        $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; 
    108111      } 
    109112      else  
    110113      { 
    111         throw new Exception('Call to undefined action: ' . $cdata->action); 
     114        throw new Exception('Call to undefined action: ' . $action); 
    112115      } 
    113116       
     
    117120      { 
    118121        $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; 
    119125      } 
    120126      else 
     
    145151      if (sfConfig::get('sf_logging_enabled')) 
    146152      { 
    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); 
    150156       
    151157      //Get the action 
     
    155161      if($actionInstance->getModuleName() == sfConfig::get('sf_error_404_module') && $actionInstance->getActionName() == sfConfig::get('sf_error_404_action')) 
    156162      { 
    157         throw new sfError404Exception("Call to undefined method: $method on action: $action"); 
     163        throw new sfError404Exception("Call to undefined method: $realMethod on action: $realAction"); 
    158164      } 
    159165       
  • plugins/dsExtDirectPlugin/trunk/lib/task/dsExtDirectGenerateApiTask.class.php

    r18427 r18476  
    9393      {  
    9494        $class = new ReflectionClass($module.'Actions'); 
     95        $class_comments = $class->getDocComment(); 
    9596        foreach($class->getMethods(ReflectionMethod::IS_PUBLIC) as $method) 
    9697        { 
    97           $comments = $method->getDocComment(); 
     98          $method_comments = $method->getDocComment(); 
    9899           
    99           if(strpos($comments, '@extdirect-enable') !== false) 
     100          if(strpos($method_comments, '@extdirect-enable') !== false) 
    100101          { 
    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); 
    102112            $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             
    105116            $method_def = array('len' => $method_len, 'formHandler' => $method_fh); 
    106117             
    107             if(!isset($api[$module])) 
     118            if(!isset($api[$action_name])) 
    108119            { 
    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 
    110125            } 
    111126            else  
    112127            { 
    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; 
    114130            } 
    115131          } 
  • plugins/dsExtDirectPlugin/trunk/package.xml

    • Property svn:mime-type set to text/plain