php Symfony-Component-Process-Process类(方法)实例源码

下面列出了php Symfony-Component-Process-Process 类(方法)源码代码实例,从而了解它的用法。

作者:Evrik    项目:Vida   
protected function execute(InputInterface $input, OutputInterface $output)
 {
     # снимаем ограничение времени выполнения скрипта (в safe-mode не работает)
     set_time_limit(0);
     $container = $this->getContainer();
     $logger = $container->get('vidal.digest_logger');
     $em = $container->get('doctrine')->getManager();
     # рассылаем с помощью EventSendCommand
     $command = 'php ' . $container->get('kernel')->getRootDir() . '/console vidal:eventsend ';
     $doctors = $em->createQuery('
                     SELECT e.username
                     FROM VidalMainBundle:User e
             ')->getResult();
     $emails = array();
     foreach ($doctors as $doctor) {
         $emails[] = $doctor['username'];
     }
     //        $emails[] = 'tulupov.m@gmail.com';
     $emails = array_diff($emails, $logger->getSentEmails());
     for ($i = 0, $c = count($emails); $i < $c; $i = $i + 100) {
         $emails100 = array_slice($emails, $i, 100);
         $emails100 = implode(' ', $emails100);
         # формируем команду для рассылки соточки
         try {
             $processCmd = $command . $emails100;
             $process = new Process($processCmd);
             $process->run();
         } catch (\Exception $e) {
             continue;
         }
         $process = null;
         sleep(40);
     }
 }

作者:hileniu    项目:homestead-symfony   
/**
  * Execute the command.
  *
  * @param  \Symfony\Component\Console\Input\InputInterface  $input
  * @param  \Symfony\Component\Console\Output\OutputInterface  $output
  * @return void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $process = new Process('vagrant resume', realpath(__DIR__ . '/../'), $_ENV, null, null);
     $process->run(function ($type, $line) use($output) {
         $output->write($line);
     });
 }

作者:matsine    项目:medus   
public function download($in_dir)
 {
     $repo = $in_dir . '/' . $this->package . ".git";
     if (is_dir($repo)) {
         return;
     }
     $cmd = 'git clone --mirror %s %s';
     $process = new Process(sprintf($cmd, $this->url, $repo));
     $process->setTimeout(3600);
     $process->run();
     if (!$process->isSuccessful()) {
         throw new \Exception($process->getErrorOutput());
     }
     $cmd = 'cd %s && git update-server-info -f';
     $process = new Process(sprintf($cmd, $repo));
     $process->setTimeout(3600);
     $process->run();
     if (!$process->isSuccessful()) {
         throw new \Exception($process->getErrorOutput());
     }
     $cmd = 'cd %s && git fsck';
     $process = new Process(sprintf($cmd, $repo));
     $process->setTimeout(3600);
     $process->run();
     if (!$process->isSuccessful()) {
         throw new \Exception($process->getErrorOutput());
     }
 }

作者:luisbrit    项目:Phraseane   
protected function dump_base(base $base, InputInterface $input, OutputInterface $output)
 {
     $date_obj = new DateTime();
     $filename = sprintf('%s%s_%s.sql', p4string::addEndSlash($input->getArgument('directory')), $base->get_dbname(), $date_obj->format('Y_m_d_H_i_s'));
     $command = sprintf('mysqldump %s %s %s %s %s %s --default-character-set=utf8', '--host=' . escapeshellarg($base->get_host()), '--port=' . escapeshellarg($base->get_port()), '--user=' . escapeshellarg($base->get_user()), '--password=' . escapeshellarg($base->get_passwd()), '--databases', escapeshellarg($base->get_dbname()));
     if ($input->getOption('gzip')) {
         $filename .= '.gz';
         $command .= ' | gzip -9';
     } elseif ($input->getOption('bzip')) {
         $filename .= '.bz2';
         $command .= ' | bzip2 -9';
     }
     $output->write(sprintf('Generating <info>%s</info> ... ', $filename));
     $command .= ' > ' . escapeshellarg($filename);
     $process = new Process($command);
     $process->setTimeout((int) $input->getOption('timeout'));
     $process->run();
     if (!$process->isSuccessful()) {
         $output->writeln('<error>Failed</error>');
         return 1;
     }
     if (file_exists($filename) && filesize($filename) > 0) {
         $output->writeln('OK');
         return 0;
     } else {
         $output->writeln('<error>Failed</error>');
         return 1;
     }
 }

作者:vladimir-    项目:ansibl   
public function __construct(\Symfony\Component\Process\Process $process)
 {
     $this->process = $process;
     $code = 0;
     $message = '';
     // Not all of the ansible errors have output in stderr. Therefore, if
     // stderr is empty we will use the stdout output instead to get clues
     // on what the actual error was.
     $error = $process->getErrorOutput();
     if (is_null($error)) {
         $error = $process->getOutput();
     }
     // Figure out the specific error that occured
     if (false !== strpos($error, 'the playbook') && false !== strpos($error, 'could not be found')) {
         $code = self::NOT_FOUND;
         $message = self::NOT_FOUND_MSG;
     } else {
         if (false !== strpos($error, 'Syntax Error while loading YAML script')) {
             $code = self::SYNTAX_ERROR;
             $message = self::SYNTAX_ERROR_MSG;
         } else {
             if (false !== strpos($error, 'One or more undefined variables')) {
                 $code = self::UNDEFINED_VARIABLE;
                 $message = self::UNDEFINED_VARIABLE_MSG;
             } else {
                 $code = self::GENERAL_ERROR;
                 $message = self::GENERAL_ERROR_MSG;
             }
         }
     }
     parent::__construct($message, $code);
 }

作者:robo4    项目:Sile   
/**
  * Compiles the Silex source code into one single Phar file.
  *
  * @param string $pharFile Name of the output Phar file
  */
 public function compile($pharFile = 'silex.phar')
 {
     if (file_exists($pharFile)) {
         unlink($pharFile);
     }
     $process = new Process('git log --pretty="%h %ci" -n1 HEAD');
     if ($process->run() > 0) {
         throw new \RuntimeException('The git binary cannot be found.');
     }
     $this->version = trim($process->getOutput());
     $phar = new \Phar($pharFile, 0, 'silex.phar');
     $phar->setSignatureAlgorithm(\Phar::SHA1);
     $phar->startBuffering();
     $finder = new Finder();
     $finder->files()->ignoreVCS(true)->name('*.php')->notName('Compiler.php')->in(__DIR__ . '/..')->in(__DIR__ . '/../../vendor/pimple/pimple/lib')->in(__DIR__ . '/../../vendor/symfony/class-loader/Symfony/Component/ClassLoader')->in(__DIR__ . '/../../vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher')->in(__DIR__ . '/../../vendor/symfony/http-foundation/Symfony/Component/HttpFoundation')->in(__DIR__ . '/../../vendor/symfony/http-kernel/Symfony/Component/HttpKernel')->in(__DIR__ . '/../../vendor/symfony/routing/Symfony/Component/Routing')->in(__DIR__ . '/../../vendor/symfony/browser-kit/Symfony/Component/BrowserKit')->in(__DIR__ . '/../../vendor/symfony/css-selector/Symfony/Component/CssSelector')->in(__DIR__ . '/../../vendor/symfony/dom-crawler/Symfony/Component/DomCrawler');
     foreach ($finder as $file) {
         $this->addFile($phar, $file);
     }
     $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../LICENSE'), false);
     $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/.composer/autoload.php'));
     $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/.composer/ClassLoader.php'));
     $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/.composer/autoload_namespaces.php'));
     // Stubs
     $phar->setStub($this->getStub());
     $phar->stopBuffering();
     // $phar->compressFiles(\Phar::GZ);
     unset($phar);
 }

作者:natxe    项目:compose   
/**
  * Compiles composer into a single phar file
  *
  * @throws \RuntimeException
  * @param string $pharFile The full path to the file to create
  */
 public function compile($pharFile = 'composer.phar')
 {
     if (file_exists($pharFile)) {
         unlink($pharFile);
     }
     $process = new Process('git log --pretty="%h" -n1 HEAD');
     if ($process->run() != 0) {
         throw new \RuntimeException('The git binary cannot be found.');
     }
     $this->version = trim($process->getOutput());
     $phar = new \Phar($pharFile, 0, 'composer.phar');
     $phar->setSignatureAlgorithm(\Phar::SHA1);
     $phar->startBuffering();
     $finder = new Finder();
     $finder->files()->ignoreVCS(true)->name('*.php')->notName('Compiler.php')->in(__DIR__ . '/..');
     foreach ($finder as $file) {
         $this->addFile($phar, $file);
     }
     $finder = new Finder();
     $finder->files()->ignoreVCS(true)->name('*.php')->in(__DIR__ . '/../../vendor/symfony/');
     foreach ($finder as $file) {
         $this->addFile($phar, $file);
     }
     $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/.composer/ClassLoader.php'));
     $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/.composer/autoload.php'));
     $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/.composer/autoload_namespaces.php'));
     $this->addComposerBin($phar);
     // Stubs
     $phar->setStub($this->getStub());
     $phar->stopBuffering();
     // disabled for interoperability with systems without gzip ext
     // $phar->compressFiles(\Phar::GZ);
     $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../LICENSE'), false);
     unset($phar);
 }

作者:pCyri    项目:php-legof   
/**
  * @Route("/file-upload", name="uploadFile")
  * @Template()
  */
 public function uploadFileAction(Request $request)
 {
     $allow = $request->get('private', false);
     /** @var File $file */
     $file = $request->files->get('file');
     $imageName = uniqid('legofy-online') . '.png';
     $command = sprintf('legofy %s/%s %s/../../../web/images/%s', $file->getPath(), $file->getFilename(), __DIR__, $imageName);
     $process = new Process($command);
     $process->run();
     if (!$process->isSuccessful()) {
         throw new ProcessFailedException($process);
     }
     $imagine = new Imagine();
     $imageFile = $imagine->open(sprintf('%s/../../../web/images/%s', __DIR__, $imageName));
     $box = $imageFile->getSize();
     if ($box->getHeight() > $box->getWidth()) {
         $imageFile->resize(new Box(400, $box->getHeight() * (400 / $box->getWidth())))->crop(new Point(0, 0), new Box(400, 400));
     } else {
         $newWidth = $box->getWidth() * (400 / $box->getHeight());
         $imageFile->resize(new Box($newWidth, 400))->crop(new Point(($newWidth - 400) / 2, 0), new Box(400, 400));
     }
     $imageFile->save(sprintf('%s/../../../web/images/thumbnails/%s', __DIR__, $imageName));
     $image = new Image();
     $image->setPrivate($allow)->setName($imageName)->setCreationDate(new \DateTime());
     $em = $this->getDoctrine()->getManager();
     $em->persist($image);
     $em->flush();
     return new JsonResponse(['url' => $this->generateUrl('editImage', ['id' => $image->getId(), 'name' => $image->getName()])]);
 }

作者:jkswood    项目:stoo   
protected function execute(InputInterface $input, OutputInterface $output)
 {
     $distribution = $input->getArgument('distribution');
     $version = $input->getArgument('version');
     $download = $this->downloadProject($distribution, $version);
     $process = new Process("tar -xzf {$download['location']} -C /tmp/");
     $process->start();
     if (substr($version, 0, 3) == '7.x') {
         $finder = new Finder();
         $process->wait();
         // Find all modules dropped in to the distribution.
         $finder->files()->name("*.info");
         $filename = array();
         foreach ($finder->in($download['locationUncompressed']) as $file) {
             $filename[] = array('path' => $file->getRealPath(), 'filename' => $file->getFileName());
         }
         // Create the array for the containing modules.
         $return = array();
         foreach ($filename as $file) {
             $contents = $this->parse_info_file(file_get_contents($file['path']));
             $machine_name = substr($file['filename'], 0, strpos($file['filename'], '.'));
             $return[$machine_name] = array('name' => $contents['name'], 'machine_name' => substr($file['filename'], 0, strpos($file['filename'], '.')), 'core' => $contents['core'], 'version' => $contents['version'], 'status' => 'Enabled', 'package' => isset($contents['package']) ? $contents['package'] : null);
         }
         $output->write(json_encode($return));
     }
 }

作者:rasod    项目:DLEM   
/**
  *@group cmd
  */
 public function testPhpdocIsInstalled()
 {
     $process = new Process('phpdoc --version');
     $process->run();
     $output = $process->getOutput();
     $this->assertContains("phpDocumentor version", $output);
 }

作者:php-lu    项目:webhoo   
/**
  * @param string $serialized
  *
  * @return Process
  */
 public function deserialize($serialized)
 {
     $data = json_decode($serialized, true);
     $process = new Process($data['command']);
     $process->setTimeout($data['timeout']);
     return $process;
 }

作者:richdynami    项目:magestea   
/**
  * @param $command
  * @param $projectPath
  * @param OutputInterface $output
  */
 protected function run($command, $projectPath, OutputInterface $output)
 {
     $process = new Process($command, $projectPath, array_merge($_SERVER, $_ENV), null, null);
     $process->run(function ($type, $line) use($output) {
         $output->write($line);
     });
 }

作者:javihgi    项目:composer-ci-tool   
/**
  * @param string $path
  * @param Event  $event
  */
 protected static function runFix($path, Event $event)
 {
     $bin = self::getOption('phpcsfixer-bin', $event);
     $failOnError = self::getOption('phpcsfixer-fail-on-error', $event);
     $logPrepend = self::getOption('phpcsfixer-log-prepend', $event);
     $level = self::getOption('phpcsfixer-level', $event);
     $fixers = self::getOption('phpcsfixer-fixers', $event);
     $config = self::getOption('phpcsfixer-config', $event);
     $dryRun = self::getOption('phpcsfixer-dry-run', $event);
     $command = array($bin, 'fix', $path);
     if ($level) {
         $command[] = '--level=' . $level;
     }
     if (!empty($fixers) && is_array($fixers)) {
         $command[] = '--fixers=' . implode(',', $fixers);
     }
     if ($config) {
         $command[] = '--config=' . $config;
     }
     if ($dryRun === true) {
         $command[] = '--dry-run';
     }
     if (!$failOnError) {
         $command[] = '|| true';
     }
     $process = new Process(implode(' ', $command), null, null, null, null, []);
     $process->mustRun(function ($type, $buffer) use($event, $logPrepend) {
         self::writeProcessBuffer($type, $buffer, $event, $logPrepend);
     });
 }

作者:kohkimakimot    项目:alta   
protected function execute(InputInterface $input, OutputInterface $output)
 {
     $container = $this->getApplication()->getContainer();
     $commandFile = realpath($_SERVER['SCRIPT_FILENAME']);
     $currentVersion = "v" . $container->getVersion();
     $updateVersion = trim(@file_get_contents('https://raw.githubusercontent.com/kohkimakimoto/altax/master/version'));
     if (!$container->isPhar()) {
         $output->writeln('<error>You can not update altax. Because altax only supports self-update command on PHAR file version.</error>');
         return 1;
     }
     if (!preg_match('/^v[0-9].[0-9]+.[0-9]+$/', $updateVersion)) {
         $output->writeln('<error>You can not update altax. Because the latest version of altax are not available for download.</error>');
         return 1;
     }
     if ($currentVersion === $updateVersion) {
         $output->writeln('<info>You are already using altax version <comment>' . $updateVersion . '</comment>.</info>');
         return 0;
     }
     $output->writeln(sprintf("Updating to version <info>%s</info>.", $updateVersion));
     $tmpDir = "/tmp/" . uniqid("altax.update.");
     $process = new Process("mkdir {$tmpDir} && cd {$tmpDir} && curl -L https://raw.githubusercontent.com/kohkimakimoto/altax/master/installer.sh | bash -s local {$updateVersion}");
     $process->setTimeout(null);
     if ($process->run() !== 0) {
         $output->writeln('<error>You can not update altax.');
         return 1;
     }
     $fs = new Filesystem();
     $fs->copy($tmpDir . "/altax.phar", $commandFile, true);
     $fs->remove($tmpDir);
     $output->writeln("Done.");
 }

作者:narog    项目:forema   
/**
  * @inheritDoc
  */
 protected function execute(InputInterface $input, OutputInterface $output, $retried = false)
 {
     if ($this->getContainer()->get('foreman.accessor')->ping()) {
         $output->writeln('<error>The Foreman Processor server is already running.');
         return;
     }
     if ($input->getOption('daemon')) {
         $phpPath = (new PhpExecutableFinder())->find();
         $process = new Process($phpPath . ' app/console foreman:processor:start' . ($input->getOption('verbose') ? ' -v' : ''));
         $process->setTimeout(0);
         $output->writeln('<info>Starting daemon server...');
         $process->start();
         $accessor = $this->getContainer()->get('foreman.accessor');
         $start = time();
         $interval = $this->getContainer()->getParameter('foreman.processor')['interval'];
         //When we try to ping the server the first time, it almost always fails.
         //The server isn't started yet by the time we get here, so we wait.
         //Timeout = 3 seconds. Should be enough for all servers.
         while (!$accessor->ping() && time() - $start < 3) {
             sleep($interval);
         }
         if ($accessor->ping()) {
             $status = $accessor->status();
             $output->writeln('<info>The server was started successfully with PID ' . $status['pid'] . '</info>');
         } else {
             $output->writeln('<error>The server could not be started at this moment.</error>');
             $output->writeln('Please check if the server port (' . $this->getContainer()->getParameter('foreman.processor.port') . ') is available.');
             $output->writeln('If you have closed the server recently, the connection may not have released. Try again ' . 'in a few seconds.');
         }
     } else {
         $output->writeln('<info>Starting the Foreman Processor...</info>');
         $this->getContainer()->get('foreman.processor')->start($output, $input->getOption('verbose'));
     }
 }

作者:nobo    项目:nobox-laravel-installe   
/**
  * Run a terminal command
  * @param  [array]         $command  [description]
  * @param  [path]          $directory [description]
  * @param  OutputInterface $output    [description]
  * @return [void]                     [description]
  */
 private function runProcess($command, $directory, $output, $alias)
 {
     $output->writeln('');
     if (is_array($command['line'])) {
         $commandLine = implode(' && ', $command['line']);
     } else {
         $commandLine = $command['line'];
     }
     $process = new Process($commandLine, $directory);
     $process->setTimeout(7600);
     $process->start();
     if ($output->isVerbose()) {
         $process->wait(function ($type, $buffer) {
             echo $buffer;
         });
     } else {
         $progress = new ProgressBar($output);
         $progress->setFormat("<comment>%message%</comment> [%bar%]");
         $progress->setMessage($command['title']);
         $progress->start();
         $progress->setRedrawFrequency(10000);
         while ($process->isRunning()) {
             $progress->advance();
         }
         $progress->finish();
         $progress->clear();
     }
     $output->writeln('');
     $output->write('<comment>' . $command['title'] . ' </comment><info>√ done</info>');
 }

作者:ktom    项目:phpstorm-downloade   
private function install(OutputInterface $output, $targetFolder, $symlinkName, $forceDownload, HttpSource $source)
 {
     $version = $source->getVersion();
     $extractedFolder = 'PhpStorm-' . $version;
     if (is_dir($targetFolder . '/' . $extractedFolder) && false === $forceDownload) {
         $output->writeln(sprintf('<comment>Phpstorm <info>%s</info> already exists, skipping download..</comment>', $version));
     } else {
         $output->write(sprintf('<comment>Download %s </comment><info>%s</info><comment>...</comment>', $source->getName(), $version));
         $downloadProcess = new Process(sprintf("wget %s -O phpstorm.tar.gz", escapeshellarg($source->getUrl())));
         $downloadProcess->setTimeout(3600);
         $downloadProcess->run();
         $output->writeln(' <info>OK</info>');
         if (!$downloadProcess->isSuccessful()) {
             throw new \RuntimeException($downloadProcess->getErrorOutput());
         }
         $output->write('<comment>Extracting...</comment>');
         $extractProcess = new Process(sprintf('tar xfz phpstorm.tar.gz; rm phpstorm.tar.gz; mv %1$s %2$s', escapeshellarg($extractedFolder), escapeshellarg($targetFolder)));
         $extractProcess->run();
         $output->writeln(' <info>OK</info>');
         if (!$extractProcess->isSuccessful()) {
             throw new \RuntimeException($extractProcess->getErrorOutput());
         }
     }
     $output->write('<comment>Linking...</comment>');
     $command = sprintf('cd %2$s && ln -s -f -T %1$s %3$s', escapeshellarg($extractedFolder), escapeshellarg($targetFolder), escapeshellarg($symlinkName));
     $linkProcess = new Process($command);
     $linkProcess->run();
     $output->writeln(' <info>OK</info>');
     if (!$linkProcess->isSuccessful()) {
         throw new \RuntimeException($linkProcess->getErrorOutput());
     }
 }

作者:rabellam    项目:pubstack-shel   
/**
  * Execute the command.
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $process = new Process('vagrant up', $_ENV['PUBSTACK_PATH'], array_merge($_SERVER, $_ENV), null, null);
     $process->run(function ($type, $line) use($output) {
         $output->write($line);
     });
 }

作者:Devdit    项目:pinboar   
protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('<info>Defining crontab task...</info>');
     $output->writeln('<info>Please enter the frequency of data aggregating</info> <comment>(frequency must be equal "pinba_stats_history" of the pinba engine config)</comment>.');
     $dialog = $this->getHelperSet()->get('dialog');
     $frequency = $dialog->askAndValidate($output, 'Frequency (in minutes, default "15"): ', function ($answer) {
         if (intval($answer) <= 0) {
             throw new \RunTimeException('You must enter positive integer value');
         }
         return $answer;
     }, false, '15');
     $process = new Process('crontab -l');
     $process->setTimeout(20);
     $process->run();
     $crontabString = $process->isSuccessful() ? $process->getOutput() : '';
     $path = realpath(__DIR__ . '/../../../console');
     $command = '*/' . $frequency . ' * * * * ' . $path . ' aggregate';
     if (strpos($crontabString, $command) === false) {
         $crontabString .= "\n" . $command . "\n";
     }
     $file = tempnam(sys_get_temp_dir(), 'ipm');
     file_put_contents($file, $crontabString);
     $process = new Process('crontab ' . $file);
     $process->setTimeout(20);
     $process->run();
     if (!$process->isSuccessful()) {
         throw new \RuntimeException($process->getErrorOutput());
     }
     $output->writeln('<info>Crontab task are defined successfully</info>');
     $output->writeln('<info>Please set parameter "aggregation_period" to value "PT' . $frequency . 'M" in config/parameters.yml</info>');
 }

作者:brighten0    项目:opencloud-zendframewor   
/**
  * Create process that lint PHP file.
  *
  * @param string $path path to file
  *
  * @return Process
  */
 public function createProcessForFile($path)
 {
     $process = new Process('php -l ' . ProcessUtils::escapeArgument($path));
     $process->setTimeout(null);
     $process->run();
     return $process;
 }


问题


面经


文章

微信
公众号

扫码关注公众号