transip/transip-api-symfony

TransIP API 客户端集成到 Symfony

安装次数: 309

依赖项: 0

建议者: 0

安全: 0

星标: 1

关注者: 6

分支: 1

公开问题: 0

类型:symfony-bundle

v1.1.1 2024-01-15 12:47 UTC

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 客户端的更多信息,请参阅其文档