uselagoon/lagoon-php-sdk

PHP库,用于与Lagoon API交互。

v1.6.2 2021-03-02 22:11 UTC

README

PHP版的Lagoon SDK使开发人员能够轻松地将应用程序连接到PHP代码中的Lagoon GraphQL服务。

入门指南

使用Composer安装包

composer require uselagoon/lagoon-php-sdk

快速示例

获取所有项目

请参阅tests/lagoon-php-sdk-test以获取一个有效示例。此脚本已在GitHub上测试。

<?php

require 'vendor/autoload.php';

use Lagoon\LagoonClient;

// The container exposes port 3000 on the host by default.
$endpoint = "http://localhost:3000/graphql";

// The development container uses this token for everyone.
$token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlIjoiYWRtaW4iLCJpc3MiOiJhcGktZGF0YS13YXRjaGVyLXB1c2hlciIsImF1ZCI6ImFwaS5kZXYiLCJzdWIiOiJhcGktZGF0YS13YXRjaGVyLXB1c2hlciJ9.GiSJpvNXF2Yj9IXVCsp7KrxVp8N2gcp7-6qpyNOakVw";

try {
  $client = new LagoonClient($endpoint, $token);
  $response = $client->project()->all()->execute();

  if ($response->hasErrors()) {
    throw new \Exception("There were errors returned from the GraphQL API: " . implode(PHP_EOL, $response->errors()));
  }
  else {
    $projects = $response->all();
    print "Projects Found: " . count($projects);
  }
} catch (\Exception $e) {
   print "ERROR: " . $e->getMessage();
   exit(1);
}

获取所有项目名称

<?php

use Lagoon\LagoonClient;

$client = new LagoonClient($endpoint, $token);
$projects = $client->project()->all()->fields(['name'])->execute();

添加项目

<?php

use Lagoon\LagoonClient;

$client = new LagoonClient($endpoint, $token);
$project = [
  'name' => $name,
  'gitUrl' => $gitUrl,
  'openshift' => 2,
  'productionEnvironment' => 'master',
  'branches' => 'true',
];
$response = $client->project()->add($project)->execute();

开发此包

此包与Lagoon容器托管系统的API进行交互。

您需要有一个正在运行的Lagoon API实例来进行开发和测试。

此包在/tests文件夹中使用composer.json的require-dev部分包含Lagoon代码库。

启动Lagoon API实例。

运行以下命令将Lagoon源代码下载到vendor/uselagoon/lagoon文件夹。

    # Composer install with --dev dependencies.  (default behavior)
    composer install

    # Composer install without --dev dependencies. 
    # Do this to build and release your codebase to production.
    composer install --no-dev

    # Run bin/api-* scripts to start and test the API containers.
    bin/api-start
    bin/api-test

测试

bin/api-test脚本将启动容器,并等待API容器在https://localhost:3000可用。

api-start脚本实际上是uselagoon/lagoon内部make api-development命令的包装。这是Lagoon开发者用来工作在API上的同一个命令,因此可以提供一个完整的发展环境。

关于此包

该项目最初由@steveworley等人在https://github.com/steveworley/lagoon-php-sdk存储库中开发。目前正在改进中,以作为Lagoon团队官方支持的版本发布。