Skip to content

Commit 06b9ac8

Browse files
committed
Add SDK
Signed-off-by: Richard McDaniel <richard.lee.mcdaniel@gmail.com>
1 parent 4d52751 commit 06b9ac8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+4516
-2
lines changed

.github/workflows/php.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: PHP Composer
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v3
19+
20+
- name: Validate composer.json and composer.lock
21+
run: composer validate --strict
22+
23+
- name: Cache Composer packages
24+
id: composer-cache
25+
uses: actions/cache@v3
26+
with:
27+
path: vendor
28+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
29+
restore-keys: |
30+
${{ runner.os }}-php-
31+
32+
- name: Install dependencies
33+
run: composer install --prefer-dist --no-progress
34+
35+
- name: Check coding style via ECS
36+
run: vendor/bin/ecs check
37+
38+
- name: Run static analysis via PHPStan
39+
run: vendor/bin/phpstan --xdebug analyse src tests
40+
41+
- name: Run test suite
42+
run: composer run-script test

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.phpunit.cache/
2+
.phpunit.result.cache
3+
composer.phar
4+
/vendor/

README.md

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,93 @@
1-
# sdk-php
2-
PHP SDK for Serverless Workflow
1+
# Serverless Workflow Specification - PHP SDK
2+
3+
Provides the PHP API/SPI for the [Serverless Workflow Specification](https://github.com/serverlessworkflow/specification).
4+
5+
With the SDK you can:
6+
* Programmatically build workflow definitions
7+
* Parse workflow JSON and YAML definitions
8+
* Validate workflow definitions
9+
10+
### Status
11+
12+
Current SDK version conforms to the [Serverless Workflow specification v0.8](https://github.com/serverlessworkflow/specification/tree/0.8.x).
13+
14+
15+
## Installation
16+
17+
```bash
18+
composer install serverlessworkflow/sdk
19+
```
20+
21+
## Build
22+
23+
```php
24+
use Serverless\Workflow\Action;
25+
use Serverless\Workflow\ActionDataFilter;
26+
use Serverless\Workflow\FunctionDef;
27+
use Serverless\Workflow\FunctionRef;
28+
use Serverless\Workflow\OperationState;
29+
use Serverless\Workflow\Workflow;
30+
31+
$workflow = new Workflow([
32+
'id' => 'greeting',
33+
'name' => 'Greeting Workflow',
34+
'description' => 'Greet Someone',
35+
'version' => '1.0',
36+
'specVersion' => '0.8',
37+
'start' => 'Greet',
38+
'states' => [
39+
new OperationState([
40+
'name' => 'Greet',
41+
'type' => 'operation',
42+
'actions' => [
43+
new Action([
44+
'functionRef' => new FunctionRef([
45+
'refName' => 'greetingFunction',
46+
'arguments' => [
47+
'name' => '${ .person.name }',
48+
],
49+
]),
50+
'actionDataFilter' => new ActionDataFilter([
51+
'results' => '${ .greeting }',
52+
]),
53+
]),
54+
],
55+
'end' => true,
56+
]),
57+
],
58+
'functions' => [
59+
new FunctionDef([
60+
'name' => 'greetingFunction',
61+
'operation' => 'file://myapis/greetingapis.json#greeting',
62+
]),
63+
],
64+
]);
65+
```
66+
67+
## Parse
68+
69+
### Convert from JSON/YAML source
70+
71+
```php
72+
$workflow = Workflow::fromJson(file_get_contents('workflow.json'));
73+
74+
$workflow = Workflow::fromYaml(file_get_contents('workflow.yaml'));
75+
```
76+
77+
### Convert to JSON/YAML
78+
79+
```php
80+
$json = $workflow->toJson();
81+
82+
$yaml = $workflow->toYaml();
83+
```
84+
85+
## Validate
86+
87+
```php
88+
use Serverless\Workflow\WorkflowValidator;
89+
90+
WorkflowValidator::validate($workflow);
91+
```
92+
93+
The `validate` method will raise an exception if the provided workflow does not comply with the specification.

composer.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "taskvalve/serverless-workflow-php",
3+
"description": "Provides the PHP API/SPI for the Serverless Workflow Specification.",
4+
"type": "library",
5+
"license": "MIT",
6+
"autoload": {
7+
"psr-4": {
8+
"Serverless\\Workflow\\": "src/"
9+
}
10+
},
11+
"authors": [
12+
{
13+
"name": "Richard McDaniel",
14+
"email": "richard.lee.mcdaniel@gmail.com"
15+
}
16+
],
17+
"require-dev": {
18+
"phpstan/phpstan": "^1.9",
19+
"phpunit/phpunit": "^10.4",
20+
"rector/rector": "^0.18.10",
21+
"symplify/easy-coding-standard": "^11.1"
22+
},
23+
"require": {
24+
"symfony/yaml": "^6.3",
25+
"phpdocumentor/reflection-docblock": "^5.3",
26+
"swaggest/json-schema": "^0.12.42"
27+
},
28+
"scripts": {
29+
"rector": "vendor/bin/rector",
30+
"ecs": "vendor/bin/ecs check --fix",
31+
"stan": "vendor/bin/phpstan analyse src tests",
32+
"test": "phpunit --testdox"
33+
}
34+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy