1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Quantum PHP Framework |
5
|
|
|
* |
6
|
|
|
* An open source software development framework for PHP |
7
|
|
|
* |
8
|
|
|
* @package Quantum |
9
|
|
|
* @author Arman Ag. <[email protected]> |
10
|
|
|
* @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) |
11
|
|
|
* @link http://quantum.softberg.org/ |
12
|
|
|
* @since 2.0.0 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Quantum\Console; |
16
|
|
|
|
17
|
|
|
use Symfony\Component\Console\Application; |
18
|
|
|
use Quantum\Bootstrap; |
19
|
|
|
use Quantum\Di\Di; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class QtConsole |
23
|
|
|
* @package Quantum\Console |
24
|
|
|
*/ |
25
|
|
|
class QtConsole |
26
|
|
|
{ |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Console application name |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
private $name = 'Qt Console Application'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Console application version |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
private $version = '2.0.0'; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Console application instance |
42
|
|
|
* @var Application |
43
|
|
|
*/ |
44
|
|
|
private $application; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Initialize the console application |
48
|
|
|
* @return mixed |
49
|
|
|
*/ |
50
|
|
|
public function init() |
51
|
|
|
{ |
52
|
|
|
|
53
|
|
|
Bootstrap::loadCoreFuncations(); |
54
|
|
|
|
55
|
|
|
Di::loadDefinitions(); |
56
|
|
|
|
57
|
|
|
$this->application = new Application($this->name, $this->version); |
58
|
|
|
|
59
|
|
|
$this->register(); |
60
|
|
|
|
61
|
|
|
return $this->application->run(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Registers commands |
66
|
|
|
* @return void |
67
|
|
|
*/ |
68
|
|
|
private function register() |
69
|
|
|
{ |
70
|
|
|
$coreClassNames = get_directory_classes(CORE_DIR . DS . 'Console' . DS . 'Commands'); |
71
|
|
|
|
72
|
|
|
foreach ($coreClassNames as $coreClassName) { |
73
|
|
|
$coreCommandClass = '\\Quantum\\Console\\Commands\\' . $coreClassName; |
74
|
|
|
|
75
|
|
|
$coreCommand = new $coreCommandClass(); |
76
|
|
|
|
77
|
|
|
if ($coreCommand instanceof QtCommand) { |
78
|
|
|
$this->application->add($coreCommand); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$classNames = get_directory_classes(BASE_DIR . DS . 'base' . DS . 'commands'); |
83
|
|
|
foreach ($classNames as $className) { |
84
|
|
|
$commandClass = '\\Base\\Commands\\' . $className; |
85
|
|
|
|
86
|
|
|
$command = new $commandClass(); |
87
|
|
|
|
88
|
|
|
if ($command instanceof QtCommand) { |
89
|
|
|
$this->application->add($command); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
} |
95
|
|
|
|