summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Pugh2017-10-26 18:20:06 (GMT)
committerJon Pugh2017-10-26 18:20:06 (GMT)
commit088401df4ad9d8e8d99829a0ec5b78a11bddeea2 (patch)
treecf9dd1c05e5c648bf1f6e04b8d166d865c245545
parent127503149adb2f4b379a0a26fed4343121587f10 (diff)
Add ServiceSubscription class and use that instead of Service on all non-server contexts.
-rw-r--r--src/Context.php24
-rw-r--r--src/Context/SiteContext.php17
-rw-r--r--src/ServiceSubscription.php25
3 files changed, 53 insertions, 13 deletions
diff --git a/src/Context.php b/src/Context.php
index 71897e8..282d6d1 100644
--- a/src/Context.php
+++ b/src/Context.php
@@ -136,10 +136,7 @@ class Context
elseif (isset($this->config['service_subscriptions'])) {
foreach ($this->config['service_subscriptions'] as $service_name => $service) {
$this->servers[$service_name] = $server = $this->application->getContext($service['server']);
- $service_type = ucfirst($server->services[$service_name]->type);
- $service_name = ucfirst($service_name);
- $service_class = "\\Aegir\\Provision\\Service\\{$service_name}\\{$service_name}{$service_type}Service";
- $this->services[strtolower($service_name)] = new $service_class($service, $this);
+ $this->services[$service_name] = new ServiceSubscription($this, $server, $service_name);
}
}
else {
@@ -346,9 +343,24 @@ class Context
*/
public function showServices(DrupalStyle $io) {
if (!empty($this->getServices())) {
+ $is_server = $this->type == 'server';
$rows = [];
+
+ $headers = $is_server?
+ ['Services']:
+ ['Service', 'Server', 'Type'];
+
foreach ($this->getServices() as $name => $service) {
- $rows[] = [$name, $service->type];
+ if ($is_server) {
+ $rows[] = [$name, $service->type];
+ }
+ else {
+ $rows[] = [
+ $name,
+ $service->server->name,
+ $service->server->getService($name)->type
+ ];
+ }
// Show all properties.
if (!empty($service->properties )) {
@@ -357,7 +369,7 @@ class Context
}
}
}
- $io->table(['Services'], $rows);
+ $io->table($headers, $rows);
}
}
diff --git a/src/Context/SiteContext.php b/src/Context/SiteContext.php
index dbb9a0c..156e8e3 100644
--- a/src/Context/SiteContext.php
+++ b/src/Context/SiteContext.php
@@ -33,15 +33,18 @@ class SiteContext extends Context implements ConfigurationInterface
parent::__construct($name, $console_config, $application, $options);
// Load "db_server" context.
- if (isset($this->config['db_server'])) {
- $this->db_server = $application->getContext($this->config['service_subscriptions']['db']['server']);
- $this->db_server->logger = $application->logger;
+// if (isset($this->config['service_subscriptions']['db'])) {
+// $this->db_server = $application->getContext($this->config['service_subscriptions']['db']['server']);
+// }
- $this->platform = $application->getContext($this->config['platform']);
- }
- else {
- throw new \Exception('No db_server found.');
+ $this->logger = $application->logger;
+
+ if (isset($this->config['platform'])) {
+ $this->platform = $application->getContext(
+ $this->config['platform']
+ );
}
+
}
static function option_documentation()
diff --git a/src/ServiceSubscription.php b/src/ServiceSubscription.php
new file mode 100644
index 0000000..bf20e29
--- /dev/null
+++ b/src/ServiceSubscription.php
@@ -0,0 +1,25 @@
+<?php
+/**
+ * @file
+ * A context's subscription to a service. Handles properties specific to a
+ * context for each service.
+ *
+ * @see Provision_Service
+ */
+
+namespace Aegir\Provision;
+
+class ServiceSubscription {
+
+ public $context;
+ public $service;
+ public $server;
+ public $type;
+
+ function __construct($context, $server, $service_name) {
+ $this->context = $context;
+ $this->server = $server;
+ $this->service = $server->getService($service_name);
+ $this->type = $server->getService($service_name)->type;
+ }
+}