本文整理汇总了PHP中Composer\Util\ProcessExecutor::execute方法的典型用法代码示例。如果您正苦于以下问题:PHP ProcessExecutor::execute方法的具体用法?PHP ProcessExecutor::execute怎么用?PHP ProcessExecutor::execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Composer\Util\ProcessExecutor
的用法示例。
在下文中一共展示了ProcessExecutor::execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: executeCommand
/**
* Executes a shell command with escaping.
*
* @param string $cmd
* @return bool
*/
protected function executeCommand($cmd)
{
// Shell-escape all arguments except the command.
$args = func_get_args();
foreach ($args as $index => $arg) {
if ($index !== 0) {
$args[$index] = escapeshellarg($arg);
}
}
// And replace the arguments.
$command = call_user_func_array('sprintf', $args);
$output = '';
if ($this->io->isVerbose()) {
$this->io->write('<comment>' . $command . '</comment>');
$io = $this->io;
$output = function ($type, $data) use($io) {
if ($type == Process::ERR) {
$io->write('<error>' . $data . '</error>');
} else {
$io->write('<comment>' . $data . '</comment>');
}
};
}
return $this->executor->execute($command, $output) == 0;
}
示例2: guessSvnVersion
private function guessSvnVersion(array $packageConfig, $path)
{
SvnUtil::cleanEnv();
// try to fetch current version from svn
if (0 === $this->process->execute('svn info --xml', $output, $path)) {
$trunkPath = isset($packageConfig['trunk-path']) ? preg_quote($packageConfig['trunk-path'], '#') : 'trunk';
$branchesPath = isset($packageConfig['branches-path']) ? preg_quote($packageConfig['branches-path'], '#') : 'branches';
$tagsPath = isset($packageConfig['tags-path']) ? preg_quote($packageConfig['tags-path'], '#') : 'tags';
$urlPattern = '#<url>.*/(' . $trunkPath . '|(' . $branchesPath . '|' . $tagsPath . ')/(.*))</url>#';
if (preg_match($urlPattern, $output, $matches)) {
if (isset($matches[2]) && ($branchesPath === $matches[2] || $tagsPath === $matches[2])) {
// we are in a branches path
$version = $this->versionParser->normalizeBranch($matches[3]);
$prettyVersion = 'dev-' . $matches[3];
if ('9999999-dev' === $version) {
$version = $prettyVersion;
}
return array('version' => $version, 'commit' => '', 'pretty_version' => $prettyVersion);
}
$prettyVersion = trim($matches[1]);
$version = $this->versionParser->normalize($prettyVersion);
return array('version' => $version, 'commit' => '', 'pretty_version' => $prettyVersion);
}
}
}
示例3: initialize
/**
* Initializes path repository.
*
* This method will basically read the folder and add the found package.
*/
protected function initialize()
{
parent::initialize();
foreach ($this->getUrlMatches() as $url) {
$path = realpath($url) . DIRECTORY_SEPARATOR;
$composerFilePath = $path . 'composer.json';
if (!file_exists($composerFilePath)) {
continue;
}
$json = file_get_contents($composerFilePath);
$package = JsonFile::parseJson($json, $composerFilePath);
$package['dist'] = array('type' => 'path', 'url' => $url, 'reference' => '');
if (!isset($package['version'])) {
$package['version'] = $this->versionGuesser->guessVersion($package, $path) ?: 'dev-master';
}
$output = '';
if (is_dir($path . DIRECTORY_SEPARATOR . '.git') && 0 === $this->process->execute('git log -n1 --pretty=%H', $output, $path)) {
$package['dist']['reference'] = trim($output);
} else {
$package['dist']['reference'] = Locker::getContentHash($json);
}
$package = $this->loader->load($package);
$this->addPackage($package);
}
if (count($this->getPackages()) == 0) {
throw new \RuntimeException(sprintf('No `composer.json` file found in any path repository in "%s"', $this->url));
}
}
示例4: initialize
/**
* Initializes path repository.
*
* This method will basically read the folder and add the found package.
*/
protected function initialize()
{
parent::initialize();
foreach ($this->getUrlMatches() as $url) {
$path = realpath($url) . DIRECTORY_SEPARATOR;
$composerFilePath = $path . 'composer.json';
if (!file_exists($composerFilePath)) {
continue;
}
$json = file_get_contents($composerFilePath);
$package = JsonFile::parseJson($json, $composerFilePath);
$package['dist'] = array('type' => 'path', 'url' => $url, 'reference' => sha1($json));
$package['transport-options'] = $this->options;
if (!isset($package['version'])) {
$versionData = $this->versionGuesser->guessVersion($package, $path);
$package['version'] = $versionData['version'] ?: 'dev-master';
}
$output = '';
if (is_dir($path . DIRECTORY_SEPARATOR . '.git') && 0 === $this->process->execute('git log -n1 --pretty=%H', $output, $path)) {
$package['dist']['reference'] = trim($output);
}
$package = $this->loader->load($package);
$this->addPackage($package);
}
}
示例5: installDependencies
private static function installDependencies(IOInterface $io, $folder)
{
$io->write("[0;32mInstalling front end dependencies from package.json[0m");
$proc = new ProcessExecutor();
$proc->execute('cd ' . $folder . ' && npm install');
$io->write("[0;32mFront end dependencies installed[0m");
}
示例6: testExecuteOutputsIfNotCaptured
public function testExecuteOutputsIfNotCaptured()
{
$process = new ProcessExecutor();
ob_start();
$process->execute('echo foo');
$output = ob_get_clean();
$this->assertEquals("foo" . PHP_EOL, $output);
}
示例7: checkGit
private function checkGit()
{
$this->process->execute('git config color.ui', $output);
if (strtolower(trim($output)) === 'always') {
return '<comment>Your git color.ui setting is set to always, this is known to create issues. Use "git config --global color.ui true" to set it correctly.</comment>';
}
return true;
}
示例8: throwException
private function throwException($message, $url)
{
// git might delete a directory when it fails and php will not know
clearstatcache();
if (0 !== $this->process->execute('git --version', $ignoredOutput)) {
throw new \RuntimeException('Failed to clone ' . self::sanitizeUrl($url) . ', git was not found, check that it is installed and in your PATH env.' . "\n\n" . $this->process->getErrorOutput());
}
throw new \RuntimeException($message);
}
示例9: addComposerTime
/**
* Add time in composer.
*
* @param array $composer
* @param ProcessExecutor $process
* @param string $cmd
* @param string $repoDir
* @param string $datetimePrefix
*
* @return array The composer
*/
protected static function addComposerTime(array $composer, ProcessExecutor $process, $cmd, $repoDir, $datetimePrefix = '')
{
if (!isset($composer['time'])) {
$process->execute($cmd, $output, $repoDir);
$date = new \DateTime($datetimePrefix . trim($output), new \DateTimeZone('UTC'));
$composer['time'] = $date->format('Y-m-d H:i:s');
}
return $composer;
}
示例10: getVersion
/**
* Retrieves the current git version.
*
* @return string|null The git version number.
*/
public function getVersion()
{
if (isset(self::$version)) {
return self::$version;
}
if (0 !== $this->process->execute('git --version', $output)) {
return;
}
if (preg_match('/^git version (\\d+(?:\\.\\d+)+)/m', $output, $matches)) {
return self::$version = $matches[1];
}
}
示例11: determineLocalPackageReference
private function determineLocalPackageReference()
{
$basePath = realpath(getcwd());
if (is_dir($basePath . DIRECTORY_SEPARATOR . '.git')) {
$process = new ProcessExecutor();
if ($process->execute('git rev-parse HEAD', $output, $basePath) === 0) {
return trim($output);
}
}
// TODO: add support for other VCS'es
return null;
}
示例12: applyPatches
public function applyPatches()
{
if (!is_dir($this->patchDir) && is_dir($this->patchDir)) {
return;
}
$patches = glob($this->patchDir . '/*.patch');
if (count($patches)) {
$io = $this->io;
$handler = function ($type, $data) use($io) {
if ($type == Process::ERR) {
$io->write('<error>' . $data . '</error>');
} else {
$io->write('<info>' . $data . '</info>');
}
};
foreach ($patches as $patchFile) {
$file = escapeshellarg($patchFile);
$io->write("<comment>Applying patches from {$file}.</comment>");
$this->executor->execute("patch -r - -p0 --no-backup-if-mismatch -i " . $file, $handler);
}
}
}
示例13: execute
/**
* Execute an SVN command and try to fix up the process with credentials
* if necessary.
*
* @param string $command SVN command to run
* @param string $url SVN url
* @param string $cwd Working directory
* @param string $path Target for a checkout
* @param Boolean $verbose Output all output to the user
*
* @return string
*
* @throws \RuntimeException
*/
public function execute($command, $url, $cwd = null, $path = null, $verbose = false)
{
$svnCommand = $this->getCommand($command, $url, $path);
$output = null;
$io = $this->io;
$handler = function ($type, $buffer) use(&$output, $io, $verbose) {
if ($type !== 'out') {
return;
}
$output .= $buffer;
if ($verbose) {
$io->write($buffer, false);
}
};
$status = $this->process->execute($svnCommand, $handler, $cwd);
if (0 === $status) {
return $output;
}
if (empty($output)) {
$output = $this->process->getErrorOutput();
}
// the error is not auth-related
if (false === stripos($output, 'authorization failed:')) {
throw new \RuntimeException($output);
}
// no auth supported for non interactive calls
if (!$this->io->isInteractive()) {
throw new \RuntimeException('can not ask for authentication in non interactive mode (' . $output . ')');
}
// TODO keep a count of user auth attempts and ask 5 times before
// failing hard (currently it fails hard directly if the URL has credentials)
// try to authenticate
if (!$this->hasAuth()) {
$this->doAuthDance();
// restart the process
return $this->execute($command, $url, $cwd, $path, $verbose);
}
throw new \RuntimeException('wrong credentials provided (' . $output . ')');
}
示例14: getRemovedFiles
/**
* Retrieve removed files list between two package versions
*
* @param PackageInterface $targert new package version to install
* @param PackageInterface $initial previous package version
*
* @return array
*/
protected function getRemovedFiles(PackageInterface $target, PackageInterface $initial)
{
$output = false;
$removedFiles = array();
if ($initial->getSourceReference() != $target->getSourceReference()) {
if ($this->io->isVerbose()) {
$this->io->write("Retrieving list of removed files from previous version installed.");
}
$command = sprintf('git diff --name-only --diff-filter=D %s %s', $initial->getSourceReference(), $target->getSourceReference());
if (0 !== $this->process->execute($command, $output, $this->rubedoRootDir)) {
throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
}
$removedFiles = explode(PHP_EOL, ltrim(rtrim($output)));
}
return $removedFiles;
}
示例15: executeCommand
/**
* Executes a shell command
*
* @param string $command the command to execute
* @param mixed $output the output will be written into this var if passed by ref
* if a callable is passed it will be used as output handler
* @param string $cwd the working directory
* @return bool
*/
protected function executeCommand($command, &$output = null, $cwd = null)
{
$success = $this->executor->execute($command, $output, $cwd) == 0;
if ($this->io->isVerbose()) {
$this->io->write('<comment>' . $command . '</comment>');
$io = $this->io;
$output = function ($type, $data) use($io) {
if ($type == Process::ERR) {
$io->write('<error>' . $data . '</error>');
} else {
$io->write('<comment>' . $data . '</comment>');
}
};
}
return $success;
}