Skip to content

Commit

Permalink
Allow configuration to be injected into ProcessManager. (#22)
Browse files Browse the repository at this point in the history
* Allow configuration to be injected into ProcessManager.

* Only run unit tests on Appveyor; skip linting and code style tests.
  • Loading branch information
greg-1-anderson authored Feb 15, 2019
1 parent 895a479 commit 28affda
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 11 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ install:
- mkdir c:\test_temp

test_script:
- php composer.phar test
- php composer.phar unit

# environment variables
environment:
Expand Down
5 changes: 3 additions & 2 deletions src/Factory/DockerComposeTransportFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Consolidation\SiteAlias\AliasRecord;
use Consolidation\SiteProcess\Transport\DockerComposeTransport;
use Consolidation\Config\ConfigInterface;

/**
* DockerComposeTransportFactory will create an DockerComposeTransport for
Expand All @@ -23,8 +24,8 @@ public function check(AliasRecord $siteAlias)
/**
* @inheritdoc
*/
public function create(AliasRecord $siteAlias)
public function create(AliasRecord $siteAlias, ConfigInterface $config)
{
return new DockerComposeTransport($siteAlias);
return new DockerComposeTransport($siteAlias, $config);
}
}
5 changes: 3 additions & 2 deletions src/Factory/SshTransportFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Consolidation\SiteAlias\AliasRecord;
use Consolidation\SiteProcess\Transport\SshTransport;
use Consolidation\Config\ConfigInterface;

/**
* SshTransportFactory will create an SshTransport for applicable site aliases.
Expand All @@ -22,8 +23,8 @@ public function check(AliasRecord $siteAlias)
/**
* @inheritdoc
*/
public function create(AliasRecord $siteAlias)
public function create(AliasRecord $siteAlias, ConfigInterface $config)
{
return new SshTransport($siteAlias);
return new SshTransport($siteAlias, $config);
}
}
3 changes: 2 additions & 1 deletion src/Factory/TransportFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Consolidation\SiteAlias\AliasRecord;
use Consolidation\SiteProcess\Transport\TransportInterface;
use Consolidation\Config\ConfigInterface;

/**
* TransportFactoryInterface defines a transport factory that is responsible
Expand All @@ -29,5 +30,5 @@ public function check(AliasRecord $siteAlias);
* @param AliasRecord $siteAlias
* @return TransportInterface
*/
public function create(AliasRecord $siteAlias);
public function create(AliasRecord $siteAlias, ConfigInterface $config);
}
18 changes: 17 additions & 1 deletion src/ProcessManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Consolidation\SiteProcess\Factory\TransportFactoryInterface;
use Consolidation\SiteProcess\Transport\LocalTransport;
use Symfony\Component\Process\Process;
use Consolidation\Config\Config;
use Consolidation\Config\ConfigInterface;

/**
* ProcessManager will create a SiteProcess to run a command on a given
Expand All @@ -20,6 +22,12 @@
class ProcessManager
{
protected $transportFactories = [];
protected $config;

public function __construct()
{
$this->config = new Config();
}

/**
* createDefault creates a Transport manager and add the default transports to it.
Expand All @@ -34,6 +42,14 @@ public static function createDefault()
return $processManager;
}

/**
* Set a reference to the config object.
*/
public function setConfig(ConfigInterface $config)
{
$this->config = $config;
}

/**
* Return a site process configured with an appropriate transport
*
Expand Down Expand Up @@ -110,7 +126,7 @@ public function getTransport(AliasRecord $siteAlias)
{
$factory = $this->getTransportFactory($siteAlias);
if ($factory) {
return $factory->create($siteAlias);
return $factory->create($siteAlias, $this->config);
}
return new LocalTransport();
}
Expand Down
7 changes: 5 additions & 2 deletions src/Transport/DockerComposeTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Consolidation\SiteProcess\SiteProcess;
use Consolidation\SiteAlias\AliasRecord;
use Consolidation\SiteProcess\Util\Shell;
use Consolidation\Config\ConfigInterface;

/**
* DockerComposeTransport knows how to wrap a command such that it executes
Expand All @@ -15,10 +16,12 @@ class DockerComposeTransport implements TransportInterface
protected $tty;
protected $siteAlias;
protected $cd_remote;
protected $config;

public function __construct(AliasRecord $siteAlias)
public function __construct(AliasRecord $siteAlias, ConfigInterface $config)
{
$this->siteAlias = $siteAlias;
$this->config = $config;
}

/**
Expand Down Expand Up @@ -61,7 +64,7 @@ public function addChdir($cd, $args)
protected function getTransportOptions()
{
$transportOptions = [
$this->siteAlias->get('docker.service', ''),
$this->siteAlias->getConfig($this->config, 'docker.service', ''),
];
if ($options = $this->siteAlias->get('docker.exec.options', '')) {
array_unshift($transportOptions, Shell::preEscaped($options));
Expand Down
7 changes: 5 additions & 2 deletions src/Transport/SshTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Consolidation\SiteProcess\Util\Escape;
use Consolidation\SiteAlias\AliasRecord;
use Consolidation\SiteProcess\Util\Shell;
use Consolidation\Config\ConfigInterface;

/**
* SshTransport knows how to wrap a command such that it runs on a remote
Expand All @@ -15,10 +16,12 @@ class SshTransport implements TransportInterface
{
protected $tty;
protected $siteAlias;
protected $config;

public function __construct(AliasRecord $siteAlias)
public function __construct(AliasRecord $siteAlias, ConfigInterface $config)
{
$this->siteAlias = $siteAlias;
$this->config = $config;
}

/**
Expand Down Expand Up @@ -67,7 +70,7 @@ public function addChdir($cd_remote, $args)
protected function getTransportOptions()
{
$transportOptions = [
Shell::preEscaped($this->siteAlias->get('ssh.options', '-o PasswordAuthentication=no')),
Shell::preEscaped($this->siteAlias->getConfig($this->config, 'ssh.options', '-o PasswordAuthentication=no')),
$this->siteAlias->remoteHostWithUser(),
];
if ($this->tty) {
Expand Down

0 comments on commit 28affda

Please sign in to comment.