summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Pugh2018-03-26 16:15:16 (GMT)
committerJon Pugh2018-03-26 16:15:16 (GMT)
commitfe683e4804bcaa0c1277544eb0545191da14f6bf (patch)
treed85dabd3820d43af76e905ce0cb4f10f8efbf67f
parentb189a0fa0e8f11b98b39198eb4fe90efec183da4 (diff)
Add servicesInvoke() method for easy running of a method on all services classes assigned to a context.
-rw-r--r--src/Provision/Context.php21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/Provision/Context.php b/src/Provision/Context.php
index 6cc7e23..5c9a2e3 100644
--- a/src/Provision/Context.php
+++ b/src/Provision/Context.php
@@ -340,6 +340,27 @@ class Context implements BuilderAwareInterface
}
/**
+ * Call method $callback on each of the context's service objects.
+ *
+ * @param $callback
+ * A Provision_Service method.
+ * @return
+ * An array of return values from method implementations.
+ */
+ function servicesInvoke(string $callback, array $args = array()) {
+ $results = array();
+ // fetch the merged list of services.
+ // These may be on different servers entirely.
+ $services = $this->getServices();
+ foreach ($services as $service_name => $service) {
+ if (method_exists($service, $callback)) {
+ $results[$service_name] = call_user_func_array(array($service, $callback), $args);
+ }
+ }
+ return $results;
+ }
+
+ /**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()