public diff_main ( string $text1, string $text2, boolean $checklines = true ) : array | ||
$text1 | string | Old string to be diffed. |
$text2 | string | New string to be diffed. |
$checklines | boolean | Optional speedup flag. If present and false, then don't run a line-level diff first to identify the changed areas. Defaults to true, which does a faster, slightly less optimal diff. |
Результат | array | Array of changes. |
public function diff_main($text1, $text2, $checklines = true)
{
return $this->diff->main($text1, $text2, $checklines)->getChanges();
}
public function actionDiff($document_history_id) { $model = History::findOne($document_history_id); if (is_null($model)) { throw new \yii\web\HttpException(404, Yii::t('burivuh', 'Record in the history does not exist')); } $document = Document::findOne($model->document_id); $previous = History::find()->where(['document_id' => $model->document_id])->andWhere('created_at<:created_at', [':created_at' => $model->created_at])->orderBy('created_at DESC')->limit(1)->one(); $diffs = []; if (!is_null($previous)) { $dmp = new DiffMatchPatch(); $diffs = $dmp->diff_main($previous->content, $model->content, false); } return $this->render('diff', ['document' => $document, 'model' => $model, 'previous' => $previous, 'diffs' => $diffs]); }