Completed
Push — master ( 23c702...854a8a )
by Andrii
06:07
created

FileController::actionTempView()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 7
ccs 0
cts 7
cp 0
crap 6
rs 9.4285
1
<?php
2
3
/*
4
 * HiPanel core package
5
 *
6
 * @link      https://hipanel.com/
7
 * @package   hipanel-core
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2014-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hipanel\controllers;
13
14
use common\models\File;
15
use Yii;
16
use yii\web\Controller;
17
use yii\web\Response;
18
19
class FileController extends Controller
20
{
21
    /* XXX ask sol
0 ignored issues
show
Unused Code Comprehensibility introduced by
51% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
22
    public function behaviors() {
23
        return [
24
            'fileAccess' => [
25
                'class' => 'common\components\filters\FileAccessFilter',
26
                'only' => ['view', 'get'],
27
            ],
28
        ];
29
    }
30
    */
31
32
    public function actionView($id, $object_id = null, $object_name = null, $nocache = false)
33
    {
34
        return File::renderFile($id, $object_id, $object_name, true, $nocache);
35
    }
36
37
    public function actionGet($id, $object_id, $object_name, $ext, $contentType)
38
    {
39
        Yii::$app->response->sendFile(File::renderFile($id, $object_id, $object_name, false), implode('.', [$id, $ext]), ['mimeType' => $contentType]);
40
    }
41
42
    public function actionTempView($temp_file, $key)
43
    {
44
        if ($key === File::getHash($temp_file)) {
45
            Yii::$app->response->sendFile(File::getTempFolder() . DIRECTORY_SEPARATOR . $temp_file);
46
        }
47
        Yii::$app->end();
48
    }
49
}
50