Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: PHP Composer

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Check coding style via ECS
run: vendor/bin/ecs check

- name: Run static analysis via PHPStan
run: vendor/bin/phpstan --xdebug analyse src tests

- name: Run test suite
run: composer run-script test
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.phpunit.cache/
.phpunit.result.cache
composer.phar
/vendor/
95 changes: 93 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,93 @@
# sdk-php
PHP SDK for Serverless Workflow
# Serverless Workflow Specification - PHP SDK

Provides the PHP API/SPI for the [Serverless Workflow Specification](https://github.com/serverlessworkflow/specification).

With the SDK you can:
* Programmatically build workflow definitions
* Parse workflow JSON and YAML definitions
* Validate workflow definitions

### Status

Current SDK version conforms to the [Serverless Workflow specification v0.8](https://github.com/serverlessworkflow/specification/tree/0.8.x).


## Installation

```bash
composer install serverlessworkflow/sdk
```

## Build

```php
use Serverless\Workflow\Action;
use Serverless\Workflow\ActionDataFilter;
use Serverless\Workflow\FunctionDef;
use Serverless\Workflow\FunctionRef;
use Serverless\Workflow\OperationState;
use Serverless\Workflow\Workflow;

$workflow = new Workflow([
'id' => 'greeting',
'name' => 'Greeting Workflow',
'description' => 'Greet Someone',
'version' => '1.0',
'specVersion' => '0.8',
'start' => 'Greet',
'states' => [
new OperationState([
'name' => 'Greet',
'type' => 'operation',
'actions' => [
new Action([
'functionRef' => new FunctionRef([
'refName' => 'greetingFunction',
'arguments' => [
'name' => '${ .person.name }',
],
]),
'actionDataFilter' => new ActionDataFilter([
'results' => '${ .greeting }',
]),
]),
],
'end' => true,
]),
],
'functions' => [
new FunctionDef([
'name' => 'greetingFunction',
'operation' => 'file://myapis/greetingapis.json#greeting',
]),
],
]);
```

## Parse

### Convert from JSON/YAML source

```php
$workflow = Workflow::fromJson(file_get_contents('workflow.json'));

$workflow = Workflow::fromYaml(file_get_contents('workflow.yaml'));
```

### Convert to JSON/YAML

```php
$json = $workflow->toJson();

$yaml = $workflow->toYaml();
```

## Validate

```php
use Serverless\Workflow\WorkflowValidator;

WorkflowValidator::validate($workflow);
```

The `validate` method will raise an exception if the provided workflow does not comply with the specification.
34 changes: 34 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "taskvalve/serverless-workflow-php",
"description": "Provides the PHP API/SPI for the Serverless Workflow Specification.",
"type": "library",
"license": "MIT",
"autoload": {
"psr-4": {
"Serverless\\Workflow\\": "src/"
}
},
"authors": [
{
"name": "Richard McDaniel",
"email": "richard.lee.mcdaniel@gmail.com"
}
],
"require-dev": {
"phpstan/phpstan": "^1.9",
"phpunit/phpunit": "^10.4",
"rector/rector": "^0.18.10",
"symplify/easy-coding-standard": "^11.1"
},
"require": {
"symfony/yaml": "^6.3",
"phpdocumentor/reflection-docblock": "^5.3",
"swaggest/json-schema": "^0.12.42"
},
"scripts": {
"rector": "vendor/bin/rector",
"ecs": "vendor/bin/ecs check --fix",
"stan": "vendor/bin/phpstan analyse src tests",
"test": "phpunit --testdox"
}
}
Loading