dagstuhl/swh-deposit-client

SoftwareHeritage Deposit API Client for PHP

0.2.1 2024-09-18 15:00 UTC

This package is not auto-updated.

Last update: 2025-03-26 13:20:34 UTC


README

SWH

SwhDepositClient

A SoftwareHeritage Deposit API Client for PHP.

License

This project is licensed under the MIT license. See LICENSE.md for details.

Install

composer require dagstuhl/swh-deposit-client

Example

<?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());