<?php
namespace PortalPeople\filediff;

use Yii;
use yii\web\Controller;
use yii\web\UploadedFile;
use NGauge\FileDiff\services\FileDiffService;

class FileDiffController extends Controller
{
    public function actionIndex()
    {
        return $this->render('index');
    }

    public function actionCompare()
    {
        $model = new \stdClass();
        $model->file = UploadedFile::getInstanceByName('file');
        $result = null;

        if ($model->file) {
            $service = new FileDiffService();
            $result = $service->compareUploaded($model->file->tempName);
        }

        return $this->render('result', [
            'result' => $result,
        ]);
    }
}
