diff --git a/src/Context.php b/src/Context.php index d1f429f..a004ac3 100644 --- a/src/Context.php +++ b/src/Context.php @@ -8,6 +8,8 @@ final class Context { + private const OPTION_LOCAL = 'local'; + /** * @param Dispatcher $dispatcher * @param DeferredIterator $deferred @@ -31,6 +33,18 @@ public function dispatch(object $message, array $options = []): void $this->dispatcher->dispatch($message, $options); } + /** + * @param object $message + * @param array $options + * @return void + */ + public function execute(object $message, array $options = []): void + { + $this->dispatcher->dispatch($message, array_replace($options, [ + self::OPTION_LOCAL => true, + ])); + } + /** * @param object $message * @param array $options @@ -97,4 +111,12 @@ public function del(string $option): self return $this; } + + /** + * @return bool + */ + public function isLocal(): bool + { + return $this->has(self::OPTION_LOCAL); + } } diff --git a/src/Remote/Gateway.php b/src/Remote/Gateway.php index d933ab4..0e13321 100644 --- a/src/Remote/Gateway.php +++ b/src/Remote/Gateway.php @@ -8,8 +8,6 @@ final class Gateway { - public const OPTION_LOCAL = 'local'; - /** * @param Transport $transport * @param Serializer $serializer @@ -41,8 +39,6 @@ public function receive(Envelope $envelope, Context $context): void { $message = $this->serializer->unserialize($envelope); - $context->dispatch($message, [ - self::OPTION_LOCAL => true, - ]); + $context->execute($message, $envelope->headers); } } diff --git a/src/Remote/RemoteMiddleware.php b/src/Remote/RemoteMiddleware.php index b274812..04d458d 100644 --- a/src/Remote/RemoteMiddleware.php +++ b/src/Remote/RemoteMiddleware.php @@ -37,6 +37,6 @@ public function call(object $message, Context $context, callable $next): void */ private function isLocal(string $class, Context $context): bool { - return $context->has(Gateway::OPTION_LOCAL) || in_array($class, $this->local); + return $context->isLocal() || in_array($class, $this->local); } }