|
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 gplcart\core\Library as CoreLibrary; |
|
13
|
|
|
use gplcart\modules\cli\controllers\Command; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Handles commands related to 3-d party libraries |
|
17
|
|
|
*/ |
|
18
|
|
|
class Library extends Command |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Library class instance |
|
23
|
|
|
* @var \gplcart\core\Library $library |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $library; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param CoreLibrary $library |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct(CoreLibrary $library) |
|
31
|
|
|
{ |
|
32
|
|
|
parent::__construct(); |
|
33
|
|
|
|
|
34
|
|
|
$this->library = $library; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Callback for "library-get" command |
|
39
|
|
|
*/ |
|
40
|
|
|
public function cmdGetLibrary() |
|
41
|
|
|
{ |
|
42
|
|
|
$list = $this->getListLibrary(); |
|
43
|
|
|
$this->outputFormat($list); |
|
44
|
|
|
$this->outputFormatTableLibrary($list); |
|
45
|
|
|
$this->output(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Returns an array of libraries |
|
50
|
|
|
* @return array |
|
51
|
|
|
*/ |
|
52
|
|
|
protected function getListLibrary() |
|
53
|
|
|
{ |
|
54
|
|
|
$id = $this->getParam(0); |
|
55
|
|
|
|
|
56
|
|
|
if (!isset($id)) { |
|
57
|
|
|
$list = $this->library->getList(); |
|
58
|
|
|
$this->limitArray($list); |
|
59
|
|
|
return $list; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
$library = $this->library->get($id); |
|
64
|
|
|
|
|
65
|
|
|
if (empty($library)) { |
|
66
|
|
|
$this->errorAndExit($this->text('Unexpected result')); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
return array($library); |
|
70
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Output libraries in a table |
|
75
|
|
|
* @param array $items |
|
76
|
|
|
*/ |
|
77
|
|
|
protected function outputFormatTableLibrary(array $items) |
|
78
|
|
|
{ |
|
79
|
|
|
$header = array( |
|
80
|
|
|
$this->text('ID'), |
|
81
|
|
|
$this->text('Name'), |
|
82
|
|
|
$this->text('Type'), |
|
83
|
|
|
$this->text('Version') |
|
84
|
|
|
); |
|
85
|
|
|
|
|
86
|
|
|
$rows = array(); |
|
87
|
|
|
|
|
88
|
|
|
foreach ($items as $item) { |
|
89
|
|
|
$rows[] = array( |
|
90
|
|
|
$item['id'], |
|
91
|
|
|
$this->text($item['name']), |
|
92
|
|
|
$this->text($item['type']), |
|
93
|
|
|
$item['version'] |
|
94
|
|
|
); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
$this->outputFormatTable($rows, $header); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
|