Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/steffenbrand/dmn-decision-tables

PHP library to programmatically create DMN decision tables.
https://github.com/steffenbrand/dmn-decision-tables

bpmn business-rules camunda decision-tables dmn

Last synced: 11 days ago
JSON representation

PHP library to programmatically create DMN decision tables.

Awesome Lists containing this project

README

        

[![Build](https://travis-ci.org/steffenbrand/dmn-decision-tables.svg?branch=master)](https://travis-ci.org/steffenbrand/dmn-decision-tables)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/steffenbrand/dmn-decision-tables/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/steffenbrand/dmn-decision-tables/?branch=master)
[![Latest Stable Version](https://poser.pugx.org/steffenbrand/dmn-decision-tables/v/stable)](https://packagist.org/packages/steffenbrand/dmn-decision-tables)
[![Total Downloads](https://poser.pugx.org/steffenbrand/dmn-decision-tables/downloads)](https://packagist.org/packages/steffenbrand/dmn-decision-tables)
[![License](https://poser.pugx.org/steffenbrand/dmn-decision-tables/license)](https://packagist.org/packages/steffenbrand/dmn-decision-tables)

# DMN Decision Tables
PHP library to programmatically create DMN decision tables

* [DMN Decision Tables on Packagist](https://packagist.org/packages/steffenbrand/dmn-decision-tables)
* [DMN Decision Tables on GitHub](https://github.com/steffenbrand/dmn-decision-tables)

## Limitations

- Generated tables have been tested with [Camunda BPM platform](https://camunda.com/) and [Camunda Cloud](https://dmn.camunda.cloud/), but have __NOT__ been tested
with any other BPMN engine
- Only [FEEL](https://docs.camunda.org/manual/latest/reference/dmn11/feel/) and JUEL expressions have been tested yet
- Only one decision table is supported per .dmn-file
- No DRD features are supported
- IDs are generated randomly, as you can see from the examples below

## How to install

```
composer require steffenbrand/dmn-decision-tables
```

## How to use

These examples show how to build the [Camunda Cloud](https://dmn.camunda.cloud/) example table

### Build decision table

```php
try {
$decisionTable = DecisionTableBuilder::getInstance()
->setName('Dish')
->setDefinitionKey('decision')
->setHitPolicy(HitPolicy::UNIQUE_POLICY)
->addInput(new Input('Season', 'season', VariableType::STRING_TYPE))
->addInput(new Input('How many guests', 'guests', VariableType::INTEGER_TYPE))
->addOutput(new Output('Dish', 'dish', VariableType::STRING_TYPE))
->addRule(
[
new InputEntry('"Fall"', ExpressionLanguage::FEEL_LANGUAGE),
new InputEntry('<= 8', ExpressionLanguage::FEEL_LANGUAGE)
],
[new OutputEntry('"Spareribs"', ExpressionLanguage::JUEL_LANGUAGE)]
)
->addRule(
[new InputEntry('"Winter"'), new InputEntry('<= 8')],
[new OutputEntry('"Roastbeef"')]
)
->addRule(
[new InputEntry('"Spring"'), new InputEntry('<= 4')],
[new OutputEntry('"Dry Aged Gourmet Steak"')]
)
->addRule(
[new InputEntry('"Spring"'), new InputEntry('[5..8]')],
[new OutputEntry('"Steak"')],
'Save money'
)
->addRule(
[new InputEntry('"Fall", "Winter", "Spring"'), new InputEntry('> 8')],
[new OutputEntry('"Stew"')],
'Less effort'
)
->addRule(
[new InputEntry('"Summer"'), new InputEntry(null)],
[new OutputEntry('"Light Salad and a nice Steak"')],
'Hey, why not!?'
)
->build();
} catch (DmnValidationException $e) {
// Build method validates before it creates the DecisionTable.
// Can be disabled, so feel free to validate yourself.
// Use the DecisionTableValidator or inject your own validator.
} catch (DmnConversionException $e) {
// Conversion to XML might fail because of invalid expressions or whatever.
}
```

### Convert to DMN string (XML)

```php
$decisionTable->toDMN();

```

### Save to filesystem

```php
$decisionTable->saveFile('/my/path/and/filename.dmn');
```

### What the result looks like

```xml





season




guests





































Save money











Less effort




8]]>






Hey, why not!?











```

## Try it

Feel free to download [generated_with_dmn_decision_tables.dmn](https://github.com/steffenbrand/dmn-decision-tables/blob/master/resources/generated_with_dmn_decision_tables.dmn)
and try it in the [Camunda Cloud](https://dmn.camunda.cloud/)