定制 whikloj/bagittools 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

whikloj/bagittools

Composer 安装命令:

composer require whikloj/bagittools

包简介

A PHP library to manipulate and verify BagIt bags.

README 文档

README

Minimum PHP Version Github Actions LICENSE codecov

Introduction

BagItTools is a PHP implementation of the BagIt v1.0 specification (RFC-8493).

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

Installation

Composer

composer require "whikloj/bagittools"

Clone from Github

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

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:

Usage

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

Command line

Validating a bag

./bin/console validate <path to bag>

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 like this

./test-harness <path to BagItTools>/bin/console -- -v validate

API

API Documentation

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

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

Jared Whiklo

License

MIT

whikloj/bagittools 适用场景与选型建议

whikloj/bagittools 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 22.91k 次下载、GitHub Stars 达 12, 最近一次更新时间为 2019 年 11 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「data」 「integrity」 「transmission」 「bags」 「bagit」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 whikloj/bagittools 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 whikloj/bagittools 我们能提供哪些服务?
定制开发 / 二次开发

基于 whikloj/bagittools 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 22.91k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 12
  • 点击次数: 25
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 12
  • Watchers: 3
  • Forks: 8
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-11-25