@@ -8,7 +8,62 @@ Add the library to your `composer.json`:
88
99> composer require dapr/php-sdk
1010
11- Some basic documentation is below, more documentation can be found [ in the docs] ( https://docs.dapr.io/developing-applications/sdks/php/ ) ;
11+ Some basic documentation is below, more documentation can be
12+ found [ in the docs] ( https://docs.dapr.io/developing-applications/sdks/php/ ) ;
13+
14+ # Migrating to 1.2
15+
16+ In preparation for gRPC support in this SDK, there's now a new DaprClient in ` \Dapr\Client\DaprClient ` . Please update
17+ your code to use the new client.
18+
19+ There shouldn't be many changes to your code to upgrade to 1.2+ from a prior version. Namely, there are some
20+ deprecations:
21+
22+ ## Deprecations
23+
24+ The following have been deprecated and will be removed in 1.4+.
25+
26+ ### \Dapr\SecretManager has been deprecated
27+
28+ Simply use the new client instead.
29+
30+ ### \Dapr\Client has been deprecated
31+
32+ Simply use the new client: ` \Dapr\Client\DaprClient ` .
33+
34+ ### \Dapr\PubSub\Publish has been deprecated
35+
36+ Simply instantiate ` \Dapr\PubSub\Topic ` directly or use the new client directly.
37+
38+ ## Fallbacks and Upgrades
39+
40+ ### \Dapr\State\StateManager
41+
42+ This class has been upgraded to use the new client. It shouldn't require any changes to your code, however, the old
43+ behavior can be utilized with ` \Dapr\State\StateManagerOld ` .
44+
45+ ### \Dapr\State\TransactionalState
46+
47+ This class has been upgrade to use the new client. It shouldn't require any changes to your code, however, the old
48+ behavior can be utilized with ` \Dapr\State\TransactionalStateOld ` .
49+
50+ # Creating a Dapr Client
51+
52+ ``` php
53+ $client = \Dapr\Client\DaprClient::clientBuilder()->build();
54+ ```
55+
56+ ## Using the Middleware
57+
58+ The ` App ` object also implements a PSR-15 compatible middleware which implements the actor routes and subscribe routes
59+ for you.
60+
61+ ``` php
62+ $app = \Dapr\App::create(configure: [
63+ // custom configuration
64+ ]);
65+ use_middleware($app);
66+ ```
1267
1368# Accessing Secrets
1469
@@ -17,19 +72,25 @@ You can access secrets easily:
1772``` php
1873<?php
1974
20- $app = Dapr\App::create();
21- $app->get('/a-secret/{name}', function(string $name, \Dapr\SecretManager $secretManager) {
22- return $secretManager->retrieve(secret_store: 'my-secret-store', name: $name);
23- });
24- $app->get('/a-secret', function(\Dapr\SecretManager $secretManager) {
25- return $secretManager->all(secret_store: 'my-secret-store');
26- });
27- $app->start();
75+ // retrieve a single secret
76+ $client->getSecret(storeName: 'kubernetes', key: 'test');
77+
78+ // retrieve all secrets
79+ $client->getBulkSecret(storeName: 'kubernetes');
2880```
2981
3082# Accessing State
3183
32- State is just Plain Old PHP Objects (POPO's) with an attribute:
84+ There are several ways to access state. You can access state directly via the client or abstract access via an object.
85+
86+ ## Accessing State Directly
87+
88+ ``` php
89+ ['value' => $value, 'etag' => $etag] = $client->getStateAndEtag(storeName: 'statestore', key: 'key', asType: SomeClass::class, consistency: \Dapr\consistency\EventualLastWrite::instance());
90+ $value = $client->getState(storeName: 'statestore', key: 'key', asType: 'string',consistency: \Dapr\consistency\StrongFirstWrite::instance())
91+ ```
92+
93+ ## Abstract via Object
3394
3495``` php
3596<?php
@@ -47,9 +108,9 @@ class MyState {
47108 public array $complex_type;
48109
49110 /**
50- * @var Exception
111+ * @var SomeObject
51112 */
52- public Exception $object_type;
113+ public SomeObject $object_type;
53114
54115 /**
55116 * @var int
@@ -82,7 +143,19 @@ $app->start();
82143## Transactional State
83144
84145You can also use transactional state to interact with state objects by extending ` TransactionalState ` with our state
85- objects.
146+ objects or commit transactions directly.
147+
148+ ### Directly with the client
149+
150+ ``` php
151+ $transaction = [
152+ \Dapr\Client\StateTransactionRequest::upsert(key: 'key', value: $client->serializer->as_json($new_value)),
153+ \Dapr\Client\StateTransactionRequest::delete(key: 'key');
154+ ];
155+ $client->executeStateTransaction(storeName: 'statestore', operations: $transaction);
156+ ```
157+
158+ ### Abstracted via an Object
86159
87160``` php
88161#[\Dapr\State\Attributes\StateStore('statestore', \Dapr\consistency\StrongFirstWrite::class)]
@@ -180,9 +253,21 @@ use Dapr\Actors\ActorProxy;
180253$app->start();
181254```
182255
256+ You can also call an actor without an interface:
257+
258+ ``` php
259+ $client->invokeActorMethod(
260+ httpMethod: 'GET',
261+ actor: new \Dapr\Actors\ActorReference(id: 'id', actor_type: 'Counter'),
262+ method: 'increment',
263+ parameter: 1
264+ );
265+ ```
266+
183267## Actor Limitations
184268
185- 1 . There's no re-entrance to an actor, this can cause deadlocks if you're not careful.
269+ 1 . There's no re-entrance to an actor, by default. You'll need to enable it in the ` ActorConfig `
270+ and [ in Dapr] ( https://docs.dapr.io/operations/support/support-preview-features/ ) .
1862712 . By design, static functions don't work.
1872723 . There's overhead cost in calling "getter" functions.
188273
@@ -195,18 +280,24 @@ implemented in this SDK.
195280
196281## Publishing
197282
198- In order to publish an event, you just instantiate the ` Publish ` object with the ` FactoryInterface ` :
283+ In order to publish an event, you just instantiate the ` Topic ` object:
199284
200285``` php
201286<?php
202287$app = \Dapr\App::create();
203- $app->get('/publish', function(\DI\FactoryInterface $factory ) {
204- $publisher = $factory->make( \Dapr\PubSub\Publish::class, [ 'pubsub' => 'redis-pubsub'] );
205- $publisher-> topic('my-topic') ->publish(['message' => 'arrive at dawn']);
288+ $app->get('/publish', function(\Dapr\Client\DaprClient $client ) {
289+ $topic = new \Dapr\PubSub\Topic(pubsub: 'pubsub', topic: 'topic', client: $client );
290+ $topic->publish(['message' => 'arrive at dawn']);
206291});
207292$app->start();
208293```
209294
295+ or you can use the new client like:
296+
297+ ``` php
298+ $client->publishEvent(pubsubName: 'pubsub', topicName: 'topic', data: ['message' => 'arrive at dawn'], contentType: 'application/json');
299+ ```
300+
210301## Subscribing
211302
212303``` php
@@ -238,13 +329,18 @@ $app->get('/', function(\Dapr\Serialization\ISerializer $serializer) {
238329$app->start();
239330```
240331
241- # Development
332+ ## Using the new client
333+
334+ ``` php
335+ $client = \Dapr\Client\DaprClient::clientBuilder()
336+ ->withDeserializationConfig($configuration)
337+ ->withSerializationConfig($configuration)
338+ ->build()
339+ ```
242340
243- Simply run ` composer start ` on a machine where ` dapr init ` has already been run. This will start the daprd service on
244- the current open terminal. Then navigate to [ http://localhost:9502/do_tests ] ( http://localhost:9502/do_tests ) to let the
245- integration tests run.
341+ # Development
246342
247- # Tests
343+ ## Tests
248344
249345Simply run ` composer test ` to run the unit tests. You can lint using ` composer lint ` .
250346
@@ -255,15 +351,11 @@ You need [`docker-compose`](https://docs.docker.com/compose/gettingstarted/) and
255351Build and start the environment, then run the integration tests and clean up.
256352
257353``` bash
258- # clean up any existing environment
259- docker-compose down -v
260- # build and deploy the containers
261- composer start
262- # run and display the test rusults
263- composer integration-tests | jq .
354+ make
264355```
265356
266357You should see output like:
358+
267359``` json
268360{
269361 "/test/actors" : {
0 commit comments