1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace SlayerBirden\DFCodeGeneration\Command; |
5
|
|
|
|
6
|
|
|
use Doctrine\Common\Annotations\AnnotationRegistry; |
7
|
|
|
use SlayerBirden\DFCodeGeneration\Writer\OutputWriter; |
8
|
|
|
use SlayerBirden\DFCodeGeneration\Writer\WriteInterface; |
9
|
|
|
use Symfony\Component\Console\Command\Command; |
10
|
|
|
use Symfony\Component\Console\Exception\InvalidArgumentException; |
11
|
|
|
use Symfony\Component\Console\Exception\LogicException; |
12
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
13
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
14
|
|
|
use Symfony\Component\Console\Input\InputOption; |
15
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
16
|
|
|
|
17
|
|
|
abstract class AbstractApiCommand extends Command |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var OutputInterface |
21
|
|
|
*/ |
22
|
|
|
protected $output; |
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $entityClassName; |
27
|
|
|
/** |
28
|
|
|
* @var bool |
29
|
|
|
*/ |
30
|
|
|
protected $force; |
31
|
|
|
/** |
32
|
|
|
* @var null|WriteInterface |
33
|
|
|
*/ |
34
|
|
|
protected $writer; |
35
|
|
|
|
36
|
2 |
|
public function __construct(?string $name = null, ?WriteInterface $writer = null) |
37
|
|
|
{ |
38
|
2 |
|
parent::__construct($name); |
39
|
2 |
|
$this->writer = $writer; |
40
|
2 |
|
} |
41
|
|
|
|
42
|
2 |
|
protected function configure() |
43
|
|
|
{ |
44
|
2 |
|
$this->addArgument('entity', InputArgument::REQUIRED, 'Entity class') |
45
|
2 |
|
->addOption('force', 'f', InputOption::VALUE_NONE, 'Without force flag no writes happen (only output).'); |
46
|
2 |
|
} |
47
|
|
|
|
48
|
2 |
|
protected function initialize(InputInterface $input, OutputInterface $output) |
49
|
|
|
{ |
50
|
2 |
|
$this->output = $output; |
51
|
2 |
|
$this->entityClassName = $input->getArgument('entity'); |
52
|
2 |
|
if (!class_exists($this->entityClassName)) { |
53
|
|
|
throw new InvalidArgumentException('Entity Class does not exist.'); |
54
|
|
|
} |
55
|
2 |
|
$this->force = $input->getOption('force'); |
56
|
|
|
// If it's not force mode we're using output writer |
57
|
2 |
|
if (!$this->force) { |
58
|
1 |
|
$this->writer = new OutputWriter($this->output); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
// we need to register the default Annotation loader |
62
|
2 |
|
AnnotationRegistry::registerLoader('class_exists'); |
|
|
|
|
63
|
2 |
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* {@inheritdoc} |
67
|
|
|
*/ |
68
|
2 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
69
|
|
|
{ |
70
|
2 |
|
$output->writeln([ |
71
|
2 |
|
'<error>IMPORTANT: please check all generated files before committing.</error>', |
72
|
|
|
'<error># You might want to run something like "php-cs-fixer" to make sure formatting is correct.</error>', |
73
|
|
|
]); |
74
|
2 |
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return WriteInterface |
78
|
|
|
*/ |
79
|
|
|
protected function getWriter(): WriteInterface |
80
|
|
|
{ |
81
|
|
|
if ($this->writer === null) { |
82
|
|
|
throw new LogicException('Writer is not defined!'); |
83
|
|
|
} |
84
|
|
|
return $this->writer; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.