forked from codeigniter4/CodeIgniter4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseCommand.php
More file actions
114 lines (96 loc) · 2.44 KB
/
Copy pathBaseCommand.php
File metadata and controls
114 lines (96 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php namespace CodeIgniter\CLI;
use Psr\Log\LoggerInterface;
/**
* Class BaseCommand
*
* @property $group
* @property $name
* @property $description
*
* @package CodeIgniter\CLI
*/
abstract class BaseCommand
{
/**
* The group the command is lumped under
* when listing commands.
*
* @var string
*/
protected $group;
/**
* The Command's name
*
* @var string
*/
protected $name;
/**
* the Command's short description
*
* @var string
*/
protected $description;
/**
* @var \Psr\Log\LoggerInterface
*/
protected $logger;
/**
* Instance of the CommandRunner controller
* so commands can call other commands.
*
* @var \CodeIgniter\CLI\CommandRunner
*/
protected $commands;
//--------------------------------------------------------------------
public function __construct(LoggerInterface $logger, CommandRunner $commands)
{
$this->logger = $logger;
$this->commands = $commands;
}
//--------------------------------------------------------------------
abstract public function run(array $params);
//--------------------------------------------------------------------
/**
* Can be used by a command to run other commands.
*
* @param string $command
* @param array $params
*/
protected function call(string $command, array $params=[])
{
// The CommandRunner will grab the first element
// for the command name.
array_unshift($params, $command);
return $this->commands->index($params);
}
//--------------------------------------------------------------------
/**
* A simple method to display an error with line/file,
* in child commands.
*
* @param \Exception $e
*/
protected function showError(\Exception $e)
{
CLI::newLine();
CLI::error($e->getMessage());
CLI::write($e->getFile().' - '.$e->getLine());
CLI::newLine();
}
//--------------------------------------------------------------------
/**
* Makes it simple to access our protected properties.
*
* @param string $key
*
* @return mixed
*/
public function __get(string $key)
{
if (isset($this->$key))
{
return $this->$key;
}
}
//--------------------------------------------------------------------
}