Download the PHP package dagstuhl/swh-archive-client without Composer
On this page you can find all versions of the php package dagstuhl/swh-archive-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dagstuhl/swh-archive-client
More information about dagstuhl/swh-archive-client
Files in dagstuhl/swh-archive-client
Package swh-archive-client
Short Description SoftwareHeritage Web API Client for PHP
License MIT
Informations about the package swh-archive-client
dagstuhl/swh-archive-client
A SoftwareHeritage web API client in php
This project provides a php wrapper around the SoftwareHeritage web API. It is used by Dagstuhl Publishing to integrate automatic archiving of software projects by authors into its publication workflow.
At https://github.com/dagstuhl-publishing/swh-deposit-client, we also provide a php client for the SoftwareHeritage Deposit API.
Installation
The client is designed to work smoothly with the config mechanism of laravel. When used inside a laravel project,
you can configure it by creating a file swh.php
inside the config
folder with the following contents:
Based on that configuration, a default client is implicitly initialized and used whenever you request a SwhObject.
In a non-laravel environment just implement a global config function config
in such a way that
config('swh.web-api.token')
is your token, config('swh.web-api.url')
is the api url, and so on.
Code Examples
1) Browsing the archive
Searching through the archive is quite intuitive, as you don't realise that you are dealing with an API. You simply request the relevant objects, like this:
Further supported objects are Revision
, Release
, Directory
, Content
.
To fetch an object by its id, just call the byId
method:
To identify a directory/file inside a snapshot, use the Context
class. Continuing the example from above, we can do the following:
2) Archiving a repository
-
In a first step, a
SaveRequest
has to be created: - In a second step, the status of the
SaveRequest
has to be watched (within a loop/cron-job). The$saveRequestId
is the id obtained at the end of the first step.
3) Error Handling
If null is returned instead of an object of the requested type, that indicates that an error has occurred.
More information about the error can be obtained from the current SwhWebApiClient
instance like so:
4) Caching and rate limit
To reduce the number of requests, all requests except for the /origin/
and the /stat/counters/
endpoint are cached.
The cache folder has to specified as absolute path in config('swh.web-api.cache-folder')
.
To clear the cache, you can use the clearCache
command:
To obtain information about your rate-limiting, call
$swhClient->getRateLimits();
. This will return an array of the following type:
All versions of swh-archive-client with dependencies
ext-json Version *
guzzlehttp/guzzle Version ^7.9
nesbot/carbon Version ^2||^3
kevinrob/guzzle-cache-middleware Version ^5.1
league/flysystem Version ^3.28