Download the PHP package dapr/php-sdk without Composer
On this page you can find all versions of the php package dapr/php-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package php-sdk
Using this library
This library is licensed with the MIT license.
Add the library to your composer.json
:
composer require dapr/php-sdk
Some basic documentation is below, more documentation can be found in the docs;
Migrating to 1.2
In preparation for gRPC support in this SDK, there's now a new DaprClient in \Dapr\Client\DaprClient
. Please update
your code to use the new client.
There shouldn't be many changes to your code to upgrade to 1.2+ from a prior version. Namely, there are some deprecations:
Deprecations
The following have been deprecated and will be removed in 1.4+.
\Dapr\SecretManager has been deprecated
Simply use the new client instead.
\Dapr\Client has been deprecated
Simply use the new client: \Dapr\Client\DaprClient
.
\Dapr\PubSub\Publish has been deprecated
Simply instantiate \Dapr\PubSub\Topic
directly or use the new client directly.
Fallbacks and Upgrades
\Dapr\State\StateManager
This class has been upgraded to use the new client. It shouldn't require any changes to your code, however, the old
behavior can be utilized with \Dapr\State\StateManagerOld
.
\Dapr\State\TransactionalState
This class has been upgrade to use the new client. It shouldn't require any changes to your code, however, the old
behavior can be utilized with \Dapr\State\TransactionalStateOld
.
Creating a Dapr Client
Using the Middleware
The App
object also implements a PSR-15 compatible middleware which implements the actor routes and subscribe routes
for you.
Accessing Secrets
You can access secrets easily:
Accessing State
There are several ways to access state. You can access state directly via the client or abstract access via an object.
Accessing State Directly
Abstract via Object
Transactional State
You can also use transactional state to interact with state objects by extending TransactionalState
with our state
objects or commit transactions directly.
Directly with the client
Abstracted via an Object
Actors
Actors are fully implemented and quite powerful. In order to define an actor, you must first define the interface. You'll likely want to put this in a separate library for easy calling from other services.
Once the interface is defined, you'll need to implement the behavior and register the actor.
The state to inject is read from the constructor arguments, the state must derive from ActorState
to be injected. You
may use as many state classes as you'd like. State is automatically saved for you if you make any changes to it during
the method call using transactional state.
The Actor
base class gives you access to some helper functions and saves you from writing some boiler-plate. You may
also implement IActor
and use the ActorTrait
as well.
Calling an Actor
In order to call an actor, simply call the ActorProxy
and get a proxy object:
You can also call an actor without an interface:
Actor Limitations
- There's no re-entrance to an actor, by default. You'll need to enable it in the
ActorConfig
and in Dapr. - By design, static functions don't work.
- There's overhead cost in calling "getter" functions.
More detail here: https://docs.dapr.io/developing-applications/building-blocks/actors/actors-overview/
Pub/Sub
Delivering events around your application is an important aspect of any application. This is supported by Dapr, and implemented in this SDK.
Publishing
In order to publish an event, you just instantiate the Topic
object:
or you can use the new client like:
Subscribing
Serializing
If you need to register a custom serializer, you can completely override the built-in serializers on a per-type basis or even the default serializers:
Using the new client
Development
Tests
Simply run composer test
to run the unit tests. You can lint using composer lint
.
Integration tests
You need docker-compose
and jq
Build and start the environment, then run the integration tests and clean up.
You should see output like:
All versions of php-sdk with dependencies
ext-json Version *
ext-mbstring Version *
guzzlehttp/guzzle Version ^7.3
laminas/laminas-httphandlerrunner Version ^1.3
monolog/monolog Version ^2.2
nette/php-generator Version ^3.5
nikic/fast-route Version ^1.3
nyholm/psr7 Version ^1.3
nyholm/psr7-server Version ^1.0
php Version ^8.0
php-di/invoker Version ^2.3
php-di/php-di Version ^6.3
psr/log Version ^1.1
psr/http-server-middleware Version >=1.0.1
jetbrains/phpstorm-attributes Version 1.0