Skip to content

Commit

Permalink
Adds interceptors support
Browse files Browse the repository at this point in the history
  • Loading branch information
butschster committed Dec 25, 2023
1 parent e56900a commit 2266613
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 48 deletions.
22 changes: 9 additions & 13 deletions src/Bootloader/TemporalBridgeBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Spiral\Boot\AbstractKernel;
use Spiral\Boot\Bootloader\Bootloader;
use Spiral\Boot\EnvironmentInterface;
use Spiral\Boot\FinalizerInterface;
use Spiral\Config\ConfiguratorInterface;
use Spiral\Config\Patch\Append;
use Spiral\Console\Bootloader\ConsoleBootloader;
Expand All @@ -20,8 +19,6 @@
use Spiral\TemporalBridge\DeclarationLocator;
use Spiral\TemporalBridge\DeclarationLocatorInterface;
use Spiral\TemporalBridge\Dispatcher;
use Spiral\TemporalBridge\Preset\PresetRegistry;
use Spiral\TemporalBridge\Preset\PresetRegistryInterface;
use Spiral\TemporalBridge\WorkerFactory;
use Spiral\TemporalBridge\WorkerFactoryInterface;
use Spiral\TemporalBridge\WorkersRegistry;
Expand Down Expand Up @@ -55,7 +52,8 @@ public function defineDependencies(): array
public function defineSingletons(): array
{
return [
WorkerFactoryInterface::class => [self::class, 'initWorkerFactory'],
TemporalWorkerFactoryInterface::class => [self::class, 'initWorkerFactory'],
WorkerFactoryInterface::class => WorkerFactory::class,
DeclarationLocatorInterface::class => [self::class, 'initDeclarationLocator'],
WorkflowClientInterface::class => [self::class, 'initWorkflowClient'],
WorkersRegistryInterface::class => WorkersRegistry::class,
Expand Down Expand Up @@ -91,7 +89,7 @@ protected function initConfig(EnvironmentInterface $env): void
[
'address' => $env->get('TEMPORAL_ADDRESS', '127.0.0.1:7233'),
'namespace' => 'App\\Endpoint\\Temporal\\Workflow',
'defaultWorker' => (string)$env->get('TEMPORAL_TASK_QUEUE', WorkerFactoryInterface::DEFAULT_TASK_QUEUE),
'defaultWorker' => (string)$env->get('TEMPORAL_TASK_QUEUE', TemporalWorkerFactoryInterface::DEFAULT_TASK_QUEUE),
'workers' => [],
],
);
Expand All @@ -115,18 +113,16 @@ protected function initDataConverter(): DataConverterInterface
return DataConverter::createDefault();
}

protected function initWorkerFactory(
DataConverterInterface $dataConverter,
): WorkerFactoryInterface {
return new WorkerFactory(
protected function initWorkerFactory(DataConverterInterface $dataConverter,): TemporalWorkerFactoryInterface
{
return new TemporalWorkerFactory(
dataConverter: $dataConverter,
rpc: Goridge::create(),
);
}

protected function initDeclarationLocator(
ClassesInterface $classes,
): DeclarationLocatorInterface {
protected function initDeclarationLocator(ClassesInterface $classes,): DeclarationLocatorInterface
{
return new DeclarationLocator(
classes: $classes,
reader: new AttributeReader(),
Expand All @@ -137,7 +133,7 @@ protected function initPipelineProvider(TemporalConfig $config, FactoryInterface
{
/** @var Interceptor[] $interceptors */
$interceptors = \array_map(
static fn (mixed $interceptor) => match (true) {
static fn(mixed $interceptor) => match (true) {
\is_string($interceptor) => $factory->make($interceptor),
$interceptor instanceof Autowire => $interceptor->resolve($factory),
default => $interceptor
Expand Down
29 changes: 0 additions & 29 deletions tests/src/Bootloader/PrototypeBootloaderTest.php

This file was deleted.

20 changes: 14 additions & 6 deletions tests/src/Bootloader/TemporalBridgeBootloaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@

class TemporalBridgeBootloaderTest extends TestCase
{
public function testTemporalWorkerFactory(): void
{
$this->assertContainerBoundAsSingleton(
TemporalWorkerFactoryInterface::class,
TemporalWorkerFactory::class,
);
}

public function testWorkerFactory(): void
{
$this->assertContainerBoundAsSingleton(
Expand All @@ -39,39 +47,39 @@ public function testDataConverter(): void
{
$this->assertContainerBoundAsSingleton(
DataConverterInterface::class,
DataConverter::class
DataConverter::class,
);
}

public function testDeclarationLocator(): void
{
$this->assertContainerBoundAsSingleton(
DeclarationLocatorInterface::class,
DeclarationLocator::class
DeclarationLocator::class,
);
}

public function testWorkflowClient(): void
{
$this->assertContainerBoundAsSingleton(
WorkflowClientInterface::class,
WorkflowClient::class
WorkflowClient::class,
);
}

public function testWorkersRegistry(): void
{
$this->assertContainerBoundAsSingleton(
WorkersRegistryInterface::class,
WorkersRegistry::class
WorkersRegistry::class,
);
}

public function testPipelineProvider(): void
{
$this->assertContainerBound(
PipelineProvider::class,
SimplePipelineProvider::class
SimplePipelineProvider::class,
);
}

Expand All @@ -86,7 +94,7 @@ public function testAddWorkerOptions(): void

$this->assertSame(
['first' => $first, 'second' => $second],
$configs->getConfig(TemporalConfig::CONFIG)['workers']
$configs->getConfig(TemporalConfig::CONFIG)['workers'],
);
}
}

0 comments on commit 2266613

Please sign in to comment.