本文整理汇总了PHP中Composer\Config::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Config::get方法的具体用法?PHP Config::get怎么用?PHP Config::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Composer\Config
的用法示例。
在下文中一共展示了Config::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct(SVNRepositoryConfig $repoConfig, IOInterface $io, Config $config)
{
// @TODO: add event dispatcher?
$this->repoConfig = $repoConfig;
$this->plugin = $repoConfig->getPlugin();
// check url immediately - can't do anything without it
$urls = [];
foreach ((array) $repoConfig->get('url') as $url) {
if (($urlParts = parse_url($url)) === false || empty($urlParts['scheme'])) {
continue;
}
// untrailingslashit
$urls[] = rtrim($url, '/');
}
if (!count($urls)) {
throw new \UnexpectedValueException('No valid URLs for SVN repository: ' . print_r($repoConfig->get('url'), true));
}
$repoConfig->set('url', $urls);
// use the cache TTL from the config?
if ($repoConfig->get('cache-ttl') === 'config') {
$repoConfig->set('cache-ttl', $config->get('cache-files-ttl'));
}
$this->io = $io;
$this->cache = new Cache($io, $config->get('cache-repo-dir') . '/' . preg_replace('{[^a-z0-9.]}i', '-', reset($urls)));
$this->loader = new ArrayLoader();
// clear out stale cache
$this->cache->gc($repoConfig->get('cache-ttl'), $config->get('cache-files-maxsize'));
$this->vendors = $repoConfig->get('vendors');
$this->defaultVendor = key($this->vendors);
// create an SvnUtil to execute commands
$this->svnUtil = new SvnUtil($io, $repoConfig->get('trust-cert'));
}
示例2: getHttpGetRequest
/**
* @param string $origin domain text
* @param string $url
* @param IO\IOInterface $io
* @param CConfig $config
* @param array $pluginConfig
* @return Aspects\HttpGetRequest
*/
public static function getHttpGetRequest($origin, $url, IO\IOInterface $io, CConfig $config, array $pluginConfig)
{
if (substr($origin, -10) === 'github.com') {
$origin = 'github.com';
$requestClass = 'GitHub';
} elseif (in_array($origin, $config->get('github-domains') ?: array())) {
$requestClass = 'GitHub';
} elseif (in_array($origin, $config->get('gitlab-domains') ?: array())) {
$requestClass = 'GitLab';
} else {
$requestClass = 'HttpGet';
}
$requestClass = __NAMESPACE__ . '\\Aspects\\' . $requestClass . 'Request';
$request = new $requestClass($origin, $url, $io);
$request->verbose = $pluginConfig['verbose'];
if ($pluginConfig['insecure']) {
$request->curlOpts[CURLOPT_SSL_VERIFYPEER] = false;
}
if (!empty($pluginConfig['capath'])) {
$request->curlOpts[CURLOPT_CAPATH] = $pluginConfig['capath'];
}
if (!empty($pluginConfig['userAgent'])) {
$request->curlOpts[CURLOPT_USERAGENT] = $pluginConfig['userAgent'];
}
return $request;
}
示例3: __construct
/**
* @param string $url
* @param string $destination
* @param bool $useRedirector
* @param IO\IOInterface $io
* @param Config $config
*/
public function __construct($url, $destination, $useRedirector, IO\IOInterface $io, Config $config)
{
$this->setURL($url);
$this->setDestination($destination);
$this->setCA($config->get('capath'), $config->get('cafile'));
$this->setupAuthentication($io, $useRedirector, $config->get('github-domains') ?: array(), $config->get('gitlab-domains') ?: array());
}
示例4: loadConfiguration
/**
* {@inheritDoc}
*/
public function loadConfiguration(Config $config)
{
$bitbucketOauth = $config->get('bitbucket-oauth') ?: array();
$githubOauth = $config->get('github-oauth') ?: array();
$gitlabOauth = $config->get('gitlab-oauth') ?: array();
$gitlabToken = $config->get('gitlab-token') ?: array();
$httpBasic = $config->get('http-basic') ?: array();
// reload oauth tokens from config if available
foreach ($bitbucketOauth as $domain => $cred) {
$this->checkAndSetAuthentication($domain, $cred['consumer-key'], $cred['consumer-secret']);
}
foreach ($githubOauth as $domain => $token) {
if (!preg_match('{^[a-z0-9]+$}', $token)) {
throw new \UnexpectedValueException('Your github oauth token for ' . $domain . ' contains invalid characters: "' . $token . '"');
}
$this->checkAndSetAuthentication($domain, $token, 'x-oauth-basic');
}
foreach ($gitlabOauth as $domain => $token) {
$this->checkAndSetAuthentication($domain, $token, 'oauth2');
}
foreach ($gitlabToken as $domain => $token) {
$this->checkAndSetAuthentication($domain, $token, 'private-token');
}
// reload http basic credentials from config if available
foreach ($httpBasic as $domain => $cred) {
$this->checkAndSetAuthentication($domain, $cred['username'], $cred['password']);
}
// setup process timeout
ProcessExecutor::setTimeout((int) $config->get('process-timeout'));
}
示例5: loadConfiguration
/**
* {@inheritDoc}
*/
public function loadConfiguration(Config $config)
{
// reload oauth token from config if available
if ($tokens = $config->get('github-oauth')) {
foreach ($tokens as $domain => $token) {
if (!preg_match('{^[a-z0-9]+$}', $token)) {
throw new \UnexpectedValueException('Your github oauth token for ' . $domain . ' contains invalid characters: "' . $token . '"');
}
$this->setAuthentication($domain, $token, 'x-oauth-basic');
}
}
if ($tokens = $config->get('gitlab-oauth')) {
foreach ($tokens as $domain => $token) {
$this->setAuthentication($domain, $token, 'oauth2');
}
}
// reload http basic credentials from config if available
if ($creds = $config->get('http-basic')) {
foreach ($creds as $domain => $cred) {
$this->setAuthentication($domain, $cred['username'], $cred['password']);
}
}
// setup process timeout
ProcessExecutor::setTimeout((int) $config->get('process-timeout'));
}
示例6: getClassmap
public function getClassmap() : \Traversable
{
$filesystem = new Filesystem();
$vendorPath = $filesystem->normalizePath(realpath($this->config->get('vendor-dir')));
$classmapPath = $vendorPath . '/composer/autoload_classmap.php';
if (!is_file($classmapPath)) {
throw new \RuntimeException('Th dumped classmap does not exists. Try to run `composer dump-autoload --optimize` first.');
}
yield from (include $vendorPath . '/composer/autoload_classmap.php');
}
示例7: __construct
public function __construct(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null, Cache $cache = null, RemoteFilesystem $rfs = null, Filesystem $filesystem = null)
{
$this->io = $io;
$this->config = $config;
$this->eventDispatcher = $eventDispatcher;
$this->rfs = $rfs ?: new RemoteFilesystem($io);
$this->filesystem = $filesystem ?: new Filesystem();
$this->cache = $cache;
if ($this->cache && $this->cache->gcIsNecessary()) {
$this->cache->gc($config->get('cache-files-ttl'), $config->get('cache-files-maxsize'));
}
}
示例8: __construct
/**
* Constructor.
*
* @param IOInterface $io The IO instance
* @param Config $config The config
* @param Cache $cache Optional cache instance
* @param RemoteFilesystem $rfs The remote filesystem
* @param Filesystem $filesystem The filesystem
*/
public function __construct(IOInterface $io, Config $config, Cache $cache = null, RemoteFilesystem $rfs = null, Filesystem $filesystem = null)
{
$this->io = $io;
$this->config = $config;
$this->rfs = $rfs ?: new RemoteFilesystem($io);
$this->filesystem = $filesystem ?: new Filesystem();
$this->cache = $cache;
if ($this->cache && !self::$cacheCollected && !mt_rand(0, 50)) {
$this->cache->gc($config->get('cache-ttl'), $config->get('cache-files-maxsize'));
}
self::$cacheCollected = true;
}
示例9: init
/**
* {@inheritdoc}
*/
public function init()
{
// Retrieve the configuration variables.
$this->config = $this->composer->getConfig();
if (isset($this->config)) {
if ($this->config->has('component-dir')) {
$this->componentDir = $this->config->get('component-dir');
}
}
// Get the available packages.
$allPackages = array();
/** @var \Composer\Package\Locker $locker */
$locker = $this->composer->getLocker();
if ($locker !== null && $locker->isLocked()) {
$lockData = $locker->getLockData();
$allPackages = $lockData['packages'];
// Also merge in any of the development packages.
$dev = isset($lockData['packages-dev']) ? $lockData['packages-dev'] : array();
foreach ($dev as $package) {
$allPackages[] = $package;
}
}
// Only add those packages that we can reasonably
// assume are components into our packages list
/** @var \Composer\Package\RootPackageInterface $rootPackage */
$rootPackage = $this->composer->getPackage();
$rootExtras = $rootPackage ? $rootPackage->getExtra() : array();
$customComponents = isset($rootExtras['component']) ? $rootExtras['component'] : array();
foreach ($allPackages as $package) {
$name = $package['name'];
if (isset($customComponents[$name]) && is_array($customComponents[$name])) {
$package['extra'] = array('component' => $customComponents[$name]);
$this->packages[] = $package;
} else {
$extra = isset($package['extra']) ? $package['extra'] : array();
if (isset($extra['component']) && is_array($extra['component'])) {
$this->packages[] = $package;
}
}
}
// Add the root package to the packages list.
$root = $this->composer->getPackage();
if ($root) {
$dumper = new ArrayDumper();
$package = $dumper->dump($root);
$package['is-root'] = true;
$this->packages[] = $package;
}
return true;
}
示例10: loadConfiguration
public function loadConfiguration(Config $config)
{
if ($tokens = $config->get('github-oauth')) {
foreach ($tokens as $domain => $token) {
if (!preg_match('{^[a-z0-9]+$}', $token)) {
throw new \UnexpectedValueException('Your github oauth token for ' . $domain . ' contains invalid characters: "' . $token . '"');
}
$this->setAuthentication($domain, $token, 'x-oauth-basic');
}
}
if ($creds = $config->get('http-basic')) {
foreach ($creds as $domain => $cred) {
$this->setAuthentication($domain, $cred['username'], $cred['password']);
}
}
}
示例11: testRedirectUrlRepositoryWithCache
/**
* @dataProvider getAssetTypes
*
* @param string $type
* @param string $filename
*/
public function testRedirectUrlRepositoryWithCache($type, $filename)
{
$originUrl = 'github.com';
$owner = 'composer-test';
$repository = 'repo-name';
$repoUrl = 'http://' . $originUrl . '/' . $owner . '/' . $repository;
$repoApiUrl = 'https://api.github.com/repos/composer-test/repo-name';
$repoApiUrlNew = $repoApiUrl . '-new';
$packageName = $type . '-asset/repo-name';
$identifier = 'v0.0.0';
$sha = 'SOMESHA';
$io = $this->getMockBuilder('Composer\\IO\\IOInterface')->getMock();
$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($repoApiUrlNew), $this->equalTo(false))->will($this->returnValue($this->createJsonComposer(array('master_branch' => 'test_master'))));
$repoConfig = array('url' => $repoUrl, 'asset-type' => $type, 'filename' => $filename, 'package-name' => $packageName);
$repoUrl = 'https://github.com/composer-test/repo-name.git';
/* @var IOInterface $io */
/* @var RemoteFilesystem $remoteFilesystem */
$cache = new Cache($io, $this->config->get('cache-repo-dir') . '/' . $originUrl . '/' . $owner . '/' . $repository);
$cache->write('redirect-api', $repoApiUrlNew);
$gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, null, $remoteFilesystem);
$gitHubDriver->initialize();
$this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha));
$this->assertEquals('test_master', $gitHubDriver->getRootIdentifier());
$dist = $gitHubDriver->getDist($sha);
$this->assertEquals('zip', $dist['type']);
$this->assertEquals('https://api.github.com/repos/composer-test/repo-name/zipball/SOMESHA', $dist['url']);
$this->assertEquals($sha, $dist['reference']);
$source = $gitHubDriver->getSource($sha);
$this->assertEquals('git', $source['type']);
$this->assertEquals($repoUrl, $source['url']);
$this->assertEquals($sha, $source['reference']);
}
示例12: __construct
public function __construct(array $repoConfig, IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null)
{
if (!preg_match('{^[\\w.]+\\??://}', $repoConfig['url'])) {
// assume http as the default protocol
$repoConfig['url'] = 'http://' . $repoConfig['url'];
}
$repoConfig['url'] = rtrim($repoConfig['url'], '/');
if ('https?' === substr($repoConfig['url'], 0, 6)) {
$repoConfig['url'] = (extension_loaded('openssl') ? 'https' : 'http') . substr($repoConfig['url'], 6);
}
$urlBits = parse_url($repoConfig['url']);
if ($urlBits === false || empty($urlBits['scheme'])) {
throw new \UnexpectedValueException('Invalid url given for Composer repository: ' . $repoConfig['url']);
}
if (!isset($repoConfig['options'])) {
$repoConfig['options'] = array();
}
if (isset($repoConfig['allow_ssl_downgrade']) && true === $repoConfig['allow_ssl_downgrade']) {
$this->allowSslDowngrade = true;
}
$this->config = $config;
$this->options = $repoConfig['options'];
$this->url = $repoConfig['url'];
$this->baseUrl = rtrim(preg_replace('{^(.*)(?:/packages.json)?(?:[?#].*)?$}', '$1', $this->url), '/');
$this->io = $io;
$this->cache = new Cache($io, $config->get('cache-repo-dir') . '/' . preg_replace('{[^a-z0-9.]}i', '-', $this->url), 'a-z0-9.$');
$this->loader = new ArrayLoader();
$this->rfs = new RemoteFilesystem($this->io, $this->config, $this->options);
$this->eventDispatcher = $eventDispatcher;
}
示例13: scan
/**
* @return string[]
*/
public function scan()
{
$parameters = ['command' => 'dump-autoload', '--no-interaction' => true, '--working-dir' => $this->directory, '--optimize' => true, '--no-dev' => true];
$this->createComposerApplication()->run(new ArrayInput($parameters), $this->output);
$config = new Config(true, $this->directory);
return require $config->get('vendor-dir') . '/composer/autoload_classmap.php';
}
示例14: testOverrideGithubProtocols
public function testOverrideGithubProtocols()
{
$config = new Config(false);
$config->merge(array('config' => array('github-protocols' => array('https', 'git'))));
$config->merge(array('config' => array('github-protocols' => array('https'))));
$this->assertEquals(array('https'), $config->get('github-protocols'));
}
示例15: has
/**
* Search for a given package version.
*
* Usage examples : Composition::has('php', '5.3.*') // PHP version
* Composition::has('ext-memcache') // PHP extension
* Composition::has('vendor/package', '>2.1') // Package version
*
* @param type $packageName The package name
* @param type $prettyString An optional version constraint
*
* @return boolean Wether or not the package has been found.
*/
public static function has($packageName, $prettyString = '*')
{
if (null === self::$pool) {
if (null === self::$rootDir) {
self::$rootDir = getcwd();
if (!file_exists(self::$rootDir . '/composer.json')) {
throw new \RuntimeException('Unable to guess the project root dir, please specify it manually using the Composition::setRootDir method.');
}
}
$minimumStability = 'dev';
$config = new Config();
$file = new JsonFile(self::$rootDir . '/composer.json');
if ($file->exists()) {
$projectConfig = $file->read();
$config->merge($projectConfig);
if (isset($projectConfig['minimum-stability'])) {
$minimumStability = $projectConfig['minimum-stability'];
}
}
$vendorDir = self::$rootDir . '/' . $config->get('vendor-dir');
$pool = new Pool($minimumStability);
$pool->addRepository(new PlatformRepository());
$pool->addRepository(new InstalledFilesystemRepository(new JsonFile($vendorDir . '/composer/installed.json')));
$pool->addRepository(new InstalledFilesystemRepository(new JsonFile($vendorDir . '/composer/installed_dev.json')));
self::$pool = $pool;
}
$parser = new VersionParser();
$constraint = $parser->parseConstraints($prettyString);
$packages = self::$pool->whatProvides($packageName, $constraint);
return empty($packages) ? false : true;
}