Changeset 955

Show
Ignore:
Timestamp:
10/03/07 11:16:59 (1 year ago)
Author:
schst
Message:

Make SMD compatible with Dojo, add the ability to pass the class name as a GET parameter to the JSON-RPC processor instead of including it per method, added example using Dojo

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/examples/docroot/index.php

    r744 r955  
    9494      <li>Event handling<ul><li><a href="events/">Simple example</a></li><li><a href="events/queue.php">Queued events</a></li></ul></li> 
    9595      <li> 
    96         <a href="json-rpc/">Out-of-the-box AJAX with the JSON-RPC processor</a> (<a href="showsource.php?group=json-rpc">show HTML/PHP source</a>, <a href="showsource.php?group=json-rpc&example=jsonrpc">show service source</a>) 
     96        JSON-RPC 
     97        <ul> 
     98          <li> 
     99            <a href="json-rpc/">Out-of-the-box AJAX with the JSON-RPC processor</a> (<a href="showsource.php?group=json-rpc">show HTML/PHP source</a>, <a href="showsource.php?group=json-rpc&example=jsonrpc">show service source</a>) 
     100          </li> 
     101          <li> 
     102            <a href="json-rpc/dojo.php">Connecting Stubbles JSON-RPC with the Dojo toolkit</a> (<a href="showsource.php?group=json-rpc&example=dojo">show HTML/PHP source</a>) 
     103          </li> 
     104        </ul> 
    97105      </li> 
    98106      <li><a href="foreignClassLoaders/">Loading classes from foreign resources with the Stubbles class loader</a></li> 
  • trunk/src/main/php/net/stubbles/service/jsonrpc/stubJsonRpcProcessor.php

    r944 r955  
    190190        if ($this->request->hasValue('processor')) { 
    191191            $processor   = $this->request->getValidatedValue(new stubPassThruValidator(), 'processor', stubRequest::SOURCE_PARAM); 
    192             $serviceUrl .= '?processor='.$processor; 
    193         } 
    194  
     192            $serviceUrl .= '?processor=' . $processor; 
     193            $serviceUrl .= '&__class=' . $class; 
     194        } 
    195195        $generator = new stubSmdGenerator($serviceUrl); 
    196196        try { 
     
    255255 
    256256        try { 
    257             $reflect = $this->getClassAndMethod($phpJsonObj->method); 
     257            $className = null; 
     258            if ($this->request->hasValue('__class')) { 
     259                $className = $this->request->getValidatedValue(new stubPassThruValidator(), '__class'); 
     260            } 
     261            $reflect = $this->getClassAndMethod($phpJsonObj->method, $className); 
    258262            $result  = $this->invokeServiceMethod($reflect['class'], $reflect['method'], $phpJsonObj->params); 
    259263            $this->response->writeResponse($phpJsonObj->id, $result); 
     
    292296     * 
    293297     * @param   string  $methodName 
     298     * @param   string  $className  optional, if used with dojo's SMD 
    294299     * @return  array 
    295300     * @throws  stubClassNotFoundException 
    296301     * @throws  stubException 
    297302     */ 
    298     protected function getClassAndMethod($methodName) 
    299     { 
    300         if (!preg_match('/'.self::CLASS_AND_METHOD_PATTERN.'/', $methodName)) { 
    301             throw new stubException('Invalid request: method-Pattern has to be <className>.<methodName>.'); 
    302         } 
    303  
    304         list($className, $methodName) = explode('.', $methodName); 
     303    protected function getClassAndMethod($methodName, $className = null) 
     304    { 
     305        if ($className === null) { 
     306            if (!preg_match('/'.self::CLASS_AND_METHOD_PATTERN.'/', $methodName)) { 
     307                throw new stubException('Invalid request: method-Pattern has to be <className>.<methodName>.'); 
     308            } 
     309 
     310            list($className, $methodName) = explode('.', $methodName); 
     311        } 
    305312        if (!isset($this->classMap[$className])) { 
    306313            throw new stubException('Unknown class ' . $className . '.'); 
  • trunk/src/main/php/net/stubbles/service/jsonrpc/util/stubSmdGenerator.php

    r922 r955  
    6464 
    6565            $methodDef = new stdClass(); 
    66             $methodDef->name       = $jsClass . '.' . $method->getName(); 
     66            $methodDef->name       = $method->getName(); 
    6767            $methodDef->parameters = array(); 
    6868            $smdData->methods[] = $methodDef;