Add some phpdocs
parent
5d2b3276eb
commit
788a822b24
|
@ -308,6 +308,10 @@ class PlatformRepository extends ArrayRepository
|
||||||
$this->addPackage($ext);
|
$this->addPackage($ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
private function buildPackageName($name)
|
private function buildPackageName($name)
|
||||||
{
|
{
|
||||||
return 'ext-' . str_replace(' ', '-', $name);
|
return 'ext-' . str_replace(' ', '-', $name);
|
||||||
|
|
|
@ -30,7 +30,11 @@ class AuthHelper
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function storeAuth($originUrl, $storeAuth)
|
/**
|
||||||
|
* @param string $origin
|
||||||
|
* @param string|bool $storeAuth
|
||||||
|
*/
|
||||||
|
public function storeAuth($origin, $storeAuth)
|
||||||
{
|
{
|
||||||
$store = false;
|
$store = false;
|
||||||
$configSource = $this->config->getAuthConfigSource();
|
$configSource = $this->config->getAuthConfigSource();
|
||||||
|
@ -38,7 +42,7 @@ class AuthHelper
|
||||||
$store = $configSource;
|
$store = $configSource;
|
||||||
} elseif ($storeAuth === 'prompt') {
|
} elseif ($storeAuth === 'prompt') {
|
||||||
$answer = $this->io->askAndValidate(
|
$answer = $this->io->askAndValidate(
|
||||||
'Do you want to store credentials for '.$originUrl.' in '.$configSource->getName().' ? [Yn] ',
|
'Do you want to store credentials for '.$origin.' in '.$configSource->getName().' ? [Yn] ',
|
||||||
function ($value) {
|
function ($value) {
|
||||||
$input = strtolower(substr(trim($value), 0, 1));
|
$input = strtolower(substr(trim($value), 0, 1));
|
||||||
if (in_array($input, array('y','n'))) {
|
if (in_array($input, array('y','n'))) {
|
||||||
|
@ -56,14 +60,23 @@ class AuthHelper
|
||||||
}
|
}
|
||||||
if ($store) {
|
if ($store) {
|
||||||
$store->addConfigSetting(
|
$store->addConfigSetting(
|
||||||
'http-basic.'.$originUrl,
|
'http-basic.'.$origin,
|
||||||
$this->io->getAuthentication($originUrl)
|
$this->io->getAuthentication($origin)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
public function promptAuthIfNeeded($url, $origin, $httpStatus, $reason = null, $warning = null, $headers = array())
|
* @param string $url
|
||||||
|
* @param string $origin
|
||||||
|
* @param int $statusCode HTTP status code that triggered this call
|
||||||
|
* @param string|null $reason a message/description explaining why this was called
|
||||||
|
* @param string $warning an authentication warning returned by the server as {"warning": ".."}, if present
|
||||||
|
* @param string[] $headers
|
||||||
|
* @return array containing retry (bool) and storeAuth (string|bool) keys, if retry is true the request should be
|
||||||
|
* retried, if storeAuth is true then on a successful retry the authentication should be persisted to auth.json
|
||||||
|
*/
|
||||||
|
public function promptAuthIfNeeded($url, $origin, $statusCode, $reason = null, $warning = null, $headers = array())
|
||||||
{
|
{
|
||||||
$storeAuth = false;
|
$storeAuth = false;
|
||||||
$retry = false;
|
$retry = false;
|
||||||
|
@ -101,11 +114,11 @@ class AuthHelper
|
||||||
throw new TransportException('Could not authenticate against '.$origin, 401);
|
throw new TransportException('Could not authenticate against '.$origin, 401);
|
||||||
}
|
}
|
||||||
} elseif (in_array($origin, $this->config->get('gitlab-domains'), true)) {
|
} elseif (in_array($origin, $this->config->get('gitlab-domains'), true)) {
|
||||||
$message = "\n".'Could not fetch '.$url.', enter your ' . $origin . ' credentials ' .($httpStatus === 401 ? 'to access private repos' : 'to go over the API rate limit');
|
$message = "\n".'Could not fetch '.$url.', enter your ' . $origin . ' credentials ' .($statusCode === 401 ? 'to access private repos' : 'to go over the API rate limit');
|
||||||
$gitLabUtil = new GitLab($this->io, $this->config, null);
|
$gitLabUtil = new GitLab($this->io, $this->config, null);
|
||||||
|
|
||||||
if ($this->io->hasAuthentication($origin) && ($auth = $this->io->getAuthentication($origin)) && $auth['password'] === 'private-token') {
|
if ($this->io->hasAuthentication($origin) && ($auth = $this->io->getAuthentication($origin)) && $auth['password'] === 'private-token') {
|
||||||
throw new TransportException("Invalid credentials for '" . $url . "', aborting.", $httpStatus);
|
throw new TransportException("Invalid credentials for '" . $url . "', aborting.", $statusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$gitLabUtil->authorizeOAuth($origin)
|
if (!$gitLabUtil->authorizeOAuth($origin)
|
||||||
|
@ -130,7 +143,7 @@ class AuthHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($askForOAuthToken) {
|
if ($askForOAuthToken) {
|
||||||
$message = "\n".'Could not fetch ' . $url . ', please create a bitbucket OAuth token to ' . (($httpStatus === 401 || $httpStatus === 403) ? 'access private repos' : 'go over the API rate limit');
|
$message = "\n".'Could not fetch ' . $url . ', please create a bitbucket OAuth token to ' . (($statusCode === 401 || $statusCode === 403) ? 'access private repos' : 'go over the API rate limit');
|
||||||
$bitBucketUtil = new Bitbucket($this->io, $this->config);
|
$bitBucketUtil = new Bitbucket($this->io, $this->config);
|
||||||
if (! $bitBucketUtil->authorizeOAuth($origin)
|
if (! $bitBucketUtil->authorizeOAuth($origin)
|
||||||
&& (! $this->io->isInteractive() || !$bitBucketUtil->authorizeOAuthInteractively($origin, $message))
|
&& (! $this->io->isInteractive() || !$bitBucketUtil->authorizeOAuthInteractively($origin, $message))
|
||||||
|
@ -140,24 +153,24 @@ class AuthHelper
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 404s are only handled for github
|
// 404s are only handled for github
|
||||||
if ($httpStatus === 404) {
|
if ($statusCode === 404) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// fail if the console is not interactive
|
// fail if the console is not interactive
|
||||||
if (!$this->io->isInteractive()) {
|
if (!$this->io->isInteractive()) {
|
||||||
if ($httpStatus === 401) {
|
if ($statusCode === 401) {
|
||||||
$message = "The '" . $url . "' URL required authentication.\nYou must be using the interactive console to authenticate";
|
$message = "The '" . $url . "' URL required authentication.\nYou must be using the interactive console to authenticate";
|
||||||
}
|
}
|
||||||
if ($httpStatus === 403) {
|
if ($statusCode === 403) {
|
||||||
$message = "The '" . $url . "' URL could not be accessed: " . $reason;
|
$message = "The '" . $url . "' URL could not be accessed: " . $reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new TransportException($message, $httpStatus);
|
throw new TransportException($message, $statusCode);
|
||||||
}
|
}
|
||||||
// fail if we already have auth
|
// fail if we already have auth
|
||||||
if ($this->io->hasAuthentication($origin)) {
|
if ($this->io->hasAuthentication($origin)) {
|
||||||
throw new TransportException("Invalid credentials for '" . $url . "', aborting.", $httpStatus);
|
throw new TransportException("Invalid credentials for '" . $url . "', aborting.", $statusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->io->overwriteError('');
|
$this->io->overwriteError('');
|
||||||
|
@ -176,6 +189,12 @@ class AuthHelper
|
||||||
return array('retry' => $retry, 'storeAuth' => $storeAuth);
|
return array('retry' => $retry, 'storeAuth' => $storeAuth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $headers
|
||||||
|
* @param string $origin
|
||||||
|
* @param string $url
|
||||||
|
* @return array updated headers array
|
||||||
|
*/
|
||||||
public function addAuthenticationHeader(array $headers, $origin, $url)
|
public function addAuthenticationHeader(array $headers, $origin, $url)
|
||||||
{
|
{
|
||||||
if ($this->io->hasAuthentication($origin)) {
|
if ($this->io->hasAuthentication($origin)) {
|
||||||
|
|
|
@ -19,6 +19,12 @@ use Composer\Config;
|
||||||
*/
|
*/
|
||||||
class Url
|
class Url
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param Config $config
|
||||||
|
* @param string $url
|
||||||
|
* @param string $ref
|
||||||
|
* @return string the updated URL
|
||||||
|
*/
|
||||||
public static function updateDistReference(Config $config, $url, $ref)
|
public static function updateDistReference(Config $config, $url, $ref)
|
||||||
{
|
{
|
||||||
$host = parse_url($url, PHP_URL_HOST);
|
$host = parse_url($url, PHP_URL_HOST);
|
||||||
|
@ -53,6 +59,10 @@ class Url
|
||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $url
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public static function getOrigin(Config $config, $url)
|
public static function getOrigin(Config $config, $url)
|
||||||
{
|
{
|
||||||
if (0 === strpos($url, 'file://')) {
|
if (0 === strpos($url, 'file://')) {
|
||||||
|
@ -89,5 +99,4 @@ class Url
|
||||||
|
|
||||||
return $origin;
|
return $origin;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue