uselagoon / lagoon-php-sdk
PHP库,用于与Lagoon API交互。
v1.6.2
2021-03-02 22:11 UTC
Requires
- php: >=7
- euautomation/graphql-client: ^0.2.0
Requires (Dev)
- couscous/couscous: ^1.7
- phpunit/phpunit: ^7.5
- uselagoon/lagoon-php-sdk-testing: @dev
This package is auto-updated.
Last update: 2024-09-11 22:38:22 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团队官方支持的版本发布。