1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Leonidas\Console\Command; |
4
|
|
|
|
5
|
|
|
use Jawira\CaseConverter\CaseConverter; |
6
|
|
|
use Leonidas\Library\Core\Abstracts\ConvertsCaseTrait; |
7
|
|
|
use Noodlehaus\Config; |
8
|
|
|
use PHP_Parallel_Lint\PhpConsoleColor\ConsoleColor; |
9
|
|
|
use PHP_Parallel_Lint\PhpConsoleHighlighter\Highlighter; |
10
|
|
|
use Symfony\Component\Console\Command\Command; |
11
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
12
|
|
|
|
13
|
|
|
abstract class HopliteCommand extends Command |
14
|
|
|
{ |
15
|
|
|
use ConvertsCaseTrait; |
16
|
|
|
|
17
|
|
|
protected Config $config; |
18
|
|
|
|
19
|
|
|
protected Filesystem $filesystem; |
20
|
|
|
|
21
|
|
|
protected Highlighter $highlighter; |
22
|
|
|
|
23
|
|
|
public function __construct(string $name = null) |
24
|
|
|
{ |
25
|
|
|
$this->config = new Config($this->external('/hoplite.yml')); |
26
|
|
|
$this->filesystem = new Filesystem(); |
27
|
|
|
$this->highlighter = new Highlighter(new ConsoleColor()); |
28
|
|
|
$this->caseConverter = new CaseConverter(); |
29
|
|
|
|
30
|
|
|
parent::__construct($name); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
protected function config(string $key, $default = null) |
34
|
|
|
{ |
35
|
|
|
return $this->config->get($key, $default); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
protected function internal(string $path = ''): string |
39
|
|
|
{ |
40
|
|
|
return dirname(__DIR__, 1) . $path; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
protected function external(string $path = ''): string |
44
|
|
|
{ |
45
|
|
|
return getcwd() . $path; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
protected function printPhp(string $code): void |
49
|
|
|
{ |
50
|
|
|
echo $this->highlighter->getWholeFile($code); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
protected function writeFile(string $path, string $content): void |
54
|
|
|
{ |
55
|
|
|
$this->filesystem->dumpFile($path, $content); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|