Completed
Push — master ( b77af5...f73d9a )
by Andrii
12:00
created

OtherPage::extractData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * Yii2 Pages Module
4
 *
5
 * @link      https://github.com/hiqdev/yii2-module-pages
6
 * @package   yii2-module-pages
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\yii2\modules\pages\models;
12
13
use hiqdev\yii2\modules\pages\Module;
14
use Yii;
15
16
class OtherPage extends AbstractPage
17
{
18
    public function render(array $params = [])
19
    {
20
        $fullPath = Module::getInstance()->getLocalPath($this->path);
21
        $mimeType = mime_content_type($fullPath);
22
23
        if ($mimeType === 'text/plain') {
24
            $text = Module::getInstance()->getStorage()->read($this->path);
25
            return "<pre>$text</pre>";
26
        }
27
28
        $response = Yii::$app->response;
29
        $response->format = $response::FORMAT_RAW;
30
        $response->headers->set('Content-Type', $mimeType);
31
        readfile($fullPath);
32
        Yii::$app->end();
33
    }
34
35
    public function extractData($path)
36
    {
37
        return [];
38
    }
39
}
40