Skip to content

Commit

Permalink
Release composer config fixes (#77)
Browse files Browse the repository at this point in the history
* Get user composer home directory independent of host OS

* Force json_decode to return assotiative array rather than object
  • Loading branch information
Steven Richardson authored Nov 4, 2016
1 parent 338c1f2 commit de33f97
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/Magestead/Exceptions/MissingComposerHomeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php namespace Magestead\Exceptions;

/**
* Class MissingComposerHomeException
* @package Magestead\Exceptions
*/
class MissingComposerHomeException extends \Exception {}
28 changes: 27 additions & 1 deletion src/Magestead/Helper/Config.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
<?php namespace Magestead\Helper;

use Magestead\Exceptions\MissingComposerHomeException;
use Magestead\Exceptions\MissingConfigFileException;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Parser;

class Config
{
protected $_config;

protected $_projectPath;

/**
* @var OutputInterface
*/
private $output;

/**
* Config constructor.
* @param OutputInterface $output
*/
public function __construct(OutputInterface $output)
{
$this->_projectPath = getcwd();
$this->_config = $this->getConfigFile($output);
$this->output = $output;
}

/**
Expand All @@ -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];
}

Expand Down Expand Up @@ -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));
}
}
7 changes: 4 additions & 3 deletions src/Magestead/Helper/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -268,4 +269,4 @@ protected function setOperatingSystem($helper, InputInterface $input, OutputInte

$this->_os = str_replace(' ', '', str_replace('.', '', strtolower($helper->ask($input, $output, $osQuestion))));
}
}
}
11 changes: 10 additions & 1 deletion src/Magestead/Installers/Magento2Project.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace Magestead\Installers;

use Magestead\Command\ProcessCommand;
use Magestead\Helper\Config;
use Magestead\Helper\HostsPluginChecker;
use Magestead\Service\Notification;
use Magestead\Service\VersionControl;
Expand All @@ -13,6 +14,11 @@
*/
class Magento2Project
{
/**
* @var OutputInterface
*/
private $output;

/**
* Magento2Project constructor.
* @param array $options
Expand All @@ -22,6 +28,7 @@ class Magento2Project
*/
public function __construct(array $options, array $config, $projectPath, OutputInterface $output)
{
$this->output = $output;
$this->composerInstall($projectPath, $output);
$this->installMagento($config, $options, $projectPath, $output);
$this->finaliseSetup($options, $projectPath, $output);
Expand Down Expand Up @@ -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');
}

Expand Down

0 comments on commit de33f97

Please sign in to comment.