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