예제 #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $rc = 0;
     $default_environment = \Config::getEnvironment();
     $environment = $input->getOption('environment') ?: $default_environment;
     $file_system = new Filesystem();
     $file_loader = new FileLoader($file_system);
     if ($input->getOption('generated-overrides')) {
         $file_saver = new FileSaver($file_system, $environment == $default_environment ? null : $environment);
     } else {
         $file_saver = new DirectFileSaver($file_system, $environment == $default_environment ? null : $environment);
     }
     $this->repository = new Repository($file_loader, $file_saver, $environment);
     try {
         $item = $input->getArgument('item');
         switch ($input->getArgument('operation')) {
             case self::OPERATION_GET:
                 $output->writeln($this->serialize($this->repository->get($item)));
                 break;
             case self::OPERATION_SET:
                 $value = $input->getArgument('value');
                 if (!isset($value)) {
                     throw new Exception('Missing new configuration value');
                 }
                 $this->repository->save($item, $this->unserialize($value));
                 break;
             default:
                 throw new Exception('Invalid operation specified. Allowed operations: ' . implode(', ', $this->getAllowedOperations()));
         }
     } catch (Exception $x) {
         $output->writeln('<error>' . $x->getMessage() . '</error>');
         $rc = 1;
     }
     return $rc;
 }
예제 #2
0
 public function testSaveNamespace()
 {
     $namespace = md5(uniqid());
     $group = md5(uniqid());
     $item = 'test.item';
     $key = "{$namespace}::{$group}.{$item}";
     $this->repository->save($key, $namespace);
     $this->assertEquals($namespace, $this->repository->get($key, false));
     $this->files->deleteDirectory(DIR_APPLICATION . "/config/generated_overrides/{$namespace}/");
 }
예제 #3
0
 public function testSaveMultiple()
 {
     $tests = array('namespace::group.test.key', 'namespace::group2.test.key', 'namespace2::group.test.key', 'namespace2::group2.test.key', 'group.test.key', 'group2.test.key', 'group.new.key', 'group2.new.key');
     $values = array();
     foreach ($tests as $test) {
         $this->repository->save($test, $values[] = uniqid($test));
     }
     $this->repository->clearCache();
     foreach ($tests as $test) {
         $this->assertEquals(array_shift($values), $this->repository->get($test), "Failed test verification for key '{$test}'.");
     }
 }
예제 #4
0
 /**
  * @param $key
  * @param $value
  *
  * @return bool
  */
 public function save($key, $value)
 {
     return $this->repository->save($this->transformKey($key), $value);
 }