DownloadService::clearBuffers()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 0
crap 6
1
<?php
2
3
/*
4
 * This file is part of the 2amigos/yii2-exportable-widget project.
5
 * (c) 2amigOS! <http://2amigos.us/>
6
 * For the full copyright and license information, please view
7
 * the LICENSE file that was distributed with this source code.
8
 */
9
10
namespace dosamigos\exportable\services;
11
12
use dosamigos\exportable\contracts\DownloadServiceInterface;
13
use Yii;
14
15
class DownloadService implements DownloadServiceInterface
16
{
17
    /**
18
     * @inheritdoc
19
     */
20
    public function run($filename, $mime, $contents)
21
    {
22
        $this->clearBuffers();
23
24
        Yii::$app->getResponse()->sendContentAsFile($contents, $filename, ['mime' => $mime]);
25
26
        Yii::$app->end();
27
    }
28
29
    /**
30
     * Clean (erase) the output buffers and turns off output buffering
31
     */
32
    protected function clearBuffers()
33
    {
34
        while (ob_get_level() > 0) {
35
            ob_end_clean();
36
        }
37
    }
38
}
39