1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Jaeger |
4
|
|
|
* |
5
|
|
|
* @author Eric Lamb <[email protected]> |
6
|
|
|
* @copyright Copyright (c) 2015-2016, mithra62, Eric Lamb |
7
|
|
|
* @link http://jaeger-app.com |
8
|
|
|
* @version 1.0 |
9
|
|
|
* @filesource ./Console.php |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace JaegerApp; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Jaeger - Console Output Object |
16
|
|
|
* |
17
|
|
|
* Handles outputting/writing data to the console |
18
|
|
|
* |
19
|
|
|
* @package Platforms\Console |
20
|
|
|
* @author Eric Lamb <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class Console |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* The arguments object |
26
|
|
|
* |
27
|
|
|
* @var \cli\Arguments |
28
|
|
|
*/ |
29
|
|
|
protected $args = null; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The mithra62 Language object |
33
|
|
|
* |
34
|
|
|
* @param |
35
|
|
|
* Language |
36
|
|
|
*/ |
37
|
|
|
protected $lang = null; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* The cli input string |
41
|
|
|
* |
42
|
|
|
* @param string $tokens |
|
|
|
|
43
|
|
|
*/ |
44
|
|
|
public function __construct() |
45
|
|
|
{} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Outputs an error to the console |
49
|
|
|
* |
50
|
|
|
* @param string $error |
51
|
|
|
* The language key for the message to display |
52
|
|
|
*/ |
53
|
|
|
public function outputError($error) |
54
|
|
|
{ |
55
|
|
|
\cli\err($this->getLang()->__($error)); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Outputs a new line |
60
|
|
|
* |
61
|
|
|
* @param string $string The output we want to display to the console out |
62
|
|
|
* @param bool $translate Whether the string should be sent through the mithra62\Language object |
63
|
|
|
* @return void |
64
|
|
|
*/ |
65
|
|
|
public function outputLine($string = '', $translate = true) |
66
|
|
|
{ |
67
|
|
|
if ($translate) { |
68
|
|
|
\cli\line($this->getLang()->__($string)); |
69
|
|
|
} else { |
70
|
|
|
\cli\line($string); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Adds a new line with page break |
76
|
|
|
*/ |
77
|
|
|
public function outputPageBreak() |
78
|
|
|
{ |
79
|
|
|
\cli\line(''); |
80
|
|
|
\cli\line('========================================================'); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* An instance of the language object |
85
|
|
|
* |
86
|
|
|
* @return \JaegerApp\Language |
87
|
|
|
*/ |
88
|
|
|
public function getLang() |
89
|
|
|
{ |
90
|
|
|
return $this->lang; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Sets the language object |
95
|
|
|
* |
96
|
|
|
* @param Language $lang |
97
|
|
|
* @return \JaegerApp\Console |
98
|
|
|
*/ |
99
|
|
|
public function setLang(Language $lang) |
100
|
|
|
{ |
101
|
|
|
$this->lang = $lang; |
102
|
|
|
return $this; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Returns the available commands the Console provides |
107
|
|
|
* @see \cli\Arguments |
108
|
|
|
* @param string $strict |
109
|
|
|
* @param string $force |
110
|
|
|
* @return \cli\Arguments |
111
|
|
|
*/ |
112
|
|
|
public function getArgs($strict = false, $force = false) |
113
|
|
|
{ |
114
|
|
|
if (is_null($this->args) || $force) { |
|
|
|
|
115
|
|
|
$this->args = new \cli\Arguments($strict); |
|
|
|
|
116
|
|
|
$this->args->addFlag(array( |
117
|
|
|
'verbose', |
118
|
|
|
'v' |
119
|
|
|
), 'Turn on verbose output'); |
|
|
|
|
120
|
|
|
$this->args->addFlag('version', 'Display the version'); |
|
|
|
|
121
|
|
|
$this->args->addFlag(array( |
122
|
|
|
'help', |
123
|
|
|
'h' |
124
|
|
|
), 'Show this help screen'); |
|
|
|
|
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
return $this->args; |
128
|
|
|
} |
129
|
|
|
} |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.