|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Magium\Cli\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Magium\Cli\ConfigurationPathInterface; |
|
6
|
|
|
use Magium\NotFoundException; |
|
7
|
|
|
use Symfony\Component\Console\Command\Command; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
10
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
12
|
|
|
use Zend\Config\Config; |
|
13
|
|
|
use Zend\Config\Writer\Json; |
|
14
|
|
|
|
|
15
|
|
|
class UnsetSetting extends Command implements ConfigurationPathInterface |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
protected $path; |
|
19
|
|
|
|
|
20
|
|
|
public function setPath($path) |
|
21
|
|
|
{ |
|
22
|
|
|
$this->path = $path; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
protected function configure() |
|
26
|
|
|
{ |
|
27
|
|
|
$this->setName('config:unset'); |
|
28
|
|
|
$this->setDescription('Removes a setting'); |
|
29
|
|
|
$this->addArgument('name', InputArgument::REQUIRED, 'Need the name of the setting'); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
33
|
|
|
{ |
|
34
|
|
|
if (!file_exists($this->path . '/magium.json')) { |
|
35
|
|
|
throw new NotFoundException('Configuration file not found. Please execute magium:init.'); |
|
36
|
|
|
} |
|
37
|
|
|
$reader = new \Zend\Config\Reader\Json(); |
|
38
|
|
|
$config = new Config($reader->fromFile($this->path . '/magium.json'), true); |
|
39
|
|
|
|
|
40
|
|
|
$name = $input->getArgument('name'); |
|
41
|
|
|
|
|
42
|
|
|
if (isset($config->config->$name)) { |
|
43
|
|
|
unset($config->config->$name); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$writer = new Json(); |
|
47
|
|
|
$writer->toFile($this->path . '/magium.json', $config); |
|
48
|
|
|
$output->writeln(sprintf('Removed value for "%s" in %s/magium.json', $name, $this->path)); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
|