From 8c602fca99fd7d11a54579c9f4c643eeecdf1051 Mon Sep 17 00:00:00 2001 From: Yamilov Stepan Date: Thu, 23 Mar 2017 12:52:24 +0500 Subject: [PATCH 1/2] Add AbstractStrategy class that implements global StrategyInterface --- src/Deploy/Strategy/AbstractStrategy.php | 42 ++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/Deploy/Strategy/AbstractStrategy.php diff --git a/src/Deploy/Strategy/AbstractStrategy.php b/src/Deploy/Strategy/AbstractStrategy.php new file mode 100644 index 0000000..83412ac --- /dev/null +++ b/src/Deploy/Strategy/AbstractStrategy.php @@ -0,0 +1,42 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Mage\Deploy\Strategy; + +use Mage\Runtime\Exception\RuntimeException; +use Mage\Runtime\Runtime; + +abstract class AbstractStrategy implements StrategyInterface +{ + /** + * @var Runtime + */ + protected $runtime; + + /** + * @param Runtime $runtime + */ + public function setRuntime(Runtime $runtime) + { + $this->runtime = $runtime; + } + + /** + * Check the runtime stage is correct + * @param $stage + * @throws RuntimeException + */ + protected function checkStage($stage) + { + if ($this->runtime->getStage() !== $stage) { + throw new RuntimeException(sprintf('Invalid stage, got "%s" but expected "%"', $this->runtime->getStage(), $stage)); + } + } +} \ No newline at end of file From dd6490e95f2eb759f5f6e9fb74322cdf4031ceb6 Mon Sep 17 00:00:00 2001 From: Yamilov Stepan Date: Thu, 23 Mar 2017 12:53:31 +0500 Subject: [PATCH 2/2] Reformat ReleasesStrategy and RsyncStrategy for handle AbstractStrategy as parent --- src/Deploy/Strategy/ReleasesStrategy.php | 26 +----------------------- src/Deploy/Strategy/RsyncStrategy.php | 26 +----------------------- 2 files changed, 2 insertions(+), 50 deletions(-) diff --git a/src/Deploy/Strategy/ReleasesStrategy.php b/src/Deploy/Strategy/ReleasesStrategy.php index ec34118..307a87a 100644 --- a/src/Deploy/Strategy/ReleasesStrategy.php +++ b/src/Deploy/Strategy/ReleasesStrategy.php @@ -10,7 +10,6 @@ namespace Mage\Deploy\Strategy; -use Mage\Runtime\Exception\RuntimeException; use Mage\Runtime\Runtime; /** @@ -18,23 +17,13 @@ use Mage\Runtime\Runtime; * * @author Andrés Montañez */ -class ReleasesStrategy implements StrategyInterface +class ReleasesStrategy extends AbstractStrategy { - /** - * @var Runtime - */ - protected $runtime; - public function getName() { return 'Releases'; } - public function setRuntime(Runtime $runtime) - { - $this->runtime = $runtime; - } - public function getPreDeployTasks() { $this->checkStage(Runtime::PRE_DEPLOY); @@ -106,17 +95,4 @@ class ReleasesStrategy implements StrategyInterface return $tasks; } - - /** - * Check the runtime stage is correct - * - * @param $stage - * @throws RuntimeException - */ - private function checkStage($stage) - { - if ($this->runtime->getStage() !== $stage) { - throw new RuntimeException(sprintf('Invalid stage, got "%s" but expected "%"', $this->runtime->getStage(), $stage)); - } - } } diff --git a/src/Deploy/Strategy/RsyncStrategy.php b/src/Deploy/Strategy/RsyncStrategy.php index 499a6f6..9751884 100644 --- a/src/Deploy/Strategy/RsyncStrategy.php +++ b/src/Deploy/Strategy/RsyncStrategy.php @@ -10,7 +10,6 @@ namespace Mage\Deploy\Strategy; -use Mage\Runtime\Exception\RuntimeException; use Mage\Runtime\Runtime; /** @@ -18,23 +17,13 @@ use Mage\Runtime\Runtime; * * @author Andrés Montañez */ -class RsyncStrategy implements StrategyInterface +class RsyncStrategy extends AbstractStrategy { - /** - * @var Runtime - */ - protected $runtime; - public function getName() { return 'Rsync'; } - public function setRuntime(Runtime $runtime) - { - $this->runtime = $runtime; - } - public function getPreDeployTasks() { $this->checkStage(Runtime::PRE_DEPLOY); @@ -80,17 +69,4 @@ class RsyncStrategy implements StrategyInterface return $tasks; } - - /** - * Check the runtime stage is correct - * - * @param $stage - * @throws RuntimeException - */ - private function checkStage($stage) - { - if ($this->runtime->getStage() !== $stage) { - throw new RuntimeException(sprintf('Invalid stage, got "%s" but expected "%"', $this->runtime->getStage(), $stage)); - } - } }