dunglas / digital-ocean-bundle
DigitalOcean API v2 客户端,适用于 Symfony 和 API Platform
v1.0.0
2021-08-31 15:22 UTC
Requires
- php: >=7.2.5
- symfony/config: ^4.4 || ^5.3
- symfony/dependency-injection: ^4.4 || ^5.3
- symfony/http-kernel: ^4.4 || ^5.3
- toin0u/digitalocean-v2: ^4.3
Requires (Dev)
- guzzlehttp/promises: ^1.4
- nyholm/psr7: ^1.4
- symfony/http-client: ^4.4 || ^5.3
- symfony/phpunit-bridge: ^5.3
README
DunglasDigitalOceanBundle 允许在您的 DigitalOcean API、Symfony 和 API Platform 项目中使用。它将 DigitalOcean PHP API 客户端 注册为 Symfony 服务。
如果您还不是 DigitalOcean 用户,请使用 此联盟链接 获得免费信用 100 美元!
如果您想将您的 Symfony 应用部署到 DigitalOcean,请查看 这篇教程。
示例
// src/Controller/DigitalOceanController.php namespace App\Controller; use DigitalOceanV2\Client; use DigitalOceanV2\ResultPager; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; class ProductController { #[Route("/droplets")] public function listDroplets(Client $doClient): Response { // get the first 100 droplets as an array $droplets = $doClient->droplet()->getAll(); // or create a new result pager $pager = new ResultPager($doClient); // and get all droplets as an array $droplets = $pager->fetchAll($doClient->droplet(), 'getAll'); // ... } }
当然,您还可以将客户端服务注入到您的命令、消息处理器和其他任何服务中。
更多示例.
安装
确保已全局安装 Composer,如 Composer 文档的 安装章节 中所述。
使用 Symfony Flex 的应用程序
打开命令行,进入您的项目目录,然后执行
$ composer require dunglas/digital-ocean-bundle symfony/http-client nyholm/psr7 guzzlehttp/promises
前面的命令安装了捆绑包、Symfony HttpClient 以及它需要的依赖项,以“提供” psr/http-client-implementation
和 psr/http-factory-implementation
。
或者,您可以使用任何其他实现这些接口的实现,如 Guzzle。
不使用 Symfony Flex 的应用程序
步骤 1:下载捆绑包
打开命令行,进入您的项目目录,然后执行以下命令以下载此捆绑包的最新稳定版本
$ composer require dunglas/digital-ocean-bundle symfony/http-client nyholm/psr7 guzzlehttp/promises
步骤 2:启用捆绑包
然后,通过将其添加到项目中 config/bundles.php
文件中注册的捆绑包列表中来启用捆绑包
// config/bundles.php return [ // ... \Dunglas\DigitalOceanBundle\DunglasDigitalOceanBundle::class => ['all' => true], ];
配置
dunglas_digital_ocean: connections: primary: # can be any name token: <your-access-token> secondary: token: <your-access-token> default_connection: primary # If not set, the first in the list will be used
此配置自动注册以下自动装配别名
DigitalOceanV2\Client $primaryClient
DigitalOceanV2\Client $secondaryClient
如果您只有一个客户端,您可以使用此快捷方式
dunglas_digital_ocean: <your-access-token>
使用 DigitalOceanV2\Client
类型注入默认的 DigitalOcean 客户端。
致谢
此捆绑包由 Kévin Dunglas 提供。它由 Les-Tilleuls.coop 赞助。