1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command; |
4
|
|
|
|
5
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\PostProcessor\FileOverrider; |
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException; |
7
|
|
|
use Exception; |
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
11
|
|
|
|
12
|
|
|
class OverrideCreateCommand extends AbstractCommand |
13
|
|
|
{ |
14
|
|
|
public const OPT_OVERRIDE_FILE = 'file'; |
15
|
|
|
public const OPT_OVERRIDE_FILE_SHORT = 'f'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var FileOverrider |
19
|
|
|
*/ |
20
|
|
|
protected $fileOverrider; |
21
|
|
|
|
22
|
1 |
|
public function __construct(FileOverrider $fileOverrider, ?string $name = null) |
23
|
|
|
{ |
24
|
1 |
|
parent::__construct($name); |
25
|
1 |
|
$this->fileOverrider = $fileOverrider; |
26
|
1 |
|
} |
27
|
|
|
|
28
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
29
|
|
|
{ |
30
|
1 |
|
$this->checkOptions($input); |
31
|
1 |
|
$output->writeln('<comment>Creating override for ' . |
32
|
1 |
|
basename($input->getOption(self::OPT_OVERRIDE_FILE)) . |
|
|
|
|
33
|
1 |
|
'</comment>'); |
34
|
1 |
|
$this->checkOptions($input); |
35
|
1 |
|
$this->fileOverrider->setPathToProjectRoot($input->getOption(self::OPT_PROJECT_ROOT_PATH)); |
36
|
1 |
|
$pathCreated = $this->fileOverrider->createNewOverride($input->getOption(self::OPT_OVERRIDE_FILE)); |
37
|
1 |
|
$output->writeln('<info>Override created at: ' . $pathCreated . '</info>'); |
38
|
1 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @throws DoctrineStaticMetaException |
42
|
|
|
*/ |
43
|
1 |
|
protected function configure(): void |
44
|
|
|
{ |
45
|
|
|
try { |
46
|
|
|
$this |
47
|
1 |
|
->setName(AbstractCommand::COMMAND_PREFIX . 'overrides:create') |
48
|
1 |
|
->setDefinition( |
49
|
|
|
[ |
50
|
1 |
|
new InputOption( |
51
|
1 |
|
self::OPT_OVERRIDE_FILE, |
52
|
1 |
|
self::OPT_OVERRIDE_FILE_SHORT, |
53
|
1 |
|
InputOption::VALUE_REQUIRED, |
54
|
1 |
|
'the absolute path of the project file you want to override' |
55
|
|
|
), |
56
|
1 |
|
$this->getProjectRootPathOption(), |
57
|
|
|
] |
58
|
1 |
|
)->setDescription( |
59
|
1 |
|
'Create new overrides for project files' |
60
|
|
|
); |
61
|
|
|
} catch (Exception $e) { |
62
|
|
|
throw new DoctrineStaticMetaException( |
63
|
|
|
'Exception in ' . __METHOD__ . ': ' . $e->getMessage(), |
64
|
|
|
$e->getCode(), |
65
|
|
|
$e |
66
|
|
|
); |
67
|
|
|
} |
68
|
1 |
|
} |
69
|
|
|
} |
70
|
|
|
|