public function get($slug)
 {
     $result = $this->getClient()->get('projects/' . $slug)->json();
     $project = new Project($result['slug']);
     $project->setName($result['name']);
     $project->setDefaultLocale($result['default_locale']);
     return $project;
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $dialog = $this->getHelperSet()->get('dialog');
     $configurationLoader = $this->get('configuration.loader');
     // Dump configuration
     $content = $this->get('configuration.dumper')->dumpConfiguration($this->configuration);
     if ($input->isInteractive()) {
         $output->writeln(['', $content]);
     }
     if (!$dialog->askConfirmation($output, '<info>Do you confirm generation</info> [<comment>yes</comment>]? ')) {
         return 1;
     }
     file_put_contents($configurationLoader->getConfigurationFilepath(), $content);
     // Destroy current container to force recreate it with configured service
     $this->getApplication()->destroyContainer();
     $projectApi = $this->get('api')->getEntryPoint('project');
     try {
         $projectSlug = $this->configuration['project'];
         $project = $projectApi->get($projectSlug);
         return;
     } catch (ClientException $e) {
         if ('404' !== $e->getResponse()->getStatusCode()) {
             throw $e;
         }
     }
     $output->writeln('');
     if ($dialog->askConfirmation($output, '<info>Would you like to create the project</info> [<comment>yes</comment>]? ')) {
         $project = new Project($projectSlug);
         $defaultName = ucfirst($project->getSlug());
         $name = $dialog->ask($output, "<info>Project's name</info> [<comment>{$defaultName}</comment>]: ", $defaultName);
         $project->setName($name);
         $defaultLocale = $dialog->ask($output, "<info>Default locale</info> [<comment>en</comment>]: ", 'en');
         $project->setDefaultLocale($defaultLocale);
         try {
             $projectApi->create($project);
         } catch (\Exception $e) {
             $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
             return 1;
         }
     }
 }