function Factory::createConfig
15 calls to Factory::createConfig()
- Application::getUseParentDirConfigValue in vendor/
composer/ composer/ src/ Composer/ Console/ Application.php - ArchiveCommand::execute in vendor/
composer/ composer/ src/ Composer/ Command/ ArchiveCommand.php - Executes the current command.
- ClearCacheCommand::execute in vendor/
composer/ composer/ src/ Composer/ Command/ ClearCacheCommand.php - Executes the current command.
- ConfigCommand::initialize in vendor/
composer/ composer/ src/ Composer/ Command/ ConfigCommand.php - ConfigCommand::suggestSettingKeys in vendor/
composer/ composer/ src/ Composer/ Command/ ConfigCommand.php - Suggest setting-keys, while taking given options in account.
File
-
vendor/
composer/ composer/ src/ Composer/ Factory.php, line 165
Class
- Factory
- Creates a configured instance of composer.
Namespace
ComposerCode
public static function createConfig(?IOInterface $io = null, ?string $cwd = null) : Config {
$cwd = $cwd ?? Platform::getCwd(true);
$config = new Config(true, $cwd);
// determine and add main dirs to the config
$home = self::getHomeDir();
$config->merge([
'config' => [
'home' => $home,
'cache-dir' => self::getCacheDir($home),
'data-dir' => self::getDataDir($home),
],
], Config::SOURCE_DEFAULT);
// load global config
$file = new JsonFile($config->get('home') . '/config.json');
if ($file->exists()) {
if ($io instanceof IOInterface) {
$io->writeError('Loading config file ' . $file->getPath(), true, IOInterface::DEBUG);
}
self::validateJsonSchema($io, $file);
$config->merge($file->read(), $file->getPath());
}
$config->setConfigSource(new JsonConfigSource($file));
$htaccessProtect = $config->get('htaccess-protect');
if ($htaccessProtect) {
// 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 = [
$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 auth file
$file = new JsonFile($config->get('home') . '/auth.json');
if ($file->exists()) {
if ($io instanceof IOInterface) {
$io->writeError('Loading config file ' . $file->getPath(), true, IOInterface::DEBUG);
}
self::validateJsonSchema($io, $file, JsonFile::AUTH_SCHEMA);
$config->merge([
'config' => $file->read(),
], $file->getPath());
}
$config->setAuthConfigSource(new JsonConfigSource($file, true));
self::loadComposerAuthEnv($config, $io);
return $config;
}