Пример #1
0
 /**
  * Internal method for handling request
  *
  * @return void
  */
 protected function _handle()
 {
     $request = $this->getRequest();
     if (!$request->isMethodError() && null === $request->getMethod()) {
         return $this->fault('Invalid Request', -32600);
     }
     if ($request->isMethodError()) {
         return $this->fault('Invalid Request', -32600);
     }
     $method = $request->getMethod();
     if (!$this->_table->hasMethod($method)) {
         return $this->fault('Method not found', -32601);
     }
     $params = $request->getParams();
     $invocable = $this->_table->getMethod($method);
     $serviceMap = $this->getServiceMap();
     $service = $serviceMap->getService($method);
     $serviceParams = $service->getParams();
     if (count($params) < count($serviceParams)) {
         $params = $this->_getDefaultParams($params, $serviceParams);
     }
     try {
         $result = $this->_dispatch($invocable, $params);
     } catch (\Exception $e) {
         return $this->fault($e->getMessage(), $e->getCode(), $e);
     }
     $this->getResponse()->setResult($result);
 }
Пример #2
0
 /**
  * Internal method for handling request
  *
  * @return void
  */
 protected function _handle()
 {
     $request = $this->getRequest();
     if (!$request->isMethodError() && null === $request->getMethod()) {
         return $this->fault('Invalid Request', -32600);
     }
     if ($request->isMethodError()) {
         return $this->fault('Invalid Request', -32600);
     }
     $method = $request->getMethod();
     if (!$this->_table->hasMethod($method)) {
         return $this->fault('Method not found', -32601);
     }
     $params = $request->getParams();
     $invocable = $this->_table->getMethod($method);
     $serviceMap = $this->getServiceMap();
     $service = $serviceMap->getService($method);
     $serviceParams = $service->getParams();
     if (count($params) < count($serviceParams)) {
         $params = $this->_getDefaultParams($params, $serviceParams);
     }
     //Make sure named parameters are passed in correct order
     if (is_string(key($params))) {
         $callback = $invocable->getCallback();
         if ('function' == $callback->getType()) {
             $reflection = new \ReflectionFunction($callback->getFunction());
             $refParams = $reflection->getParameters();
         } else {
             $reflection = new \ReflectionMethod($callback->getClass(), $callback->getMethod());
             $refParams = $reflection->getParameters();
         }
         $orderedParams = array();
         foreach ($reflection->getParameters() as $refParam) {
             if (isset($params[$refParam->getName()])) {
                 $orderedParams[$refParam->getName()] = $params[$refParam->getName()];
             } elseif ($refParam->isOptional()) {
                 $orderedParams[$refParam->getName()] = null;
             } else {
                 throw new Exception('Missing required parameter: ' . $refParam->getName());
             }
         }
         $params = $orderedParams;
     }
     try {
         $result = $this->_dispatch($invocable, $params);
     } catch (\Exception $e) {
         return $this->fault($e->getMessage(), $e->getCode(), $e);
     }
     $this->getResponse()->setResult($result);
 }