cerpus/imageservice-client

用于处理与 Cerpus ImageService 通信的客户端

v2.2.1 2023-04-18 11:57 UTC

README

PHP 库,用于与 Cerpus 图像服务通信

安装

使用 composer 需求包

composer require cerpus/imageservice-client

Laravel

composer 完成后,将服务提供者添加到 config/app.php 文件的 providers 数组中

Cerpus\ImageServiceClient\Providers\ImageServiceClientServiceProvider::class,

config/app.php 文件的 alias 数组中添加以下内容

'ImageService' => \Cerpus\ImageServiceClient\ImageServiceClient::class,

发布包中的配置文件

php artisan vendor:publish --provider="Cerpus\ImageServiceClient\Providers\ImageServiceClientServiceProvider" --tag=config

Lumen

未测试,但应能工作。如果不起作用,欢迎更新此文档!

app/Providers/AppServiceProvider.php 中添加服务提供者

public function register()
{
    $this->app->register(Cerpus\ImageServiceClient\Providers\ImageServiceClientServiceProvider::class);
}

取消注释 bootstrap/app.php 中加载服务提供者的行

$app->register(App\Providers\AppServiceProvider::class);

编辑配置文件

编辑 config/imageservice-client.php

<?php
return [
    "adapters" => [
        "imageservice" => [
            "handler" => \Cerpus\ImageServiceClient\Adapters\ImageServiceAdapter::class,
            "base-url" => '<url to service>',
            "system-name" => '<system name>',
        ],
    ],
];

开发者配置示例

<?php

return [
    "adapters" => [
        "imageservice" => [
            "handler" => \Cerpus\ImageServiceClient\Adapters\ImageServiceAdapter::class,
	    "base-url" => env('IMAGESERVICE_URL'),
	    "system-name" => env('VERSION_SYSTEM_NAME')
        ],
    ],
];

用法

从 Laravel 容器解析

$cerpusImage = app(Cerpus\ImageServiceClient\Contracts\ImageServiceContract::class)

或别名

$cerpusImage = ImageService::<Class Method>

或直接

$cerpusImage = new Cerpus\ImageServiceClient\Adapters\ImageServiceAdapter(Client $client, $containerName);

最后一种方法不推荐使用。

类方法

方法调用返回对象或在失败时抛出异常。

get($id) - 返回一个包含特定 ID 信息的数据对象

store($filePath, array $metadata = []) - 在一个操作中创建并上传新图像。

delete($id) - 从图像服务中删除文件。

getHostingUrl($id, ImageParamsObject $params) - 返回一个可以找到文件的 URL。

getHostingUrls(array $ids) - 返回图像的 URL 数组。

loadRaw($id, $toFile) - 将图像下载到指定位置。

getErrors() - 返回发生错误数组

更多信息

请参阅 Confluence 图像存储服务 API 文档

许可证

此软件包根据 GNU 通用公共许可证 3.0 发布。有关更多信息,请参阅 LICENSE 文件。