public function findByProject(Project $project)
 {
     $results = $this->getClient()->get('resources', ['query' => ['project' => $project->getSlug()]])->json();
     $resources = array();
     foreach ($results as $result) {
         $resource = new Resource($result['project']);
         $resource->setId($result['id']);
         $resource->setPathname($result['pathname']);
         $resources[] = $resource;
     }
     return $resources;
 }
Example #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;
         }
     }
 }
 public function update(Project $project)
 {
     $this->getClient()->put('projects/' . $project->getSlug(), ['headers' => ['Content-Type' => 'application/json'], 'body' => json_encode(['name' => $project->getName(), 'default_locale' => $project->getDefaultLocale()])]);
 }