|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class Nip_Tool |
|
|
|
|
|
|
4
|
|
|
{ |
|
5
|
|
|
|
|
6
|
|
|
protected $_console; |
|
7
|
|
|
protected $_generator; |
|
8
|
|
|
protected $_menus = []; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @return Nip_Tool_Generator |
|
12
|
|
|
*/ |
|
13
|
|
|
public function getGenerator() |
|
14
|
|
|
{ |
|
15
|
|
|
if (!$this->_generator) { |
|
16
|
|
|
$this->_generator = new Nip_Tool_Generator(); |
|
17
|
|
|
$this->_generator->setTool($this); |
|
18
|
|
|
} |
|
19
|
|
|
return $this->_generator; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function bootstrap() |
|
23
|
|
|
{ |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function run() |
|
27
|
|
|
{ |
|
28
|
|
|
$this->intro(); |
|
29
|
|
|
return $this->mainMenu(); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function intro() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->getConsole()->output("*************************** |
|
35
|
|
|
*** Nip Tool *** |
|
36
|
|
|
*************************** |
|
37
|
|
|
"); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @return Nip_Tool_Console |
|
42
|
|
|
*/ |
|
43
|
|
|
public function getConsole() |
|
44
|
|
|
{ |
|
45
|
|
|
if (!$this->_console) { |
|
46
|
|
|
$this->_console = new Nip_Tool_Console(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
return $this->_console; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function mainMenu() |
|
53
|
|
|
{ |
|
54
|
|
|
$response = $this->getConsole()->askVariant('How can i serve you today master ?', array( |
|
55
|
|
|
'model' => 'Models', |
|
56
|
|
|
'module' => 'Module', |
|
57
|
|
|
'controller' => 'Controller', |
|
58
|
|
|
'exit' => 'Exit', |
|
59
|
|
|
)); |
|
60
|
|
|
return $this->runMenu($response); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @return Nip_Tool_Menu_Abstract |
|
65
|
|
|
*/ |
|
66
|
|
|
public function runMenu($name) |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->getMenu($name)->main(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @return Nip_Tool_Menu_Abstract |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getMenu($name) |
|
75
|
|
|
{ |
|
76
|
|
|
if (!$this->_menus[$name]) { |
|
77
|
|
|
$class = 'Nip_Tool_Menu_'.ucfirst($name); |
|
78
|
|
|
$this->_menus[$name] = new $class(); |
|
79
|
|
|
$this->_menus[$name]->setTool($this); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return $this->_menus[$name]; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.