-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathCommand.php
More file actions
50 lines (44 loc) · 1.62 KB
/
Command.php
File metadata and controls
50 lines (44 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace Webman\Console;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command as Commands;
class Command extends Application
{
public function installInternalCommands()
{
$this->installCommands(__DIR__ . '/Commands', 'Webman\Console\Commands');
}
public function installCommands($path, $namspace = 'app\command')
{
$dir_iterator = new \RecursiveDirectoryIterator($path);
$iterator = new \RecursiveIteratorIterator($dir_iterator);
foreach ($iterator as $file) {
/** @var \SplFileInfo $file */
if (strpos($file->getFilename(), '.') === 0) {
continue;
}
if ($file->getExtension() !== 'php') {
continue;
}
$relativePath = str_replace(str_replace('/', '\\', $path . '\\'), '', str_replace('/', '\\', $file->getRealPath()));
$realNamespace = trim($namspace . trim(dirname($relativePath), '.'), '\\');
$class_name = trim($realNamespace . '\\' . $file->getBasename('.php'), '\\');
if (!is_a($class_name, Commands::class, true)) {
continue;
}
$this->add(new $class_name);
}
}
public function installUserCommands()
{
//get command from config
$commands = config('command', []);
foreach ($commands as $command) {
// check command class whether instanceof SymfonyCommand
if (!is_a($command, Commands::class, true)) {
continue;
}
$this->add(new $command);
}
}
}