/home/techb158/ileadtechnology.com/vendor/composer/composer/src/Composer/Util
NameSizeModeActions
AuthHelper.php16950644editdlrm
Bitbucket.php85870644editdlrm
ComposerMirror.php17870644editdlrm
ConfigValidator.php86170644editdlrm
ErrorHandler.php28190644editdlrm
Filesystem.php223240644editdlrm
Git.php184220644editdlrm
GitHub.php60600644editdlrm
GitLab.php64010644editdlrm
Hg.php28820644editdlrm
IniHelper.php16320644editdlrm
NoProxyPattern.php106830644editdlrm
PackageSorter.php24600644editdlrm
Perforce.php175090644editdlrm
Platform.php26000644editdlrm
ProcessExecutor.php63580644editdlrm
RemoteFilesystem.php477310644editdlrm
Silencer.php21660644editdlrm
SpdxLicense.php5700644editdlrm
StreamContextFactory.php72950644editdlrm
Svn.php100440644editdlrm
TlsHelper.php66240644editdlrm
Url.php29040644editdlrm
Zip.php29580644editdlrm
Edit: /home/techb158/ileadtechnology.com/vendor/composer/composer/src/Composer/Util/GitHub.php (6060B)
* Jordi Boggiano * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Composer\Util; use Composer\Factory; use Composer\IO\IOInterface; use Composer\Config; use Composer\Downloader\TransportException; /** * @author Jordi Boggiano */ class GitHub { protected $io; protected $config; protected $process; protected $remoteFilesystem; /** * Constructor. * * @param IOInterface $io The IO instance * @param Config $config The composer configuration * @param ProcessExecutor $process Process instance, injectable for mocking * @param RemoteFilesystem $remoteFilesystem Remote Filesystem, injectable for mocking */ public function __construct(IOInterface $io, Config $config, ProcessExecutor $process = null, RemoteFilesystem $remoteFilesystem = null) { $this->io = $io; $this->config = $config; $this->process = $process ?: new ProcessExecutor($io); $this->remoteFilesystem = $remoteFilesystem ?: Factory::createRemoteFilesystem($this->io, $config); } /** * Attempts to authorize a GitHub domain via OAuth * * @param string $originUrl The host this GitHub instance is located at * @return bool true on success */ public function authorizeOAuth($originUrl) { if (!in_array($originUrl, $this->config->get('github-domains'))) { return false; } // if available use token from git config if (0 === $this->process->execute('git config github.accesstoken', $output)) { $this->io->setAuthentication($originUrl, trim($output), 'x-oauth-basic'); return true; } return false; } /** * Authorizes a GitHub domain interactively via OAuth * * @param string $originUrl The host this GitHub instance is located at * @param string $message The reason this authorization is required * @throws \RuntimeException * @throws TransportException|\Exception * @return bool true on success */ public function authorizeOAuthInteractively($originUrl, $message = null) { if ($message) { $this->io->writeError($message); } $note = 'Composer'; if ($this->config->get('github-expose-hostname') === true && 0 === $this->process->execute('hostname', $output)) { $note .= ' on ' . trim($output); } $note .= ' ' . date('Y-m-d Hi'); $url = 'https://'.$originUrl.'/settings/tokens/new?scopes=repo&description=' . str_replace('%20', '+', rawurlencode($note)); $this->io->writeError(sprintf('Head to %s', $url)); $this->io->writeError(sprintf('to retrieve a token. It will be stored in "%s" for future use by Composer.', $this->config->getAuthConfigSource()->getName())); $token = trim($this->io->askAndHideAnswer('Token (hidden): ')); if (!$token) { $this->io->writeError('No token given, aborting.'); $this->io->writeError('You can also add it manually later by using "composer config --global --auth github-oauth.github.com "'); return false; } $this->io->setAuthentication($originUrl, $token, 'x-oauth-basic'); try { $apiUrl = ('github.com' === $originUrl) ? 'api.github.com/' : $originUrl . '/api/v3/'; $this->remoteFilesystem->getContents($originUrl, 'https://'. $apiUrl, false, array( 'retry-auth-failure' => false, )); } catch (TransportException $e) { if (in_array($e->getCode(), array(403, 401))) { $this->io->writeError('Invalid token provided.'); $this->io->writeError('You can also add it manually later by using "composer config --global --auth github-oauth.github.com "'); return false; } throw $e; } // store value in user config $this->config->getConfigSource()->removeConfigSetting('github-oauth.'.$originUrl); $this->config->getAuthConfigSource()->addConfigSetting('github-oauth.'.$originUrl, $token); $this->io->writeError('Token stored successfully.'); return true; } /** * Extract ratelimit from response. * * @param array $headers Headers from Composer\Downloader\TransportException. * * @return array Associative array with the keys limit and reset. */ public function getRateLimit(array $headers) { $rateLimit = array( 'limit' => '?', 'reset' => '?', ); foreach ($headers as $header) { $header = trim($header); if (false === strpos($header, 'X-RateLimit-')) { continue; } list($type, $value) = explode(':', $header, 2); switch ($type) { case 'X-RateLimit-Limit': $rateLimit['limit'] = (int) trim($value); break; case 'X-RateLimit-Reset': $rateLimit['reset'] = date('Y-m-d H:i:s', (int) trim($value)); break; } } return $rateLimit; } /** * Finds whether a request failed due to rate limiting * * @param array $headers Headers from Composer\Downloader\TransportException. * * @return bool */ public function isRateLimited(array $headers) { foreach ($headers as $header) { if (preg_match('{^X-RateLimit-Remaining: *0$}i', trim($header))) { return true; } } return false; } }