本文整理汇总了PHP中Composer\Factory::createConfig方法的典型用法代码示例。如果您正苦于以下问题:PHP Factory::createConfig方法的具体用法?PHP Factory::createConfig怎么用?PHP Factory::createConfig使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Composer\Factory
的用法示例。
在下文中一共展示了Factory::createConfig方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
parent::setUp();
$factory = new Factory();
$this->manager = $factory->createArchiveManager($factory->createConfig());
$this->targetDir = $this->testDir . '/composer_archiver_tests';
}
示例2: __construct
/**
* @param string $url
* @param string $token
* @param bool $cacheDir
* @param null $bufferIO
*
* @throws \Exception
*/
public function __construct($url, $token = '', $cacheDir = false, $bufferIO = null)
{
$this->url = $url;
$this->io = new NullIO();
$this->log = $bufferIO ? $bufferIO : new BufferIO();
$config = Factory::createConfig();
$cfg = ['config' => []];
if ($cacheDir) {
$cfg['config']['cache-dir'] = $cacheDir;
}
if ($token) {
$cfg['config']['github-oauth'] = ['github.com' => $token];
}
$config->merge($cfg);
$this->cacheDir = $cacheDir;
$this->io->loadConfiguration($config);
$this->repository = new Repository\VcsRepository(['url' => $url, 'no-api' => false], $this->io, $config);
$driver = $this->vcsDriver = $this->repository->getDriver();
if (!$driver) {
throw new \Exception('No driver found for <' . $url . '>');
}
$this->driver = $driver;
$composerInfoMaster = $this->driver->getComposerInformation($this->driver->getRootIdentifier());
if (!$composerInfoMaster) {
throw new \Exception('master must have a valid composer.json');
}
$this->name = $composerInfoMaster['name'];
list($this->vendorName, $this->packageName) = explode('/', $this->name);
preg_match('#^(?:(?:https?|git)://([^/]+)/|git@([^:]+):)([^/]+)/(.+?)(?:\\.git|/)?$#', $this->url, $match);
$this->gitHubVendorName = $match[3];
$this->gitHubRepositoryName = $match[4];
$client = new \Github\Client();
$client->authenticate($token, null, \GitHub\Client::AUTH_URL_TOKEN);
$this->client = $client;
}
示例3: directories
/**
* Returns a list of directory paths in which scaffold files
* are to be searched for, in order to build an index
*
* @return string[]
*/
public function directories()
{
$composerConfig = Factory::createConfig(null, getcwd());
$vendorDir = $composerConfig->get('vendor-dir');
$globalVendorDir = Factory::createConfig(null, $composerConfig->get('home'))->get('vendor-dir');
return [$globalVendorDir, $vendorDir, getcwd() . DIRECTORY_SEPARATOR];
}
示例4: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$config = Factory::createConfig();
$preferSource = false;
$preferDist = false;
switch ($config->get('preferred-install')) {
case 'source':
$preferSource = true;
break;
case 'dist':
$preferDist = true;
break;
case 'auto':
default:
break;
}
if ($input->getOption('prefer-source') || $input->getOption('prefer-dist')) {
$preferSource = $input->getOption('prefer-source');
$preferDist = $input->getOption('prefer-dist');
}
if ($input->getOption('no-custom-installers')) {
$output->writeln('<warning>You are using the deprecated option "no-custom-installers". Use "no-plugins" instead.</warning>');
$input->setOption('no-plugins', true);
}
return $this->installProject($this->getIO(), $config, $input->getArgument('package'), $input->getArgument('directory'), $input->getArgument('version'), $input->getOption('stability'), $preferSource, $preferDist, !$input->getOption('no-dev'), $input->getOption('repository-url'), $input->getOption('no-plugins'), $input->getOption('no-scripts'), $input->getOption('keep-vcs'), $input->getOption('no-progress'), $input->getOption('no-install'));
}
示例5: initialize
protected function initialize(InputInterface $input, OutputInterface $output)
{
parent::initialize($input, $output);
if ($input->getOption('global') && 'composer.json' !== $input->getOption('file')) {
throw new \RuntimeException('--file and --global can not be combined');
}
$this->config = Factory::createConfig($this->getIO());
$configFile = $input->getOption('global') ? $this->config->get('home') . '/config.json' : $input->getOption('file');
$this->configFile = new JsonFile($configFile);
$this->configSource = new JsonConfigSource($this->configFile);
$authConfigFile = $input->getOption('global') ? $this->config->get('home') . '/auth.json' : dirname(realpath($input->getOption('file'))) . '/auth.json';
$this->authConfigFile = new JsonFile($authConfigFile);
$this->authConfigSource = new JsonConfigSource($this->authConfigFile, true);
if ($input->getOption('global') && !$this->configFile->exists()) {
touch($this->configFile->getPath());
$this->configFile->write(array('config' => new \ArrayObject()));
@chmod($this->configFile->getPath(), 0600);
}
if ($input->getOption('global') && !$this->authConfigFile->exists()) {
touch($this->authConfigFile->getPath());
$this->authConfigFile->write(array('http-basic' => new \ArrayObject(), 'github-oauth' => new \ArrayObject()));
@chmod($this->authConfigFile->getPath(), 0600);
}
if (!$this->configFile->exists()) {
throw new \RuntimeException(sprintf('File "%s" cannot be found in the current directory', $configFile));
}
}
示例6: dump
/**
* Builds the archives of the repository.
*
* @param array $packages List of packages to dump
*/
public function dump(array $packages)
{
$helper = new ArchiveBuilderHelper($this->output, $this->config['archive']);
$directory = $helper->getDirectory($this->outputDir);
$this->output->writeln(sprintf("<info>Creating local downloads in '%s'</info>", $directory));
$format = isset($this->config['archive']['format']) ? $this->config['archive']['format'] : 'zip';
$endpoint = isset($this->config['archive']['prefix-url']) ? $this->config['archive']['prefix-url'] : $this->config['homepage'];
$includeArchiveChecksum = isset($this->config['archive']['checksum']) ? (bool) $this->config['archive']['checksum'] : true;
$composerConfig = Factory::createConfig();
$factory = new Factory();
$io = new ConsoleIO($this->input, $this->output, $this->helperSet);
$io->loadConfiguration($composerConfig);
/* @var \Composer\Downloader\DownloadManager $downloadManager */
$downloadManager = $factory->createDownloadManager($io, $composerConfig);
/* @var \Composer\Package\Archiver\ArchiveManager $archiveManager */
$archiveManager = $factory->createArchiveManager($composerConfig, $downloadManager);
$archiveManager->setOverwriteFiles(false);
shuffle($packages);
/* @var \Composer\Package\CompletePackage $package */
foreach ($packages as $package) {
if ($helper->isSkippable($package)) {
continue;
}
$this->output->writeln(sprintf("<info>Dumping '%s'.</info>", $package->getName()));
try {
if ('pear-library' === $package->getType()) {
// PEAR packages are archives already
$filesystem = new Filesystem();
$packageName = $archiveManager->getPackageFilename($package);
$path = realpath($directory) . '/' . $packageName . '.' . pathinfo($package->getDistUrl(), PATHINFO_EXTENSION);
if (!file_exists($path)) {
$downloadDir = sys_get_temp_dir() . '/composer_archiver/' . $packageName;
$filesystem->ensureDirectoryExists($downloadDir);
$downloadManager->download($package, $downloadDir, false);
$filesystem->ensureDirectoryExists($directory);
$filesystem->rename($downloadDir . '/' . pathinfo($package->getDistUrl(), PATHINFO_BASENAME), $path);
$filesystem->removeDirectory($downloadDir);
}
// Set archive format to `file` to tell composer to download it as is
$archiveFormat = 'file';
} else {
$path = $archiveManager->archive($package, $format, $directory);
$archiveFormat = $format;
}
$archive = basename($path);
$distUrl = sprintf('%s/%s/%s', $endpoint, $this->config['archive']['directory'], $archive);
$package->setDistType($archiveFormat);
$package->setDistUrl($distUrl);
if ($includeArchiveChecksum) {
$package->setDistSha1Checksum(hash_file('sha1', $path));
}
$package->setDistReference($package->getSourceReference());
} catch (\Exception $exception) {
if (!$this->skipErrors) {
throw $exception;
}
$this->output->writeln(sprintf("<error>Skipping Exception '%s'.</error>", $exception->getMessage()));
}
}
}
示例7: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->rfs = new RemoteFilesystem($this->getIO());
$output->write('Checking platform settings: ');
$this->outputResult($output, $this->checkPlatform());
$output->write('Checking http connectivity: ');
$this->outputResult($output, $this->checkHttp());
$opts = stream_context_get_options(StreamContextFactory::getContext());
if (!empty($opts['http']['proxy'])) {
$output->write('Checking HTTP proxy: ');
$this->outputResult($output, $this->checkHttpProxy());
$output->write('Checking HTTPS proxy support for request_fulluri: ');
$this->outputResult($output, $this->checkHttpsProxyFullUriRequestParam());
}
$composer = $this->getComposer(false);
if ($composer) {
$output->write('Checking composer.json: ');
$this->outputResult($output, $this->checkComposerSchema());
}
if ($composer) {
$config = $composer->getConfig();
} else {
$config = Factory::createConfig();
}
if ($oauth = $config->get('github-oauth')) {
foreach ($oauth as $domain => $token) {
$output->write('Checking ' . $domain . ' oauth access: ');
$this->outputResult($output, $this->checkGithubOauth($domain, $token));
}
}
$output->write('Checking composer version: ');
$this->outputResult($output, $this->checkVersion());
return $this->failures;
}
示例8: run
public function run(InputInterface $input, OutputInterface $output)
{
// extract real command name
$tokens = preg_split('{\\s+}', $input->__toString());
$args = array();
foreach ($tokens as $token) {
if ($token && $token[0] !== '-') {
$args[] = $token;
if (count($args) >= 2) {
break;
}
}
}
// show help for this command if no command was found
if (count($args) < 2) {
return parent::run($input, $output);
}
// change to global dir
$config = Factory::createConfig();
chdir($config->get('home'));
$this->getIO()->writeError('<info>Changed current directory to ' . $config->get('home') . '</info>');
// create new input without "global" command prefix
$input = new StringInput(preg_replace('{\\bg(?:l(?:o(?:b(?:a(?:l)?)?)?)?)?\\b}', '', $input->__toString(), 1));
$this->getApplication()->resetComposer();
return $this->getApplication()->run($input, $output);
}
示例9: initialize
/**
* {@inheritDoc}
*/
protected function initialize(InputInterface $input, OutputInterface $output)
{
if ($input->getOption('global') && 'composer.json' !== $input->getOption('file')) {
throw new \RuntimeException('--file and --global can not be combined');
}
$this->config = Factory::createConfig($this->getIO());
// Get the local composer.json, global config.json, or if the user
// passed in a file to use
$configFile = $input->getOption('global') ? $this->config->get('home') . '/config.json' : $input->getOption('file');
$this->configFile = new JsonFile($configFile);
$this->configSource = new JsonConfigSource($this->configFile);
$authConfigFile = $input->getOption('global') ? $this->config->get('home') . '/auth.json' : dirname(realpath($input->getOption('file'))) . '/auth.json';
$this->authConfigFile = new JsonFile($authConfigFile);
$this->authConfigSource = new JsonConfigSource($this->authConfigFile, true);
// initialize the global file if it's not there
if ($input->getOption('global') && !$this->configFile->exists()) {
touch($this->configFile->getPath());
$this->configFile->write(array('config' => new \ArrayObject()));
@chmod($this->configFile->getPath(), 0600);
}
if ($input->getOption('global') && !$this->authConfigFile->exists()) {
touch($this->authConfigFile->getPath());
$this->authConfigFile->write(array('http-basic' => new \ArrayObject(), 'github-oauth' => new \ArrayObject()));
@chmod($this->authConfigFile->getPath(), 0600);
}
if (!$this->configFile->exists()) {
throw new \RuntimeException('No composer.json found in the current directory');
}
}
示例10: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$baseUrl = (extension_loaded('openssl') ? 'https' : 'http') . '://' . self::HOMEPAGE;
$config = Factory::createConfig();
$remoteFilesystem = new RemoteFilesystem($this->getIO(), $config);
$cacheDir = $config->get('cache-dir');
$rollbackDir = $config->get('home');
$localFilename = realpath($_SERVER['argv'][0]) ?: $_SERVER['argv'][0];
// check if current dir is writable and if not try the cache dir from settings
$tmpDir = is_writable(dirname($localFilename)) ? dirname($localFilename) : $cacheDir;
// check for permissions in local filesystem before start connection process
if (!is_writable($tmpDir)) {
throw new FilesystemException('Composer update failed: the "' . $tmpDir . '" directory used to download the temp file could not be written');
}
if (!is_writable($localFilename)) {
throw new FilesystemException('Composer update failed: the "' . $localFilename . '" file could not be written');
}
if ($input->getOption('rollback')) {
return $this->rollback($output, $rollbackDir, $localFilename);
}
$latestVersion = trim($remoteFilesystem->getContents(self::HOMEPAGE, $baseUrl . '/version', false));
$updateVersion = $input->getArgument('version') ?: $latestVersion;
if (preg_match('{^[0-9a-f]{40}$}', $updateVersion) && $updateVersion !== $latestVersion) {
$output->writeln('<error>You can not update to a specific SHA-1 as those phars are not available for download</error>');
return 1;
}
if (Composer::VERSION === $updateVersion) {
$output->writeln('<info>You are already using composer version ' . $updateVersion . '.</info>');
return 0;
}
$tempFilename = $tmpDir . '/' . basename($localFilename, '.phar') . '-temp.phar';
$backupFile = sprintf('%s/%s-%s%s', $rollbackDir, strtr(Composer::RELEASE_DATE, ' :', '_-'), preg_replace('{^([0-9a-f]{7})[0-9a-f]{33}$}', '$1', Composer::VERSION), self::OLD_INSTALL_EXT);
$output->writeln(sprintf("Updating to version <info>%s</info>.", $updateVersion));
$remoteFilename = $baseUrl . (preg_match('{^[0-9a-f]{40}$}', $updateVersion) ? '/composer.phar' : "/download/{$updateVersion}/composer.phar");
$remoteFilesystem->copy(self::HOMEPAGE, $remoteFilename, $tempFilename);
if (!file_exists($tempFilename)) {
$output->writeln('<error>The download of the new composer version failed for an unexpected reason</error>');
return 1;
}
// remove saved installations of composer
if ($input->getOption('clean-backups')) {
$finder = $this->getOldInstallationFinder($rollbackDir);
$fs = new Filesystem();
foreach ($finder as $file) {
$file = (string) $file;
$output->writeln('<info>Removing: ' . $file . '</info>');
$fs->remove($file);
}
}
if ($err = $this->setLocalPhar($localFilename, $tempFilename, $backupFile)) {
$output->writeln('<error>The file is corrupted (' . $err->getMessage() . ').</error>');
$output->writeln('<error>Please re-run the self-update command to try again.</error>');
return 1;
}
if (file_exists($backupFile)) {
$output->writeln('Use <info>composer self-update --rollback</info> to return to version ' . Composer::VERSION);
} else {
$output->writeln('<warning>A backup of the current version could not be written to ' . $backupFile . ', no rollback possible</warning>');
}
}
示例11: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$composer = $this->getComposer(false);
if ($composer) {
$commandEvent = new CommandEvent(PluginEvents::COMMAND, 'diagnose', $input, $output);
$composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
$this->getIO()->write('Checking composer.json: ', false);
$this->outputResult($this->checkComposerSchema());
}
if ($composer) {
$config = $composer->getConfig();
} else {
$config = Factory::createConfig();
}
$this->rfs = new RemoteFilesystem($this->getIO(), $config);
$this->process = new ProcessExecutor($this->getIO());
$this->getIO()->write('Checking platform settings: ', false);
$this->outputResult($this->checkPlatform());
$this->getIO()->write('Checking git settings: ', false);
$this->outputResult($this->checkGit());
$this->getIO()->write('Checking http connectivity: ', false);
$this->outputResult($this->checkHttp());
$opts = stream_context_get_options(StreamContextFactory::getContext('http://example.org'));
if (!empty($opts['http']['proxy'])) {
$this->getIO()->write('Checking HTTP proxy: ', false);
$this->outputResult($this->checkHttpProxy());
$this->getIO()->write('Checking HTTP proxy support for request_fulluri: ', false);
$this->outputResult($this->checkHttpProxyFullUriRequestParam());
$this->getIO()->write('Checking HTTPS proxy support for request_fulluri: ', false);
$this->outputResult($this->checkHttpsProxyFullUriRequestParam());
}
if ($oauth = $config->get('github-oauth')) {
foreach ($oauth as $domain => $token) {
$this->getIO()->write('Checking ' . $domain . ' oauth access: ', false);
$this->outputResult($this->checkGithubOauth($domain, $token));
}
} else {
$this->getIO()->write('Checking github.com rate limit: ', false);
try {
$rate = $this->getGithubRateLimit('github.com');
$this->outputResult(true);
if (10 > $rate['remaining']) {
$this->getIO()->write('<warning>WARNING</warning>');
$this->getIO()->write(sprintf('<comment>Github has a rate limit on their API. ' . 'You currently have <options=bold>%u</options=bold> ' . 'out of <options=bold>%u</options=bold> requests left.' . PHP_EOL . 'See https://developer.github.com/v3/#rate-limiting and also' . PHP_EOL . ' https://getcomposer.org/doc/articles/troubleshooting.md#api-rate-limit-and-oauth-tokens</comment>', $rate['remaining'], $rate['limit']));
}
} catch (\Exception $e) {
if ($e instanceof TransportException && $e->getCode() === 401) {
$this->outputResult('<comment>The oauth token for github.com seems invalid, run "composer config --global --unset github-oauth.github.com" to remove it</comment>');
} else {
$this->outputResult($e);
}
}
}
$this->getIO()->write('Checking disk free space: ', false);
$this->outputResult($this->checkDiskSpace($config));
$this->getIO()->write('Checking composer version: ', false);
$this->outputResult($this->checkVersion());
return $this->failures;
}
示例12: getDownloadManager
private function getDownloadManager()
{
if (!$this->downloadManager) {
$config = Factory::createConfig();
$factory = new Factory();
$this->downloadManager = $factory->createDownloadManager($this->getIO(), $config);
}
return $this->downloadManager;
}
示例13: loadConfiguration
/**
* @return \Composer\Config
*/
public static function loadConfiguration()
{
try {
$configuration = Factory::createConfig();
} catch (Exception $e) {
throw RuntimeException::fromAnyException($e);
}
return $configuration;
}
示例14: execute
/**
* {@inheritDoc}
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
* @throws FilesystemException When the temporary directory or local file are not writable.
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$originName = $this->getOriginName();
$config = Factory::createConfig();
$inputOutput = $this->getIO();
$this->rfs = new RemoteFilesystem($inputOutput, $config);
$cacheDir = $config->get('cache-dir');
$rollbackDir = $config->get('home');
$localFilename = $this->determineLocalFileName();
// check if current dir is writable and if not try the cache dir from settings
$tmpDir = is_writable(dirname($localFilename)) ? dirname($localFilename) : $cacheDir;
// check for permissions in local filesystem before start connection process
if (!is_writable($tmpDir)) {
throw new FilesystemException(sprintf('Self update failed: the "%s" directory used to download the temp file could not be written', $tmpDir));
}
if (!is_writable($localFilename)) {
throw new FilesystemException('Self update failed: "' . $localFilename . '" is not writable.');
}
if ($input->getOption('rollback')) {
return $this->rollback($rollbackDir, $localFilename);
}
$latestVersion = $this->getLatestVersion();
$updateVersion = $input->getArgument('version') ?: $latestVersion;
if (preg_match('{^[0-9a-f]{40}$}', $updateVersion) && $updateVersion !== $latestVersion) {
$inputOutput->writeError('<error>You can not update to a specific SHA-1 as those phars are not available for download</error>');
return 1;
}
if (Tenside::VERSION === $updateVersion) {
$inputOutput->writeError('<info>You are already using version ' . $updateVersion . '.</info>');
return 0;
}
$tempFilename = $tmpDir . '/' . basename($localFilename, '.phar') . '-temp.phar';
$backupFile = sprintf('%s/%s-%s%s', $rollbackDir, strtr(Tenside::RELEASE_DATE, ' :', '_-'), preg_replace('{^([0-9a-f]{7})[0-9a-f]{33}$}', '$1', Tenside::VERSION), self::OLD_INSTALL_EXT);
$inputOutput->writeError(sprintf('Updating to version <info>%s</info>.', $updateVersion));
$remoteFilename = $this->determineRemoteFilename($updateVersion);
$this->rfs->copy($originName, $remoteFilename, $tempFilename, !$input->getOption('no-progress'));
if (!file_exists($tempFilename)) {
$inputOutput->writeError('<error>The download of the new version failed for an unexpected reason</error>');
return 1;
}
// remove saved installations of tenside
if ($input->getOption('clean-backups')) {
$this->cleanupOldBackups($rollbackDir);
}
if ($err = $this->setLocalPhar($localFilename, $tempFilename, $backupFile)) {
$inputOutput->writeError('<error>The file is corrupted (' . $err->getMessage() . ').</error>');
$inputOutput->writeError('<error>Please re-run the self-update command to try again.</error>');
return 1;
}
if (file_exists($backupFile)) {
$inputOutput->writeError(sprintf('Use <info>%s self-update --rollback</info> to return to version %s', $localFilename, Tenside::VERSION));
return 0;
}
$inputOutput->writeError(sprintf('<warning>A backup of the current version could not be written to %s, ' . 'no rollback possible</warning>', $backupFile));
return 0;
}
示例15: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$config = Factory::createConfig();
$this->updatePreferredOptions($config, $input, $preferSource, $preferDist, true);
if ($input->getOption('no-custom-installers')) {
$this->getIO()->writeError('<warning>You are using the deprecated option "no-custom-installers". Use "no-plugins" instead.</warning>');
$input->setOption('no-plugins', true);
}
return $this->installProject($this->getIO(), $config, $input->getArgument('package'), $input->getArgument('directory'), $input->getArgument('version'), $input->getOption('stability'), $preferSource, $preferDist, !$input->getOption('no-dev'), $input->getOption('repository-url'), $input->getOption('no-plugins'), $input->getOption('no-scripts'), $input->getOption('keep-vcs'), $input->getOption('no-progress'), $input->getOption('no-install'), $input->getOption('ignore-platform-reqs'), $input);
}