加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

sugarcrm rest api 实现流程

发布时间:2020-12-17 00:39:23 所属栏目:安全 来源:网络整理
导读:一.REST???????? 方式实现流程 1.??????入口: http://www.example.com/sugar/service/v2/rest.php 代码如下: $webservice_class ='SugarRestService'; $webservice_path ='service/core/SugarRestService.php';//rest 核心类 $webservice_impl_class ='Su

一.REST???????? 方式实现流程

1.??????入口:http://www.example.com/sugar/service/v2/rest.php

代码如下:

$webservice_class ='SugarRestService';

$webservice_path ='service/core/SugarRestService.php';//rest 核心类

$webservice_impl_class ='SugarWebServiceImplv4';//最核心的method所在

$registry_class ='registry'; //注册一些函数

$location ='/service/v4/rest.php';//代表本文件路径

$registry_path ='service/v4/registry.php';//注册函数的文件路径

require_once('service/core/webservice.php');//启动程序

2.??????启动程序:http://www.example.com/sugar/service/core/webservice.php

代码如下:

/*** This file intializethe service class and does all the setters based on the values provided insoap/rest entry point and calls serve method which takes the request and sendresponse back to the client? */

require_once($webservice_path);//include SugarRestService class

require_once($registry_path);..v2/registry.php

$url =$GLOBALS['sugar_config']['site_url'].$location; ../v2/rest.php

$service = new $webservice_class($url);new SugarRestService../v2/rest.php

$service->registerClass($registry_class);

$service->register();//想要排除的函数 exclude

$service->registerImplClass($webservice_impl_class);//参数 ?SugarWebServiceImplv4

$service->serve();//调用SugarRestServiceserve方法,这个方法很核心.

?

3.??????Rest 核心类SugarRestService

代码如下:

?? classSugarRestService extends SugarWebService{

?????? protected$implementationClass = 'SugarRestServiceImpl';

??????

?????? function __construct($url){

?????? ??????? $this->restURL = $url;

?????? ?????? $this->serverClass=$this->_getTypeName(@$_REQUEST['input_type']);

//returnfor example: SugarRestJSON;

????????????? require_once('service/core/REST/'.$this->serverClass . '.php');

?????? }

??????

?????? functionregisterImplClass($className){

????????????? $this->implementationClass= $className;

????????????? $this->implementation= new $this->implementationClass();

//new SugarWebServiceImplv4()

????????????? $this->server= new $this->serverClass($this->implementation);

????????????? //new SugarRestJSON(new SugarWebServiceImplv4() )

????????????? $this->server->registerd= $this->registeredFunc;

?????? }

??????

?????? /**

?????? ?* It passes request data to REST server andsends response back to client

?????? ?* @access public

?????? ?*/

?????? functionserve(){

????????????? require_once('service/core/REST/'.$this->responseClass . '.php');

????????????? $response? = $this->responseClass;//new SugarRestJSON

$responseServer= new $response($this->implementation);

????????????? $this->server->faultServer= $responseServer;

????????????? $responseServer->faultServer= $responseServer;

????????????? $responseServer->generateResponse($this->server->serve());

????????????? //$this->server->serve()调用的是SugarRestJSONserve()

?????? }

?????? functiongetServer(){

????????????? return$this->server;

?????? }

4.??????类SugarRestJSON分析

??????? function serve(){

????????????? ?…

?????? ??????

?????? ?????? $method = $_REQUEST['method'];

????????????? $json= getJSONObj();

????????????? $data =$json->decode($json_data);

????????????? if(!is_array($data))$data= array($data);

????????????? $res =call_user_func_array(array( $this->implementation,$method),$data);

????????????? $GLOBALS['log']->info('End:SugarRestJSON->serve');

????????????? return$res;

?????? }

5.??????SugarRestJSON的基类SugarRest分析

function serve(){

? ?…

? $method = $_REQUEST['method'];

? return? $this->implementation->$method();

//implementation是类SugarWebServiceImplv4

}

6.??????最核心类SugarWebServiceImpl分析

方法定义:

functionget_entries($session,$module_name,$ids,$select_fields,$link_name_to_fields_array){

$linkoutput_list = array();

$output_list = array();

$class_name = $beanList[$module_name];

require_once($beanFiles[$class_name]);

$temp = new $class_name();

foreach($ids as $id) {

??????? $seed = @clone($temp);

?????? $output_list[] =self::$helperObject->get_return_value_for_fields($seed,$select_fields);

??????? if (!empty($link_name_to_fields_array)) {

?????????????? $linkoutput_list[]= self::$helperObject->get_return_value_for_link_fields($seed,$link_name_to_fields_array);

??????? }

}

returnarray('entry_list'=>$output_list,'relationship_list' =>$linkoutput_list);

}

?

OVER

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读