PHP code example of steffenbrand / dmn-decision-tables
1. Go to this page and download the library: Download steffenbrand/dmn-decision-tables library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
steffenbrand / dmn-decision-tables example snippets
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.
}