定制 eliashaeussler/gitattributes 二次开发

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

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

eliashaeussler/gitattributes

最新稳定版本:2.0.1

Composer 安装命令:

composer require eliashaeussler/gitattributes

包简介

Parser for .gitattributes files in an object-oriented way

README 文档

README

Object-oriented .gitattributes file handling

Coverage CGL Tests Supported PHP Versions

A PHP library to parse and dump .gitattributes file in an object-oriented way. The library provides a GitattributesDumper and GitattributesParser to either read or write contents to or from .gitattributes files. All attributes as of Git v2.46.0 according to the official documentation are supported.

🔥 Installation

Packagist Packagist Downloads

composer require eliashaeussler/gitattributes

⚡ Usage

Parse rules from .gitattributes file

The main parsing functionality is provided by the GitattributesParser. It can be used as follows:

use EliasHaeussler\Gitattributes;

$parser = new Gitattributes\GitattributesParser(__DIR__);
$ruleset = $parser->parse('.gitattributes');

The returned ruleset contains the original filename as well as all parsed rules as instances of Rule\Rule. A rule contains the file pattern and a list of attributes:

foreach ($ruleset->rules() as $rule) {
    echo $rule->pattern()->toString().' ';

    foreach ($rule->attributes() as $attribute) {
        echo $attribute->toString().' ';
    }

    echo PHP_EOL;
}

Important

Only attribute names listed in the official documentation are supported by the library. Using other than the supported attributes will raise an exception. See Rule\Attribute\AttributeName for an overview.

Dump .gitattributes file from rules

It is also possible to create a new .gitattributes file by dumping a list of prepared rules. This functionality is provided by the GitattributesDumper:

use EliasHaeussler\Gitattributes;

$rules = [
    // You can create rules in an object-oriented way
    new Gitattributes\Rule\Rule(
        new Gitattributes\Rule\Pattern\FilePattern('/tests'),
        [
            Gitattributes\Rule\Attribute\Attribute::set(Gitattributes\Rule\Attribute\AttributeName::ExportIgnore),
        ],
    ),
    // ... or using a string input
    Gitattributes\Rule\Rule::fromString('/phpunit.xml export-ignore'),
];

$dumper = new Gitattributes\GitattributesDumper(__DIR__);
$result = $dumper->dump('.gitattributes', $rules);

Note

A file must not exist when dumping file contents. Otherwise, an exception is thrown.

🧑‍💻 Contributing

Please have a look at CONTRIBUTING.md.

⭐ License

This project is licensed under GNU General Public License 3.0 (or later).

统计信息

  • 总下载量: 17
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2024-11-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固