From de33f978123551d15cf5e969a6f7bfcb048b487c Mon Sep 17 00:00:00 2001 From: Steven Richardson Date: Fri, 4 Nov 2016 21:52:11 +0000 Subject: [PATCH] Release composer config fixes (#77) * Get user composer home directory independent of host OS * Force json_decode to return assotiative array rather than object --- .../MissingComposerHomeException.php | 7 +++++ src/Magestead/Helper/Config.php | 28 ++++++++++++++++++- src/Magestead/Helper/Options.php | 7 +++-- src/Magestead/Installers/Magento2Project.php | 11 +++++++- 4 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 src/Magestead/Exceptions/MissingComposerHomeException.php diff --git a/src/Magestead/Exceptions/MissingComposerHomeException.php b/src/Magestead/Exceptions/MissingComposerHomeException.php new file mode 100644 index 0000000..b56cb91 --- /dev/null +++ b/src/Magestead/Exceptions/MissingComposerHomeException.php @@ -0,0 +1,7 @@ +_projectPath = getcwd(); - $this->_config = $this->getConfigFile($output); + $this->output = $output; } /** @@ -25,6 +33,7 @@ public function __construct(OutputInterface $output) */ function __get($name) { + $this->_config = $this->getConfigFile($this->output); return $this->_config['magestead']['apps']['mba_12345'][$name]; } @@ -56,4 +65,21 @@ protected function readConfigFile() return file_get_contents($this->_projectPath . '/magestead.yaml'); } + + /** + * Find the composer home directory on non Mac environments (experimental) + * + * @return string + * @throws MissingComposerHomeException + */ + public function getComposerHomeDir() + { + $composerConfig = shell_exec('composer config --list --global | grep home'); + + if (is_null($composerConfig)) { + throw new MissingComposerHomeException('Composer home directory is not found. Do you have it installed?'); + } + + return trim(str_replace('[home] ', '', $composerConfig)); + } } diff --git a/src/Magestead/Helper/Options.php b/src/Magestead/Helper/Options.php index 866c107..ad8725c 100644 --- a/src/Magestead/Helper/Options.php +++ b/src/Magestead/Helper/Options.php @@ -179,12 +179,13 @@ protected function askForAuth($helper, InputInterface $input, OutputInterface $o */ protected function verifyAuth($helper, InputInterface $input, OutputInterface $output) { - $authFile = $_SERVER['HOME'] . "/.composer/auth.json"; + $composerHome = (new Config($output))->getComposerHomeDir(); + $authFile = $composerHome . "/auth.json"; $authObj = []; if (file_exists($authFile)) { $authJson = file_get_contents($authFile); - $authObj = (array)json_decode($authJson); + $authObj = (array)json_decode($authJson, true); if (isset($authObj['http-basic']) && isset($authObj['http-basic']->{'repo.magento.com'})) { return true; @@ -268,4 +269,4 @@ protected function setOperatingSystem($helper, InputInterface $input, OutputInte $this->_os = str_replace(' ', '', str_replace('.', '', strtolower($helper->ask($input, $output, $osQuestion)))); } -} \ No newline at end of file +} diff --git a/src/Magestead/Installers/Magento2Project.php b/src/Magestead/Installers/Magento2Project.php index 32d180e..e1080c9 100644 --- a/src/Magestead/Installers/Magento2Project.php +++ b/src/Magestead/Installers/Magento2Project.php @@ -1,6 +1,7 @@ output = $output; $this->composerInstall($projectPath, $output); $this->installMagento($config, $options, $projectPath, $output); $this->finaliseSetup($options, $projectPath, $output); @@ -52,7 +59,9 @@ protected function composerInstall($projectPath, OutputInterface $output) */ protected function copyAuthFile($destination) { - $authFile = $_SERVER['HOME'] . "/.composer/auth.json"; + $composerHome = (new Config($this->output))->getComposerHomeDir(); + $authFile = $composerHome . "/auth.json"; + return copy($authFile, $destination . '/public/auth.json'); }