1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by Adam Jakab. |
4
|
|
|
* Date: 07/10/15 |
5
|
|
|
* Time: 14.21 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace SuiteCrm\Console; |
9
|
|
|
|
10
|
|
|
use Symfony\Component\Console\Application as BaseApplication; |
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
class Application extends BaseApplication { |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @param string $name |
19
|
|
|
* @param string $version |
20
|
|
|
*/ |
21
|
|
|
public function __construct($name, $version) { |
22
|
|
|
parent::__construct($name, $version); |
23
|
|
|
$commands = $this->enumerateCommands(); |
24
|
|
|
foreach ($commands as $command) { |
25
|
|
|
$this->add(new $command); |
26
|
|
|
} |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Runs the current application. |
31
|
|
|
* |
32
|
|
|
* @param InputInterface $input An Input instance |
33
|
|
|
* @param OutputInterface $output An Output instance |
34
|
|
|
* |
35
|
|
|
* @return int 0 if everything went fine, or an error code |
36
|
|
|
* |
37
|
|
|
* @throws \Exception When doRun returns Exception |
38
|
|
|
*/ |
39
|
|
|
public function run(InputInterface $input = NULL, OutputInterface $output = NULL) { |
40
|
|
|
$res = parent::run($input, $output); |
41
|
|
|
return $res; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Returns array of FQCN of classes found under src directory |
46
|
|
|
* 1) named: *Command.php |
47
|
|
|
* 2) implementing the CommandInterface |
48
|
|
|
* @return array |
49
|
|
|
*/ |
50
|
|
|
protected function enumerateCommands() { |
51
|
|
|
$answer = []; |
52
|
|
|
$searchPath = realpath(PROJECT_ROOT . '/src'); |
53
|
|
|
$iterator = new \RecursiveDirectoryIterator($searchPath); |
54
|
|
|
foreach (new \RecursiveIteratorIterator($iterator) as $file) { |
55
|
|
|
if (strpos($file, 'Command.php') !== FALSE) { |
56
|
|
|
if (is_file($file)) { |
57
|
|
|
$cmdClassPath = str_replace($searchPath . '/', '', $file); |
58
|
|
|
$cmdClassPath = str_replace('.php', '', $cmdClassPath); |
59
|
|
|
$cmdClassPath = str_replace('/', '\\', $cmdClassPath); |
60
|
|
|
if (in_array('SuiteCrm\Command\CommandInterface', class_implements($cmdClassPath))) { |
61
|
|
|
$answer[] = $cmdClassPath; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
return $answer; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|