RpcController.class.php 1.8 KB

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