mihui/

php-vcap

访问IBM Cloud VCAP_SERVICES环境变量的库。

dev-master 2018-07-27 08:09 UTC

This package is not auto-updated.

Last update: 2024-09-29 05:02:03 UTC


README

Language: PHP Build Status codecov

访问IBM Cloud VCAP_SERVICES环境变量的库。

安装

使用Composer安装将更容易管理应用程序的依赖项。

运行Composer命令安装最新的Watson PHP SDK版本

composer require mihui/php-vcap:dev-master

如果php-vcap已从GitHub下载,则运行更新命令

composer update

在您的应用程序中包含autoload.php

require 'vendor/autoload.php';

命名空间

对于常用,WatsonCredentialSimpleTokenProvider的命名空间中之一可以是非必须的,这取决于如何调用Watson服务,您可以像这样引用类

use ENV\VCAP;

如何使用

参考此存储库中的env.json文件,这是IBM Cloud/Cloudfoundry的VCAP_SERVICES环境数据的示例,它将成为您在机器上本地开发工作的env文件,您**不应该**将env.json文件放在云端。为了做到这一点,请将env.json添加到您的.gitignore。如果您必须出于其他目的使用此文件,请告知我,我将添加一个选项来更改文件名。

{
    "tone_analyzer": [
        {
            "credentials": {
                "url": "https://gateway.watsonplatform.net/tone-analyzer/api",
                "username": "your_username_tone_analyzer",
                "password": "your_password_tone_analyzer"
            },
            "syslog_drain_url": null,
            "volume_mounts": [],
            "label": "tone_analyzer",
            "provider": null,
            "plan": "standard",
            "name": "Tone Analyzer",
            "tags": [
                "ibm_created",
                "ibm_dedicated_public",
                "lite",
                "watson"
            ]
        }
    ],
    "cloudantNoSQLDB": [
        {
            "credentials": {
                "username": "your_username",
                "password": "your_password",
                "host": "your_username-bluemix.cloudant.com",
                "port": 443,
                "url": "https://your_username-bluemix:your_password@cyour_username-bluemix.cloudant.com"
            },
            "syslog_drain_url": null,
            "volume_mounts": [],
            "label": "cloudantNoSQLDB",
            "provider": null,
            "plan": "Shared",
            "name": "Cloudant NoSQL DB",
            "tags": [
                "data_management",
                "ibm_created",
                "lite",
                "ibm_dedicated_public"
            ]
        }
    ],
    "conversation": [
        {
            "credentials": {
                "url": "https://gateway.watsonplatform.net/conversation/api",
                "username": "your_username",
                "password": "your_password"
            },
            "syslog_drain_url": null,
            "volume_mounts": [],
            "label": "conversation",
            "provider": null,
            "plan": "free",
            "name": "Conversation",
            "tags": [
                "eu_access",
                "ibm_created",
                "ibm_dedicated_public",
                "lite",
                "watson"
            ]
        }
    ]
}

为了获取tone_analyzer的凭证,请使用以下示例代码,参数tone_analyzer必须是您的JSON中的键

$credentails = VCAP::getInstance()->getServiceCredential('tone_analyzer');

echo $credentails['username'];
echo $credentails['password'];
echo $credentails['url'];

许可

版权所有2018年,根据Apache 2.0许可