Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rmcdaniel committed Nov 17, 2023
0 parents commit 099ae19
Show file tree
Hide file tree
Showing 72 changed files with 4,537 additions and 0 deletions.
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/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 TaskValve

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
93 changes: 93 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# 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 taskvalve/serverless-workflow-php
```

## 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

0 comments on commit 099ae19

Please sign in to comment.