RpcController.class.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * 洛阳赤炎鹰网络科技有限公司
  4. * https://www.cyyvip.com
  5. * Copyright (c) 2022 赤店商城 All rights reserved.
  6. */
  7. // +----------------------------------------------------------------------
  8. // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
  9. // +----------------------------------------------------------------------
  10. // | Copyright (c) 2006-2014 http://thinkphp.cn All rights reserved.
  11. // +----------------------------------------------------------------------
  12. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  13. // +----------------------------------------------------------------------
  14. // | Author: liu21st <liu21st@gmail.com>
  15. // +----------------------------------------------------------------------
  16. namespace Think\Controller;
  17. /**
  18. * ThinkPHP RPC控制器类
  19. */
  20. class RpcController {
  21. protected $allowMethodList = '';
  22. protected $debug = false;
  23. /**
  24. * 架构函数
  25. * @access public
  26. */
  27. public function __construct() {
  28. //控制器初始化
  29. if(method_exists($this,'_initialize'))
  30. $this->_initialize();
  31. //导入类库
  32. Vendor('phpRPC.phprpc_server');
  33. //实例化phprpc
  34. $server = new \PHPRPC_Server();
  35. if($this->allowMethodList){
  36. $methods = $this->allowMethodList;
  37. }else{
  38. $methods = get_class_methods($this);
  39. $methods = array_diff($methods,array('__construct','__call','_initialize'));
  40. }
  41. $server->add($methods,$this);
  42. if(APP_DEBUG || $this->debug ) {
  43. $server->setDebugMode(true);
  44. }
  45. $server->setEnableGZIP(true);
  46. $server->start();
  47. echo $server->comment();
  48. }
  49. /**
  50. * 魔术方法 有不存在的操作的时候执行
  51. * @access public
  52. * @param string $method 方法名
  53. * @param array $args 参数
  54. * @return mixed
  55. */
  56. public function __call($method,$args){}
  57. }