tilleuls/ovh-bundle

OVH SDK集成

v1.0.3 2020-08-11 10:20 UTC

This package is auto-updated.

Last update: 2024-09-11 19:22:10 UTC


README

此包将OVH官方PHP SDK集成到Symfony框架中。

Build Status SensioLabsInsight Coverage Status

安装

使用Composer安装此包

composer require tilleuls/ovh-bundle

然后,更新您的app/config/AppKernel.php文件

    public function registerBundles()
    {
        $bundles = array(
            // ...
            new CoopTilleuls\OvhBundle\CoopTilleulsOvhBundle(),
            // ...
        );

        return $bundles;
    }

app/config/config.yml中配置此包

coop_tilleuls_ovh:
    endpoint_name:      "%ovh_endpoint_name%"
    application_key:    "%ovh_application_key%"
    application_secret: "%ovh_application_secret%"
    consumer_key:       "%ovh_consumer_key%"

最后,更新您的app/config/parameters.yml文件以存储您的OVH API凭证

parameters:
    # ...
    ovh_endpoint_name:      "ovh-eu"
    ovh_application_key:    "MyOvhApplicationKey"
    ovh_application_secret: "MyOvhApplicationSecret"
    ovh_consumer_key:       "MyOvhConsumerKey"

用法

该包自动在依赖注入容器中注册一个名为ovh的服务。该服务是\Ovh\Api的实例。

控制器中的示例用法

// ...

    public function smsAction(\Ovh\Api $ovhApi)
    {
        // Send a SMS
        $ovhApi
            ->post(
                sprintf('/sms/%s/users/%s/jobs', 'my-service-name', 'my-login'),
                [
                    'message' => 'Si tu veux me parler, envoie-moi un... fax !',
                    'receivers' => ['+33612345678'],
                    'sender' => 'my-login',
                ]
            )
        ;

        // ...
    }

// ...
}

致谢

Kévin DunglasLes-Tilleuls.coop创建。