Exemplo n.º 1
0
 /**
  * Creates and returns a new Database
  *
  * @param RequestInfo $requestInfo
  * @param mixed       $data
  * @return HandlerResult
  */
 protected function _createDatabase(RequestInfo $requestInfo, $data)
 {
     if ($requestInfo->getDataIdentifier()) {
         throw new InvalidRequestParameterException('Document identifier in request path is not allowed when creating a Database', 1413278767);
     }
     $databaseIdentifier = $requestInfo->getDatabaseIdentifier();
     $database = $this->coordinator->createDatabase($databaseIdentifier);
     if ($database) {
         $this->eventEmitter->emit(Event::DATABASE_CREATED, array($database));
         return new HandlerResult(201, sprintf('Database "%s" created', $databaseIdentifier));
     } else {
         return new HandlerResult(400);
     }
 }
Exemplo n.º 2
0
 /**
  * Executes a subcommand
  *
  * @param string          $subcommand
  * @param array           $arguments
  * @param OutputInterface $output
  */
 public function executeSubCommand($subcommand, $arguments, OutputInterface $output)
 {
     try {
         switch ($subcommand) {
             case 'create':
                 $databaseIdentifier = array_shift($arguments);
                 $options = $arguments;
                 if (!$databaseIdentifier) {
                     throw new \InvalidArgumentException('Missing database identifier argument', 1412524227);
                 }
                 $database = $this->coordinator->createDatabase($databaseIdentifier, $options);
                 if ($database) {
                     $output->writeln(sprintf('<info>Created database %s</info>', $databaseIdentifier));
                 }
                 break;
             case 'drop':
                 $databaseIdentifier = array_shift($arguments);
                 if (!$databaseIdentifier) {
                     throw new \InvalidArgumentException('Missing database identifier argument', 1412524227);
                 }
                 $this->coordinator->dropDatabase($databaseIdentifier);
                 $output->writeln(sprintf('<info>Dropped database %s</info>', $databaseIdentifier));
                 break;
             case 'list':
             case 'll':
                 $databases = $this->coordinator->listDatabases();
                 if ($databases) {
                     $output->writeln('<info>Databases:</info>');
                     foreach ($databases as $databaseIdentifier) {
                         $output->writeln($databaseIdentifier);
                     }
                 } else {
                     $output->writeln('<info>No databases found</info>');
                 }
                 break;
             default:
                 throw new \InvalidArgumentException(sprintf('Undefined sub command "%s"', $subcommand), 1412525230);
         }
     } catch (\Exception $exception) {
         $output->writeln('<error>' . $exception->getMessage() . '</error>');
     }
 }