Skip to content

Commit

Permalink
Use SiteAliasWithConfig class (#30)
Browse files Browse the repository at this point in the history
* Use SiteAliasWithConfig class
  • Loading branch information
greg-1-anderson authored Mar 2, 2019
1 parent 7e76331 commit c1baaae
Show file tree
Hide file tree
Showing 16 changed files with 88 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .scenarios.lock/phpunit5/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
},
"require": {
"php": ">=5.6.0",
"consolidation/site-alias": "^2.1.1",
"consolidation/config": "^1.2",
"consolidation/site-alias": "^3.0.0-alpha1",
"symfony/process": "^3.4"
},
"require-dev": {
Expand Down
16 changes: 9 additions & 7 deletions .scenarios.lock/phpunit5/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

DEPENDENCY LICENSES:

Name Version License
consolidation/config 1.2.0 MIT
consolidation/site-alias 2.1.1 MIT
dflydev/dot-access-data v1.1.0 MIT
grasmash/expander 1.0.0 MIT
symfony/process v3.4.22 MIT
Name Version License
consolidation/config 1.2.0 MIT
consolidation/site-alias 3.0.0-alpha1 MIT
dflydev/dot-access-data v1.1.0 MIT
grasmash/expander 1.0.0 MIT
symfony/process v3.4.22 MIT
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
},
"require": {
"php": ">=5.6.0",
"consolidation/site-alias": "^2.1.1",
"consolidation/config": "^1.2",
"consolidation/site-alias": "^3.0.0-alpha1",
"symfony/process": "^3.4"
},
"require-dev": {
Expand Down
16 changes: 9 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/Factory/DockerComposeTransportFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Consolidation\SiteProcess\Factory;

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

Expand All @@ -15,7 +15,7 @@ class DockerComposeTransportFactory implements TransportFactoryInterface
/**
* @inheritdoc
*/
public function check(AliasRecord $siteAlias)
public function check(AliasRecordInterface $siteAlias)
{
// TODO: deprecate and eventually remove 'isContainer()', and move the logic here.
return $siteAlias->isContainer();
Expand All @@ -24,8 +24,8 @@ public function check(AliasRecord $siteAlias)
/**
* @inheritdoc
*/
public function create(AliasRecord $siteAlias, ConfigInterface $config)
public function create(AliasRecordInterface $siteAlias)
{
return new DockerComposeTransport($siteAlias, $config);
return new DockerComposeTransport($siteAlias);
}
}
8 changes: 4 additions & 4 deletions src/Factory/SshTransportFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Consolidation\SiteProcess\Factory;

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

Expand All @@ -14,7 +14,7 @@ class SshTransportFactory implements TransportFactoryInterface
/**
* @inheritdoc
*/
public function check(AliasRecord $siteAlias)
public function check(AliasRecordInterface $siteAlias)
{
// TODO: deprecate and eventually remove 'isRemote()', and move the logic here.
return $siteAlias->isRemote();
Expand All @@ -23,8 +23,8 @@ public function check(AliasRecord $siteAlias)
/**
* @inheritdoc
*/
public function create(AliasRecord $siteAlias, ConfigInterface $config)
public function create(AliasRecordInterface $siteAlias)
{
return new SshTransport($siteAlias, $config);
return new SshTransport($siteAlias);
}
}
10 changes: 5 additions & 5 deletions src/Factory/TransportFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Consolidation\SiteProcess\Factory;

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

Expand All @@ -20,15 +20,15 @@ interface TransportFactoryInterface
{
/**
* Check to see if a provided site alias is applicable to this transport type.
* @param AliasRecord $siteAlias
* @param AliasRecordInterface $siteAlias
* @return bool
*/
public function check(AliasRecord $siteAlias);
public function check(AliasRecordInterface $siteAlias);

/**
* Create a transport instance for an applicable site alias.
* @param AliasRecord $siteAlias
* @param AliasRecordInterface $siteAlias
* @return TransportInterface
*/
public function create(AliasRecord $siteAlias, ConfigInterface $config);
public function create(AliasRecordInterface $siteAlias);
}
42 changes: 32 additions & 10 deletions src/ProcessManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Consolidation\SiteProcess;

use Psr\Log\LoggerInterface;
use Consolidation\SiteAlias\AliasRecord;
use Consolidation\SiteAlias\AliasRecordInterface;
use Consolidation\SiteProcess\Factory\SshTransportFactory;
use Consolidation\SiteProcess\Factory\DockerComposeTransportFactory;
use Consolidation\SiteProcess\Factory\TransportFactoryInterface;
Expand All @@ -13,6 +13,7 @@
use Consolidation\Config\ConfigInterface;
use Consolidation\Config\ConfigAwareInterface;
use Consolidation\Config\ConfigAwareTrait;
use Consolidation\SiteAlias\SiteAliasWithConfig;

/**
* ProcessManager will create a SiteProcess to run a command on a given
Expand All @@ -25,11 +26,29 @@ class ProcessManager implements ConfigAwareInterface
{
use ConfigAwareTrait;

/** @var ConfigInterface */
protected $configRuntime;

protected $transportFactories = [];

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

/**
* setConfigRuntime sets the config object that holds runtime config
* items, i.e. config set from the commandline rather than a config file.
* Configuration priority (highest to lowest) is:
* - config runtime
* - site alias
* - config files
*/
public function setConfigRuntime(ConfigInterface $configRuntime)
{
$this->configRuntime = $configRuntime;
return $this;
}

/**
Expand All @@ -48,13 +67,13 @@ public static function createDefault()
/**
* Return a site process configured with an appropriate transport
*
* @param AliasRecord $siteAlias Target for command
* @param AliasRecordInterface $siteAlias Target for command
* @param array $args Command arguments
* @param array $options Associative array of command options
* @param array $optionsPassedAsArgs Associtive array of options to be passed as arguments (after double-dash)
* @return Process
*/
public function siteProcess(AliasRecord $siteAlias, $args = [], $options = [], $optionsPassedAsArgs = [])
public function siteProcess(AliasRecordInterface $siteAlias, $args = [], $options = [], $optionsPassedAsArgs = [])
{
$transport = $this->getTransport($siteAlias);
$process = new SiteProcess($siteAlias, $transport, $args, $options, $optionsPassedAsArgs);
Expand Down Expand Up @@ -103,36 +122,39 @@ public function add(TransportFactoryInterface $factory)
* hasTransport determines if there is a transport that handles the
* provided site alias.
*
* @param AliasRecord $siteAlias
* @param AliasRecordInterface $siteAlias
* @return boolean
*/
public function hasTransport(AliasRecord $siteAlias)
public function hasTransport(AliasRecordInterface $siteAlias)
{
return $this->getTransportFactory($siteAlias) !== null;
}

/**
* getTransport returns a transport that is applicable to the provided site alias.
*
* @param AliasRecord $siteAlias
* @param AliasRecordInterface $siteAlias
* @return TransportInterface
*/
public function getTransport(AliasRecord $siteAlias)
public function getTransport(AliasRecordInterface $siteAlias)
{
$factory = $this->getTransportFactory($siteAlias);

$siteAliasWithConfig = new SiteAliasWithConfig($this->configRuntime, $siteAlias, $this->config);

if ($factory) {
return $factory->create($siteAlias, $this->config);
return $factory->create($siteAliasWithConfig);
}
return new LocalTransport();
}

/**
* getTransportFactory returns a factory for the provided site alias.
*
* @param AliasRecord $siteAlias
* @param AliasRecordInterface $siteAlias
* @return TransportFactoryInterface
*/
protected function getTransportFactory(AliasRecord $siteAlias)
protected function getTransportFactory(AliasRecordInterface $siteAlias)
{
foreach ($this->transportFactories as $factory) {
if ($factory->check($siteAlias)) {
Expand Down
10 changes: 5 additions & 5 deletions src/SiteProcess.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Consolidation\SiteProcess;

use Consolidation\SiteAlias\AliasRecord;
use Consolidation\SiteAlias\AliasRecordInterface;
use Consolidation\SiteProcess\Transport\DockerComposeTransport;
use Consolidation\SiteProcess\Util\ArgumentProcessor;
use Consolidation\SiteProcess\Transport\LocalTransport;
Expand All @@ -21,7 +21,7 @@
*/
class SiteProcess extends ProcessBase
{
/** @var AliasRecord */
/** @var AliasRecordInterface */
protected $siteAlias;
/** @var string[] */
protected $args;
Expand All @@ -38,7 +38,7 @@ class SiteProcess extends ProcessBase
* Process arguments and options per the site alias and build the
* actual command to run.
*/
public function __construct(AliasRecord $siteAlias, TransportInterface $transport, $args, $options = [], $optionsPassedAsArgs = [])
public function __construct(AliasRecordInterface $siteAlias, TransportInterface $transport, $args, $options = [], $optionsPassedAsArgs = [])
{
$this->siteAlias = $siteAlias;
$this->transport = $transport;
Expand Down Expand Up @@ -147,7 +147,7 @@ public function setTransport($transport)
* Ask the transport manager for the correct transport for the
* provided alias.
*/
protected function getTransport(AliasRecord $siteAlias)
protected function getTransport(AliasRecordInterface $siteAlias)
{
return $this->transport;
}
Expand Down Expand Up @@ -198,7 +198,7 @@ public function wait(callable $callback = null)
* It is possible to use dot notation in the keys to access nested elements
* within the site alias record.
*
* @param AliasRecord $siteAlias
* @param AliasRecordInterface $siteAlias
* @param type $args
* @return type
*/
Expand Down
Loading

0 comments on commit c1baaae

Please sign in to comment.