本文整理汇总了PHP中Symfony\Component\Process\ProcessBuilder::setWorkingDirectory方法的典型用法代码示例。如果您正苦于以下问题:PHP ProcessBuilder::setWorkingDirectory方法的具体用法?PHP ProcessBuilder::setWorkingDirectory怎么用?PHP ProcessBuilder::setWorkingDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Process\ProcessBuilder
的用法示例。
在下文中一共展示了ProcessBuilder::setWorkingDirectory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor.
*
* @param GitRepository $repository The git repository to work on.
*/
public function __construct(GitRepository $repository)
{
$this->repository = $repository;
$this->processBuilder = new ProcessBuilder();
$this->processBuilder->setWorkingDirectory($repository->getRepositoryPath());
$this->processBuilder->add($this->repository->getConfig()->getGitExecutablePath());
$this->initializeProcessBuilder();
}
示例2: handle
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
echo "Run task: #" . $this->job_id, "\n";
$task = Tasks::find($this->job_id);
$task->status = Tasks::RUN;
$task->save();
$client = new \Hoa\Websocket\Client(new \Hoa\Socket\Client('tcp://127.0.0.1:8889'));
$client->setHost('127.0.0.1');
$client->connect();
$client->send(json_encode(["command" => webSocket::BROADCASTIF, "jobid" => $this->job_id, "msg" => json_encode(["jid" => $this->job_id, "status" => Tasks::RUN])]));
$builder = new ProcessBuilder();
$builder->setPrefix('ansible-playbook');
$builder->setArguments(["-i", "inv" . $this->job_id, "yml" . $this->job_id]);
$builder->setWorkingDirectory(storage_path("roles"));
$process = $builder->getProcess();
$process->run();
//echo $process->getOutput() . "\n";
$client->send(json_encode(["command" => webSocket::BROADCASTIF, "jobid" => $this->job_id, "msg" => json_encode(["jid" => $this->job_id, "status" => Tasks::FINISH])]));
$client->close();
$task->status = Tasks::FINISH;
$task->content = file_get_contents(storage_path("tmp/log" . $this->job_id . ".txt"));
$task->save();
unlink(storage_path("roles/yml" . $this->job_id));
unlink(storage_path("roles/inv" . $this->job_id));
unlink(storage_path("tmp/log" . $this->job_id . ".txt"));
echo "End task: #" . $this->job_id, "\n";
}
示例3: startProcess
/**
* Creates the given process
*
* @throws \Exception
*/
private function startProcess(OutputInterface $output)
{
$arguments = $this->resolveProcessArgs();
$name = sha1(serialize($arguments));
if ($this->background->hasProcess($name)) {
throw new \RuntimeException("Service is already running.");
}
$builder = new ProcessBuilder($arguments);
if ($this->hasParameter('cwd')) {
$builder->setWorkingDirectory($this->getParameter('cwd'));
}
$process = $builder->getProcess();
if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) {
$output->writeln($process->getCommandLine());
}
if ($this->hasParameter('output')) {
$append = $this->hasParameter('append') && $this->getParameter('append') ? 'a' : 'w';
$stream = fopen($this->getParameter('output'), $append);
$output = new StreamOutput($stream, StreamOutput::VERBOSITY_NORMAL, true);
}
$process->start(function ($type, $buffer) use($output) {
$output->write($buffer);
});
$this->background->addProcess($name, $process);
if (!in_array($process->getExitCode(), $this->getParameter('successCodes'))) {
throw new TaskRuntimeException($this->getName(), $process->getErrorOutput());
}
}
示例4: isTracked
/**
* {@inheritdoc}
*/
public function isTracked($file)
{
$processBuilder = new ProcessBuilder([$this->binaryPath, 'locate', $file]);
$processBuilder->setWorkingDirectory($this->root);
$process = $processBuilder->getProcess();
$process->run();
return $process->isSuccessful();
}
示例5: __destruct
public function __destruct()
{
if ($this->temp !== null) {
$processBuilder = new ProcessBuilder(['rm', '-rf', $this->temp]);
$processBuilder->setWorkingDirectory($this->root);
$process = $processBuilder->getProcess();
$process->run();
}
}
示例6: migrationCommandBuilder
/**
* Returns ProcessBuilder instance with predefined process command for migration command execution.
*
* @return \Symfony\Component\Process\ProcessBuilder
*/
private function migrationCommandBuilder($migrationPath = '', $migrationTable = '{{%migration}}', $down = false)
{
$builder = new ProcessBuilder();
$builder->setWorkingDirectory(Yii::getAlias('@app'))->setPrefix($this->getPhpExecutable())->setArguments([realpath(Yii::getAlias('@app') . '/yii'), 'migrate/' . ($down ? 'down' : 'up'), '--color=0', '--interactive=0', '--migrationTable=' . $migrationTable, $down ? 65536 : 0]);
if (empty($migrationPath) === false) {
$builder->add('--migrationPath=' . $migrationPath);
}
return $builder;
}
示例7: createProcess
/**
* @param array $commands
* @param \Hshn\NpmBundle\Npm\ConfigurationInterface $configuration
* @return \Symfony\Component\Process\Process
*/
private function createProcess(array $commands, ConfigurationInterface $configuration)
{
$builder = new ProcessBuilder([$this->binPath]);
$builder->setWorkingDirectory($configuration->getDirectory());
$builder->setTimeout(600);
foreach ($commands as $command) {
$builder->add($command);
}
return $builder->getProcess();
}
示例8: getProcess
protected function getProcess($drupal, $dsn)
{
$builder = new ProcessBuilder();
$builder->inheritEnvironmentVariables(true);
$builder->setWorkingDirectory($drupal);
$builder->setPrefix('php');
$builder->setArguments(array('-d sendmail_path=`which true`', $this->drush, 'site-install', 'standard', "--db-url={$dsn}", '-y'));
$process = $builder->getProcess();
return $process;
}
示例9: getProcessBuilder
/**
* {@inheritdoc}
*/
public function getProcessBuilder(array $arguments, $timeout = self::DEFAULT_PROCESS_TIMEOUT)
{
$builder = new ProcessBuilder();
$builder->setPrefix($this->getPhpBinary());
$builder->setWorkingDirectory($this->getCwd());
$builder->setArguments($arguments);
$builder->setTimeout($timeout);
$builder->inheritEnvironmentVariables(true);
return $builder;
}
示例10: sortUseStatements
/**
* Executes the Marc Morera's PHP-Formatter sort use statements command.
*
* @param array $parameters The project parameters
*
* @throws \LIN3S\CS\Exception\CheckFailException
*/
private static function sortUseStatements($parameters)
{
$processBuilder = new ProcessBuilder(['php', 'vendor/mmoreram/php-formatter/bin/php-formatter', 'formatter:use:sort', $parameters['phpformatter_path']]);
$processBuilder->setWorkingDirectory($parameters['root_directory']);
$process = $processBuilder->getProcess();
$process->run();
if (!$process->isSuccessful()) {
throw new CheckFailException('PHP Formatter', 'Something fails during php formatter\'s sort uses process');
}
}
示例11: startWebServer
private function startWebServer(InputInterface $input, OutputInterface $output, $targetDirectory)
{
$builder = new ProcessBuilder([PHP_BINARY, '-S', $input->getArgument('address')]);
$builder->setWorkingDirectory($targetDirectory);
$builder->setTimeout(null);
$process = $builder->getProcess();
$process->start();
$output->writeln(sprintf("Server running on <comment>%s</comment>", $input->getArgument('address')));
return $process;
}
示例12: execute
public function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln(sprintf("Server running on <info>http://%s</info>\n", $input->getArgument('address')));
$builder = new ProcessBuilder(array(PHP_BINARY, '-S', $input->getArgument('address')));
$builder->setWorkingDirectory($input->getOption('web-dir'));
$builder->setTimeout(null);
$builder->getProcess()->mustRun(function ($type, $buffer) use($output) {
if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
$output->write($buffer);
}
});
}
示例13: execute
/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln(sprintf("Server running on <info>%s</info>\n", $input->getArgument('address')));
$builder = new ProcessBuilder(array(PHP_BINARY, '-S', $input->getArgument('address'), __DIR__ . '/../../../src/router.php'));
$builder->setWorkingDirectory($input->getOption('docroot'));
$builder->setTimeout(null);
$builder->getProcess()->run(function ($type, $buffer) use($output) {
if (OutputInterface::VERBOSITY_VERBOSE === $output->getVerbosity()) {
$output->write($buffer);
}
});
}
示例14: execute
protected function execute($arguments)
{
array_unshift($arguments, $this->gitPath);
$builder = new ProcessBuilder($arguments);
$builder->setWorkingDirectory($this->repo);
$process = $builder->getProcess();
$process->run();
if (!$process->isSuccessful()) {
throw new \RuntimeException(sprintf('Unable to run the command (%s).', $process->getErrorOutput()));
}
return $process->getOutput();
}
示例15: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$router = $input->getOption('router') ?: $this->getContainer()->get('kernel')->locateResource('@FrameworkBundle/Resources/config/router.php');
$output->writeln(sprintf("Server running on <info>%s</info>\n", $input->getArgument('address')));
$builder = new ProcessBuilder(array(PHP_BINARY, '-S', $input->getArgument('address'), $router));
$builder->setWorkingDirectory($input->getOption('docroot'));
$builder->setTimeout(null);
$builder->getProcess()->run(function ($type, $buffer) use($output) {
if (OutputInterface::VERBOSITY_VERBOSE === $output->getVerbosity()) {
$output->write($buffer);
}
});
}