本文整理汇总了PHP中Composer\IO\IOInterface::overwrite方法的典型用法代码示例。如果您正苦于以下问题:PHP IOInterface::overwrite方法的具体用法?PHP IOInterface::overwrite怎么用?PHP IOInterface::overwrite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Composer\IO\IOInterface
的用法示例。
在下文中一共展示了IOInterface::overwrite方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: referencePackages
public function referencePackages(PackageSet $packageSet, IOInterface $io, $apiUrl = null)
{
if (!$apiUrl) {
$apiUrl = 'https://php-bach.org';
}
$apiUrlFormat = $apiUrl . '/p/%s.json';
//cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
/** @var Package $package */
foreach ($packageSet as $package) {
$packageName = $package->getPackageName();
$versionName = $package->getVersion();
$url = sprintf($apiUrlFormat, $packageName);
curl_setopt($ch, CURLOPT_URL, $url);
$response = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$message = '<info>Checking:</info> ' . $packageName . ' (' . $versionName . ') ...';
$io->write($message);
if ('200' === (string) $code) {
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
// ヘッダサイズ取得
$body = substr($response, $header_size);
// bodyだけ切り出し
if ($this->parseResponse($package, $body)) {
$io->overwrite('<info>Done.</info>');
} else {
$io->overwrite('<fg=white;bg=magenta>Version not found.</>');
}
} elseif ('404' === (string) $code) {
$io->overwrite('<fg=white;bg=magenta>Package not found.</>');
} else {
$io->overwriteError($message . '<error>Connection error.</error>');
}
}
curl_close($ch);
}
示例2: download
/**
* @param string $url URL of the archive on Amazon S3.
* @param bool $progress Show progress
* @param string $to Target file name
*
* @throws \Composer\Downloader\TransportException
*/
public function download($url, $progress, $to = null)
{
list($bucket, $key) = $this->determineBucketAndKey($url);
if ($progress) {
$this->io->write(" Downloading: <comment>connection...</comment>", false);
}
try {
$params = array('Bucket' => $bucket, 'Key' => $key);
if ($to) {
$params['command.response_body'] = \Guzzle\Http\EntityBody::factory(fopen($to, 'w+'));
}
$s3 = self::s3factory($this->config);
$result = $s3->getObject($params);
if ($progress) {
$this->io->overwrite(" Downloading: <comment>100%</comment>");
}
if ($to) {
if (false === file_exists($to) || !filesize($to)) {
$errorMessage = sprintf("Unknown error occurred: '%s' was not downloaded from '%s'.", $key, $url);
throw new TransportException($errorMessage);
}
} else {
return $result['Body'];
}
} catch (\Aws\Common\Exception\InstanceProfileCredentialsException $e) {
$msg = "Please add key/secret into config.json or set up an IAM profile for your EC2 instance.";
throw new TransportException($msg, 403, $e);
} catch (Aws\S3\Exception\S3Exception $e) {
throw new TransportException("Connection to Amazon S3 failed.", null, $e);
} catch (TransportException $e) {
throw $e;
// just re-throw
} catch (\Exception $e) {
throw new TransportException("Problem?", null, $e);
}
return $this;
}
示例3: load
/**
* {@inheritDoc}
*/
public function load(LazyPackageInterface $package)
{
if (isset($this->cache[$package->getUniqueName()])) {
return $this->cache[$package->getUniqueName()];
}
$this->validateConfig();
$filename = $this->assetType->getFilename();
$msg = 'Reading ' . $filename . ' of <info>' . $package->getName() . '</info> (<comment>' . $package->getPrettyVersion() . '</comment>)';
if ($this->verbose) {
$this->io->write($msg);
} else {
$this->io->overwrite($msg, false);
}
$realPackage = $this->loadRealPackage($package);
$this->cache[$package->getUniqueName()] = $realPackage;
if (!$this->verbose) {
$this->io->overwrite('', false);
}
return $realPackage;
}
示例4: promptAuth
public function promptAuth(HttpGetResponse $res, CConfig $config, IO\IOInterface $io)
{
$httpCode = $res->info['http_code'];
// 404s are only handled for github
if (404 === $httpCode) {
return false;
}
// fail if the console is not interactive
if (!$io->isInteractive()) {
switch ($httpCode) {
case 401:
$message = "The '{$this->getURL()}' URL required authentication.\nYou must be using the interactive console to authenticate";
break;
case 403:
$message = "The '{$this->getURL()}' URL could not be accessed.";
break;
}
throw new Downloader\TransportException($message, $httpCode);
}
// fail if we already have auth
if ($io->hasAuthentication($this->origin)) {
throw new Downloader\TransportException("Invalid credentials for '{$this->getURL()}', aborting.", $httpCode);
}
$io->overwrite(" Authentication required (<info>{$this->host}</info>):");
$username = $io->ask(' Username: ');
$password = $io->askAndHideAnswer(' Password: ');
$io->setAuthentication($this->origin, $username, $password);
return true;
}
示例5: runTask
/**
* @param string $message
* @param callable $task
*/
private static function runTask($message, callable $task)
{
self::$io->write(sprintf('<info> - [ ] %s</info>', $message), false);
$task();
self::$io->overwrite(sprintf('<info> - [x] %s</info>', $message), true);
}