Esempio n. 1
0
 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));
     }
 }
Esempio n. 2
0
 /**
  * {@inheritDoc}
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     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);
     // 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') ?: trim(getenv('COMPOSER')) ?: 'composer.json');
     // create global composer.json if this was invoked using `composer global config`
     if ($configFile === 'composer.json' && !file_exists($configFile) && realpath(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 = $input->getOption('global') ? $this->config->get('home') . '/auth.json' : dirname(realpath($configFile)) . '/auth.json';
     $this->authConfigFile = new JsonFile($authConfigFile, null, $io);
     $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(), 'gitlab-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));
     }
 }