定制 facebook/difflib 二次开发

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

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

facebook/difflib

最新稳定版本:v1.3.0

Composer 安装命令:

composer require facebook/difflib

包简介

无描述信息

README 文档

README

Continuous Integration

DiffLib is a Hack library for creating and parsing diffs. Diffs can be created between any two sequences of items. Additional helpers (such as support for unified diffs, and colored diffs) are provided for string diffs.

Diffs are represented as a sequence of DiffOp operations; these can 'keep' an element (i.e. it's unchanged in both sequences), insert an element, or delete an element. For example, in a unified diff, these would be:

 DiffKeepOp -DiffDeleteOp +DiffInsertOp

String diffs are typically represented as a sequence of lines, but can also be represented as a sequence of characters, allowing intra-line diffs.

Diff output formats

difflib can create standard unified diffs:

@@ -1 +1@@ -Foo Bat Baz +Foo Bar Baz

difflib can also create colored diffs, with intra-line edits highlighted:

same diff as above, but with 'Bat' highlighted red, 'Bar' highlighted green

A concrete implementation is provided for standard CLI terminals, and an abstract base class for other implementations, such as HTML or XHP.

Examples

use namespace Facebook\DiffLib; function create_unified_diff(string $from, string $to): string { return DiffLib\StringDiff::lines($from, $to)->getUnifiedDiff(); } function create_colored_diff(string $from, string $to): string { return DiffLib\CLIColoredUnifiedDiff::create($from, $to); } final class IntDiff extends DiffLib\Diff { const type TContent = int; } function dump_int_diff(vec<int> $from, vec<int> $to): void { $diff = (new IntDiff($from, $to))->getDiff(); foreach ($diff as $op) { if ($op is DiffLib\DiffKeepOp<_>) { \printf(" %d\n", $op->getContent()); } else if ($op is DiffLib\DiffDeleteOp<_>) { \printf("- %d\n", $op->getContent()); } else { $op = $op as DiffLib\DiffInsertOp<_>; printf("+ %d\n", $op->getContent()); } } } 

dump_int_diff(vec[1, 3, 9], vec[1, 4, 9]) will produce this output:

 1 - 3 + 4 9 

Requirements

  • The current release version of HHVM

Installing DiffLib

composer require facebook/difflib 

How DiffLib works

Diffs are created using Myers' diff algorithm: Myers, E.W. Algorithmica (1986) 1: 251. https://doi.org/10.1007/BF01840446

For more details, see the commented implementation.

Full documentation

  • DiffLib\Diff: abstract base class. Needs to be subclassed to operate on any particular type.
  • DiffLib\StringDiff: final class for diffing strings, and adds support for creating unified diffs
  • DiffLib\ColoredUnifiedDiff: abstract class for rendering unified diffs. Output may be any type - for example, strings or XHP.
  • DiffLib\CLIColoredUnifiedDiff: abstract final class for rendering unified diffs to a terminal that supports color escape sequences. Provides intra-line highlighting.
  • DiffLib\DiffOp: abstract class for a diff operation. Sealed to DiffInsertOp, DiffKeepOp, and DiffDeleteOp.
  • DiffLib\cluster(): utility function to group together sequential operations of the same kind. Converts vec<DiffOp<T>> to a generally shorter number of vec<DiffOp<vec<T>>>

License

DiffLib is MIT licensed, as found in the LICENSE file.

facebook/difflib 适用场景与选型建议

facebook/difflib 是一款 基于 Hack 开发的 Composer 扩展包,目前已累计 623.85k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 623.85k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 14
  • 依赖项目数: 11
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 22
  • Forks: 7
  • 开发语言: Hack

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04