Skip to content

Commit d9c877f

Browse files
authored
* Add workflow for version 4 development (whikloj#59) * Remove support of PHP < 8.0 (whikloj#58) * Remove support of PHP < 8.0 * More changes * Add version 5 action * More PHP 8 and phpstan fixes (whikloj#62) * Add Tag Files functions (whikloj#65) * Add addTagFile() * Add removeTagFile and tests * Build pushed feature branches * Update action versions * Fix messages * Cover the new private function shared by addTagFile and removeTagFile * Change bag to extended when adding a fetch file (whikloj#66) * Add BagProfile (whikloj#67) * Initial BagItProfile work * More testing * More tests * Track serializations * Load and validate profiles * Return file path in archive type exception * Windows test * Clean up extension handling * Add more profile tests * Fixes and more profile tests * Always check for Allow-Fetch before Require-Fetch, so the reverse test is unnecessary * Fix callable in array_filter * Move json into tests * More tests * Add methods to add profile to bag and some tests * Allow other bag-info tag options * Test bag is valid before creating a package * Read BagIt Profile identifiers from bag-info.txt and validate Additional tests Handle long lines without a space to break at * Add a change log * Some tidying * Correct PIPEWAIT and add test for trait * Build on push and allow manual runs * Clean up for PHPStan level 7 (whikloj#68) * Clean up for PHPStan level 7 * Clean up some testing * Prep for v5 merge * Revert "Prep for v5 merge" This reverts commit bd2b380.
1 parent 3e6c20e commit d9c877f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+8427
-821
lines changed

.github/workflows/v5.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Build version 5 development
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "v5"
7+
push:
8+
branches:
9+
- "v5"
10+
- "feature/v5/*"
11+
workflow_dispatch:
12+
13+
jobs:
14+
build:
15+
runs-on: ${{ matrix.host-os }}
16+
continue-on-error: ${{ matrix.experimental }}
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
php-versions: ["8.0", "8.1", "8.2", "8.3"]
21+
host-os: ["ubuntu-latest", "windows-latest"]
22+
experimental: [false]
23+
24+
name: PHP ${{ matrix.php-versions }} - OS ${{ matrix.host-os }}
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
29+
- name: Setup PHP
30+
uses: shivammathur/setup-php@v2
31+
with:
32+
php-version: ${{ matrix.php-versions }}
33+
coverage: none
34+
extensions: sockets, intl, bz2, zip
35+
36+
- name: Get composer cache directory (Ubuntu)
37+
id: composercache-ubuntu
38+
run: |
39+
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
40+
if: ${{ startsWith( matrix.host-os , 'ubuntu') }}
41+
42+
- name: Cache dependencies (Ubuntu)
43+
uses: actions/cache@v4
44+
with:
45+
path: ${{ steps.composercache-ubuntu.outputs.dir }}
46+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
47+
restore-keys: |
48+
${{ runner.os }}-composer-
49+
if: ${{ startsWith( matrix.host-os , 'ubuntu') }}
50+
51+
- name: Get composer cache directory (Windows)
52+
id: composercache-windows
53+
run: |
54+
echo "dir=$(composer config cache-files-dir)" >> $env:GITHUB_OUTPUT
55+
if: ${{ startsWith( matrix.host-os , 'windows') }}
56+
57+
- name: Cache dependencies (Windows)
58+
uses: actions/cache@v4
59+
with:
60+
path: ${{ steps.composercache-windows.outputs.dir }}
61+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
62+
restore-keys: |
63+
${{ runner.os }}-composer-
64+
if: ${{ startsWith( matrix.host-os , 'windows') }}
65+
66+
- name: Install dependencies
67+
run: composer install --prefer-dist --no-progress
68+
69+
- name: Check codestyle
70+
run: composer check
71+
72+
- name: Run test suite
73+
run: composer phpunit
74+
75+
- name: Upload coverage to Codecov
76+
uses: codecov/codecov-action@v4
77+
with:
78+
file: ./clover.xml
79+
fail_ci_if_error: true
80+
token: ${{ secrets.CODECOV_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
vendor/
33
clover.xml
44
mytracedir/
5+
.phpunit.result.cache

CHANGELOG.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Change Log
2+
3+
The purpose of this document is to provide a list of changes included in a release under the covers that
4+
may have an impact on the user. This is not a comprehensive list of all changes, but hopefully catches most and
5+
provides a reasoning for the changes.
6+
7+
## v5.0.0
8+
9+
### Added
10+
11+
#### BagIt Profile support.
12+
13+
You can now add BagIt Profile(s) to a newly created bag and/or they will be downloaded and parsed when validating an
14+
existing bag, assuming the profile is available at the URL specified in the bag-info.txt file.
15+
16+
Profiles are validated against the [BagIt Profile Specification (v1.4.0)](https://bagit-profiles.github.io/bagit-profiles-specification/)
17+
and profile rules are enforced when validating a bag (`$bag->isValid()`) and any errors are displayed in the `$bag->getErrors()` array.
18+
19+
To add a profile to a bag you can use either:
20+
- `$bag->addProfileByJson($jsonString)` - To add a profile from a JSON string.
21+
- `$bag->addProfileByURL($url)` - To add a profile from a URL.
22+
23+
Profiles are stored internally using their `BagIt-Profile-Identifier` as a key. You can only add a profile once
24+
per identifier. If you try to add a profile with the same identifier it will be ignored.
25+
26+
To remove a profile you can use `$bag->removeBagProfile($profileIdentifier)` to remove a profile.
27+
28+
You can also use `$bag->clearAllProfiles()` to remove all profiles from a bag.
29+
30+
#### Package command validates the bag
31+
32+
Previous versions allowed you to package without validating the bag. Now the package command will validate the bag
33+
before packaging. If the bag is not valid the package command will fail with a `BagItException::class` being thrown.
34+
35+
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
36+
an invalid bag.
37+
38+
TODO: Validate the serialization being attempted during package validation.
39+
40+
### Removed
41+
42+
#### PHP 7 Support
43+
44+
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.

README.md

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# BagItTools
22

3-
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.4-8892BF.svg?style=flat-square)](https://php.net/)
4-
[![Github Actions](https://github.com/whikloj/BagItTools/workflows/Build/badge.svg?branch=main)](https://github.com/whikloj/BagItTools/actions?query=workflow%3A%22Build%22+branch%3Amain)
3+
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%208.0-8892BF.svg?style=flat-square)](https://php.net/)
4+
[![Github Actions](https://github.com/whikloj/BagItTools/actions/workflows/main.yml/badge.svg)](https://github.com/whikloj/BagItTools/actions/workflows/main.yml)
55
[![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](./LICENSE)
66
[![codecov](https://codecov.io/gh/whikloj/BagItTools/branch/main/graph/badge.svg)](https://codecov.io/gh/whikloj/BagItTools)
77

@@ -26,6 +26,8 @@ Features:
2626
* Create an archive (zip, tar, tar.gz, tgz, tar.bz2)
2727
* In-place upgrade of bag from v0.97 to v1.0
2828

29+
## [Change Log](./CHANGELOG.md)
30+
2931
## Installation
3032

3133
**Composer**
@@ -169,12 +171,33 @@ if ($bag->hasBagInfoTag('contact-name')) {
169171
$bag->removeBagInfoTag('contact-name');
170172
}
171173

172-
// Write bagit support files (manifests, bag-info, etc)
173-
$bag->update();
174-
175174
// Write the bag to the specified path and filename using the expected archiving method.
176175
$bag->package('./archive.tar.bz2');
176+
```
177+
178+
#### Using a BagIt Profile
179+
```php
180+
require_once './vendor/autoload.php';
181+
182+
use \whikloj\BagItTools\Bag;
183+
184+
$dir = "./newbag";
185+
186+
// Create new bag as directory $dir
187+
$bag = Bag::create($dir);
188+
// Add a profile by URL
189+
$bag->addBagProfileByURL("https://some.example.com/bagit-profile.json");
190+
// or add a profile by JSON
191+
$bag->addBagProfileByJson(file_get_contents("path/to/bagit-profile.json"));
192+
193+
// Add a file
194+
$bag->addFile('../README.md', 'data/documentation/myreadme.md');
195+
196+
// Add another algorithm
197+
$bag->addAlgorithm('sha1');
177198

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

180203
## Maintainer
@@ -184,9 +207,3 @@ $bag->package('./archive.tar.bz2');
184207
## License
185208

186209
[MIT](./LICENSE)
187-
188-
## Development
189-
190-
To-Do:
191-
192-
* CLI interface to handle simple bag CRUD (CReate/Update/Delete) functions.

composer.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@
1414
],
1515
"require": {
1616
"pear/archive_tar": "^1.4.14",
17-
"php": ">=7.4",
17+
"php": ">=8.0",
1818
"ext-curl": "*",
1919
"ext-zip": "*",
2020
"ext-mbstring": "*",
2121
"ext-intl": "*",
2222
"symfony/console": "^5.4"
2323
},
2424
"require-dev": {
25-
"phpunit/phpunit": "^9.0",
26-
"sebastian/phpcpd": "^6.0",
25+
"phpunit/phpunit": "^9.6",
2726
"squizlabs/php_codesniffer": "^3.5",
2827
"donatj/mock-webserver": "^2.6",
2928
"phpstan/phpstan": "^1.4"
@@ -40,21 +39,21 @@
4039
},
4140
"scripts": {
4241
"phpstan": [
43-
"php -d memory_limit=-1 ./vendor/bin/phpstan analyze -l 3 src tests"
42+
"php -d memory_limit=-1 ./vendor/bin/phpstan analyze -l 7 src tests"
4443
],
4544
"profile": [
4645
"php -d xdebug.mode=profile -d xdebug.output_dir=mytracedir/ -d xdebug.start_with_request=yes -d xdebug.use_compression=true ./vendor/bin/phpunit"
4746
],
4847
"check": [
49-
"./vendor/bin/phpcs --standard=PSR12 src tests",
50-
"./vendor/bin/phpcpd --suffix='.php' src"
48+
"./vendor/bin/phpcs --standard=PSR12 src tests"
5149
],
5250
"phpunit": [
53-
"phpdbg -qrr ./vendor/bin/phpunit -d memory_limit=-1 --testsuite BagIt"
51+
"phpdbg -qrr ./vendor/bin/phpunit -d memory_limit=-1 --verbose --testsuite BagIt"
5452
],
5553
"test": [
5654
"@check",
57-
"@phpunit"
55+
"@phpunit",
56+
"@phpstan"
5857
]
5958
},
6059
"config": {

0 commit comments

Comments
 (0)