1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* neuralyzer : Data Anonymization Library and CLI Tool |
4
|
|
|
* |
5
|
|
|
* PHP Version 7.1 |
6
|
|
|
* |
7
|
|
|
* @author Emmanuel Dyan |
8
|
|
|
* @author Rémi Sauvat |
9
|
|
|
* @copyright 2018 Emmanuel Dyan |
10
|
|
|
* |
11
|
|
|
* @package edyan/neuralyzer |
12
|
|
|
* |
13
|
|
|
* @license GNU General Public License v2.0 |
14
|
|
|
* |
15
|
|
|
* @link https://github.com/edyan/neuralyzer |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
namespace Edyan\Neuralyzer\Console\Commands; |
19
|
|
|
|
20
|
|
|
use Symfony\Component\Console\Command\Command; |
21
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
22
|
|
|
use Symfony\Component\Console\Input\InputOption; |
23
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Command to validate a config file |
27
|
|
|
*/ |
28
|
|
|
class ConfigValidateCommand extends Command |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* Set the command shortcut to be used in configuration |
32
|
|
|
* |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $command = 'config:validate'; |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Configure the command |
40
|
|
|
* |
41
|
|
|
* @return void |
42
|
|
|
*/ |
43
|
28 |
|
protected function configure(): void |
44
|
|
|
{ |
45
|
|
|
// First command : Test the DB Connexion |
46
|
28 |
|
$this->setName($this->command) |
47
|
28 |
|
->setDescription( |
48
|
28 |
|
'Validate a configuration for the Anonymizer' |
49
|
28 |
|
)->setHelp( |
50
|
28 |
|
'This command will validate that the configuration provided is valid' . PHP_EOL . |
51
|
28 |
|
"Usage: neuralyzer <info>{$this->command}</info> -f neuralyzer.yml" |
52
|
28 |
|
)->addOption( |
53
|
28 |
|
'file', |
54
|
28 |
|
'f', |
55
|
28 |
|
InputOption::VALUE_REQUIRED, |
56
|
28 |
|
'File', |
57
|
28 |
|
'neuralyzer.yml' |
58
|
|
|
); |
59
|
28 |
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Execute the command |
63
|
|
|
* |
64
|
|
|
* @param InputInterface $input |
65
|
|
|
* @param OutputInterface $output |
66
|
|
|
* |
67
|
|
|
* @throws \Edyan\Neuralyzer\Exception\NeuralyzerConfigurationException |
68
|
|
|
* @throws \Edyan\Neuralyzer\Exception\NeuralyzerException |
69
|
|
|
* |
70
|
|
|
* @return void |
71
|
|
|
*/ |
72
|
3 |
|
protected function execute(InputInterface $input, OutputInterface $output): void |
73
|
|
|
{ |
74
|
|
|
try { |
75
|
3 |
|
$reader = new \Edyan\Neuralyzer\Configuration\Reader($input->getOption('file')); |
76
|
2 |
|
} catch (\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException $e) { |
77
|
1 |
|
throw new \Edyan\Neuralyzer\Exception\NeuralyzerConfigurationException($e->getMessage()); |
78
|
1 |
|
} catch (\Symfony\Component\Config\Exception\FileLocatorFileNotFoundException $e) { |
79
|
1 |
|
throw new \Edyan\Neuralyzer\Exception\NeuralyzerException($e->getMessage()); |
80
|
|
|
} |
81
|
|
|
|
82
|
1 |
|
if (!empty($reader->getDepreciationMessages())) { |
83
|
|
|
foreach ($reader->getDepreciationMessages() as $message) { |
84
|
|
|
$output->writeln("<comment>WARNING : $message</comment>"); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
1 |
|
$output->writeln("<info>Your config is valid !</info>"); |
89
|
1 |
|
} |
90
|
|
|
} |
91
|
|
|
|