Skip to content


Subversion checkout URL

You can clone with
Download ZIP
SWORD v2 PHP API library
Branch: master

Merge pull request #9 from jwhitney/sword-statement-category

Prevent warnings when category isn't provided in SWORD statement entry
latest commit 0113f2ef07
@stuartlewis stuartlewis authored
Failed to load latest commit information.
test Add ability to complete incomplete deposits
LICENCE Initial v2 development commit
README Updating README ready for v0.1 release
collection.php Adding support for <atom:accept alternative="multipart-related"> types.
packager_atom_multipart.php Allow attributes on dcterms elements in Atom entries
packager_atom_multipart_eprints.php Allow attributes on dcterms elements in Atom entries
packager_atom_twostep.php Allow attributes on dcterms elements in Atom entries
packager_mets_swap.php Clean copyrightholder
stream.php Streaming of large multipart files (need to fix temporary file name)
swordappclient.php Init swordappclient with user-specified curl opts
swordappentry.php Add property to SWORDAppEntry for Atom feed representation of media r…
swordapperrordocument.php Add summary & verbose error description to SWORDAPPErrorDocument
swordapplibraryuseragent.php Updating version string into user agent string
swordapplink.php Adding support to deposit receipt / entry for links (New class to sto…
swordappresponse.php Add website ability to delete containers
swordappservicedocument.php Correct constructor comment
swordappstatement.php Prevent warnings when category isn't provided in SWORD statement entry
swordappstatemententry.php Addition of SWORD Statement (atom serialization)
utils.php Changing to clrf line endings in base64 encoded streams
workspace.php Add namespace declarations


Welcome to the SWORD v2 PHP client library!
Version: 0.1

The SWORDAPP v2 PHP client library is a PHP library designed to assist with
the creation of SWORD deposit tools. The client library allows PHP code to
easily make use of the two SWORD functions:

 - GETting a Service Document
 - POSTing a package or file into a repository
 - PUTting an updated file into a repository
 - DELETEing a file or item from a repository

The library was originally written by Stuart Lewis ( as
part of the JISC funded SWORD2 project. Limited support for the library is
availble via the sword-app-tech email list:


The latest version of the library can be downloaded from GitHub:


The library is licenced with the New BSD Licence. See the file LICENCE in the
distribution directory.

SWORD Compatibility
This version of the library is compatible with SWORD version 2.0

This library requires:

 - PHP version 5
    + CURL extension
    + SimpleXML extension
    + ZIP extension (for the packager only)

How to use the library
The easiest way to understand the library is to look at the 
test/test-swordappclient.php file which exercises all the functions and
variables of the library.

The main methods to use are from swordappclient.php:

 - servicedocument($sac_url, $sac_u, $sac_p, $sac_obo)
 - deposit($sac_url, $sac_u, $sac_p, $sac_obo, $sac_fname, $sac_packaging= '', $sac_contenttype = '', $sac_inprogress = false)
 - depositMultipart($sac_url, $sac_u, $sac_p, $sac_obo, $sac_package, $sac_inprogress = false)
 - depositAtomEntry($sac_url, $sac_u, $sac_p, $sac_obo, $sac_fname, $sac_inprogress = false)
 - completeIncompleteDeposit($sac_url, $sac_u, $sac_p, $sac_obo)
 - retrieveContent($sac_url, $sac_u, $sac_p, $sac_obo, $sac_accept_packaging = "")
 - retrieveDepositReceipt($sac_url, $sac_u, $sac_p, $sac_obo, $sac_accept_packaging = "")
 - replaceFileContent($sac_url, $sac_u, $sac_p, $sac_obo, $sac_fname, $sac_packaging= '', $sac_contenttype = '', $sac_metadata_relevant = false)
 - replaceMetadata($sac_url, $sac_u, $sac_p, $sac_obo, $sac_fname, $sac_inprogress = false)
 - replaceMetadataAndFile($sac_url, $sac_u, $sac_p, $sac_obo, $sac_package, $sac_inprogress = false)
 - addExtraFileToMediaResource($sac_url, $sac_u, $sac_p, $sac_obo, $sac_fname, $sac_contenttype = '', $sac_metadata_relevant = false)
 - addExtraPackage($sac_url, $sac_u, $sac_p, $sac_obo, $sac_fname, $sac_packaging = '', $sac_contenttype, $sac_inprogress = false)
 - addExtraAtomEntry($sac_url, $sac_u, $sac_p, $sac_obo, $sac_fname, $sac_inprogress = false)
 - addExtraMultipartPackage($sac_url, $sac_u, $sac_p, $sac_obo, $sac_package, $sac_inprogress = false)
 - deleteContainer($sac_url, $sac_u, $sac_p, $sac_obo)
 - deleteResourceContent($sac_url, $sac_u, $sac_p, $sac_obo)
 - retrieveAtomStatement($sac_url, $sac_u, $sac_p, $sac_obo)
 - retrieveOAIOREStatement($sac_url, $sac_u, $sac_p, $sac_obo)

The functions return a SWORDAPPServiceDocument, a SWORDAPPEntry, a
SWORDAPPResponse or a SWORDAPPErrorDocument object as appropriate.
These classes can then be interrogated (e.g. $servicedocument->sac_workspaces).

The main function parameters are:

 - $sac_url: The URL to interact with (e.g. service document URL, deposit URL, etc)
 - $sac_u: The username
 - $sac_p: The password
 - $sac_obo: The on-behalf-of user name (optional, can be left empty)
 - $sac_fname: Filename to deposit
 - $sac_packaging: THe packaging format of the package being deposited
 - $sac_inprogress: Whether or not the deposit should be considered 'in-progress'

The SWORD v2 specification can be seen at:


Deposits can be made using packages.  By default, all SWORD v2 interfaces
should accept Atom Multipart pacakges.  These can be generated using the
'package_atom_multipart.php' class.

Some repositories will accept METS+SWAP packages.  These can be generated
using the 'package_mets_swap.php' class.

An example website that can also be used for testing is included in

Configure your web server to serve that directory (and child directories)
to try the application.

Example uses of the packagers, and the SWORD client can be seen in the
/test directory.

0.1 (18th October 2011)
 - First release, forked from version 1 of the library
Something went wrong with that request. Please try again.