PHPackages                             tomphp/patch-builder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. tomphp/patch-builder

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

tomphp/patch-builder
====================

PHP Library for manipulating files to produce a patch.

v0.1.0(12y ago)25981PHPPHP &gt;=5.3

Since Jan 10Pushed 11y ago1 watchersCompare

[ Source](https://github.com/tomphp/patch-builder)[ Packagist](https://packagist.org/packages/tomphp/patch-builder)[ RSS](/packages/tomphp-patch-builder/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (1)Dependencies (6)Versions (3)Used By (1)

PatchBuilder
============

[](#patchbuilder)

[![Build Status](https://camo.githubusercontent.com/eff82dbf156edff4b13b166db4bbf0e3826deb11e589820420a81ebcdda87f1d/68747470733a2f2f7472617669732d63692e6f72672f746f6d7068702f50617463684275696c6465722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/tomphp/PatchBuilder)[![Scrutinizer Quality Score](https://camo.githubusercontent.com/77441f451402f25308f8bc221e385b9c734e29da507ad2955aedd5ecee7bce18/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f746f6d7068702f50617463684275696c6465722f6261646765732f7175616c6974792d73636f72652e706e673f733d64333361303733393566646663316130383639326538623031643333383832346438643631626266)](https://scrutinizer-ci.com/g/tomphp/PatchBuilder/)[![Coverage Status](https://camo.githubusercontent.com/26e59c009a94facb72657215009f550990d2fdbf1a60f213286e473c6a8272d7/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f746f6d7068702f50617463684275696c6465722f62616467652e706e67)](https://coveralls.io/r/tomphp/PatchBuilder)

A PHP Library which allows your to load some text, make some modifications to it and then generate a patch.

Installation
------------

[](#installation)

Installation is quite and easy with composer:

`composer require tomphp/patch-builder:dev-master`

Usage
-----

[](#usage)

Simply create a `PatchBuffer` containing the content you want to modify then apply the modifications with the methods available:

```
use TomPHP\PatchBuilder\PatchBuffer;
use TomPHP\PatchBuilder\Types\LineNumber;
use TomPHP\PatchBuilder\Types\LineRange;

$buffer = PatchBuffer::createWithContents(file('somedata.txt'));

// Insert 2 at line 27
$buffer->insert(new LineNumber(27), array('hello', 'world'));

// Delete lines 12 to 16
$buffer->delete(LineRange::createFromNumbers(12, 16));

// Replace line 4 and 5 with a new line
$buffer->replace(LineRange::createFromNumbers(4, 5), array('hello moon'));
```

\###Line Numbers

Line numbers and ranges are specified as `TomPHP\PatchBuilder\Types\LineNumber`and `TomPHP\PatchBuilder\Types\LineRange` objects and refer to the line in the buffer in it's modified state.

If you want to refer to a line but its number in the original content you can use a `TomPHP\PatchBuilder\Types\OriginalLineNumber` object instead and it will be translated to the current line number in the modified file.

```
use TomPHP\PatchBuilder\PatchBuffer;
use TomPHP\PatchBuilder\Types\LineNumber;
use TomPHP\PatchBuilder\Types\OrignalLineNumber;

$buffer = PatchBuffer::createWithContents(file('somedata.txt'));

// Insert 2 at line 5
$buffer->insert(new LineNumber(5), array('hello', 'world'));

// Actually inserts at line 8 because 2 lines have been added before here.
$buffer->insert(new OriginalLineNumber(6), array('hello', 'moon'));
```

If you try to access a line by original line number which has since been deleted a `TomPHP\PatchBuilder\LineTracker\Exception\DeletedLineException` will be thrown.

\###Outputting the patch

The buffer can be converted to a patch using a `PatchBuilder` class. Currently only 1 `PatchBuilder` class is provided:

```
use TomPHP\PatchBuilder\PatchBuffer;
use TomPHP\PatchBuilder\Builder\PhpDiffBuilder;

$filename = 'myfile.txt';

$src = 'orignal/' . $filename;
$dest = 'new/' . $filename;

$buffer = PatchBuffer::createWithContents(file($src));

// ... perform buffer manipulations ...

$builder = new PhpDiffBuilder();

echo $builder->buildPatch($src, $dest, $buffer);
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

4509d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1959183?v=4)[Tom Oram](/maintainers/tomphp)[@tomphp](https://github.com/tomphp)

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/tomphp-patch-builder/health.svg)

```
[![Health](https://phpackages.com/badges/tomphp-patch-builder/health.svg)](https://phpackages.com/packages/tomphp-patch-builder)
```

###  Alternatives

[wyndow/fuzzywuzzy

Fuzzy string matching based on FuzzyWuzzy from Seatgeek

742.0M6](/packages/wyndow-fuzzywuzzy)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
