eliashaeussler/gitattributes
Composer 安装命令:
composer require eliashaeussler/gitattributes
包简介
Parser for .gitattributes files in an object-oriented way
README 文档
README
Object-oriented .gitattributes file handling
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
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).
eliashaeussler/gitattributes 适用场景与选型建议
eliashaeussler/gitattributes 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17 次下载、GitHub Stars 达 4, 最近一次更新时间为 2024 年 11 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 eliashaeussler/gitattributes 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 eliashaeussler/gitattributes 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 17
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2024-11-08