protected function execute(InputInterface $input, OutputInterface $output) { if (!file_exists($this->path . '/magium.json')) { throw new NotFoundException('Configuration file not found. Please execute magium:init.'); } $reader = new \Zend\Config\Reader\Json(); $config = new Config($reader->fromFile($this->path . '/magium.json'), true); $class = $input->getArgument('class'); $property = $input->getArgument('property'); $value = $input->getArgument('value'); if ($input->getOption('json')) { $value = json_decode($value); } if (!$config->magium) { $config->magium = []; } if (!class_exists($class)) { throw new NotFoundException('Could not find class: ' . $class . '. You might need to escape blackslashes (\\\\)'); } $class = strtolower($class); $s = $config->magium; if (!isset($s[$class])) { $s[$class] = []; } $s[$class]->{$property} = $value; $writer = new Json(); $writer->toFile($this->path . '/magium.json', $config); $output->writeln(sprintf('Wrote value %s for "%s:%s" to %s/magium.json', $value, $class, $property, $this->path)); }
protected function execute(InputInterface $input, OutputInterface $output) { if (!file_exists($this->path . '/magium.json')) { throw new NotFoundException('Configuration file not found. Please execute magium:init.'); } $reader = new \Zend\Config\Reader\Json(); $config = new Config($reader->fromFile($this->path . '/magium.json'), true); $name = strtolower($input->getArgument('class')); if (isset($config->magium->{$name})) { $property = $input->getArgument('property'); if ($property && isset($config->magium->{$name}->{$property})) { unset($config->magium->{$name}->{$property}); $output->writeln(sprintf('Removed the property %s in %s in %s/magium.json', $property, $input->getArgument('class'), $this->path)); if (count($config->magium->{$name}) == 0) { unset($config->magium->{$name}); $output->writeln(sprintf('Removed empty settings for %s in %s/magium.json', $input->getArgument('class'), $this->path)); } } elseif ($property === null) { unset($config->magium->{$name}); $output->writeln(sprintf('Removed all %s settings in %s/magium.json', $input->getArgument('class'), $this->path)); } else { $output->writeln(sprintf('Property %s in %s not found in %s/magium.json', $property, $input->getArgument('class'), $this->path)); } } else { $output->writeln(sprintf('%s was not found in %s/magium.json', $input->getArgument('class'), $this->path)); } $writer = new Json(); $writer->toFile($this->path . '/magium.json', $config); }
protected function execute(InputInterface $input, OutputInterface $output) { if (!file_exists($this->path . '/magium.json')) { throw new NotFoundException('Configuration file not found. Please execute magium:init.'); } $reader = new \Zend\Config\Reader\Json(); $config = new Config($reader->fromFile($this->path . '/magium.json'), true); $name = $input->getArgument('name'); if (isset($config->config->{$name})) { unset($config->config->{$name}); } $writer = new Json(); $writer->toFile($this->path . '/magium.json', $config); $output->writeln(sprintf('Removed value for "%s" in %s/magium.json', $name, $this->path)); }
protected function execute(InputInterface $input, OutputInterface $output) { if (!file_exists($this->path . '/magium.json')) { throw new NotFoundException('Configuration file not found. Please execute magium:init.'); } $reader = new \Zend\Config\Reader\Json(); $config = new Config($reader->fromFile($this->path . '/magium.json'), true); $name = $input->getArgument('name'); $value = $input->getArgument('value'); $output->writeln($value); if ($input->getOption('json')) { $value = json_decode($value); } if (!$config->config) { $config->config = []; } $config->config->{$name} = $value; $writer = new Json(); $writer->toFile($this->path . '/magium.json', $config); $output->writeln(sprintf('Wrote value for "%s" to %s/magium.json', $name, $this->path)); }
public function testCanWritePrettyPrintedVersion() { $config = new JsonConfig(__DIR__ . '/files/allsections-pretty.json'); $writer = new JsonWriter(array('config' => $config, 'filename' => $this->_tempName)); $writer->setPrettyPrint(true); $writer->write(); $testOutput = file_get_contents($this->_tempName); $this->assertRegExp('/^\s+/m', $testOutput); }