dagstuhl/swh-deposit-client

PHP的SoftwareHeritage Deposit API客户端

0.2.1 2024-09-18 15:00 UTC

This package is not auto-updated.

Last update: 2024-09-25 11:03:30 UTC


README

PHP的SoftwareHeritage Deposit API客户端。

许可证

本项目采用MIT许可证。详细信息请参阅LICENSE.md

安装

composer require dagstuhl/swh-deposit-client

示例

<?PHP
use Dagstuhl\SwhDepositClient\SwhDepositClient;
use Dagstuhl\SwhDepositClient\SwhDepositMetadata;

// Create a client with authorization parameters
$client = new SwhDepositClient("https://deposit.staging.swh.network/", "username", "password");

// Create the metadata of a deposit
$metadata = new SwhDepositMetadata();
$metadata->add("title", [], "Awesome Project");
$metadata->add("author", [], "Yannick Schillo");

// Import Codemeta-JSON
$codemetaJson = json_decode("...");
$metadata->importCodemetaJson($codemetaJson);
// Alternatively: $metadata = SwhDepositMetadata::fromCodemetaJson($codemetaJson);

$depositMetadata = $metadata->add("swhdeposit:deposit");
$createOrigin = $depositMetadata->add("swhdeposit:create_origin");
$createOrigin->add("swhdeposit:origin", [ "url" => "https://example.com/yannick-schillo/awesome-project/" ]);

// Open the archive
$archive = fopen("path/to/archive.zip", "r");
// In Laravel: $archive = Storage::readStream("path/to/archive.zip");

// Create the deposit
$res = $client->createDeposit("mycollection", true, $metadata, "application/zip", $archive);
$depositId = $res->getDepositId();

// Query the status of the deposit
$res = $client->getStatus("mycollection", $depositId);
var_dump($res->getDepositId());
var_dump($res->getDepositStatus());
var_dump($res->getDepositSwhId());
var_dump($res->getDepositSwhIdContext());