diff options
author | Jon Pugh | 2017-11-14 19:12:38 (GMT) |
---|---|---|
committer | Jon Pugh | 2017-11-14 19:12:38 (GMT) |
commit | ba547cdf3d4e8f8ce2887cfbe12a7fdced9f534c (patch) | |
tree | 43d86e72fc0a3327a358a46ef3f9df826a47f617 | |
parent | 868e6d54061dae207ef37569021ba818ed3941c8 (diff) |
Load platform http subscription into site contexts.
-rw-r--r-- | src/Context/SiteContext.php | 21 | ||||
-rw-r--r-- | src/ContextSubscriber.php | 7 |
2 files changed, 27 insertions, 1 deletions
diff --git a/src/Context/SiteContext.php b/src/Context/SiteContext.php index f9d07e2..98bd2b8 100644 --- a/src/Context/SiteContext.php +++ b/src/Context/SiteContext.php @@ -43,6 +43,11 @@ class SiteContext extends ContextSubscriber implements ConfigurationInterface // $this->db_server = $application->getContext($this->properties['db_server']); $this->platform = Application::getContext($this->properties['platform'], $application); + + + // Add platform http service subscription. + $this->serviceSubscriptions['http'] = $this->platform->getSubscription('http'); + } static function option_documentation() @@ -70,4 +75,20 @@ class SiteContext extends ContextSubscriber implements ConfigurationInterface 'platform' => 'platform' ]; } + + /** + * Overrides ContextSubscriber::getSubscriptions() to add in the platform's subscriptions. + * + * @return array + */ + public function getSubscriptions() { + + // Load this context's subscriptions. + $subscriptions = parent::getSubscriptions(); + + // Load the platform's subscriptions. + $subscriptions += $this->platform->getSubscriptions(); + + return $subscriptions; + } } diff --git a/src/ContextSubscriber.php b/src/ContextSubscriber.php index 7a8318e..a2a68f3 100644 --- a/src/ContextSubscriber.php +++ b/src/ContextSubscriber.php @@ -35,7 +35,12 @@ class ContextSubscriber extends Context } foreach ($this->properties['service_subscriptions'] as $service_name => $service) { + + // Load into serviceSubscriptions property. $this->serviceSubscriptions[$service_name] = new ServiceSubscription($this, $service['server'], $service_name); + + // Also load into services property for easy access. + $this->services[$service_name] = $this->serviceSubscriptions[$service_name]->service; } } @@ -61,7 +66,7 @@ class ContextSubscriber extends Context return $this->serviceSubscriptions[$type]; } else { - throw new \Exception("Service '$type' does not exist in the context '{$this->name}'."); + throw new \Exception("Service subscription '$type' does not exist in the context '{$this->name}'."); } } |