public function executeProcess($output, $processArguments, $file, $prefixes, $postfixes, $arguments, $options) { foreach ($prefixes as $prefix) { $processArguments[] = $prefix; } $processArguments[] = $file; foreach ($postfixes as $postfix) { $processArguments[] = $postfix; } $processBuilder = new ProcessBuilder($processArguments); foreach ($arguments as $argument) { $processBuilder->add($argument); } foreach ($options as $optionName => $optionValue) { $processBuilder->setOption($optionName, $optionValue); } $process = $processBuilder->getProcess(); $process->run(); if (!$process->isSuccessful()) { $output->writeln(sprintf('<error>%s</error>', trim($process->getErrorOutput()))); } if ($process->getOutput()) { $output->writeln($process->getOutput()); } return $process; }
/** * Adds a proc_open option. * * @param string $name The option name * @param string $value The option value * * @return ProcessBuilderProxyInterface */ public function setOption(string $name, string $value) : ProcessBuilderProxyInterface { $this->processBuilder->setOption($name, $value); return $this; }
private function analyzer($output, $analyzer, $files, $config) { $enabled = $config->get('application.analyzer.' . $analyzer . '.enabled'); if (!$enabled) { return; } $exception = $config->get('application.analyzer.' . $analyzer . '.exception'); $options = $config->get('application.analyzer.' . $analyzer . '.options'); $arguments = $config->get('application.analyzer.' . $analyzer . '.arguments'); if ($arguments) { $arguments = array_keys($arguments); } $success = true; $this->validateBinary('bin/' . $analyzer); $output->writeln(sprintf('<info>%s</info>', $config->get('application.messages.' . $analyzer . '.info'))); foreach ($files as $file) { if (!preg_match($this->needle, $file) && !is_dir(realpath($this->directory . $file))) { continue; } $arguments[] = $file; $processBuilder = new ProcessBuilder(['php', $this->directory . 'bin/' . $analyzer]); if ($arguments) { foreach ($arguments as $argument) { $processBuilder->add($argument); } } if ($options) { foreach ($options as $optionName => $optionValue) { $processBuilder->setOption($optionName, $optionValue); } } $process = $processBuilder->getProcess(); $process->run(); if (!$process->isSuccessful()) { $output->writeln(sprintf('<error>%s</error>', trim($process->getErrorOutput()))); $success = false; } $output->writeln(sprintf('<comment>%s</comment>', trim($process->getOutput()))); } if ($exception && !$success) { throw new \Exception($config->get('application.messages.' . $analyzer . '.error')); } }