diff options
author | Jon Pugh | 2017-11-20 17:07:31 (GMT) |
---|---|---|
committer | Jon Pugh | 2017-11-20 17:07:31 (GMT) |
commit | 180b08505056d6b65491ea0afa6b7e3307cc386c (patch) | |
tree | 7b1f9572cf4c466f68853f496f042bfee042b190 | |
parent | 1c661063289b91a19f0d0459f3f83ad09d593bba (diff) |
Refactor Context to be ProvisionAware, instead of Application aware.
-rw-r--r-- | src/Command.php | 4 | ||||
-rw-r--r-- | src/Common/ProvisionAwareTrait.php | 4 | ||||
-rw-r--r-- | src/Context.php | 26 | ||||
-rw-r--r-- | src/Context/PlatformContext.php | 12 | ||||
-rw-r--r-- | src/Context/SiteContext.php | 11 | ||||
-rw-r--r-- | src/Provision.php | 10 | ||||
-rw-r--r-- | src/Service.php | 10 | ||||
-rw-r--r-- | src/ServiceSubscription.php | 14 |
8 files changed, 53 insertions, 38 deletions
diff --git a/src/Command.php b/src/Command.php index d360660..eeedf56 100644 --- a/src/Command.php +++ b/src/Command.php @@ -83,7 +83,7 @@ abstract class Command extends BaseCommand try { // Load context from context_name argument. $this->context_name = $this->input->getArgument('context_name'); - $this->context = Provision::getContext($this->context_name, $this->getApplication()); + $this->context = Provision::getContext($this->context_name, $this->getProvision()); } catch (\Exception $e) { @@ -105,7 +105,7 @@ abstract class Command extends BaseCommand $this->input->setArgument('context_name', $this->context_name); try { - $this->context = Provision::getContext($this->context_name, $this->getApplication()); + $this->context = Provision::getContext($this->context_name, $this->getProvision()); } catch (\Exception $e) { $this->context = NULL; diff --git a/src/Common/ProvisionAwareTrait.php b/src/Common/ProvisionAwareTrait.php index 800ecc0..02620c3 100644 --- a/src/Common/ProvisionAwareTrait.php +++ b/src/Common/ProvisionAwareTrait.php @@ -9,14 +9,14 @@ trait ProvisionAwareTrait /** * @var Provision */ - protected $provision; + protected $provision = NULL; /** * @param Provision $provision * * @return $this */ - public function setProvision(Provision $provision) + public function setProvision(Provision $provision = NULL) { $this->provision = $provision; diff --git a/src/Context.php b/src/Context.php index feae403..b134514 100644 --- a/src/Context.php +++ b/src/Context.php @@ -6,6 +6,7 @@ namespace Aegir\Provision; +use Aegir\Provision\Common\ProvisionAwareTrait; use Aegir\Provision\Console\Config; use Consolidation\AnnotatedCommand\CommandFileDiscovery; use Drupal\Console\Core\Style\DrupalStyle; @@ -30,6 +31,7 @@ class Context implements BuilderAwareInterface { use BuilderAwareTrait; + use ProvisionAwareTrait; /** * @var string @@ -64,11 +66,6 @@ class Context implements BuilderAwareInterface * init(), set defaults with setProperty(). */ protected $properties = []; - - /** - * @var \Aegir\Provision\Application; - */ - public $application; /** * @var LoggerInterface @@ -81,15 +78,18 @@ class Context implements BuilderAwareInterface * @param $name * @param array $options */ - function __construct($name, Application $application = NULL, $options = []) + function __construct( + $name, + Provision $provision = NULL, + $options = []) { $this->name = $name; - $this->application = $application; $this->loadContextConfig($options); $this->prepareServices(); - if ($this->application) { - $this->setBuilder($this->application->getProvision()->getBuilder()); + if ($provision) { + $this->setProvision($provision); + $this->setBuilder($this->getProvision()->getBuilder()); } } @@ -102,8 +102,8 @@ class Context implements BuilderAwareInterface */ private function loadContextConfig($options = []) { - if ($this->application) { - $this->config_path = $this->application->getConfig()->get('config_path') . '/provision/' . $this->type . '.' . $this->name . '.yml'; + if ($this->getProvision()) { + $this->config_path = $this->getProvision()->getConfig()->get('config_path') . '/provision/' . $this->type . '.' . $this->name . '.yml'; } else { $config = new Config(); @@ -481,13 +481,13 @@ class Context implements BuilderAwareInterface $friendlyName = $service->getFriendlyName(); if ($this->isProvider()) { - $this->application->io->section("Verify service: {$friendlyName}"); + $this->getProvision()->io()->section("Verify service: {$friendlyName}"); foreach ($service->verify() as $type => $verify_success) { $return_codes[] = $verify_success? 0: 1; } } else { - $this->application->io->section("Verify service: {$friendlyName} on {$service->provider->name}"); + $this->getProvision()->io()->section("Verify service: {$friendlyName} on {$service->provider->name}"); // First verify the service provider. foreach ($service->verifyProvider() as $verify_part => $verify_success) { diff --git a/src/Context/PlatformContext.php b/src/Context/PlatformContext.php index 01eb590..04e7903 100644 --- a/src/Context/PlatformContext.php +++ b/src/Context/PlatformContext.php @@ -4,6 +4,7 @@ namespace Aegir\Provision\Context; use Aegir\Provision\Application; use Aegir\Provision\ContextSubscriber; +use Aegir\Provision\Provision; use Symfony\Component\Config\Definition\ConfigurationInterface; /** @@ -30,12 +31,15 @@ class PlatformContext extends ContextSubscriber implements ConfigurationInterfac * PlatformContext constructor. * * @param $name - * @param Application $application + * @param Provision $provision * @param array $options */ - function __construct($name, Application $application = NULL, array $options = []) - { - parent::__construct($name, $application, $options); + function __construct( + $name, + Provision $provision = NULL, + $options = [] + ) { + parent::__construct($name, $provision, $options); // Load "web_server" context. // There is no need to validate for $this->properties['web_server'] because the config system does that. diff --git a/src/Context/SiteContext.php b/src/Context/SiteContext.php index 06d5914..060556e 100644 --- a/src/Context/SiteContext.php +++ b/src/Context/SiteContext.php @@ -35,15 +35,18 @@ class SiteContext extends ContextSubscriber implements ConfigurationInterface * @param Application $application * @param array $options */ - function __construct($name, Application $application = NULL, array $options = []) - { - parent::__construct($name, $application, $options); + function __construct( + $name, + Provision $provision = NULL, + $options = [] + ) { + parent::__construct($name, $provision, $options); // Load "web_server" and "platform" contexts. // There is no need to check if the property exists because the config system does that. // $this->db_server = $application->getContext($this->properties['db_server']); - $this->platform = Provision::getContext($this->properties['platform'], $application); + $this->platform = Provision::getContext($this->properties['platform'], $provision); // Add platform http service subscription. diff --git a/src/Provision.php b/src/Provision.php index 343eedc..7a00023 100644 --- a/src/Provision.php +++ b/src/Provision.php @@ -148,7 +148,7 @@ class Provision implements ConfigAwareInterface, ContainerAwareInterface, Logger * * @return array */ - static function getAllContexts($name = '', $application = NULL) { + static function getAllContexts($name = '', Provision $provision = NULL) { $contexts = []; $config = new Config(); @@ -166,7 +166,7 @@ class Provision implements ConfigAwareInterface, ContainerAwareInterface, Logger foreach ($context_files as $context) { $class = Context::getClassName($context['type']); - $contexts[$context['name']] = new $class($context['name'], $application); + $contexts[$context['name']] = new $class($context['name'], $provision); } if ($name && isset($contexts[$name])) { @@ -228,14 +228,14 @@ class Provision implements ConfigAwareInterface, ContainerAwareInterface, Logger * @return \Aegir\Provision\Context * @throws \Exception */ - static public function getContext($name, Application $application = NULL) { + static public function getContext($name, Provision $provision = NULL) { if (empty($name)) { throw new \Exception('Context name must not be empty.'); } - if (empty(Provision::getAllContexts($name, $application))) { + if (empty(Provision::getAllContexts($name, $provision))) { throw new \Exception('Context not found with name: ' . $name); } - return Provision::getAllContexts($name, $application); + return Provision::getAllContexts($name, $provision); } /** diff --git a/src/Service.php b/src/Service.php index 95399b5..e846916 100644 --- a/src/Service.php +++ b/src/Service.php @@ -8,6 +8,7 @@ namespace Aegir\Provision; +use Aegir\Provision\Common\ProvisionAwareTrait; use Robo\Common\BuilderAwareTrait; use Robo\Common\OutputAdapter; use Robo\Contract\BuilderAwareInterface; @@ -16,6 +17,7 @@ class Service implements BuilderAwareInterface { use BuilderAwareTrait; + use ProvisionAwareTrait; public $type; @@ -30,11 +32,6 @@ class Service implements BuilderAwareInterface public $provider; /** - * @var \Aegir\Provision\Application; - */ - public $application; - - /** * @var string * The machine name of the service. ie. http, db */ @@ -49,7 +46,8 @@ class Service implements BuilderAwareInterface function __construct($service_config, Context $provider_context) { $this->provider = $provider_context; - $this->application = $provider_context->application; + $this->setProvision($provider_context->getProvision()); + $this->type = $service_config['type']; $this->properties = $service_config['properties']; if ($provider_context->getBuilder()) { diff --git a/src/ServiceSubscription.php b/src/ServiceSubscription.php index 26a95e6..b7d9932 100644 --- a/src/ServiceSubscription.php +++ b/src/ServiceSubscription.php @@ -9,6 +9,8 @@ namespace Aegir\Provision; +use Aegir\Provision\Common\ProvisionAwareTrait; + class ServiceSubscription { public $context; @@ -16,16 +18,24 @@ class ServiceSubscription { public $server; public $type; public $properties = []; + + use ProvisionAwareTrait; - function __construct($context, $server, $service_name) { + function __construct( + Context $context, + $server, + $service_name + ) { $this->context = $context; - $this->server = Provision::getContext($server, $context->application); + $this->server = Provision::getContext($server, $context->getProvision()); $this->service = $this->server->getService($service_name); $this->type = $this->server->getService($service_name)->type; if (isset($context->config['service_subscriptions'][$service_name]['properties'])) { $this->properties = $context->config['service_subscriptions'][$service_name]['properties']; } + + $this->setProvision($context->getProvision()); } public function verify() { |