transip / transip-api-symfony
TransIP API 客户端集成到 Symfony
v1.1.1
2024-01-15 12:47 UTC
Requires
- php: ^8.0
- nyholm/psr7: ^1.4
- php-http/client-common: ^1.6 || ^2.0
- php-http/client-implementation: ^1.0
- php-http/discovery: ^1.0
- php-http/httplug: ^1.1 || ^2.0
- psr/http-client: ^1.0
- symfony/config: ^4.4 || ^5.4 || ^6.4 || ^7.0
- symfony/dependency-injection: ^4.4 || ^5.4 || ^6.4 || ^7.0
- symfony/http-kernel: ^4.4 || ^5.4 || ^6.4 || ^7.0
- transip/transip-api-php: ^6.25
Requires (Dev)
- dg/bypass-finals: ^1.3
- phpstan/phpstan: ^0.12.99
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.6
- symfony/http-client: ^4.4 || ^5.4 || ^6.4 || ^7.0
This package is auto-updated.
Last update: 2024-09-15 14:29:43 UTC
README
TransIP RestAPI 包用于 Symfony
此包为 Symfony 的 Container 提供了一个 \Transip\Api\Library\TransipAPI
实例。
要求
为了正常工作,TransIP RestAPI 包用于 Symfony 需要以下条件
安装
您可以使用 Composer 安装 RestAPI 库。运行以下命令
composer require transip/transip-api-symfony
然后注册您的包到 Symfony
<?php
return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true],
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true],
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
Twig\Extra\TwigExtraBundle\TwigExtraBundle::class => ['all' => true],
+ Transip\Bundle\RestApi\TransipApiBundle::class => ['all' => true],
];
最后创建一个配置文件
# config/packages/transip.yaml transip_api: options: generateWhitelistOnlyTokens: true authentication: username: '%env(TRANSIP_USERNAME)%' # The username you use to login onto the Control Panel privateKey: '%env(TRANSIP_PRIVATE_KEY)%' # Your Private Key create from the Control Panel
入门
<?php // src/Controller/TransIPApiController.php namespace App\Controller; use Symfony\Component\HttpFoundation\Response; use Transip\Api\Library\TransipAPI; class TransIPApiController { public function getVpses( TransipAPI $apiClient ): Response { // Get all VPSes for account #0 (authentication in config) $apiClient->vps()->getAll(); // Authenticate client with Token (account #1) $apiClient->setToken('some.jwt.token'); // Get all VPSes for account #1 $apiClient->vps()->getAll(); // Request Token with username and private key (account #2) $token = $apiClient->auth()->createToken( $transipUsername, $transipPrivateKey, false, // Create IP Whitelisted tokens false, // Create a read only token '' // Add Token label '1 day' // Create token expire ); // Set token in library $apiClient->setToken($token); // Get all VPSes for account #2 $apiClient->vps()->getAll(); } }
使用客户端
有关使用 TransIP API 客户端的更多信息,请参阅其文档