Skip to content

Commit

Permalink
Static method canServe, stable SF version
Browse files Browse the repository at this point in the history
  • Loading branch information
msmakouz committed Mar 1, 2024
1 parent 450de73 commit 8ea5fa4
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"temporal/sdk": "^2.7"
},
"require-dev": {
"spiral/framework": "dev-feature/scopes as 3.12.0",
"spiral/framework": "^3.12",
"spiral/testing": "^2.6",
"vimeo/psalm": "^5.17"
},
Expand Down
2 changes: 1 addition & 1 deletion src/Bootloader/TemporalBridgeBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function init(
$this->initConfig($env);

$console->addCommand(Commands\InfoCommand::class);
$kernel->addDispatcher($this->factory->make(Dispatcher::class));
$kernel->addDispatcher(Dispatcher::class);
}

public function addWorkerOptions(string $worker, WorkerOptions $options): void
Expand Down
10 changes: 4 additions & 6 deletions src/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,24 @@
use Spiral\Core\FactoryInterface;
use Spiral\Core\Scope;
use Spiral\Core\ScopeInterface;
use Spiral\Framework\Spiral;
use Spiral\RoadRunnerBridge\RoadRunnerMode;
use Temporal\Activity\ActivityInterface;
use Temporal\Worker\WorkerFactoryInterface;
use Temporal\Workflow\WorkflowInterface;

#[DispatcherScope(Spiral::Temporal)]
#[DispatcherScope('temporal')]
final class Dispatcher implements DispatcherInterface
{
public function __construct(
private readonly RoadRunnerMode $mode,
private readonly ContainerInterface $container,
private readonly DeclarationWorkerResolver $workerResolver,
private readonly ScopeInterface $scope,
) {
}

public function canServe(): bool
public static function canServe(RoadRunnerMode $mode): bool

Check warning on line 29 in src/Dispatcher.php

View check run for this annotation

Codecov / codecov/patch

src/Dispatcher.php#L29

Added line #L29 was not covered by tests
{
return \PHP_SAPI === 'cli' && $this->mode === RoadRunnerMode::Temporal;
return \PHP_SAPI === 'cli' && $mode === RoadRunnerMode::Temporal;

Check warning on line 31 in src/Dispatcher.php

View check run for this annotation

Codecov / codecov/patch

src/Dispatcher.php#L31

Added line #L31 was not covered by tests
}

public function serve(): void
Expand Down Expand Up @@ -81,7 +79,7 @@ private function makeActivity(ReflectionClass $class): object
{
/** @psalm-suppress InvalidArgument */
return $this->scope->runScope(
new Scope(Spiral::TemporalActivity),
new Scope('temporal.activity'),
static fn(FactoryInterface $factory): object => $factory->make($class->getName()),
);
}
Expand Down
5 changes: 1 addition & 4 deletions tests/src/DispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

use Mockery as m;
use Spiral\Attributes\AttributeReader;
use Spiral\Framework\Spiral;
use Spiral\RoadRunnerBridge\RoadRunnerMode;
use Spiral\TemporalBridge\Config\TemporalConfig;
use Spiral\TemporalBridge\DeclarationLocatorInterface;
use Spiral\TemporalBridge\DeclarationWorkerResolver;
Expand All @@ -32,7 +30,6 @@ protected function setUp(): void
parent::setUp();

$this->dispatcher = new Dispatcher(
RoadRunnerMode::Temporal,
$this->getContainer(),
new DeclarationWorkerResolver(
new AttributeReader(),
Expand Down Expand Up @@ -107,7 +104,7 @@ public function testServeWithDeclarations(): void

public function testScope(): void
{
$binder = $this->getContainer()->getBinder(Spiral::TemporalActivity);
$binder = $this->getContainer()->getBinder('temporal.activity');
$binder->bind(SomeActivityWithScope::class, SomeActivityWithScope::class);
$binder->bind(\ArrayAccess::class, $this->createMock(\ArrayAccess::class));

Expand Down

0 comments on commit 8ea5fa4

Please sign in to comment.