Completed
Pull Request — master (#44)
by
unknown
04:35
created

DownloadAction   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 1
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 15
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 9 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: execut
5
 * Date: 5/19/17
6
 * Time: 11:59 AM
7
 */
8
9
namespace pastuhov\ymlcatalog\actions;
10
11
12
use yii\base\Action;
13
14
class DownloadAction extends Action
15
{
16
    public $fileName = null;
17
    public $publicPath = null;
18
19
    public function run() {
20
        $file = \yii::getAlias($this->publicPath) . '/' . $this->fileName;
21
        $response = \Yii::$app->getResponse();
22
        $response->setDownloadHeaders($this->fileName, mime_content_type($file));
23
24
        $response->sendContentAsFile(file_get_contents($file), $this->fileName);
25
26
        return $response;
27
    }
28
}