summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Pugh2017-10-26 17:47:47 (GMT)
committerJon Pugh2017-10-26 17:47:47 (GMT)
commit127503149adb2f4b379a0a26fed4343121587f10 (patch)
tree9de51e1a193196ed695eb64038698368e6b18083
parentf7322fc8990ba79d8c7a4b47aa16c73c299d712a (diff)
Add allowedContexts() method for limiting what services can be subscribed to by which contexts.
-rw-r--r--src/Context.php5
-rw-r--r--src/Service.php8
-rw-r--r--src/Service/DbService.php12
-rw-r--r--src/Service/HttpService.php10
4 files changed, 33 insertions, 2 deletions
diff --git a/src/Context.php b/src/Context.php
index 641ce08..71897e8 100644
--- a/src/Context.php
+++ b/src/Context.php
@@ -160,7 +160,10 @@ class Context
$discovery->setSearchPattern('*Service.php');
$servicesFiles = $discovery->discover(__DIR__ .'/Service', '\Aegir\Provision\Service');
foreach ($servicesFiles as $serviceClass) {
- $classes[$serviceClass::SERVICE] = $serviceClass;
+ // If this is a server, show all services. If it is not, but service allows this type of context, load it.
+ if ($this->type == 'server' || in_array($this->type, $serviceClass::allowedContexts())) {
+ $classes[$serviceClass::SERVICE] = $serviceClass;
+ }
}
if ($service && isset($classes[$service])) {
diff --git a/src/Service.php b/src/Service.php
index d253cd3..f780552 100644
--- a/src/Service.php
+++ b/src/Service.php
@@ -27,6 +27,14 @@ class Service {
function verify() {
$this->writeConfigurations();
}
+
+ /**
+ * List context types that are allowed to subscribe to this service.
+ * @return array
+ */
+ static function allowedContexts() {
+ return [];
+ }
/**
* Write this service's configurations.
diff --git a/src/Service/DbService.php b/src/Service/DbService.php
index 7042a68..8988e7a 100644
--- a/src/Service/DbService.php
+++ b/src/Service/DbService.php
@@ -36,7 +36,17 @@ class DbService extends Service
'db_grant_all_hosts' => 'Grant access to site database users from any web host. If set to TRUE, any host will be allowed to connect to MySQL site databases on this server using the generated username and password. If set to FALSE, web hosts will be granted access by their detected IP address.',
];
}
-
+
+ /**
+ * List context types that are allowed to subscribe to this service.
+ * @return array
+ */
+ static function allowedContexts() {
+ return [
+ 'site'
+ ];
+ }
+
/**
* Implements Service::server_options()
*
diff --git a/src/Service/HttpService.php b/src/Service/HttpService.php
index 0fbdc7a..af6ce49 100644
--- a/src/Service/HttpService.php
+++ b/src/Service/HttpService.php
@@ -40,6 +40,16 @@ class HttpService extends Service {
'restart_command' => 'The command to reload the web server configuration;'
];
}
+
+ /**
+ * List context types that are allowed to subscribe to this service.
+ * @return array
+ */
+ static function allowedContexts() {
+ return [
+ 'platform'
+ ];
+ }
/**
* Support the ability to cloak the database credentials using environment variables.