/**
  * @param string $cmd
  * @param bool   $ignoreErrors
  *
  * @throws Exception
  */
 private function execCmd($cmd, $ignoreErrors = false)
 {
     $cmd = 'cd ' . $this->workspacePath . ' && ' . $cmd;
     if ($this->io->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
         $this->io->comment($cmd);
     }
     $process = new Process($cmd);
     $process->run(function ($type, $buffer) use($ignoreErrors) {
         if (Process::ERR === $type) {
             if ($ignoreErrors) {
                 if ($this->io->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
                     $this->io->comment($buffer);
                 }
             } else {
                 $this->io->error($buffer);
             }
         } else {
             if ($this->io->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
                 $this->io->comment($buffer);
             }
         }
     });
     if (!$ignoreErrors && !$process->isSuccessful()) {
         throw new Exception($process->getOutput() . $process->getErrorOutput());
     }
 }
Exemple #2
0
 /**
  * Execute a bash command.
  *
  * @param array $command
  * @param bool  $showOutput
  *
  * @return string
  */
 protected function execute(array $command, $showOutput = true)
 {
     $helper = new ProcessHelper();
     $helper->setHelperSet(new HelperSet(['debug_formatter' => new DebugFormatterHelper()]));
     // Compute new verbosity
     $previousVerbosity = $this->output->getVerbosity();
     $verbosity = $showOutput ? OutputInterface::VERBOSITY_DEBUG : OutputInterface::VERBOSITY_QUIET;
     // Execute command with defined verbosity
     $this->output->setVerbosity($verbosity);
     $process = $helper->run($this->output, $command);
     $this->output->setVerbosity($previousVerbosity);
     return $process->getOutput();
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->io = new SymfonyStyle($input, $output);
     $this->io->block('Running server...');
     $verbosity = $this->io->getVerbosity();
     switch ($verbosity) {
         case 16:
             $verbosity = 'quiet';
             break;
         case 32:
             $verbosity = 'normal';
             break;
         case 64:
             $verbosity = 'verbose';
             break;
         case 128:
             $verbosity = 'very_verbose';
             break;
         case 256:
             $verbosity = 'debug';
             break;
     }
     $this->io->note('Verbosity is "' . $verbosity . '". To set verbosity, add "-v", "-vv" or "-vvv" end the end of this command.');
     $this->socketPort = $this->getContainer()->getParameter('socket_port');
     $em = $this->getContainer()->get('doctrine.orm.default_entity_manager');
     $logger = $this->getContainer()->get('logger');
     $socketUrl = $this->getContainer()->getParameter('socket_server_url');
     $webUrl = $this->getContainer()->getParameter('web_server_url');
     $webHooks = $em->getRepository('AppBundle:WebHook')->findAll();
     $logger->info(count($webHooks) . ' webHook(s)');
     $server = new Server($em, $webHooks, $webUrl, $socketUrl, $logger);
     $this->killExistingSocketServer();
     $ioServer = IoServer::factory(new HttpServer(new WsServer($server)), $this->socketPort);
     $logger->info('Run socket server on port ' . $this->socketPort . '...');
     $ioServer->run();
 }
Exemple #4
0
 /**
  * @param SymfonyStyle $io
  * @param string       $address
  * @param string       $webDir
  * @param string       $router
  *
  * @return null|\Symfony\Component\Process\Process
  */
 protected function createServerProcess(SymfonyStyle $io, $address, $webDir, $router)
 {
     if (!file_exists($router)) {
         $io->error(sprintf('The router script "%s" does not exist', $router));
         return null;
     }
     $finder = new PhpExecutableFinder();
     if (($binary = $finder->find()) === false) {
         $io->error('Unable to find PHP binary to run server.');
         return null;
     }
     $builder = new ProcessBuilder([$binary, '-S', $address, '-t', $webDir, $router]);
     $builder->setTimeout(null);
     if ($io->getVerbosity() < OutputInterface::VERBOSITY_VERBOSE) {
         $builder->disableOutput();
     }
     return $builder->getProcess();
 }
 /**
  * @param string $msg
  * @param        $color
  */
 protected function verboseLog($msg, $color)
 {
     if ($this->io && $this->io->getVerbosity() === OutputInterface::VERBOSITY_DEBUG) {
         $this->io->comment('<' . $color . '>' . date('[Y-m-d H:i:s]') . $msg . '</' . $color . '>');
     }
 }