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