Open Journal Systems  3.3.0
BagIt Class Reference

Public Member Functions

 __construct ( $bag, $validate=false, $extended=true, $fetch=false, $bagInfoData=null)
 
 addFile ($src, $dest)
 
 clearBagInfoData ($key)
 
 createFile ($content, $dest)
 
 getBagContents ()
 
 getBagErrors ($validate=false)
 
 getBagInfo ()
 
 getBagInfoData ($key)
 
 getDataDirectory ()
 
 getHashEncoding ()
 
 hasBagInfoData ($key)
 
 isExtended ()
 
 isValid ()
 
 package ($destination, $method='tgz')
 
 setBagInfoData ($key, $value)
 
 setHashEncoding ($hashAlgorithm)
 
 update ()
 
 validate ()
 

Data Fields

 $bag
 
 $bagCompression
 
 $bagDirectory
 
 $bagErrors
 
 $bagInfoData
 
 $bagInfoFile
 
 $bagitFile
 
 $bagVersion
 
 $extended
 
 $fetch
 
 $manifest
 
 $tagFileEncoding
 
 $tagManifest
 

Detailed Description

Definition at line 69 of file bagit.php.

Constructor & Destructor Documentation

◆ __construct()

BagIt::__construct (   $bag,
  $validate = false,
  $extended = true,
  $fetch = false,
  $bagInfoData = null 
)

Define a new BagIt instance.

Parameters
string$bagEither a non-existing folder name (will create a new bag here); an existing folder name (this will treat it as a bag and create any missing files or folders needed); or an existing compressed file (this will un-compress it to a temporary directory and treat it as a bag).
boolean$validateThis will validate all files in the bag, including running checksums on all of them. Default is false.
boolean$extendedThis will ensure that optional 'bag-info.txt', 'fetch.txt', and 'tagmanifest-{sha1,md5}.txt' are created. Default is true.
boolean$fetchIf true, it will download all files in 'fetch.txt'. Default is false.
array$bagInfoDataIf given, this sets the bagInfoData property.

Definition at line 229 of file bagit.php.

References $bag, $bagInfoData, $extended, $fetch, and validate().

Member Function Documentation

◆ addFile()

BagIt::addFile (   $src,
  $dest 
)

This copies the file specified into the bag at the place given.

$dest should begin with "data/", but if it doesn't that will be added.

Parameters
string$srcThe file name for the source file.
string$destThe file name for the destination file. This should be relative to the bag directory.
Returns
void

Definition at line 461 of file bagit.php.

◆ clearBagInfoData()

BagIt::clearBagInfoData (   $key)

This removes all the values for a key in the bag-info.txt file.

Parameters
string$keyThe key to clear.
Returns
void
Author
Eric Rochester eroch.nosp@m.est@.nosp@m.virgi.nosp@m.nia..nosp@m.edu

Definition at line 579 of file bagit.php.

◆ createFile()

BagIt::createFile (   $content,
  $dest 
)

Create a new file in the bag at $dest, with the contents in $content.

$dest should begin with "data/", but if it doesn't that will be added.

Parameters
mixed$contentthe content to write to the file. May be binary data.
string$destThe file name for the destination file. This should be relative to the bag directory.
Exceptions
BagitExceptionif the file already exists.
Returns
null

Definition at line 493 of file bagit.php.

◆ getBagContents()

BagIt::getBagContents ( )

Return an array of all files in the data directory

Returns
array An array of absolute paths for all of the files in the data directory.

Definition at line 351 of file bagit.php.

References getDataDirectory().

◆ getBagErrors()

BagIt::getBagErrors (   $validate = false)

Return errors for a bag

Parameters
boolean$validateIf true, then it will run this->validate() to verify the integrity first. Default is false.
Returns
array An array of all bag errors.

Definition at line 364 of file bagit.php.

References $bagErrors, and validate().

◆ getBagInfo()

BagIt::getBagInfo ( )

Return the info keys

Returns
array A dictionary array containing these keys: 'version', 'encoding', 'hash'.

Definition at line 291 of file bagit.php.

References getHashEncoding().

◆ getBagInfoData()

BagIt::getBagInfoData (   $key)

This returns the value for a key from bagInfoData.

Parameters
string$keyThis is the key to get the value associated with.
Returns
string|null
Author
Eric Rochester eroch.nosp@m.est@.nosp@m.virgi.nosp@m.nia..nosp@m.edu

Definition at line 594 of file bagit.php.

◆ getDataDirectory()

BagIt::getDataDirectory ( )

Get the absolute path of the bag's data directory

Returns
string The absolute path to the bag's data directory.

Definition at line 309 of file bagit.php.

Referenced by getBagContents(), update(), and validate().

◆ getHashEncoding()

BagIt::getHashEncoding ( )

Determine hash encoding

Returns
string The bag's checksum encoding scheme.

Definition at line 319 of file bagit.php.

Referenced by getBagInfo().

◆ hasBagInfoData()

BagIt::hasBagInfoData (   $key)

