PHPackages                             whikloj/bagittools - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. whikloj/bagittools

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

whikloj/bagittools
==================

A PHP library to manipulate and verify BagIt bags.

6.0.0(4mo ago)1220.5k—10%7[3 issues](https://github.com/whikloj/BagItTools/issues)[1 PRs](https://github.com/whikloj/BagItTools/pulls)1MITPHPPHP &gt;=8.2CI passing

Since Nov 25Pushed 3mo ago3 watchersCompare

[ Source](https://github.com/whikloj/BagItTools)[ Packagist](https://packagist.org/packages/whikloj/bagittools)[ Docs](https://github.com/whikloj/bagittools)[ RSS](/packages/whikloj-bagittools/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (24)Used By (1)

BagItTools
==========

[](#bagittools)

[![Minimum PHP Version](https://camo.githubusercontent.com/8c32682ae90a5572e9197155d70259dafa8239f353150d19f9214037ad67f32d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230382e322d3838393242462e7376673f7374796c653d666c61742d737175617265)](https://php.net/)[![Github Actions](https://github.com/whikloj/BagItTools/actions/workflows/main.yml/badge.svg)](https://github.com/whikloj/BagItTools/actions/workflows/main.yml)[![LICENSE](https://camo.githubusercontent.com/942e017bf0672002dd32a857c95d66f28c5900ab541838c6c664442516309c8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d737175617265)](./LICENSE)[![codecov](https://camo.githubusercontent.com/33a08b00e6111d7941d7b3890ec295d4253eec87b3ebbdf9dce3b628b2c905e2/68747470733a2f2f636f6465636f762e696f2f67682f7768696b6c6f6a2f4261674974546f6f6c732f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/whikloj/BagItTools)

Introduction
------------

[](#introduction)

BagItTools is a PHP implementation of the BagIt v1.0 specification ([RFC-8493](https://tools.ietf.org/html/rfc8493)).

Features:

- Create new bag
- Load existing directory as a bag.
- Load archive file (\*.zip, \*.tar, \*.tar.gz, \*.tgz, \*.tar.bz2)
- Validate a bag
- Add/Remove files
- Add/Remove fetch urls
- Add/Remove hash algorithms (md5, sha1, sha224, sha256, sha384, sha512, sha3-224, sha3-256, sha3-384, sha3-512)
- Generate payload for all data/ files for all hash algorithms (depending on PHP support)
- Generate tag manifests for all root level files and any additional tag directories/files.
- Add/Remove tags from bag-info.txt files, maintains ordering of tags loaded.
- Generates/updates payload-oxum and bagging-date.
- Passes all bagit-conformance-suite tests.
- Create an archive (zip, tar, tar.gz, tgz, tar.bz2)
- In-place upgrade of bag from v0.97 to v1.0

[Change Log](./CHANGELOG.md)
----------------------------

[](#change-log)

Installation
------------

[](#installation)

**Composer**

```
composer require "whikloj/bagittools"
```

**Clone from Github**

```
git clone https://github.com/whikloj/BagItTools
cd BagItTools
composer install --no-dev
```

Dependencies
------------

[](#dependencies)

All dependencies are installed or identified by composer.

Some PHP extensions are required and this library will not install if they cannot be found in the default PHP installation (the one used by composer).

The required extensions are:

- [Client URL Library](https://www.php.net/manual/en/book.curl.php)
- [Internationalization functions](https://www.php.net/manual/en/book.intl.php)
- [Multibyte string](https://www.php.net/manual/en/book.mbstring.php)
- [Zip](https://www.php.net/manual/en/book.zip.php)

Usage
-----

[](#usage)

You can integrate BagItTools into your own code as a library using the [API](#api), or use the CLI commands for some simple functionality.

### Command line

[](#command-line)

#### Validating a bag

[](#validating-a-bag)

```
./bin/console validate
```

This will output a message as to whether the bag is or is NOT valid. It will also respond with an appropriate exit code (0 == valid, 1 == invalid).

If you add the `-v` flag it will also print any errors or warnings.

This can command can be used with the [bagit-conformance-suite](https://github.com/LibraryOfCongress/bagit-conformance-suite)like this

```
./test-harness /bin/console -- -v validate
```

### API

[](#api)

[API Documentation](https://whikloj.github.io/BagItTools/namespaces/whikloj.html)

#### Create a new bag

[](#create-a-new-bag)

As this is a v1.0 implementation, by default bags created use the UTF-8 file encoding and the SHA-512 hash algorithm.

```
require_once './vendor/autoload.php';

use \whikloj\BagItTools\Bag;

$dir = "./newbag";

// Create new bag as directory $dir
$bag = Bag::create($dir);

// Add a file
$bag->addFile('../README.md', 'data/documentation/myreadme.md');

// Add another algorithm
$bag->addAlgorithm('sha1');

// Get the algorithms
$algos = $bag->getAlgorithms();
var_dump($algos); // array(
                  //   'sha512',
                  //   'sha1',
                  // )

// Add a fetch url
$bag->addFetchFile('http://www.google.ca', 'data/mywebsite.html');

// Add some bag-info tags
$bag->addBagInfoTag('Contact-Name', 'Jared Whiklo');
$bag->addBagInfoTag('CONTACT-NAME', 'Additional admins');

// Check for tags.
if ($bag->hasBagInfoTag('contact-name')) {

    // Get tags
    $tags = $bag->getBagInfoByTag('contact-name');

    var_dump($tags); // array(
                     //    'Jared Whiklo',
                     //    'Additional admins',
                     // )

    // Remove a specific tag value using array index from the above listing.
    $bag->removeBagInfoTagIndex('contact-name', 1);

    // Get tags
    $tags = $bag->getBagInfoByTag('contact-name');

    var_dump($tags); // array(
                     //    'Jared Whiklo',
                     // )

    $bag->addBagInfoTag('Contact-NAME', 'Bob Saget');
    // Get tags
    $tags = $bag->getBagInfoByTag('contact-name');

    var_dump($tags); // array(
                     //    'Jared Whiklo',
                     //    'Bob Saget',
                     // )
    // Without the case sensitive flag as true, you must be exact.
    $bag->removeBagInfoTagValue('contact-name', 'bob saget');
    $tags = $bag->getBagInfoByTag('contact-name');

    var_dump($tags); // array(
                     //    'Jared Whiklo',
                     //    'Bob Saget',
                     // )

    // With the case sensitive flag set to false, you can be less careful
    $bag->removeBagInfoTagValue('contact-name', 'bob saget', false);
    $tags = $bag->getBagInfoByTag('contact-name');

    var_dump($tags); // array(
                     //    'Jared Whiklo',
                     // )

    // Remove all values for the specified tag.
    $bag->removeBagInfoTag('contact-name');
}

// Write the bag to the specified path and filename using the expected archiving method.
$bag->package('./archive.tar.bz2');
```

#### Using a BagIt Profile

[](#using-a-bagit-profile)

```
require_once './vendor/autoload.php';

use \whikloj\BagItTools\Bag;

$dir = "./newbag";

// Create new bag as directory $dir
$bag = Bag::create($dir);
// Add a profile by URL
$bag->addBagProfileByURL("https://some.example.com/bagit-profile.json");
// or add a profile by JSON
$bag->addBagProfileByJson(file_get_contents("path/to/bagit-profile.json"));

// Add a file
$bag->addFile('../README.md', 'data/documentation/myreadme.md');

// Add another algorithm
$bag->addAlgorithm('sha1');

// Write the bag to the specified path and filename using the expected archiving method.
$bag->package('./archive.tar.bz2');
```

Maintainer
----------

[](#maintainer)

[Jared Whiklo](https://github.com/whikloj)

License
-------

[](#license)

[MIT](./LICENSE)

###  Health Score

56

—

FairBetter than 98% of packages

Maintenance73

Regular maintenance activity

Popularity36

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 95.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~106 days

Recently: every ~284 days

Total

22

Last Release

131d ago

Major Versions

1.4.1 → 2.0.02020-10-27

2.1.0 → 3.0.02021-07-06

3.0.2 → 4.0.02022-02-24

v4.x-dev → 5.0.02024-11-21

5.0.0 → 6.0.02026-01-07

PHP version history (6 changes)1.0.0PHP &gt;=5.6

2.0.0PHP &gt;=7.2

3.0.0PHP &gt;=7.3

v4.x-devPHP &gt;=7.4

5.0.0PHP &gt;=8.0

6.0.0PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/4703a4545b6059c95c19547895d9d61e3d284d8461b3fa59d66975c470f437b7?d=identicon)[whikloj](/maintainers/whikloj)

---

Top Contributors

[![whikloj](https://avatars.githubusercontent.com/u/2857697?v=4)](https://github.com/whikloj "whikloj (97 commits)")[![henning-gerhardt](https://avatars.githubusercontent.com/u/2129672?v=4)](https://github.com/henning-gerhardt "henning-gerhardt (3 commits)")[![jonasraoni](https://avatars.githubusercontent.com/u/361921?v=4)](https://github.com/jonasraoni "jonasraoni (2 commits)")

---

Tags

databagstransmissionintegritybagit

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/whikloj-bagittools/health.svg)

```
[![Health](https://phpackages.com/badges/whikloj-bagittools/health.svg)](https://phpackages.com/packages/whikloj-bagittools)
```

###  Alternatives

[fakerphp/faker

Faker is a PHP library that generates fake data for you.

4.0k358.5M3.5k](/packages/fakerphp-faker)[dflydev/dot-access-data

Given a deep data structure, access data by dot notation.

720359.1M86](/packages/dflydev-dot-access-data)[mbezhanov/faker-provider-collection

A collection of custom providers for the Faker library

2138.6M24](/packages/mbezhanov-faker-provider-collection)[php-units-of-measure/php-units-of-measure

A PHP library for converting between standard units of measure.

3123.4M20](/packages/php-units-of-measure-php-units-of-measure)[amenadiel/jpgraph

Composer Friendly, full refactor of JpGraph, library to make graphs and charts

1492.2M7](/packages/amenadiel-jpgraph)[jbzoo/data

An extended version of the ArrayObject object for working with system settings or just for working with data arrays

891.6M23](/packages/jbzoo-data)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
