Skip to content

Commit f1790b1

Browse files
committed
fix client
Signed-off-by: Robert Landers <landers.robert@gmail.com>
1 parent 298352a commit f1790b1

1 file changed

Lines changed: 11 additions & 36 deletions

File tree

src/DurableClient.php

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626

2727
use Amp\Http\Client\HttpClientBuilder;
2828
use Bottledcode\DurablePhp\Events\Shares\Operation;
29+
use Bottledcode\DurablePhp\Ext\Worker;
2930
use Bottledcode\DurablePhp\Glue\Provenance;
31+
use Bottledcode\DurablePhp\Proxy\SpyProxy;
3032
use Bottledcode\DurablePhp\Search\EntityFilter;
3133
use Bottledcode\DurablePhp\State\EntityId;
3234
use Bottledcode\DurablePhp\State\EntityState;
@@ -44,41 +46,21 @@ public function __construct(
4446
private OrchestrationClientInterface $orchestrationClient,
4547
) {}
4648

47-
public static function get(string $apiHost = 'http://localhost:8080', ?Provenance $userContext = null): self
49+
public static function local(?Provenance $userContext = null): self
4850
{
49-
if (function_exists('Bottledcode\DurablePhp\Ext\emit_event')) {
50-
$entityClient = new LocalEntityClient();
51-
$orchestrationClient = new LocalOrchestrationClient();
52-
53-
if ($userContext !== null) {
54-
$entityClient->setUserContext($userContext);
55-
$orchestrationClient->setUserContext($userContext);
56-
}
57-
58-
return new self($entityClient, $orchestrationClient);
59-
}
60-
61-
$builder = new HttpClientBuilder();
62-
$builder->retry(3);
63-
64-
$httpClient = $builder->build();
65-
$entityClient = new RemoteEntityClient($apiHost, $httpClient);
66-
$orchestrationClient = new RemoteOrchestrationClient($apiHost, $httpClient);
51+
$entityClient = new LocalEntityClient(new SpyProxy(), new Worker());
52+
$orchestrationClient = new LocalOrchestrationClient(new SpyProxy(), new Worker());
53+
$entityClient->withAuth($userContext);
54+
$orchestrationClient->withAuth($userContext);
6755

6856
return new self($entityClient, $orchestrationClient);
6957
}
7058

71-
public static function local(?Provenance $userContext = null): self
59+
#[Override]
60+
public function withAuth(Provenance|string|null $token): void
7261
{
73-
$entityClient = new LocalEntityClient();
74-
$orchestrationClient = new LocalOrchestrationClient();
75-
76-
if ($userContext !== null) {
77-
$entityClient->setUserContext($userContext);
78-
$orchestrationClient->setUserContext($userContext);
79-
}
80-
81-
return new self($entityClient, $orchestrationClient);
62+
$this->orchestrationClient->withAuth($token);
63+
$this->entityClient->withAuth($token);
8264
}
8365

8466
public static function remote(string $apiHost = 'http://localhost:8080'): self
@@ -170,13 +152,6 @@ public function signal(EntityId|string $entityId, Closure $signal): void
170152
$this->entityClient->signal($entityId, $signal);
171153
}
172154

173-
#[Override]
174-
public function withAuth(Provenance|string|null $token): void
175-
{
176-
$this->orchestrationClient->withAuth($token);
177-
$this->entityClient->withAuth($token);
178-
}
179-
180155
public function deleteEntity(EntityId $entityId): void
181156
{
182157
$this->entityClient->deleteEntity($entityId);

0 commit comments

Comments
 (0)