1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Console; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Application; |
6
|
|
|
use Symfony\Component\Finder\Finder; |
7
|
|
|
use Slim\Container; |
8
|
|
|
|
9
|
|
|
class Partisan extends Application |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Namespace for commands |
13
|
|
|
*/ |
14
|
|
|
const COMMANDS_NAMESPACE = '\App\Console\Commands'; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var Container |
18
|
|
|
*/ |
19
|
|
|
public $container; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
private $logo = ' |
25
|
|
|
____ __ _ |
26
|
|
|
/ __ \____ ______/ /_(_)________ _____ |
27
|
|
|
/ /_/ / __ `/ ___/ __/ / ___/ __ `/ __ \ |
28
|
|
|
/ ____/ /_/ / / / /_/ (__ ) /_/ / / / / |
29
|
|
|
/_/ \__,_/_/ \__/_/____/\__,_/_/ /_/ |
30
|
|
|
'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Partisan constructor. |
34
|
|
|
* |
35
|
|
|
* @param Container $container |
36
|
|
|
* @param string $name The name of the application |
37
|
|
|
* @param string $version The version of the application |
38
|
|
|
* @throws \Exception |
39
|
|
|
*/ |
40
|
|
|
public function __construct(Container $container, $name = 'UNKNOWN', $version = 'UNKNOWN') |
41
|
|
|
{ |
42
|
|
|
parent::__construct($name, $version); |
43
|
|
|
$this->container = $container; |
44
|
|
|
$this->registerCommands(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Register commands |
49
|
|
|
*/ |
50
|
|
|
public function registerCommands() |
51
|
|
|
{ |
52
|
|
|
$finder = new Finder(); |
53
|
|
|
$finder->files()->name('*Command.php')->in(COMMANDS_PATH); |
54
|
|
|
|
55
|
|
|
foreach ($finder as $file) { |
56
|
|
|
$ns = self::COMMANDS_NAMESPACE; |
57
|
|
|
/* @var \Symfony\Component\Finder\SplFileInfo $file*/ |
58
|
|
|
$relativePath = $file->getRelativePath(); |
59
|
|
|
if ($relativePath) { |
60
|
|
|
$ns .= '\\'.strtr($relativePath, '/', '\\'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$r = new \ReflectionClass($ns.'\\'.$file->getBasename('.php')); |
64
|
|
|
if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract()) { |
65
|
|
|
$this->add($r->newInstance()); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Returns the long version of the application. |
72
|
|
|
* |
73
|
|
|
* @return string The long application version |
74
|
|
|
* |
75
|
|
|
* @api |
76
|
|
|
*/ |
77
|
|
|
public function getLongVersion() |
78
|
|
|
{ |
79
|
|
|
if ('UNKNOWN' !== $this->getName() && 'UNKNOWN' !== $this->getVersion()) { |
80
|
|
|
return sprintf('<info>%s</info> version <comment>%s</comment>', $this->getName(), $this->getVersion()); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return '<info>' . $this->logo . '</info>'; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|