1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* TechDivision\Import\Cli\Command\ImportClearPidFileCommand |
4
|
|
|
* |
5
|
|
|
* PHP version 7 |
6
|
|
|
* |
7
|
|
|
* @author [email protected] |
8
|
|
|
* @copyright 2023 TechDivision GmbH <[email protected]> |
9
|
|
|
* @license https://opensource.org/licenses/MIT |
10
|
|
|
* @link https://github.com/techdivision/import-cli-simple |
11
|
|
|
* @link http://www.techdivision.com |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace TechDivision\Import\Cli\Command; |
15
|
|
|
|
16
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
18
|
|
|
use TechDivision\Import\Configuration\ConfigurationInterface; |
19
|
|
|
use TechDivision\Import\Utils\CommandNames; |
20
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The import command implementation. |
24
|
|
|
* |
25
|
|
|
* @author [email protected] |
26
|
|
|
* @copyright 2023 TechDivision GmbH <[email protected]> |
27
|
|
|
* @license https://opensource.org/licenses/MIT |
28
|
|
|
* @link https://github.com/techdivision/import-cli-simple |
29
|
|
|
* @link http://www.techdivision.com |
30
|
|
|
*/ |
31
|
|
|
class ImportCreateDefaultConfigCommand extends AbstractSimpleImportCommand |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* Configures the current command. |
35
|
|
|
* |
36
|
|
|
* @return void |
37
|
|
|
* @see \Symfony\Component\Console\Command\Command::configure() |
38
|
|
|
*/ |
39
|
|
|
protected function configure(): void |
40
|
|
|
{ |
41
|
|
|
// initialize the command with the required/optional options |
42
|
|
|
$this->setName(CommandNames::IMPORT_CREATE_CONFIG) |
43
|
|
|
->setDescription('Create the default config file which is used by the diff command'); |
44
|
|
|
|
45
|
|
|
// invoke the parent method |
46
|
|
|
parent::configure(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Finally executes the simple command. |
51
|
|
|
* |
52
|
|
|
* @param ConfigurationInterface $configuration The configuration instance |
53
|
|
|
* @param InputInterface $input An InputInterface instance |
54
|
|
|
* @param OutputInterface $output An OutputInterface instance |
55
|
|
|
* |
56
|
|
|
* @return int |
57
|
|
|
*/ |
58
|
|
|
protected function executeSimpleCommand( |
59
|
|
|
ConfigurationInterface $configuration, |
60
|
|
|
InputInterface $input, |
61
|
|
|
OutputInterface $output |
62
|
|
|
): int { |
63
|
|
|
$serializer = $this->createSerializer(); |
64
|
|
|
$configValues = $serializer->serialize($configuration, 'json'); |
65
|
|
|
|
66
|
|
|
// create new default json file |
67
|
|
|
$fs = new Filesystem(); |
68
|
|
|
$fs->remove($this->getFilePathComplete()); |
69
|
|
|
$fs->appendToFile($this->getFilePathComplete(), $configValues); |
70
|
|
|
|
71
|
|
|
$output->writeln('[*] successfully created default file'); |
72
|
|
|
return 0; |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return string |
77
|
|
|
*/ |
78
|
|
|
public function getFileName(): string |
79
|
|
|
{ |
80
|
|
|
return ImportConfigDiffCommand::DEFAULT_FILE; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return string |
85
|
|
|
*/ |
86
|
|
|
public function getFilePathComplete(): string |
87
|
|
|
{ |
88
|
|
|
return __DIR__ . '/../../' . $this->getFileName() . '.simple'; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: