imanaging-document/api-communication-bundle

基于API的多种应用程序之间的通信服务

v2.0 2021-09-23 10:45 UTC

This package is auto-updated.

Last update: 2024-09-30 01:24:43 UTC


README

此包允许不同的imanaging-document应用程序之间进行通信。

此包不能在imanaging-document应用程序之外使用。

使用以下命令安装包

$ composer require imanaging-document/api-communication-bundle

配置

您需要创建一个config/packages/imanaging_api_communication.yaml文件

imanaging_api_communication:
    project_dir: '%kernel.project_dir%'
    zeus_api_url: ~
    zeus_api_login: ~
    zeus_api_password: ~
    zeus_mock_dir: ~
    client_traitement: ~
    core_api_url: ~
    core_api_token: ~
    core_mock_dir: ~

在服务中使用

在您的config/services.yaml文件中为您的服务添加一个新的参数

login:
    class: App\Service\MyBeautifulService
    arguments: [..., '@api_zeus_communication', ...]

以此方式获取ApiZeusCommunication

class MyBeautifulService
{
  private ...
  private $apiZeusCommunication;
  private ...
  
  /**
   * ...
   * @param ApiZeusCommunication $apiZeusCommunication
   * ...
   */
  public function __construct(..., ApiZeusCommunication $apiZeusCommunication, ...){
    ...
    $this->apiZeusCommunication = $apiZeusCommunication;
    ...
  }
  ...
}

示例

GET 示例

$url = '/my-beautiful-get-url';
$response = $this->apiZeusCommunication->sendGetRequest($url);

if ($response->getHttpCode() === 200) {
  // SOME LOGIC
}

POST 示例

$postData = array(
  '...' => '...',
  'my_post_key' => $myPostValue,
  '...' => '...',
);

$url = '/my-beautiful-post-url';
$response = $this->apiZeusCommunicationService->sendPostRequest($url, $postData);

if ($response->getHttpCode() === 201) {
  // SOME LOGIC
}