Skip to content

Commit

Permalink
Update php docs (#124)
Browse files Browse the repository at this point in the history
* Update php docs

* Clarify installation

* Fix code tab
  • Loading branch information
withinboredom authored Dec 19, 2021
1 parent 657c3a6 commit f0d66c3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
2 changes: 1 addition & 1 deletion daprdocs/content/en/php-sdk-docs/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 23 additions & 0 deletions daprdocs/content/en/php-sdk-docs/php-app/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<?php

require_once __DIR__ . '/vendor/autoload.php';

$clientBuilder = \Dapr\Client\DaprClient::clientBuilder();

// you can customize (de)serialization or comment out to use the default JSON serializers.
$clientBuilder = $clientBuilder->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
12 changes: 4 additions & 8 deletions daprdocs/content/en/php-sdk-docs/php-pubsub/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@ you can also just pass an array that conforms to the cloud event spec or use ano

```php
<?php
$app->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']);
});
```

Expand Down Expand Up @@ -45,9 +41,9 @@ $event->data_content_type = 'application/xml';
```php
<?php
/**
* @var \Dapr\PubSub\Publish $publisher
* @var \Dapr\Client\DaprClient $daprClient
*/
$publisher->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" %}}
Expand Down
10 changes: 7 additions & 3 deletions daprdocs/content/en/php-sdk-docs/php-state/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ behavior. The PHP SDK allows you to pass that metadata through:

```php
<?php
// using the state manager
$app->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.

Expand Down Expand Up @@ -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" >}}

Expand Down

0 comments on commit f0d66c3

Please sign in to comment.