PHP code example of dagstuhl / swh-deposit-client

1. Go to this page and download the library: Download dagstuhl/swh-deposit-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dagstuhl / swh-deposit-client example snippets


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