1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command; |
4
|
|
|
|
5
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\NamespaceHelper; |
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\PostProcessor\FileOverrider; |
7
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException; |
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, NamespaceHelper $namespaceHelper, ?string $name = null) |
23
|
|
|
{ |
24
|
1 |
|
parent::__construct($namespaceHelper, $name); |
25
|
1 |
|
$this->fileOverrider = $fileOverrider; |
26
|
1 |
|
} |
27
|
|
|
|
28
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
29
|
|
|
{ |
30
|
1 |
|
$this->fileOverrider->setPathToProjectRoot($input->getOption(self::OPT_PROJECT_ROOT_PATH)); |
31
|
1 |
|
$pathCreated = $this->fileOverrider->createNewOverride($input->getOption(self::OPT_OVERRIDE_FILE)); |
32
|
1 |
|
$output->writeln('<info>Override created at: ' . $pathCreated . '</info>'); |
33
|
1 |
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @throws DoctrineStaticMetaException |
37
|
|
|
*/ |
38
|
1 |
|
protected function configure(): void |
39
|
|
|
{ |
40
|
|
|
try { |
41
|
|
|
$this |
42
|
1 |
|
->setName(AbstractCommand::COMMAND_PREFIX . 'overrides:create') |
43
|
1 |
|
->setDefinition( |
44
|
|
|
[ |
45
|
1 |
|
new InputOption( |
46
|
1 |
|
self::OPT_OVERRIDE_FILE, |
47
|
1 |
|
self::OPT_OVERRIDE_FILE_SHORT, |
48
|
1 |
|
InputOption::VALUE_REQUIRED, |
49
|
1 |
|
'the absolute path of the project file you want to override' |
50
|
|
|
), |
51
|
1 |
|
$this->getProjectRootPathOption(), |
52
|
|
|
] |
53
|
1 |
|
)->setDescription( |
54
|
1 |
|
'Create new overrides for project files' |
55
|
|
|
); |
56
|
|
|
} catch (\Exception $e) { |
57
|
|
|
throw new DoctrineStaticMetaException( |
58
|
|
|
'Exception in ' . __METHOD__ . ': ' . $e->getMessage(), |
59
|
|
|
$e->getCode(), |
60
|
|
|
$e |
61
|
|
|
); |
62
|
|
|
} |
63
|
1 |
|
} |
64
|
|
|
} |
65
|
|
|
|