承接 vi-kon/laravel-diff 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

vi-kon/laravel-diff

最新稳定版本:v1.0.2

Composer 安装命令:

composer require vi-kon/laravel-diff

包简介

Diff tool for Laravel 5

README 文档

README

This package is for comparison strings and show changes.

Table of content

Back to top

Features

  • compare strings
  • compare files
  • group string differences into hunk groups

Installation

Via composer:

composer require vi-kon/laravel-diff

Back to top

Usage

Simple usage:

// Compare string line by line
$diff = Diff::compare("hello\na", "hello\nasd\na");
// Outputs span, ins, del HTML tags, depend if entry
// is unmodified, inserted or deleted
echo $diff->toHTML();

Compare two file:

// Compare files line by line
$diff = Diff::compareFiles("a.txt", "b.txt");
echo $diff->toHTML();

You can customize output by getting raw data:

$options = [
    // Compare by line or by characters
    'compareCharacters' => false,
    // Offset size in hunk groups
    'offset'            => 2,
];

$diff = Diff::compare("hello\na", "hello\nasd\na", $options);
$groups = $diff->getGroups();

foreach($groups as $i => $group)
{
    // Output: Hunk 1 : Lines 2 - 6
    echo 'Hunk ' . $i . ' : Lines ' 
         . $group->getFirstPosition() . ' - ' . $group->getLastPosition(); 
    
    // Output changed lines (entries)
    foreach($group->getEntries() as $entry)
    {
        // Output old position of line
        echo $entry instanceof \ViKon\Diff\Entry\InsertedEntry 
            ? '-'
            : $entry->getOldPosition() + 1;

        echo ' | ';

        // Output new position of line
        echo $entry instanceof \ViKon\Diff\Entry\DeletedEntry 
            ? '-'
            : $entry->getNewPosition() + 1;
        
        echo ' - ';        

        // Output line (entry)
        echo $entry;
    }
}

Back to top

License

This package is licensed under the MIT License

Back to top

统计信息

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

GitHub 信息

  • Stars: 30
  • Watchers: 2
  • Forks: 9
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-02-28