Development

Changeset 8141

You must first sign up to be able to contribute.

Changeset 8141

Show
Ignore:
Timestamp:
03/29/08 01:04:56 (5 months ago)
Author:
chrisk
Message:

[ckWebServicePlugin] implemented mixin to get the action result

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/ckWebServicePlugin/trunk/lib/controller/ckWebServiceController.class.php

    r8064 r8141  
    138138      } 
    139139 
    140       //check if we are able to call the result getter 
    141       if(is_callable(array($actionInstance, $soapResultCallback))) 
    142       { 
     140      //check if we are able to call a custom result getter 
     141      if(!method_exists(array($actionInstance, $soapResultCallback))) 
     142      { 
     143        $soapResultCallback = 'defaultResultCallback'; 
     144         
    143145        if (sfConfig::get('sf_logging_enabled')) 
    144146        { 
    145           sfContext::getInstance()->getLogger()->info(sprintf('{%s} Calling soapResultCallback \'%s\'.', __CLASS__, $soapResultCallback)); 
     147          sfContext::getInstance()->getLogger()->info(sprintf('{%s} Hooking defaultResultCallback in \'sfComponent\' as \'%s\'.', __CLASS__, $soapResultCallback)); 
    146148        } 
    147  
    148         //return the result of our action 
    149         return $actionInstance->$soapResultCallback(); 
    150       } 
    151       else 
    152       { 
    153         return; 
    154       } 
     149         
     150        //hook in the default result getter 
     151        sfMixer::register('sfComponent', array($this, $soapResultCallback)); 
     152      } 
     153      if (sfConfig::get('sf_logging_enabled')) 
     154      { 
     155        sfContext::getInstance()->getLogger()->info(sprintf('{%s} Calling soapResultCallback \'%s\'.', __CLASS__, $soapResultCallback)); 
     156      } 
     157 
     158      //return the result of our action 
     159      return $actionInstance->$soapResultCallback();       
    155160    } 
    156161    catch(Exception $e) 
     
    160165    } 
    161166  } 
     167   
     168  /** 
     169   * Implements the default behavior to get the result of a soap action. 
     170   * 
     171   * @param sfAction $actionInstance The hooked sfAction instance 
     172   *  
     173   * @return mixed The result of the hooked sfAction instance 
     174   */ 
     175  public function defaultResultCallback($actionInstance) 
     176  { 
     177    $vars = $actionInstance->getVarHolder()->getAll(); 
     178     
     179    //if we have one or more vars and shouldn't render 
     180    if(count($vars) > 0 && $this->getRenderMode() == sfView::RENDER_NONE) 
     181    { 
     182      //get the default result array key 
     183      $default_key = sfConfig::get('mod_'.$actionInstance->getModuleName().'_soap_return_key_'.$actionInstance->getActionName(), 'result'); 
     184       
     185      //if there is only one var stored we return it 
     186      if(count($vars) == 1) 
     187      { 
     188        reset($vars); 
     189        return current($vars); 
     190      } 
     191      //if the default key exists we return the value 
     192      else if(array_key_exists($default_key, $vars)) 
     193      { 
     194        return $vars[$default_key]; 
     195      } 
     196    } 
     197     
     198    return; 
     199  } 
    162200}