Skip to content

Commit 34342fc

Browse files
authored
Merge pull request #1 from Micro-PHP/v1.0
v1.0
2 parents b06f385 + 6a30dce commit 34342fc

13 files changed

Lines changed: 96 additions & 28 deletions

composer.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Micro Framework: TemporalIO plugin",
44
"type": "library",
55
"license": "MIT",
6-
"version": "0.1",
6+
"version": "1.0",
77
"autoload": {
88
"psr-4": {
99
"Micro\\Plugin\\Temporal\\": "src/"
@@ -15,15 +15,13 @@
1515
"email": "stanislau_komar@epam.com"
1616
}
1717
],
18-
"scripts": {
19-
"phpcs": "phpcs -p ./src --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --runtime-set testVersion 8.0"
20-
},
2118
"require": {
19+
"micro/kernel": "^1",
2220
"temporal/sdk": ">=2.0",
2321
"spiral/tokenizer": ">=2.7"
2422
},
2523
"require-dev": {
26-
"squizlabs/php_codesniffer": "^3.7",
27-
"phpcompatibility/php-compatibility": "^9.3"
24+
},
25+
"scripts": {
2826
}
2927
}

src/Activity/Builder/ActivityStubBuilderInterface.php

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Micro\Plugin\Temporal\Activity\Factory;
4+
5+
use Temporal\Activity\ActivityOptions;
6+
use Temporal\Internal\Workflow\ActivityProxy;
7+
use Temporal\Workflow;
8+
9+
class ActivityStubFactory implements ActivityStubFactoryInterface
10+
{
11+
/**
12+
* {@inheritDoc}
13+
*/
14+
public function create(string $activityInterface): ActivityProxy
15+
{
16+
return Workflow::newActivityStub($activityInterface,
17+
ActivityOptions::new()
18+
);
19+
}
20+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Micro\Plugin\Temporal\Activity\Factory;
4+
5+
use Temporal\Internal\Workflow\ActivityProxy;
6+
7+
interface ActivityStubFactoryInterface
8+
{
9+
/**
10+
* @template T
11+
*
12+
* @param class-string<T> $activityInterface
13+
*
14+
* @return T
15+
*/
16+
public function create(string $activityInterface): ActivityProxy;
17+
}

src/Configuration/Client/WorkflowClientConfiguration.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
use Micro\Framework\Kernel\Configuration\PluginRoutingKeyConfiguration;
66

7-
class WorkflowClientConfiguration extends PluginRoutingKeyConfiguration implements WorkflowClientConfigurationInterface
7+
class
8+
WorkflowClientConfiguration extends PluginRoutingKeyConfiguration implements WorkflowClientConfigurationInterface
89
{
910
const CFG_TEMPORAL_HOST = 'TEMPORAL_CLIENT_%s_HOST';
1011
const CFG_TEMPORAL_PORT = 'TEMPORAL_CLIENT_%s_PORT';

src/Configuration/RoadRunner/RoadRunnerConfiguration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ class RoadRunnerConfiguration extends PluginRoutingKeyConfiguration implements R
1717
*/
1818
public function getRelayAddress(): string
1919
{
20-
return $this->get(self::CFG_RELAY_ADDRESS, 'tcp://127.0.0.1:7233');
20+
return $this->get(self::CFG_RELAY_ADDRESS, 'tcp://localhost:7233');
2121
}
2222

2323
/**
2424
* {@inheritDoc}
2525
*/
2626
public function getRPCAddress(): string
2727
{
28-
return $this->get(self::CFG_RPC_ADDRESS, 'tcp://127.0.0.1:6001');
28+
return $this->get(self::CFG_RPC_ADDRESS, 'tcp://localhost:6001');
2929
}
3030

3131
#[ExpectedValues(valuesFromClass: Mode::class)]

src/Configuration/Worker/WorkflowWorkerConfiguration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ class WorkflowWorkerConfiguration extends PluginRoutingKeyConfiguration implemen
2323
*/
2424
public function getRelayAddress(): string
2525
{
26-
return $this->get(self::CFG_RELAY_ADDRESS, 'tcp://127.0.0.1:7233');
26+
return $this->get(self::CFG_RELAY_ADDRESS, 'tcp://localhost:7233');
2727
}
2828

2929
/**
3030
* {@inheritDoc}
3131
*/
3232
public function getRPCAddress(): string
3333
{
34-
return $this->get(self::CFG_RPC_ADDRESS, 'tcp://127.0.0.1:6001');
34+
return $this->get(self::CFG_RPC_ADDRESS, 'tcp://localhost:6001');
3535
}
3636

3737
/**

src/Facade/TemporalFacade.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,27 @@
22

33
namespace Micro\Plugin\Temporal\Facade;
44

5+
use Micro\Plugin\Temporal\Activity\Factory\ActivityStubFactoryInterface;
56
use Micro\Plugin\Temporal\Configuration\TemporalPluginConfigurationInterface;
67
use Micro\Plugin\Temporal\Worker\Factory\WorkerFactoryInterface;
78
use Micro\Plugin\Temporal\Workflow\Client\Repository\ClientRepositoryInterface;
89
use Temporal\Client\WorkflowClientInterface;
910
use Temporal\Client\WorkflowOptions;
1011
use Temporal\Internal\Support\Options;
12+
use Temporal\Internal\Workflow\ActivityProxy;
1113
use Temporal\Worker\WorkerFactoryInterface as TemporalWorkerFactoryInterface;
1214

1315
class TemporalFacade implements TemporalFacadeInterface
1416
{
1517
/**
1618
* @param ClientRepositoryInterface $clientRepository
1719
* @param WorkerFactoryInterface $workerFactory
20+
* @param ActivityStubFactoryInterface $activityStubFactory
1821
*/
1922
public function __construct(
2023
private readonly ClientRepositoryInterface $clientRepository,
21-
private readonly WorkerFactoryInterface $workerFactory
24+
private readonly WorkerFactoryInterface $workerFactory,
25+
private readonly ActivityStubFactoryInterface $activityStubFactory
2226
)
2327
{
2428
}
@@ -31,6 +35,14 @@ public function workflowClient(string $clientName = TemporalPluginConfigurationI
3135
return $this->clientRepository->client($clientName);
3236
}
3337

38+
/**
39+
* {@inheritDoc}
40+
*/
41+
public function createActivityStub(string $activityInterface): ActivityProxy
42+
{
43+
return $this->activityStubFactory->create($activityInterface);
44+
}
45+
3446
/**
3547
* {@inheritDoc}
3648
*/

src/Facade/TemporalFacadeInterface.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Micro\Plugin\Temporal\Configuration\TemporalPluginConfigurationInterface;
66
use Temporal\Client\WorkflowClientInterface;
77
use Temporal\Internal\Support\Options;
8+
use Temporal\Internal\Workflow\ActivityProxy;
89
use Temporal\Worker\WorkerFactoryInterface as TemporalWorkerFactoryInterface;
910

1011
interface TemporalFacadeInterface
@@ -16,6 +17,15 @@ interface TemporalFacadeInterface
1617
*/
1718
public function workflowClient(string $clientName = TemporalPluginConfigurationInterface::CLIENT_DEFAULT): WorkflowClientInterface;
1819

20+
/**
21+
* @template T
22+
*
23+
* @param class-string<T> $activityInterface
24+
*
25+
* @return T
26+
*/
27+
public function createActivityStub(string $activityInterface): ActivityProxy;
28+
1929
/**
2030
* @return Options
2131
*/

src/TemporalPlugin.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
use Micro\Component\DependencyInjection\Autowire\AutowireHelperFactory;
66
use Micro\Component\DependencyInjection\Autowire\AutowireHelperFactoryInterface;
77
use Micro\Component\DependencyInjection\Container;
8-
use Micro\Framework\Kernel\Plugin\AbstractPlugin;
8+
use Micro\Framework\Kernel\Plugin\ConfigurableInterface;
9+
use Micro\Framework\Kernel\Plugin\DependencyProviderInterface;
10+
use Micro\Framework\Kernel\Plugin\PluginConfigurationTrait;
911
use Micro\Library\DTO\SerializerFacadeInterface;
1012
use Micro\Plugin\Locator\Facade\LocatorFacadeInterface;
13+
use Micro\Plugin\Temporal\Activity\Factory\ActivityStubFactory;
14+
use Micro\Plugin\Temporal\Activity\Factory\ActivityStubFactoryInterface;
1115
use Micro\Plugin\Temporal\Configuration\TemporalPluginConfigurationInterface;
1216
use Micro\Plugin\Temporal\Facade\TemporalFacade;
1317
use Micro\Plugin\Temporal\Facade\TemporalFacadeInterface;
@@ -19,17 +23,19 @@
1923
use Micro\Plugin\Temporal\Worker\Factory\WorkerFactoryInterface;
2024
use Micro\Plugin\Temporal\Workflow\Client\Factory\ClientFactory;
2125
use Micro\Plugin\Temporal\Workflow\Client\Factory\ClientFactoryInterface;
22-
use Micro\Plugin\Temporal\Workflow\Client\Repository\ClientRepository;
2326
use Micro\Plugin\Temporal\Workflow\Client\Repository\ClientRepositoryFactory;
2427
use Micro\Plugin\Temporal\Workflow\Client\Repository\ClientRepositoryFactoryInterface;
28+
use Micro\Plugin\Temporal\Workflow\Client\Repository\ClientRepositoryInterface;
2529
use Micro\Plugin\Temporal\Workflow\DataConverter\DataConverterFactory;
2630
use Micro\Plugin\Temporal\Workflow\DataConverter\DataConverterFactoryInterface;
2731

2832
/**
2933
* @method TemporalPluginConfigurationInterface configuration()
3034
*/
31-
class TemporalPlugin extends AbstractPlugin
35+
class TemporalPlugin implements DependencyProviderInterface, ConfigurableInterface
3236
{
37+
use PluginConfigurationTrait;
38+
3339
/**
3440
* @var SerializerFacadeInterface|null
3541
*/
@@ -69,7 +75,8 @@ protected function createFacade(): TemporalFacadeInterface
6975
{
7076
return new TemporalFacade(
7177
clientRepository: $this->createWorkflowClientRepository(),
72-
workerFactory: $this->createWorkerFactory()
78+
workerFactory: $this->createWorkerFactory(),
79+
activityStubFactory: $this->createActivityStubFactory()
7380
);
7481
}
7582

@@ -101,9 +108,9 @@ protected function createWorkflowClientRepositoryFactory(): ClientRepositoryFact
101108
}
102109

103110
/**
104-
* @return ClientRepository
111+
* @return ClientRepositoryInterface
105112
*/
106-
protected function createWorkflowClientRepository(): ClientRepository
113+
protected function createWorkflowClientRepository(): ClientRepositoryInterface
107114
{
108115
return $this->createWorkflowClientRepositoryFactory()->create();
109116
}
@@ -116,6 +123,17 @@ protected function createWorkerExpanderFactory(): WorkerExpanderFactoryInterface
116123
);
117124
}
118125

126+
/**
127+
* @return ActivityStubFactoryInterface
128+
*/
129+
protected function createActivityStubFactory(): ActivityStubFactoryInterface
130+
{
131+
return new ActivityStubFactory();
132+
}
133+
134+
/**
135+
* @return WorkerFactoryInterface
136+
*/
119137
protected function createWorkerFactory(): WorkerFactoryInterface
120138
{
121139
return new WorkerFactory(

0 commit comments

Comments
 (0)