Skip to content

Commit

Permalink
Proxy income envelope headers to local context
Browse files Browse the repository at this point in the history
  • Loading branch information
zloyuser committed Dec 20, 2023
1 parent 383300c commit fc6f659
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
22 changes: 22 additions & 0 deletions src/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

final class Context
{
private const OPTION_LOCAL = 'local';

/**
* @param Dispatcher $dispatcher
* @param DeferredIterator $deferred
Expand All @@ -31,6 +33,18 @@ public function dispatch(object $message, array $options = []): void
$this->dispatcher->dispatch($message, $options);
}

/**
* @param object $message
* @param array<string, mixed> $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<string, mixed> $options
Expand Down Expand Up @@ -97,4 +111,12 @@ public function del(string $option): self

return $this;
}

/**
* @return bool
*/
public function isLocal(): bool
{
return $this->has(self::OPTION_LOCAL);
}
}
6 changes: 1 addition & 5 deletions src/Remote/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

final class Gateway
{
public const OPTION_LOCAL = 'local';

/**
* @param Transport $transport
* @param Serializer $serializer
Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/Remote/RemoteMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit fc6f659

Please sign in to comment.