Skip to content

Commit f0d66c3

Browse files
Update php docs (#124)
* Update php docs * Clarify installation * Fix code tab
1 parent 657c3a6 commit f0d66c3

File tree

4 files changed

+35
-12
lines changed

4 files changed

+35
-12
lines changed

daprdocs/content/en/php-sdk-docs/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Dapr offers an SDK to help with the development of PHP applications. Using it, y
2424
## Initialize your project
2525

2626
In a directory where you want to create your service, run `composer init` and answer the questions.
27-
Install `dapr/php-sdk` and any other dependencies you may wish to use.
27+
Install with `composer require dapr/php-sdk` and any other dependencies you may wish to use.
2828

2929
## Configure your service
3030

daprdocs/content/en/php-sdk-docs/php-app/_index.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,26 @@ require_once __DIR__ . '/vendor/autoload.php';
6565
$app = \Dapr\App::create(configure: fn(\DI\ContainerBuilder $builder) => $builder->enableCompilation(__DIR__));
6666
$result = $app->run(fn(\Dapr\DaprClient $client) => $client->get('/invoke/other-app/method/my-method'));
6767
```
68+
69+
## Using in other frameworks
70+
71+
A `DaprClient` object is provided, in fact, all the sugar used by the `App` object is built on the `DaprClient`.
72+
73+
```php
74+
<?php
75+
76+
require_once __DIR__ . '/vendor/autoload.php';
77+
78+
$clientBuilder = \Dapr\Client\DaprClient::clientBuilder();
79+
80+
// you can customize (de)serialization or comment out to use the default JSON serializers.
81+
$clientBuilder = $clientBuilder->withSerializationConfig($yourSerializer)->withDeserializationConfig($yourDeserializer);
82+
83+
// you can also pass it a logger
84+
$clientBuilder = $clientBuilder->withLogger($myLogger);
85+
86+
// and change the url of the sidecar, for example, using https
87+
$clientBuilder = $clientBuilder->useHttpClient('https://localhost:3800')
88+
```
89+
90+
There are several functions you can call before

daprdocs/content/en/php-sdk-docs/php-pubsub/_index.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,8 @@ you can also just pass an array that conforms to the cloud event spec or use ano
1212

1313
```php
1414
<?php
15-
$app->post('/publish', function(\DI\FactoryInterface $factory) {
16-
// create a new publisher that publishes to my-pub-sub component
17-
$publisher = $factory->make(\Dapr\PubSub\Publish::class, ['pubsub' => 'my-pubsub']);
18-
19-
// publish that something happened to my-topic
20-
$publisher->topic('my-topic')->publish(['something' => 'happened']);
15+
$app->post('/publish', function(\Dapr\Client\DaprClient $daprClient) {
16+
$daprClient->publishEvent(pubsubName: 'pubsub', topicName: 'my-topic', data: ['something' => 'happened']);
2117
});
2218
```
2319

@@ -45,9 +41,9 @@ $event->data_content_type = 'application/xml';
4541
```php
4642
<?php
4743
/**
48-
* @var \Dapr\PubSub\Publish $publisher
44+
* @var \Dapr\Client\DaprClient $daprClient
4945
*/
50-
$publisher->topic('my-topic')->publish($raw_data, content_type: 'application/octet-stream');
46+
$daprClient->publishEvent(pubsubName: 'pubsub', topicName: 'my-topic', data: $raw_data, contentType: 'application/octet-stream');
5147
```
5248

5349
{{% alert title="Binary data" color="warning" %}}

daprdocs/content/en/php-sdk-docs/php-state/_index.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@ behavior. The PHP SDK allows you to pass that metadata through:
1717

1818
```php
1919
<?php
20+
// using the state manager
2021
$app->run(
2122
fn(\Dapr\State\StateManager $stateManager) =>
2223
$stateManager->save_state('statestore', new \Dapr\State\StateItem('key', 'value', metadata: ['port' => '112'])));
24+
25+
// using the DaprClient
26+
$app->run(fn(\Dapr\Client\DaprClient $daprClient) => $daprClient->saveState(storeName: 'statestore', key: 'key', value: 'value', metadata: ['port' => '112']))
2327
```
2428

25-
This is an example of how you might pass the port metadata to [Cassandra]({{< ref setup-cassandra.md >}}).
29+
This is an example of how you might pass the port metadata to [Cassandra]({{< ref setup-cassandra.md >}}).
2630

2731
Every state operation allows passing metadata.
2832

@@ -51,8 +55,8 @@ the load on the state store at the expense of performance. The default is `10`.
5155

5256
## Prefix
5357

54-
Hardcoded key names are useful, but why not make state objects more reusable? When committing a transaction or saving
55-
an object to state, you can pass a prefix that is applied to every key in the object.
58+
Hardcoded key names are useful, but why not make state objects more reusable? When committing a transaction or saving an
59+
object to state, you can pass a prefix that is applied to every key in the object.
5660

5761
{{< tabs "Transaction prefix" "StateManager prefix" >}}
5862

0 commit comments

Comments
 (0)