本文整理汇总了PHP中Composer\Util\ProcessExecutor::escape方法的典型用法代码示例。如果您正苦于以下问题:PHP ProcessExecutor::escape方法的具体用法?PHP ProcessExecutor::escape怎么用?PHP ProcessExecutor::escape使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Composer\Util\ProcessExecutor
的用法示例。
在下文中一共展示了ProcessExecutor::escape方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: extract
protected function extract($file, $path)
{
$processError = null;
// Try to use unrar on *nix
if (!Platform::isWindows()) {
$command = 'unrar x ' . ProcessExecutor::escape($file) . ' ' . ProcessExecutor::escape($path) . ' >/dev/null && chmod -R u+w ' . ProcessExecutor::escape($path);
if (0 === $this->process->execute($command, $ignoredOutput)) {
return;
}
$processError = 'Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput();
}
if (!class_exists('RarArchive')) {
// php.ini path is added to the error message to help users find the correct file
$iniMessage = IniHelper::getMessage();
$error = "Could not decompress the archive, enable the PHP rar extension or install unrar.\n" . $iniMessage . "\n" . $processError;
if (!Platform::isWindows()) {
$error = "Could not decompress the archive, enable the PHP rar extension.\n" . $iniMessage;
}
throw new \RuntimeException($error);
}
$rarArchive = RarArchive::open($file);
if (false === $rarArchive) {
throw new \UnexpectedValueException('Could not open RAR archive: ' . $file);
}
$entries = $rarArchive->getEntries();
if (false === $entries) {
throw new \RuntimeException('Could not retrieve RAR archive entries');
}
foreach ($entries as $entry) {
if (false === $entry->extract($path)) {
throw new \RuntimeException('Could not extract entry');
}
}
$rarArchive->close();
}
示例2: get
protected function get($originUrl, $fileUrl, $options = [], $fileName = null, $progress = true)
{
if (strpos($fileUrl, 'ssh://') !== 0) {
throw new \UnexpectedValueException("This does not appear to be a file that should be downloaded via ssh: {$fileUrl}");
}
// strip off the pseudo protocol
$fileUrl = substr($fileUrl, 6);
if ($this->io->isVerbose()) {
$this->io->write("Downloading {$fileUrl} via ssh.");
}
// filename means we want to save
if ($fileName) {
$cmd = 'scp ' . ProcessExecutor::escape($fileUrl) . ' ' . ProcessExecutor::escape($fileName);
} else {
// otherwise just return the file contents
list($host, $path) = explode(':', $fileUrl);
$cmd = 'ssh ' . ProcessExecutor::escape($host) . ' ' . ProcessExecutor::escape('cat ' . ProcessExecutor::escape($path));
}
if ($progress) {
$this->io->writeError(' Downloading: <comment>Connecting...</comment>', false);
}
// success?
// @todo: do we need to catch any exceptions here?
if ($this->process->execute($cmd, $output) === 0) {
if ($progress) {
$this->io->overwriteError(' Downloading: <comment>100%</comment>');
}
return $output;
} else {
// some sort of error - boo!
throw new \RuntimeException("Could not download {$fileUrl}. " . $process->getErrorOutput());
}
}
示例3: extract
protected function extract($file, $path)
{
$processError = null;
if (self::$hasSystemUnzip && !(class_exists('ZipArchive') && Platform::isWindows())) {
$command = 'unzip ' . ProcessExecutor::escape($file) . ' -d ' . ProcessExecutor::escape($path);
if (!Platform::isWindows()) {
$command .= ' && chmod -R u+w ' . ProcessExecutor::escape($path);
}
try {
if (0 === $this->process->execute($command, $ignoredOutput)) {
return;
}
$processError = 'Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput();
} catch (\Exception $e) {
$processError = 'Failed to execute ' . $command . "\n\n" . $e->getMessage();
}
if (!class_exists('ZipArchive')) {
throw new \RuntimeException($processError);
}
}
$zipArchive = new ZipArchive();
if (true !== ($retval = $zipArchive->open($file))) {
throw new \UnexpectedValueException(rtrim($this->getErrorMessage($retval, $file) . "\n" . $processError), $retval);
}
if (true !== $zipArchive->extractTo($path)) {
throw new \RuntimeException(rtrim("There was an error extracting the ZIP file, it is either corrupted or using an invalid format.\n" . $processError));
}
$zipArchive->close();
}
示例4: extract
protected function extract($file, $path)
{
// we must use cmdline tar, as PharData::extract() messes up symlinks
$command = 'tar -xzf ' . ProcessExecutor::escape($file) . ' -C ' . ProcessExecutor::escape($path);
if (0 === $this->process->execute($command, $ignoredOutput)) {
return;
}
throw new \RuntimeException("Failed to execute '{$command}'\n\n" . $this->process->getErrorOutput());
}
示例5: extract
protected function extract($file, $path)
{
$command = 'tar -xJf ' . ProcessExecutor::escape($file) . ' -C ' . ProcessExecutor::escape($path);
if (0 === $this->process->execute($command, $ignoredOutput)) {
return;
}
$processError = 'Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput();
throw new \RuntimeException($processError);
}
示例6: doUpdate
public function doUpdate(PackageInterface $initial, PackageInterface $target, $path, $url)
{
$url = ProcessExecutor::escape($url);
$ref = ProcessExecutor::escape($target->getSourceReference());
$this->io->writeError(" Updating to " . $target->getSourceReference());
if (!is_dir($path . '/.hg')) {
throw new \RuntimeException('The .hg directory is missing from ' . $path . ', see http://getcomposer.org/commit-deps for more information');
}
$command = sprintf('hg pull %s && hg up %s', $url, $ref);
if (0 !== $this->process->execute($command, $ignoredOutput, realpath($path))) {
throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
}
}
示例7: doUpdate
/**
* {@inheritDoc}
*/
public function doUpdate(PackageInterface $initial, PackageInterface $target, $path, $url)
{
// Ensure we are allowed to use this URL by config
$this->config->prohibitUrlByConfig($url, $this->io);
$url = ProcessExecutor::escape($url);
$ref = ProcessExecutor::escape($target->getSourceReference());
$this->io->writeError(" Updating to " . $target->getSourceReference());
if (!$this->hasMetadataRepository($path)) {
throw new \RuntimeException('The .hg directory is missing from ' . $path . ', see https://getcomposer.org/commit-deps for more information');
}
$command = sprintf('hg pull %s && hg up %s', $url, $ref);
if (0 !== $this->process->execute($command, $ignoredOutput, realpath($path))) {
throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
}
}
示例8: extract
protected function extract($file, $path)
{
$targetFilepath = $path . DIRECTORY_SEPARATOR . basename(substr($file, 0, -3));
if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
$command = 'gzip -cd ' . ProcessExecutor::escape($file) . ' > ' . ProcessExecutor::escape($targetFilepath);
if (0 === $this->process->execute($command, $ignoredOutput)) {
return;
}
$processError = 'Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput();
throw new \RuntimeException($processError);
}
$archiveFile = gzopen($file, 'rb');
$targetFile = fopen($targetFilepath, 'wb');
while ($string = gzread($archiveFile, 4096)) {
fwrite($targetFile, $string, strlen($string));
}
gzclose($archiveFile);
fclose($targetFile);
}
示例9: generateWindowsProxyCode
protected function generateWindowsProxyCode($bin, $link)
{
$binPath = $this->filesystem->findShortestPath($link, $bin);
if ('.bat' === substr($bin, -4)) {
$caller = 'call';
} else {
$handle = fopen($bin, 'r');
$line = fgets($handle);
fclose($handle);
if (preg_match('{^#!/(?:usr/bin/env )?(?:[^/]+/)*(.+)$}m', $line, $match)) {
$caller = trim($match[1]);
} else {
$caller = 'php';
}
if ($caller === 'php') {
return "@echo off\r\n" . "pushd .\r\n" . "cd %~dp0\r\n" . "set PHP_PROXY=%CD%\\composer-php.bat\r\n" . "cd " . ProcessExecutor::escape(dirname($binPath)) . "\r\n" . "set BIN_TARGET=%CD%\\" . basename($binPath) . "\r\n" . "popd\r\n" . "%PHP_PROXY% \"%BIN_TARGET%\" %*\r\n";
}
}
return "@echo off\r\n" . "pushd .\r\n" . "cd %~dp0\r\n" . "cd " . ProcessExecutor::escape(dirname($binPath)) . "\r\n" . "set BIN_TARGET=%CD%\\" . basename($binPath) . "\r\n" . "popd\r\n" . $caller . " \"%BIN_TARGET%\" %*\r\n";
}
示例10: extract
protected function extract($file, $path)
{
$targetFilepath = $path . DIRECTORY_SEPARATOR . basename(substr($file, 0, -3));
// Try to use gunzip on *nix
if (!Platform::isWindows()) {
$command = 'gzip -cd ' . ProcessExecutor::escape($file) . ' > ' . ProcessExecutor::escape($targetFilepath);
if (0 === $this->process->execute($command, $ignoredOutput)) {
return;
}
if (extension_loaded('zlib')) {
// Fallback to using the PHP extension.
$this->extractUsingExt($file, $targetFilepath);
return;
}
$processError = 'Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput();
throw new \RuntimeException($processError);
}
// Windows version of PHP has built-in support of gzip functions
$this->extractUsingExt($file, $targetFilepath);
}
示例11: extract
protected function extract($file, $path)
{
$processError = null;
// Try to use unrar on *nix
if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
$command = 'unrar x ' . ProcessExecutor::escape($file) . ' ' . ProcessExecutor::escape($path) . ' && chmod -R u+w ' . ProcessExecutor::escape($path);
if (0 === $this->process->execute($command, $ignoredOutput)) {
return;
}
$processError = 'Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput();
}
if (!class_exists('RarArchive')) {
// php.ini path is added to the error message to help users find the correct file
$iniPath = php_ini_loaded_file();
if ($iniPath) {
$iniMessage = 'The php.ini used by your command-line PHP is: ' . $iniPath;
} else {
$iniMessage = 'A php.ini file does not exist. You will have to create one.';
}
$error = "Could not decompress the archive, enable the PHP rar extension or install unrar.\n" . $iniMessage . "\n" . $processError;
if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
$error = "Could not decompress the archive, enable the PHP rar extension.\n" . $iniMessage;
}
throw new \RuntimeException($error);
}
$rarArchive = RarArchive::open($file);
if (false === $rarArchive) {
throw new \UnexpectedValueException('Could not open RAR archive: ' . $file);
}
$entries = $rarArchive->getEntries();
if (false === $entries) {
throw new \RuntimeException('Could not retrieve RAR archive entries');
}
foreach ($entries as $entry) {
if (false === $entry->extract($path)) {
throw new \RuntimeException('Could not extract entry');
}
}
$rarArchive->close();
}
示例12: extract
protected function extract($file, $path)
{
$processError = null;
if (self::$hasSystemUnzip) {
$command = 'unzip ' . ProcessExecutor::escape($file) . ' -d ' . ProcessExecutor::escape($path);
if (!Platform::isWindows()) {
$command .= ' && chmod -R u+w ' . ProcessExecutor::escape($path);
}
try {
if (0 === $this->process->execute($command, $ignoredOutput)) {
return;
}
$processError = 'Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput();
} catch (\Exception $e) {
$processError = 'Failed to execute ' . $command . "\n\n" . $e->getMessage();
}
}
if (!class_exists('ZipArchive')) {
// php.ini path is added to the error message to help users find the correct file
$iniPath = php_ini_loaded_file();
if ($iniPath) {
$iniMessage = 'The php.ini used by your command-line PHP is: ' . $iniPath;
} else {
$iniMessage = 'A php.ini file does not exist. You will have to create one.';
}
$error = "Could not decompress the archive, enable the PHP zip extension or install unzip.\n" . $iniMessage . ($processError ? "\n" . $processError : '');
throw new \RuntimeException($error);
}
$zipArchive = new ZipArchive();
if (true !== ($retval = $zipArchive->open($file))) {
throw new \UnexpectedValueException(rtrim($this->getErrorMessage($retval, $file) . "\n" . $processError), $retval);
}
if (true !== $zipArchive->extractTo($path)) {
$this->io->writeError("<warn>As there is no 'unzip' command installed zip files are being unpacked using the PHP zip extension.</warn>");
$this->io->writeError("<warn>This may cause invalid reports of corrupted archives. Installing 'unzip' may remediate them.</warn>");
throw new \RuntimeException("There was an error extracting the ZIP file, it is either corrupted or using an invalid format");
}
$zipArchive->close();
}
示例13: extract
protected function extract($file, $path)
{
$processError = null;
// try to use unzip on *nix
if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
$command = 'unzip ' . ProcessExecutor::escape($file) . ' -d ' . ProcessExecutor::escape($path) . ' && chmod -R u+w ' . ProcessExecutor::escape($path);
try {
if (0 === $this->process->execute($command, $ignoredOutput)) {
return;
}
$processError = 'Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput();
} catch (\Exception $e) {
$processError = 'Failed to execute ' . $command . "\n\n" . $e->getMessage();
}
}
if (!class_exists('ZipArchive')) {
// php.ini path is added to the error message to help users find the correct file
$iniPath = php_ini_loaded_file();
if ($iniPath) {
$iniMessage = 'The php.ini used by your command-line PHP is: ' . $iniPath;
} else {
$iniMessage = 'A php.ini file does not exist. You will have to create one.';
}
$error = "Could not decompress the archive, enable the PHP zip extension or install unzip.\n" . $iniMessage . "\n" . $processError;
if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
$error = "Could not decompress the archive, enable the PHP zip extension.\n" . $iniMessage;
}
throw new \RuntimeException($error);
}
$zipArchive = new ZipArchive();
if (true !== ($retval = $zipArchive->open($file))) {
throw new \UnexpectedValueException($this->getErrorMessage($retval, $file), $retval);
}
if (true !== $zipArchive->extractTo($path)) {
throw new \RuntimeException("There was an error extracting the ZIP file. Corrupt file?");
}
$zipArchive->close();
}
示例14: setPushUrl
protected function setPushUrl($path, $url)
{
// set push url for github projects
if (preg_match('{^(?:https?|git)://' . GitUtil::getGitHubDomainsRegex($this->config) . '/([^/]+)/([^/]+?)(?:\\.git)?$}', $url, $match)) {
$protocols = $this->config->get('github-protocols');
$pushUrl = 'git@' . $match[1] . ':' . $match[2] . '/' . $match[3] . '.git';
if (!in_array('ssh', $protocols, true)) {
$pushUrl = 'https://' . $match[1] . '/' . $match[2] . '/' . $match[3] . '.git';
}
$cmd = sprintf('git remote set-url --push origin %s', ProcessExecutor::escape($pushUrl));
$this->process->execute($cmd, $ignoredOutput, $path);
}
}
示例15: supports
/**
* {@inheritDoc}
*/
public static function supports(IOInterface $io, Config $config, $url, $deep = false)
{
if (preg_match('#(^(?:https?|ssh)://(?:[^@]@)?bitbucket.org|https://(?:.*?)\\.kilnhg.com)#i', $url)) {
return true;
}
// local filesystem
if (Filesystem::isLocalPath($url)) {
$url = Filesystem::getPlatformPath($url);
if (!is_dir($url)) {
throw new \RuntimeException('Directory does not exist: ' . $url);
}
$process = new ProcessExecutor();
// check whether there is a hg repo in that path
if ($process->execute('hg summary', $output, $url) === 0) {
return true;
}
}
if (!$deep) {
return false;
}
$processExecutor = new ProcessExecutor();
$exit = $processExecutor->execute(sprintf('hg identify %s', ProcessExecutor::escape($url)), $ignored);
return $exit === 0;
}