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); }
/** * */ public function testAclRoleJsonReader() { echo PHP_EOL . 'Acl Role Json Reader' . PHP_EOL; $oReader = new \Application\Model\AclRoleJsonReader($this->sFilepath, 'user'); $oReader->updateAccount('watsonp', 'admin'); $oReader->addAccount('prewettc', 'user'); $oReader->deleteAccount('silverb'); $reader = new \Zend\Config\Reader\Json(); $data = $reader->fromFile($this->sFilepath); print_r(\Zend\Json\Json::encode($data)); $this->assertNotContains('silverb', \Zend\Json\Json::encode($data)); }
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)); }
/** * Returns an array of all users and roles. * * @return array * @throws ACLRolesException */ public function getAllAccounts() { try { $reader = new \Zend\Config\Reader\Json(); return $reader->fromFile($this->sFilepath); } catch (\Zend\Config\Exception\RuntimeException $oExp) { throw ACLRolesException::invalidSetup($oExp); } }