container)) { $this->container = TestEnvironmentManager::getContainer(); } return $this->container; } protected function configure() { $this->setName('class:testenv') ->setDescription('Uploads a class into the current test environment.') ->addArgument('coid', InputArgument::REQUIRED, 'The COID of the object.') ->addOption('config', null, InputOption::VALUE_NONE, 'Upload the local configuration of the class to the test environment instead of retrieving it from CloudObjects.') ->addOption('watch', null, InputOption::VALUE_NONE, 'Keep watching for changes of the file and reupload automatically.'); } private function upload(OutputInterface $output) { try { $this->validator->validate(file_get_contents($this->phpFileName), $this->coid, $this->getAdditionalTypes()); $this->getContainer()->get('testenv.client')->put('/uploadTestenv?type=source&coid='.urlencode((string)$this->coid), [ 'body' => file_get_contents($this->phpFileName) ]); $output->writeln('File uploaded successfully!'); } catch (BadResponseException $e) { if ($e->getResponse()->getContentType()=='application/json') { $errorMessage = $e->getResponse()->json(); $output->writeln(''.$errorMessage['error_code'].': ' .$errorMessage['error_message']); } else $output->writeln(''.get_class($e).' '.(string)$e->getResponse()); } catch (\Exception $e) { $output->writeln(''.get_class($e).' '.$e->getMessage()); } } protected function execute(InputInterface $input, OutputInterface $output) { $this->requireCloudObjectsCLI(); $container = $this->getContainer(); if (!$container->has('testenv.client')) throw new \Exception("No test environment configured."); $this->parse($input->getArgument('coid')); $this->assertRDF(); if (!in_array('coid://phpmae.dev/Class', $this->rdfTypes) && !in_array('coid://phpmae.dev/HTTPInvokableClass', $this->rdfTypes)) throw new \Exception("Object does not have a valid class type."); $this->assertPHPExists(); // Print URL so developer can easily access it $output->writeln("Test Environment Base URL for Class Execution:"); $output->writeln("➡️ ".$container->get('testenv.url').$this->coid->getHost() .$this->coid->getPath()); $output->writeln(""); if ($input->getOption('config')) { // Upload configuration before uploading implementation $this->ensureFilenameInConfig($output); $container->get('testenv.client')->put('/uploadTestenv?type=config&coid='.urlencode((string)$this->coid), [ 'body' => file_get_contents($this->xmlFileName) ]); $output->writeln('Configuration uploaded successfully!'); } $this->validator = new ClassValidator; $this->upload($output); if ($input->getOption('watch')) { $cmd = $this; $this->watchPHPFile($output, function() use ($cmd, $output) { $cmd->upload($output); }); } } }