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

FileController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 31
ccs 0
cts 15
cp 0
rs 10
wmc 4
lcom 0
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A actionView() 0 4 1
A actionGet() 0 4 1
A actionTempView() 0 7 2
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