Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function parse($file)
 {
     $content = file_get_contents($file);
     if (false === $content) {
         throw new ResourceException(sprintf('File "%s" is not exists or is not readable', $file));
     }
     $content = json_decode(file_get_contents($file), true);
     if (null === $content) {
         throw new ResourceException(sprintf('File "%s" is not at JSON format', $file));
     }
     $backend = isset($content['backend']) ? $content['backend'] : 'basic';
     $backend = Factory::create($backend);
     $backend->buildMetadatas($file, $content);
     return $backend;
 }
Beispiel #2
0
 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $directory = getcwd();
     $config = $input->getOption('configuration-file') ?: $directory . DIRECTORY_SEPARATOR . '.vaultage.json';
     if (file_exists($config)) {
         throw new \InvalidArgumentException(sprintf('Configuration file "%s" is already exists.', $config));
     }
     $io = $this->getIO();
     $backends = Factory::getAvailableBackends();
     $validation = function ($v) use($backends) {
         if (!in_array($v, array_values($backends))) {
             throw new \InvalidArgumentException(sprintf('Backend "%s" is invalid.', $v));
         }
         return $v;
     };
     $default = 'basic';
     $backend = $io->askAndValidate(sprintf('Choose a backend from <comment>%s</comment> (default is %s): ', implode(', ', $backends), $default), $validation, false, $default, $backends);
     Factory::create($backend)->setIO($io)->initialize($config);
 }