本文整理汇总了PHP中Composer\Config::setAuthConfigSource方法的典型用法代码示例。如果您正苦于以下问题:PHP Config::setAuthConfigSource方法的具体用法?PHP Config::setAuthConfigSource怎么用?PHP Config::setAuthConfigSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Composer\Config
的用法示例。
在下文中一共展示了Config::setAuthConfigSource方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createConfig
public static function createConfig(IOInterface $io = null, $cwd = null)
{
$cwd = $cwd ?: getcwd();
$home = self::getHomeDir();
$cacheDir = self::getCacheDir($home);
foreach (array($home, $cacheDir) as $dir) {
if (!file_exists($dir . '/.htaccess')) {
if (!is_dir($dir)) {
@mkdir($dir, 0777, true);
}
@file_put_contents($dir . '/.htaccess', 'Deny from all');
}
}
$config = new Config(true, $cwd);
$config->merge(array('config' => array('home' => $home, 'cache-dir' => $cacheDir)));
$file = new JsonFile($config->get('home') . '/config.json');
if ($file->exists()) {
if ($io && $io->isDebug()) {
$io->writeError('Loading config file ' . $file->getPath());
}
$config->merge($file->read());
}
$config->setConfigSource(new JsonConfigSource($file));
$file = new JsonFile($config->get('home') . '/auth.json');
if ($file->exists()) {
if ($io && $io->isDebug()) {
$io->writeError('Loading config file ' . $file->getPath());
}
$config->merge(array('config' => $file->read()));
}
$config->setAuthConfigSource(new JsonConfigSource($file, true));
return $config;
}
示例2: testRedirectUrlWithNonexistentRepository
/**
* @dataProvider getAssetTypes
*/
public function testRedirectUrlWithNonexistentRepository($type, $filename)
{
$this->setExpectedException('RuntimeException');
$repoUrl = 'http://github.com/composer-test/repo-name';
$repoApiUrl = 'https://api.github.com/repos/composer-test/repo-name';
$identifier = 'v0.0.0';
$io = $this->getMock('Composer\\IO\\IOInterface');
$io->expects($this->any())->method('isInteractive')->will($this->returnValue(true));
$remoteFilesystem = $this->getMockBuilder('Composer\\Util\\RemoteFilesystem')->setConstructorArgs(array($io))->getMock();
$remoteFilesystem->expects($this->at(0))->method('getContents')->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false))->will($this->throwException(new TransportException('HTTP/1.1 404 Not Found', 404)));
$io->expects($this->once())->method('ask')->with($this->equalTo('Username: '))->will($this->returnValue('someuser'));
$io->expects($this->once())->method('askAndHideAnswer')->with($this->equalTo('Password: '))->will($this->returnValue('somepassword'));
$io->expects($this->any())->method('setAuthentication')->with($this->equalTo('github.com'), $this->matchesRegularExpression('{someuser|abcdef}'), $this->matchesRegularExpression('{somepassword|x-oauth-basic}'));
$remoteFilesystem->expects($this->at(1))->method('getContents')->with($this->equalTo('github.com'), $this->equalTo('https://github.com/composer-test/repo-name'), $this->equalTo(false))->will($this->throwException(new TransportException('HTTP/1.1 404 Not Found', 404)));
$remoteFilesystem->expects($this->at(2))->method('getContents')->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false))->will($this->throwException(new TransportException('HTTP/1.1 404 Not Found', 404)));
$remoteFilesystem->expects($this->at(3))->method('getContents')->with($this->equalTo('github.com'), $this->equalTo('https://api.github.com/authorizations'), $this->equalTo(false))->will($this->returnValue('[]'));
$remoteFilesystem->expects($this->at(4))->method('getContents')->with($this->equalTo('github.com'), $this->equalTo('https://api.github.com/authorizations'), $this->equalTo(false))->will($this->returnValue('{"token": "abcdef"}'));
$remoteFilesystem->expects($this->at(5))->method('getContents')->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false))->will($this->throwException(new TransportException('HTTP/1.1 404 Not Found', 404)));
$remoteFilesystem->expects($this->at(6))->method('getContents')->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl . '/contents/' . $filename . '?ref=' . $identifier), $this->equalTo(false))->will($this->throwException(new TransportException('HTTP/1.1 404 Not Found', 404)));
$configSource = $this->getMock('Composer\\Config\\ConfigSourceInterface');
$authConfigSource = $this->getMock('Composer\\Config\\ConfigSourceInterface');
/* @var ConfigSourceInterface $configSource */
/* @var ConfigSourceInterface $authConfigSource */
$this->config->setConfigSource($configSource);
$this->config->setAuthConfigSource($authConfigSource);
$repoConfig = array('url' => $repoUrl, 'asset-type' => $type, 'filename' => $filename);
/* @var IOInterface $io */
/* @var RemoteFilesystem $remoteFilesystem */
$gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, null, $remoteFilesystem);
$firstNonexistent = false;
try {
$gitHubDriver->initialize();
} catch (TransportException $e) {
$firstNonexistent = true;
}
$this->assertTrue($firstNonexistent);
$gitHubDriver->getComposerInformation($identifier);
}
示例3: getConfiguration
/**
* @return Config
*/
private function getConfiguration()
{
$config = new Config();
// add dir to the config
$config->merge(array('config' => array('home' => $this->getComposerHome())));
// load global auth file
$file = new JsonFile($config->get('home') . '/auth.json');
if ($file->exists()) {
$config->merge(array('config' => $file->read()));
}
$config->setAuthConfigSource(new JsonConfigSource($file, true));
return $config;
}
示例4: createConfig
/**
* @param IOInterface|null $io
* @return Config
*/
public static function createConfig(IOInterface $io = null, $cwd = null)
{
$cwd = $cwd ?: getcwd();
$config = new Config(true, $cwd);
// determine and add main dirs to the config
$home = self::getHomeDir();
$config->merge(array('config' => array('home' => $home, 'cache-dir' => self::getCacheDir($home), 'data-dir' => self::getDataDir($home))));
// Protect directory against web access. Since HOME could be
// the www-data's user home and be web-accessible it is a
// potential security risk
$dirs = array($config->get('home'), $config->get('cache-dir'), $config->get('data-dir'));
foreach ($dirs as $dir) {
if (!file_exists($dir . '/.htaccess')) {
if (!is_dir($dir)) {
Silencer::call('mkdir', $dir, 0777, true);
}
Silencer::call('file_put_contents', $dir . '/.htaccess', 'Deny from all');
}
}
// load global config
$file = new JsonFile($config->get('home') . '/config.json');
if ($file->exists()) {
if ($io && $io->isDebug()) {
$io->writeError('Loading config file ' . $file->getPath());
}
$config->merge($file->read());
}
$config->setConfigSource(new JsonConfigSource($file));
// load global auth file
$file = new JsonFile($config->get('home') . '/auth.json');
if ($file->exists()) {
if ($io && $io->isDebug()) {
$io->writeError('Loading config file ' . $file->getPath());
}
$config->merge(array('config' => $file->read()));
}
$config->setAuthConfigSource(new JsonConfigSource($file, true));
// load COMPOSER_AUTH environment variable if set
if ($composerAuthEnv = getenv('COMPOSER_AUTH')) {
$authData = json_decode($composerAuthEnv, true);
if (is_null($authData)) {
throw new \UnexpectedValueException('COMPOSER_AUTH environment variable is malformed, should be a valid JSON object');
}
if ($io && $io->isDebug()) {
$io->writeError('Loading auth config from COMPOSER_AUTH');
}
$config->merge(array('config' => $authData));
}
return $config;
}
示例5: createConfig
/**
* @param IOInterface|null $io
* @return Config
*/
public static function createConfig(IOInterface $io = null, $cwd = null)
{
$cwd = $cwd ?: getcwd();
// determine home and cache dirs
$home = self::getHomeDir();
$cacheDir = self::getCacheDir($home);
$dataDir = self::getDataDir($home);
// Protect directory against web access. Since HOME could be
// the www-data's user home and be web-accessible it is a
// potential security risk
foreach (array($home, $cacheDir, $dataDir) as $dir) {
if (!file_exists($dir . '/.htaccess')) {
if (!is_dir($dir)) {
@mkdir($dir, 0777, true);
}
@file_put_contents($dir . '/.htaccess', 'Deny from all');
}
}
$config = new Config(true, $cwd);
// add dirs to the config
$config->merge(array('config' => array('home' => $home, 'cache-dir' => $cacheDir, 'data-dir' => $dataDir)));
// load global config
$file = new JsonFile($config->get('home') . '/config.json');
if ($file->exists()) {
if ($io && $io->isDebug()) {
$io->writeError('Loading config file ' . $file->getPath());
}
$config->merge($file->read());
}
$config->setConfigSource(new JsonConfigSource($file));
// load global auth file
$file = new JsonFile($config->get('home') . '/auth.json');
if ($file->exists()) {
if ($io && $io->isDebug()) {
$io->writeError('Loading config file ' . $file->getPath());
}
$config->merge(array('config' => $file->read()));
}
$config->setAuthConfigSource(new JsonConfigSource($file, true));
return $config;
}