This tests whether bagInfoData has a key.

Parameters
string$keyThe key to test for existence of.
Returns
bool
Author
Eric Rochester eroch.nosp@m.est@.nosp@m.virgi.nosp@m.nia..nosp@m.edu

Definition at line 548 of file bagit.php.

◆ isExtended()

BagIt::isExtended ( )

Test if a bag has optional files

Returns
boolean True if the bag contains the optional files 'bag-info.txt', 'fetch.txt', or 'tagmanifest-{sha1,md5}.txt'.

Definition at line 280 of file bagit.php.

References $extended.

◆ isValid()

BagIt::isValid ( )

Test if a Bag is valid

Returns
boolean True if no validation errors occurred.

Definition at line 269 of file bagit.php.

◆ package()

BagIt::package (   $destination,
  $method = 'tgz' 
)

Compresses the bag into a file.

Parameters
string$destinationThe file to put the bag into.
string$methodEither 'tgz' or 'zip'. Default is 'tgz'.
Returns
void

Definition at line 522 of file bagit.php.

◆ setBagInfoData()

BagIt::setBagInfoData (   $key,
  $value 
)

This inserts a value into bagInfoData.

Parameters
string$keyThis is the key to insert into the data.
string$valueThis is the value to associate with the key.
Returns
void
Author
Eric Rochester eroch.nosp@m.est@.nosp@m.virgi.nosp@m.nia..nosp@m.edu

Definition at line 563 of file bagit.php.

◆ setHashEncoding()

BagIt::setHashEncoding (   $hashAlgorithm)

Sets the bag's checksum hash algorithm.

Parameters
string$hashAlgorithmThe bag's checksum hash algorithm. Must be either 'sha1' or 'md5'.
Returns
void

Definition at line 332 of file bagit.php.

◆ update()

BagIt::update ( )

This method is used whenever something is added to or removed from the bag. It performs these steps:

  • Ensures that required files are present;
  • Sanitizes file names;
  • Makes sure that checksums are up-to-date;
  • Adds checksums and file entries for new files;
  • Removes checksums and file entries for missing files; and
  • If it's an extended bag, makes sure that those files are also up-to-date.
Returns
void

Definition at line 409 of file bagit.php.

References $bagDirectory, and getDataDirectory().

◆ validate()

BagIt::validate ( )

Runs the bag validator on the contents of the bag. This verifies the presence of required iles and folders and verifies the checksum for each file.

For the results of validation, check isValid() and getBagErrors().

Returns
array The list of bag errors.

Definition at line 381 of file bagit.php.

References $bagErrors, and getDataDirectory().

Referenced by __construct(), and getBagErrors().

Field Documentation

◆ $bag

string BagIt::$bag

The bag as passed into the constructor. This could be a directory or a file name, and it may not exist.

Definition at line 83 of file bagit.php.

Referenced by __construct().

◆ $bagCompression

string BagIt::$bagCompression

If the bag came from a compressed file, this contains either 'tgz' or 'zip' to indicate the file's compression format.

Definition at line 194 of file bagit.php.

◆ $bagDirectory

string BagIt::$bagDirectory

Absolute path to the bag directory.

Definition at line 93 of file bagit.php.

Referenced by update().

◆ $bagErrors

array BagIt::$bagErrors

An array of all bag validation errors. Each entries is a two-element array containing the path of the file and the error message.

Definition at line 205 of file bagit.php.

Referenced by getBagErrors(), and validate().

◆ $bagInfoData

array BagIt::$bagInfoData

A dictionary array containing the 'bag-info.txt' file contents.

Definition at line 183 of file bagit.php.

Referenced by __construct().

◆ $bagInfoFile

string BagIt::$bagInfoFile

Absolute path to the 'bag-info.txt' file or null.

Definition at line 173 of file bagit.php.

◆ $bagitFile

string BagIt::$bagitFile

Absolute path to the bagit file.

Definition at line 133 of file bagit.php.

◆ $bagVersion

array BagIt::$bagVersion

The version information declared in 'bagit.txt'.

Definition at line 113 of file bagit.php.

◆ $extended

boolean BagIt::$extended

True if the bag is extended.

Definition at line 103 of file bagit.php.

Referenced by __construct(), and isExtended().

◆ $fetch

BagItFetch BagIt::$fetch

Information about files that need to be downloaded, listed in fetch.txt.

Definition at line 163 of file bagit.php.

Referenced by __construct().

◆ $manifest

BagItManifest BagIt::$manifest

Information about the 'manifest-(sha1|md5).txt'.

Definition at line 143 of file bagit.php.

◆ $tagFileEncoding

string BagIt::$tagFileEncoding

The tag file encoding declared in 'bagit.txt'. Default is 'utf-8'.

Definition at line 123 of file bagit.php.

◆ $tagManifest

BagItManifest BagIt::$tagManifest

Information about the 'tagmanifest-{sha1,md5}.txt' or null.

Definition at line 153 of file bagit.php.


The documentation for this class was generated from the following file: