From f0d66c38fbe7ade9b7f51a432fa1f7ed1f015bf8 Mon Sep 17 00:00:00 2001 From: Rob Landers Date: Sun, 19 Dec 2021 13:49:40 +0100 Subject: [PATCH] Update php docs (#124) * Update php docs * Clarify installation * Fix code tab --- daprdocs/content/en/php-sdk-docs/_index.md | 2 +- .../content/en/php-sdk-docs/php-app/_index.md | 23 +++++++++++++++++++ .../en/php-sdk-docs/php-pubsub/_index.md | 12 ++++------ .../en/php-sdk-docs/php-state/_index.md | 10 +++++--- 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/daprdocs/content/en/php-sdk-docs/_index.md b/daprdocs/content/en/php-sdk-docs/_index.md index 61ce33c..7e02b03 100644 --- a/daprdocs/content/en/php-sdk-docs/_index.md +++ b/daprdocs/content/en/php-sdk-docs/_index.md @@ -24,7 +24,7 @@ Dapr offers an SDK to help with the development of PHP applications. Using it, y ## Initialize your project In a directory where you want to create your service, run `composer init` and answer the questions. -Install `dapr/php-sdk` and any other dependencies you may wish to use. +Install with `composer require dapr/php-sdk` and any other dependencies you may wish to use. ## Configure your service diff --git a/daprdocs/content/en/php-sdk-docs/php-app/_index.md b/daprdocs/content/en/php-sdk-docs/php-app/_index.md index 40d9f23..1eab0af 100644 --- a/daprdocs/content/en/php-sdk-docs/php-app/_index.md +++ b/daprdocs/content/en/php-sdk-docs/php-app/_index.md @@ -65,3 +65,26 @@ require_once __DIR__ . '/vendor/autoload.php'; $app = \Dapr\App::create(configure: fn(\DI\ContainerBuilder $builder) => $builder->enableCompilation(__DIR__)); $result = $app->run(fn(\Dapr\DaprClient $client) => $client->get('/invoke/other-app/method/my-method')); ``` + +## Using in other frameworks + +A `DaprClient` object is provided, in fact, all the sugar used by the `App` object is built on the `DaprClient`. + +```php +withSerializationConfig($yourSerializer)->withDeserializationConfig($yourDeserializer); + +// you can also pass it a logger +$clientBuilder = $clientBuilder->withLogger($myLogger); + +// and change the url of the sidecar, for example, using https +$clientBuilder = $clientBuilder->useHttpClient('https://localhost:3800') +``` + +There are several functions you can call before diff --git a/daprdocs/content/en/php-sdk-docs/php-pubsub/_index.md b/daprdocs/content/en/php-sdk-docs/php-pubsub/_index.md index e2d047a..dfb1f3a 100644 --- a/daprdocs/content/en/php-sdk-docs/php-pubsub/_index.md +++ b/daprdocs/content/en/php-sdk-docs/php-pubsub/_index.md @@ -12,12 +12,8 @@ you can also just pass an array that conforms to the cloud event spec or use ano ```php post('/publish', function(\DI\FactoryInterface $factory) { - // create a new publisher that publishes to my-pub-sub component - $publisher = $factory->make(\Dapr\PubSub\Publish::class, ['pubsub' => 'my-pubsub']); - - // publish that something happened to my-topic - $publisher->topic('my-topic')->publish(['something' => 'happened']); +$app->post('/publish', function(\Dapr\Client\DaprClient $daprClient) { + $daprClient->publishEvent(pubsubName: 'pubsub', topicName: 'my-topic', data: ['something' => 'happened']); }); ``` @@ -45,9 +41,9 @@ $event->data_content_type = 'application/xml'; ```php topic('my-topic')->publish($raw_data, content_type: 'application/octet-stream'); +$daprClient->publishEvent(pubsubName: 'pubsub', topicName: 'my-topic', data: $raw_data, contentType: 'application/octet-stream'); ``` {{% alert title="Binary data" color="warning" %}} diff --git a/daprdocs/content/en/php-sdk-docs/php-state/_index.md b/daprdocs/content/en/php-sdk-docs/php-state/_index.md index e169df4..fe55ed1 100644 --- a/daprdocs/content/en/php-sdk-docs/php-state/_index.md +++ b/daprdocs/content/en/php-sdk-docs/php-state/_index.md @@ -17,12 +17,16 @@ behavior. The PHP SDK allows you to pass that metadata through: ```php run( fn(\Dapr\State\StateManager $stateManager) => $stateManager->save_state('statestore', new \Dapr\State\StateItem('key', 'value', metadata: ['port' => '112']))); + +// using the DaprClient +$app->run(fn(\Dapr\Client\DaprClient $daprClient) => $daprClient->saveState(storeName: 'statestore', key: 'key', value: 'value', metadata: ['port' => '112'])) ``` -This is an example of how you might pass the port metadata to [Cassandra]({{< ref setup-cassandra.md >}}). +This is an example of how you might pass the port metadata to [Cassandra]({{< ref setup-cassandra.md >}}). Every state operation allows passing metadata. @@ -51,8 +55,8 @@ the load on the state store at the expense of performance. The default is `10`. ## Prefix -Hardcoded key names are useful, but why not make state objects more reusable? When committing a transaction or saving -an object to state, you can pass a prefix that is applied to every key in the object. +Hardcoded key names are useful, but why not make state objects more reusable? When committing a transaction or saving an +object to state, you can pass a prefix that is applied to every key in the object. {{< tabs "Transaction prefix" "StateManager prefix" >}}