diff --git a/.scenarios.lock/phpunit5/composer.json b/.scenarios.lock/phpunit5/composer.json index 1890456..a2df403 100644 --- a/.scenarios.lock/phpunit5/composer.json +++ b/.scenarios.lock/phpunit5/composer.json @@ -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": { diff --git a/.scenarios.lock/phpunit5/composer.lock b/.scenarios.lock/phpunit5/composer.lock index ec7aed2..e308cd0 100644 --- a/.scenarios.lock/phpunit5/composer.lock +++ b/.scenarios.lock/phpunit5/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "63b35bfea71d5c8b96919a13523a2e28", + "content-hash": "5abb8a8a3c310c6a39e84096ac31d3ea", "packages": [ { "name": "consolidation/config", @@ -89,16 +89,16 @@ }, { "name": "consolidation/site-alias", - "version": "2.1.1", + "version": "3.0.0-alpha1", "source": { "type": "git", "url": "https://github.com/consolidation/site-alias.git", - "reference": "13588daf533c9a8df4c9495e3418685cd06867c4" + "reference": "cbf66ca26ad897b13162164905e099abf386035a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/consolidation/site-alias/zipball/13588daf533c9a8df4c9495e3418685cd06867c4", - "reference": "13588daf533c9a8df4c9495e3418685cd06867c4", + "url": "https://api.github.com/repos/consolidation/site-alias/zipball/cbf66ca26ad897b13162164905e099abf386035a", + "reference": "cbf66ca26ad897b13162164905e099abf386035a", "shasum": "" }, "require": { @@ -156,7 +156,7 @@ } ], "description": "Manage alias records for local and remote sites.", - "time": "2019-01-03T14:40:53+00:00" + "time": "2019-03-02T05:48:32+00:00" }, { "name": "dflydev/dot-access-data", @@ -3778,7 +3778,9 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "consolidation/site-alias": 15 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/LICENSE b/LICENSE index 356b3e6..d56f2d9 100644 --- a/LICENSE +++ b/LICENSE @@ -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 \ No newline at end of file +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 \ No newline at end of file diff --git a/composer.json b/composer.json index 7dcc8ad..f1659ba 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/composer.lock b/composer.lock index b31de87..e0e479d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "23afb1800049fe5125ebd61bd7f03d3a", + "content-hash": "bc9eba0080b87ac7b7969e4b785a3768", "packages": [ { "name": "consolidation/config", @@ -89,16 +89,16 @@ }, { "name": "consolidation/site-alias", - "version": "2.1.1", + "version": "3.0.0-alpha1", "source": { "type": "git", "url": "https://github.com/consolidation/site-alias.git", - "reference": "13588daf533c9a8df4c9495e3418685cd06867c4" + "reference": "cbf66ca26ad897b13162164905e099abf386035a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/consolidation/site-alias/zipball/13588daf533c9a8df4c9495e3418685cd06867c4", - "reference": "13588daf533c9a8df4c9495e3418685cd06867c4", + "url": "https://api.github.com/repos/consolidation/site-alias/zipball/cbf66ca26ad897b13162164905e099abf386035a", + "reference": "cbf66ca26ad897b13162164905e099abf386035a", "shasum": "" }, "require": { @@ -156,7 +156,7 @@ } ], "description": "Manage alias records for local and remote sites.", - "time": "2019-01-03T14:40:53+00:00" + "time": "2019-03-02T05:48:32+00:00" }, { "name": "dflydev/dot-access-data", @@ -4257,7 +4257,9 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "consolidation/site-alias": 15 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/src/Factory/DockerComposeTransportFactory.php b/src/Factory/DockerComposeTransportFactory.php index 7a882cf..465e763 100644 --- a/src/Factory/DockerComposeTransportFactory.php +++ b/src/Factory/DockerComposeTransportFactory.php @@ -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; @@ -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(); @@ -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); } } diff --git a/src/Factory/SshTransportFactory.php b/src/Factory/SshTransportFactory.php index d91a7fb..316afa4 100644 --- a/src/Factory/SshTransportFactory.php +++ b/src/Factory/SshTransportFactory.php @@ -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; @@ -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(); @@ -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); } } diff --git a/src/Factory/TransportFactoryInterface.php b/src/Factory/TransportFactoryInterface.php index f429e16..634087e 100644 --- a/src/Factory/TransportFactoryInterface.php +++ b/src/Factory/TransportFactoryInterface.php @@ -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; @@ -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); } diff --git a/src/ProcessManager.php b/src/ProcessManager.php index ab0bf33..dce186c 100644 --- a/src/ProcessManager.php +++ b/src/ProcessManager.php @@ -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; @@ -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 @@ -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; } /** @@ -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); @@ -103,10 +122,10 @@ 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; } @@ -114,14 +133,17 @@ public function hasTransport(AliasRecord $siteAlias) /** * 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(); } @@ -129,10 +151,10 @@ public function getTransport(AliasRecord $siteAlias) /** * 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)) { diff --git a/src/SiteProcess.php b/src/SiteProcess.php index c10fb80..4e39312 100644 --- a/src/SiteProcess.php +++ b/src/SiteProcess.php @@ -1,7 +1,7 @@ siteAlias = $siteAlias; $this->transport = $transport; @@ -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; } @@ -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 */ diff --git a/src/Transport/DockerComposeTransport.php b/src/Transport/DockerComposeTransport.php index bb0012f..92f7d42 100644 --- a/src/Transport/DockerComposeTransport.php +++ b/src/Transport/DockerComposeTransport.php @@ -3,7 +3,7 @@ namespace Consolidation\SiteProcess\Transport; use Consolidation\SiteProcess\SiteProcess; -use Consolidation\SiteAlias\AliasRecord; +use Consolidation\SiteAlias\AliasRecordInterface; use Consolidation\SiteProcess\Util\Shell; use Consolidation\Config\ConfigInterface; @@ -16,12 +16,10 @@ class DockerComposeTransport implements TransportInterface protected $tty; protected $siteAlias; protected $cd_remote; - protected $config; - public function __construct(AliasRecord $siteAlias, ConfigInterface $config) + public function __construct(AliasRecordInterface $siteAlias) { $this->siteAlias = $siteAlias; - $this->config = $config; } /** @@ -64,7 +62,7 @@ public function addChdir($cd, $args) protected function getTransportOptions() { $transportOptions = [ - $this->siteAlias->getConfig($this->config, 'docker.service', ''), + $this->siteAlias->get('docker.service', ''), ]; if ($options = $this->siteAlias->get('docker.exec.options', '')) { array_unshift($transportOptions, Shell::preEscaped($options)); diff --git a/src/Transport/SshTransport.php b/src/Transport/SshTransport.php index 72e8a17..33e9fc2 100644 --- a/src/Transport/SshTransport.php +++ b/src/Transport/SshTransport.php @@ -4,7 +4,7 @@ use Consolidation\SiteProcess\SiteProcess; use Consolidation\SiteProcess\Util\Escape; -use Consolidation\SiteAlias\AliasRecord; +use Consolidation\SiteAlias\AliasRecordInterface; use Consolidation\SiteProcess\Util\Shell; use Consolidation\Config\ConfigInterface; @@ -16,12 +16,10 @@ class SshTransport implements TransportInterface { protected $tty; protected $siteAlias; - protected $config; - public function __construct(AliasRecord $siteAlias, ConfigInterface $config) + public function __construct(AliasRecordInterface $siteAlias) { $this->siteAlias = $siteAlias; - $this->config = $config; } /** @@ -70,7 +68,7 @@ public function addChdir($cd_remote, $args) protected function getTransportOptions() { $transportOptions = [ - Shell::preEscaped($this->siteAlias->getConfig($this->config, 'ssh.options', '-o PasswordAuthentication=no')), + Shell::preEscaped($this->siteAlias->get('ssh.options', '-o PasswordAuthentication=no')), $this->siteAlias->remoteHostWithUser(), ]; if ($this->tty) { diff --git a/src/Transport/TransportInterface.php b/src/Transport/TransportInterface.php index 9ac3787..77c7bc6 100644 --- a/src/Transport/TransportInterface.php +++ b/src/Transport/TransportInterface.php @@ -14,7 +14,6 @@ */ interface TransportInterface { - /** * Configure ourselves based on the settings of the process object * (e.g. isTty()). @@ -29,7 +28,6 @@ public function configure(SiteProcess $process); * alias points at a remote system, though, then the arguments are * escaped and wrapped in an appropriate ssh command. * - * @param AliasRecord $siteAlias alias record of target site. * @param array $args arguments provided by caller. * @return array command and arguments to execute. */ diff --git a/src/Util/ArgumentProcessor.php b/src/Util/ArgumentProcessor.php index 69c9721..01eb811 100644 --- a/src/Util/ArgumentProcessor.php +++ b/src/Util/ArgumentProcessor.php @@ -1,7 +1,7 @@ findArgSeparator($args); diff --git a/src/Util/Escape.php b/src/Util/Escape.php index 7e643cc..2732a16 100644 --- a/src/Util/Escape.php +++ b/src/Util/Escape.php @@ -1,7 +1,7 @@ os()); } diff --git a/src/Util/RealtimeOutputHandler.php b/src/Util/RealtimeOutputHandler.php index 8bceec0..8a71611 100644 --- a/src/Util/RealtimeOutputHandler.php +++ b/src/Util/RealtimeOutputHandler.php @@ -1,7 +1,6 @@