Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BagProfile #67

Merged
merged 21 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Change Log

The purpose of this document is to provide a list of changes included in a release under the covers that
may have an impact on the user. This is not a comprehensive list of all changes, but hopefully catches most and
provides a reasoning for the changes.

## v5.0.0

### Added

#### BagIt Profile support.
You can now add BagIt Profile(s) to a newly created bag and/or they will be downloaded and parsed when validating an
existing bag, assuming the profile is available at the URL specified in the bag-info.txt file.

Profiles are validated against the [BagIt Profile Specification (v1.4.0)](https://bagit-profiles.github.io/bagit-profiles-specification/)
and profile rules are enforced when validating a bag (`$bag->isValid()`) and any errors are displayed in the `$bag->getErrors()` array.

To add a profile to a bag you can use either:
- `$bag->addProfileByJson($jsonString)` - To add a profile from a JSON string.
- `$bag->addProfileByURL($url)` - To add a profile from a URL.

Profiles are stored internally using their `BagIt-Profile-Identifier` as a key. You can only add a profile once
per identifier. If you try to add a profile with the same identifier it will be ignored.

To remove a profile you can use `$bag->removeBagProfile($profileIdentifier)` to remove a profile.

You can also use `$bag->clearAllProfiles()` to remove all profiles from a bag.

#### Package command validates the bag

Previous versions allowed you to package without validating the bag. Now the package command will validate the bag
before packaging. If the bag is not valid the package command will fail with a `BagItException::class` being thrown.

This is due to the addition of BagIt Profile support, if you add a profile to a bag we want to ensure you do not package
an invalid bag.

TODO: Validate the serialization being attempted during package validation.

### Removed

#### PHP 7 Support

This library now requires PHP 8.0 or higher, while PHP 8.0 is already end of life we will support it for the time being.
35 changes: 26 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Features:
* 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)

## Installation

**Composer**
Expand Down Expand Up @@ -169,12 +171,33 @@ if ($bag->hasBagInfoTag('contact-name')) {
$bag->removeBagInfoTag('contact-name');
}

// Write bagit support files (manifests, bag-info, etc)
$bag->update();

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

#### Using a BagIt Profile
```php
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
Expand All @@ -184,9 +207,3 @@ $bag->package('./archive.tar.bz2');
## License

[MIT](./LICENSE)

## Development

To-Do:

* CLI interface to handle simple bag CRUD (CReate/Update/Delete) functions.
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
"symfony/console": "^5.4"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"sebastian/phpcpd": "^6.0",
"phpunit/phpunit": "^9.6",
"squizlabs/php_codesniffer": "^3.5",
"donatj/mock-webserver": "^2.6",
"phpstan/phpstan": "^1.4"
Expand All @@ -46,15 +45,15 @@
"php -d xdebug.mode=profile -d xdebug.output_dir=mytracedir/ -d xdebug.start_with_request=yes -d xdebug.use_compression=true ./vendor/bin/phpunit"
],
"check": [
"./vendor/bin/phpcs --standard=PSR12 src tests",
"./vendor/bin/phpcpd --suffix='.php' src"
"./vendor/bin/phpcs --standard=PSR12 src tests"
],
"phpunit": [
"phpdbg -qrr ./vendor/bin/phpunit -d memory_limit=-1 --verbose --testsuite BagIt"
],
"test": [
"@check",
"@phpunit"
"@phpunit",
"@phpstan"
]
},
"config": {
Expand Down
64 changes: 1 addition & 63 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
processIsolation="false"
stopOnFailure="false"
bootstrap="./vendor/autoload.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
Expand Down
Loading