function ConfigCommand::initialize
Throws
\Exception
Overrides BaseCommand::initialize
File
-
vendor/
composer/ composer/ src/ Composer/ Command/ ConfigCommand.php, line 175
Class
- ConfigCommand
- @author Joshua Estes <Joshua.Estes@iostudio.com> @author Jordi Boggiano <j.boggiano@seld.be>
Namespace
Composer\CommandCode
protected function initialize(InputInterface $input, OutputInterface $output) : void {
parent::initialize($input, $output);
if ($input->getOption('global') && null !== $input->getOption('file')) {
throw new \RuntimeException('--file and --global can not be combined');
}
$io = $this->getIO();
$this->config = Factory::createConfig($io);
$configFile = $this->getComposerConfigFile($input, $this->config);
// Create global composer.json if this was invoked using `composer global config`
if (($configFile === 'composer.json' || $configFile === './composer.json') && !file_exists($configFile) && realpath(Platform::getCwd()) === realpath($this->config
->get('home'))) {
file_put_contents($configFile, "{\n}\n");
}
$this->configFile = new JsonFile($configFile, null, $io);
$this->configSource = new JsonConfigSource($this->configFile);
$authConfigFile = $this->getAuthConfigFile($input, $this->config);
$this->authConfigFile = new JsonFile($authConfigFile, null, $io);
$this->authConfigSource = new JsonConfigSource($this->authConfigFile, true);
// Initialize the global file if it's not there, ignoring any warnings or notices
if ($input->getOption('global') && !$this->configFile
->exists()) {
touch($this->configFile
->getPath());
$this->configFile
->write([
'config' => new \ArrayObject(),
]);
Silencer::call('chmod', $this->configFile
->getPath(), 0600);
}
if ($input->getOption('global') && !$this->authConfigFile
->exists()) {
touch($this->authConfigFile
->getPath());
$this->authConfigFile
->write([
'bitbucket-oauth' => new \ArrayObject(),
'github-oauth' => new \ArrayObject(),
'gitlab-oauth' => new \ArrayObject(),
'gitlab-token' => new \ArrayObject(),
'http-basic' => new \ArrayObject(),
'bearer' => new \ArrayObject(),
]);
Silencer::call('chmod', $this->authConfigFile
->getPath(), 0600);
}
if (!$this->configFile
->exists()) {
throw new \RuntimeException(sprintf('File "%s" cannot be found in the current directory', $configFile));
}
}