cti / saprfc
Saprfc抽象层
2.0.0
2014-04-09 09:56 UTC
Requires (Dev)
- phpunit/phpunit: 4.0.*
- satooshi/php-coveralls: 0.7.*@dev
This package is auto-updated.
Last update: 2024-09-08 06:16:04 UTC
README
此组件是对原生saprfc扩展(saprfc.sourceforge.net)的包装。
功能模块逆向工程,并提供一个方法来完成所有任务。
您可以使用GatewayInterface编写代码,然后使用代理或直接连接。
安装
使用composer。
{ "require": { "cti/saprfc": "*" } }
基本用法
服务器有saprfc扩展,并且可以连接到SAP R/3(同一网络)。
<?php use Cti\SapRfc\Gateway; // params for saprfc_open // http://saprfc.sourceforge.net/src/saprfc.html#function.saprfc-open.html $connectionParams = array( 'USER' => 'USERNAME', 'PASSWD' => 'PASSWORD', // ... ); $sap = new Gateway($connectionParams); $request = array( // use import params 'I_ID_USER' => 12345, 'I_LIMIT' => 50, 'I_OFFSET' => 25, // fill tables 'IT_FILTER' => array( array('FIELD' => 'STATUS', 'VALUE' => 'ACTIVE') ) ); $response = array( // use export params 'TOTAL_CNT', 'LAST_UPDATE', // use table result 'IT_RECIPE_LIST' ); $result = $sap->execute('Z_GET_RECIPE_LIST', $request, $response); // $result contains properties TOTAL_CNT, LAST_UPDATE, IT_RECIPE_LIST. // TOTAL_CNT and LAST_UPDATE are scalar values // IT_RECIPE_LIST is array of data // echo $result->TOTAL_CNT; foreach($result->IT_RECIPE_LIST as $recipe) { echo $recipe->ID_RECIPE, ' ', $recipe->name, '<br/>'; }
代理用法
Sap rfc库可以在代理模式下使用。例如
- 第一个服务器在内网中,并且可以连接到Sap R/3
- 第二个服务器通过VPN连接到第一个服务器,但没有saprfc扩展
第一个服务器的proxy.php文件
<?php use Cti\SapRfc\Gateway; use Cti\SapRfc\Proxy; // params for saprfc_open // http://saprfc.sourceforge.net/src/saprfc.html#function.saprfc-open.html $connectionParams = array( 'USER' => 'USERNAME', 'PASSWD' => 'PASSWORD', // ... ); $sap = new Gateway($connectionParams); $proxy = new Proxy(); $proxy->processRequest($sap);
第二个服务器的request.php文件
<?php use Cti\SapRfc\Proxy; $request = array( // use import params 'I_ID_USER' => 12345, 'I_LIMIT' => 50, 'I_OFFSET' => 25, // fill tables 'IT_FILTER' => array( array('FIELD' => 'STATUS', 'VALUE' => 'ACTIVE') ) ); $response = array( // use export params 'TOTAL_CNT', 'LAST_UPDATE', // use table result 'IT_RECIPE_LIST' ); $proxy = new Proxy(); $proxy->setUrl("http://intranet_server_url/proxy.php"); $result = $proxy->execute('Z_GET_RECIPE_LIST', $request, $response); // $result contains properties TOTAL_CNT, LAST_UPDATE, IT_RECIPE_LIST. // TOTAL_CNT and LAST_UPDATE are scalar values // IT_RECIPE_LIST is array of data // echo $result->TOTAL_CNT; foreach($result->IT_RECIPE_LIST as $recipe) { echo $recipe->ID_RECIPE, ' ', $recipe->name, '<br/>'; }
分析您的请求
网关接口提供分析器注入。
使用此对象,您可以分析您的调用、时间和内存使用。
<?php use Cti\SapRfc\Gateway; use Cti\SapRfc\Profiler; // params for saprfc_open // http://saprfc.sourceforge.net/src/saprfc.html#function.saprfc-open.html $connectionParams = array( 'USER' => 'USERNAME', 'PASSWD' => 'PASSWORD', // ... ); $sap = new Gateway($connectionParams); $sap->setProfiler(new Profiler()); $name = 'FUNCTIONAL_MODULE_NAME'; $request = array( // ... ); $response = array( // ... ); $result = $sap->execute($name, $request, $response); foreach($sap->getProfiler()->getData() as $transaction) { echo $transaction->name; var_dump($transaction->request); if($transaction->success) { var_dump($transaction->response); } else { echo 'FAIL: ', $transaction->message; } echo $transaction->time, ' seconds' ; }