swp/bridge-bundle

该套餐件作为Superdesk Web publisher和Superdesk Content API之间的桥梁。

v2.1.0 2021-01-18 15:19 UTC

README

Build Status Scrutinizer Code Quality Code Climate

该套餐件是Superdesk Content API和Superdesk Publisher之间的桥梁。

安装

  1. 下载SWPBridgeBundle
  2. 启用套餐件及其依赖项
  3. 导入SWPUpdaterBundle路由文件
  4. 配置SWPBridgeBundle

步骤1:使用Composer安装SWPBridgeBundle

运行以下composer require命令

$ php composer.phar require swp/bridge-bundle

步骤2:启用套餐件及其依赖项

AppKernel.php中启用套餐件。

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new SWP\Bundle\BridgeBundle\SWPBridgeBundle()
    );
}

步骤3:导入SWPBridgeBundle路由文件

您必须导入SWPBridgeBundle路由文件。您可以使用YAML或XML格式。

YAML

# app/config/routing.yml
swp_bridge:
    resource: "@SWPBridgeBundle/Resources/config/routing.yml"
    prefix:   /

步骤4:配置SWPBridgeBundle

将以下参数添加到您的config.yml文件中。

# app/config/config.yml
swp_bridge:
    api:
        host: 'example.com'
    auth:
        client_id: 'my_client_id'
        username: 'my_username'
        password: 'my_password'

这是开始的最小要求,有关更多详细信息,请参阅配置的详细说明

有关配置的详细说明

配置参考

swp_bridge:
    api:
        host: 'The hostname of your Content API instance. This option is required.'
        port: 'The port of your Content API Instance, defaults to 80.'
        protocol: 'Protocol to use to connect to your Content API Instance, options are: _http_ and _https_. Defaults to _http_.'
    auth:
        client_id: 'Client ID for authenticating with your Content API Instance. This option is required.'
        username: 'Username for authenticating with your Content API Instance. This option is required.'
        password: 'Password for authenticating with your Content API Instance. This option is required.'
    options: 'An array of options which will included in each call in GuzzleApiClient->makeApiCall(). The values defined here will override values from the Request object if the keys are identical.'

添加自定义http客户端选项

SWPBridgeBundle使用Guzzle从外部服务器获取数据。您可以通过在配置中添加选项数组作为参数来为您的http客户端添加自定义Guzzle选项/头。
以下示例显示如何添加自定义curl选项。

# app/config/config.yml
swp_bridge:
    options:
        curl: # http://guzzle.readthedocs.org/en/latest/faq.html#how-can-i-add-custom-curl-options
            10203: # integer value of CURLOPT_RESOLVE
                 - "example.com:5050:localhost"  # This will resolve the host example.com to your localhost 

有关更多详细信息,请参阅Guzzle文档

在此阶段,该套餐件已准备好供您的应用程序使用。

开发配置

上述示例针对Guzzle客户端,允许您在开发环境中使用docker时进行自定义主机名解析。只需将127.0.0.1 publicapi添加到您的hosts文件,并将值localhost更改为您publicapi docker容器的IP地址。