Completed
Push — master ( 853dbc...35e61c )
by Iurii
01:26
created

Cache::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
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;
11
12
use gplcart\core\Cache as CoreCache;
13
14
/**
15
 * Handles commands related to system cache
16
 */
17
class Cache extends Base
18
{
19
20
    /**
21
     * Cache class instance
22
     * @var \gplcart\core\Cache $cache
23
     */
24
    protected $cache;
25
26
    /**
27
     * @param CoreCache $cache
28
     */
29
    public function __construct(CoreCache $cache)
30
    {
31
        parent::__construct();
32
33
        $this->cache = $cache;
34
    }
35
36
    /**
37
     * Callback for "cache-clear" command
38
     */
39
    public function cmdClearCache()
40
    {
41
        $id = $this->getParam(0);
42
        $all = $this->getParam('all');
43
44
        if (!isset($id) && empty($all)) {
45
            $this->errorExit($this->text('Invalid command'));
46
        }
47
48
        $result = false;
49
50
        if (isset($id)) {
51
            $pattern = $this->getParam('pattern');
52
            if (isset($pattern)) {
53
                $result = $this->cache->clear($id, array('pattern' => $pattern));
54
            } else {
55
                $result = $this->cache->clear($id);
56
            }
57
        } else if ($all) {
58
            $result = $this->cache->clear(null);
59
        }
60
61
        if (!$result) {
62
            $this->errorExit($this->text('An error occurred'));
63
        }
64
65
        $this->output();
66
    }
67
68
}
69