RpcController.class.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. protected $allowMethodList = '';
  17. protected $debug = false;
  18. /**
  19. * 架构函数
  20. * @access public
  21. */
  22. public function __construct() {
  23. //控制器初始化
  24. if(method_exists($this,'_initialize'))
  25. $this->_initialize();
  26. //导入类库
  27. Vendor('phpRPC.phprpc_server');
  28. //实例化phprpc
  29. $server = new \PHPRPC_Server();
  30. if($this->allowMethodList){
  31. $methods = $this->allowMethodList;
  32. }else{
  33. $methods = get_class_methods($this);
  34. $methods = array_diff($methods,array('__construct','__call','_initialize'));
  35. }
  36. $server->add($methods,$this);
  37. if(APP_DEBUG || $this->debug ) {
  38. $server->setDebugMode(true);
  39. }
  40. $server->setEnableGZIP(true);
  41. $server->start();
  42. echo $server->comment();
  43. }
  44. /**
  45. * 魔术方法 有不存在的操作的时候执行
  46. * @access public
  47. * @param string $method 方法名
  48. * @param array $args 参数
  49. * @return mixed
  50. */
  51. public function __call($method,$args){}
  52. }