Skip to content

Commit

Permalink
Fix listener
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed May 22, 2024
1 parent 908683b commit 6f54fea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/DeclarationLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
use Temporal\Workflow\WorkflowInterface;

#[Singleton]
#[TargetAttribute(WorkflowInterface::class)]
#[TargetAttribute(ActivityInterface::class)]
// #[TargetAttribute(WorkflowInterface::class)]
// #[TargetAttribute(ActivityInterface::class)]
final class DeclarationLocator implements
DeclarationRegistryInterface,
TokenizationListenerInterface,
Expand Down Expand Up @@ -63,13 +63,13 @@ public function listen(\ReflectionClass $class): void
/** @var DeclarationType|null $type */
$type = null;

foreach (\array_merge($class->getInterfaces(), [$class]) as $type) {
if ($this->reader->firstClassMetadata($type, WorkflowInterface::class) !== null) {
foreach (\array_merge($class->getInterfaces(), [$class]) as $reflection) {
if ($this->reader->firstClassMetadata($reflection, WorkflowInterface::class) !== null) {
$type = DeclarationType::Workflow;
break;
}

if ($this->reader->firstClassMetadata($type, ActivityInterface::class) !== null) {
if ($this->reader->firstClassMetadata($reflection, ActivityInterface::class) !== null) {
$type = DeclarationType::Activity;
break;
}
Expand Down
13 changes: 13 additions & 0 deletions tests/src/DeclarationLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,19 @@ class: new \ReflectionClass(TestActivityClassWithInterface::class),
$this->assertSame(ActivityInterface::class, $result[3][0]);
$this->assertSame(TestActivityClassWithInterface::class, $result[3][1]->getName());
}

public function testWrongClasses(): void
{
$this->locator->listen(new \ReflectionClass(\stdClass::class));

$result = [];

foreach ($this->locator->getDeclarations() as $type => $class) {
$result[] = [$type, $class];
}

$this->assertCount(0, $result);
}
}

enum TestEnum
Expand Down

0 comments on commit 6f54fea

Please sign in to comment.