Exemple #1
0
 /**
  * @return mixed
  * @throws JsonRpcException
  */
 protected function getHandler()
 {
     if (strpos($this->getMethod(), '.') !== false) {
         list($object, $method) = explode(".", $this->getMethod());
         $pinba_filename = $object . "_" . $method;
         try {
             $object = Yii::createObject(JsonRPCModule::getInstance()->apiNamespace . '\\' . $object);
         } catch (\Exception $e) {
             throw new JsonRpcException($e->getMessage(), JsonRpcException::METHOD_NOT_FOUND, $e);
         }
     } else {
         $object = 'Base';
         $method = $this->getMethod();
         $class = get_class($this);
         $namespace = '';
         if (($pos = strrpos($class, '\\')) !== false) {
             $namespace = substr($class, 0, $pos) . '\\';
         }
         $pinba_filename = $object . "_" . $method;
         $object = Yii::createObject($namespace . $object);
     }
     if (function_exists('pinba_script_name_set')) {
         pinba_script_name_set($pinba_filename);
     }
     $this->setMethod($method);
     $this->setObject($object);
     $class = new \ReflectionClass($this->getObject());
     if (!$class->hasMethod($this->getMethod())) {
         throw new JsonRpcException("Method not found " . $this->getMethod(), JsonRpcException::METHOD_NOT_FOUND);
     }
     $method = $class->getMethod($this->getMethod());
     return $method;
 }
Exemple #2
0
 /**
  * Получение справки по методу.
  * Например  man("Test.sum")
  * @param string $method
  * @return array
  */
 public function man($method = null)
 {
     $return = [];
     if (!$method) {
         $classes = [];
         foreach (glob(JsonRPCModule::getInstance()->apiPath . "*.php") as $file) {
             $classes[] = $this->classinfo_parse_file($file);
         }
         if ($classes) {
             foreach ($classes as $class) {
                 $classname = key($class);
                 foreach ($class[$classname]['#methods'] as $method => $info) {
                     $return[] = $info['#class'] . "." . $method . "(" . $info['arguments'] . ")";
                 }
             }
         }
     } else {
         if (strpos($method, '.') !== false) {
             list($object, $method) = explode(".", $method);
             $info = $this->classinfo_parse_file(JsonRPCModule::getInstance()->apiPath . $object . ".php");
         } else {
             $info = $this->classinfo_parse_file(__FILE__);
         }
         if ($info) {
             $classname = key($info);
             foreach ($info[$classname]['#methods'] as $mName => $info) {
                 if ($mName == $method) {
                     $return = [$mName => $info];
                     break;
                 }
             }
         }
     }
     return $return;
 }