Completed
Push — master ( b0f4f0...bce789 )
by Iurii
01:44
created

Asset::__construct()   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 0
1
<?php
2
3
/**
4
 * @package CLI
5
 * @author Iurii Makukh <[email protected]>
6
 * @copyright Copyright (c) 2018, Iurii Makukh <[email protected]>
7
 * @license https://www.gnu.org/licenses/gpl-3.0.en.html GPL-3.0+
8
 */
9
10
namespace gplcart\modules\cli\controllers\commands;
11
12
use DirectoryIterator;
13
use gplcart\modules\cli\controllers\Command;
14
15
/**
16
 * Handles commands related to asset files (JS and CSS)
17
 */
18
class Asset extends Command
19
{
20
21
    /**
22
     * Callback for "asset-clear" command
23
     */
24
    public function cmdClearAsset()
25
    {
26
        $params = $this->getParam();
27
28
        if (empty($params)) {
29
            foreach (new DirectoryIterator(GC_DIR_ASSET_COMPILED) as $file) {
30
                if ($file->isDir() && !$file->isDot()) {
31
                    gplcart_file_delete_recursive($file->getRealPath());
32
                }
33
            }
34
        } else {
35
36
            $file = null;
37
38
            if (!empty($params['css'])) {
39
                $file = GC_DIR_ASSET_COMPILED . '/css';
40
            } else if (!empty($params['js'])) {
41
                $file = GC_DIR_ASSET_COMPILED . '/js';
42
            }
43
44
            if (empty($file) || !is_dir($file)) {
45
                $this->errorAndExit($this->text('Invalid command'));
46
            }
47
48
            gplcart_file_delete_recursive($file);
49
        }
50
51
        $this->output();
52
    }
53
54
}
55