PHP code example of ptlis / diff-parser
1. Go to this page and download the library: Download ptlis/diff-parser library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ptlis / diff-parser example snippets
$parser = new \ptlis\DiffParser\Parser();
$changeset = $parser->parseFile('path/to/git/diff', Parser::VCS_GIT);
$changeset = $parser->parse($patchData, Parser::VCS_SVN);
\file_put_contents('my.patch', $changeset);
foreach ($changeset->files as $file) {
// $file is an instance of ptlis\DiffParser\File
}
$file->filename->original; // Eg 'readme.md' or '' (empty) on create
$file->filename->new; // EG 'README.md' or '' (empty) on delete
$file->operation; // One of File::CREATED, File::CHANGED, File::DELETED
foreach ($file->hunks as $hunk) {
// $hunk is an instance of ptlis\DiffParser\Hunk
}
$hunk->startLine->original; // Eg '0'
$hunk->startLine->new; // Eg '0'
$hunk->affectedLines->original; // Eg '5'
$hunk->affectedLines->new; // Eg '7'
foreach ($hunk->lines as $line) {
// $line is an instance of ptlis\DiffParser\Line
}
$line->number->original; // Eg '7' or '-1' on create
$line->number->new; // Eg '7' or '-1' on delete
$line->operation; // One of Line::ADDED, Line::REMOVED, Line::UNCHANGED
$line->content; // Eg ' $foo = bar;'