定制 tomphp/patch-builder 二次开发

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

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

tomphp/patch-builder

Composer 安装命令:

composer require tomphp/patch-builder

包简介

PHP Library for manipulating files to produce a patch.

README 文档

README

Build Status Scrutinizer Quality Score Coverage Status

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

Installation

Installation is quite and easy with composer:

composer require tomphp/patch-builder:dev-master

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);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2013-12-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固