phpflo / phpflo-fbp
fbp implementation for php
Installs: 3 200
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 2
Open Issues: 1
Requires
- php: >=7.0.0
- symfony/yaml: >=2.7 <=4.0
Requires (Dev)
- mikey179/vfsstream: ^1.6
- phpunit/phpunit: ^5.0
README
Flowbased programming protocol (FBP) config file loader, using the FBP domain specific language (DSL).
Introduction
This library allows you to load and parse configuration for your phpflo project. It also works standalone if you want to convert your old JSON configs to FBP spec. Supported config formats are JSON (.json), YAML (.yml) and FBP (.fbp), output is an object of type FbpDefinition. This allows you to output your parsed content in different formats, ranging from array over FBP, JSON to YAML.
Code Samples
Basic usage:
// load FBP config $defintiion = PhpFlo\Loader\Loader::load('my/fbp/config/file.fbp');
You can load JSON, YAML and FBP that way.
Parser by itself:
$myFbpConfig = <<<EOF # Read a file and cout its lines 'test.file' -> IN ReadFile(ReadFile) ReadFile(ReadFile) OUT -> IN SplitbyLines(SplitStr) ReadFile() ERROR -> IN Display(Output) SplitbyLines() OUT -> IN CountLines(Counter) CountLines() COUNT -> IN Display() EOF; $parser = new PhpFlo\Fbp\FbpParser(); $definition = $parser->run($myFbpConfig);
Dump your flow to a format:
$json = PhpFlo\Fbp\FbpDumper::toJson($definition); $yaml = PhpFlo\Fbp\FbpDumper::toYaml($definition); $fbp = PhpFlo\Fbp\FbpDumper::toFbp($definition);
The definition has following schema:
$schema = [ 'properties' => ['name' => '',], 'initializers' => [ [ 'data' => '', 'tgt' => [ 'process' => '', 'port' => '', ], ], ], 'processes' => [ 'ReadFile' => [ 'component' => '', 'metadata' => [ 'label' => '', ], ], ], 'connections' => [ [ 'src' => [ 'process' => '', 'port' => '', ], 'tgt' => [ 'process' => '', 'port' => '', ], ], ], ]
FBP DSL defintions
If you want to write definition files, here are the rules:
General syntax:
// <process_alias>(<optional_process_name>) <port><[optional_port_number]> -> <port><[optional_port_number]> <process_alias>(<optional_process_name>)
// examples
ReadFile(ReadFile) OUT -> IN SplitbyLines(SplitStr)
ReadFile() OUT -> IN SplitbyLines()
ReadFile() out[1] -> In[3] SplitbyLines()
- All elements are case sensitive
- The parentheses at the end of a process definition are mandatory (even if empty):
<process>()
- Process names are w+
- Port names can be [a-zA-Z_]
- Each line determines a new chain of events, meaning at least two processes with two connecting ports, separated by a " -> " like
<process>() <port> -> <port> <process>()
- Otherwise there is a
<initializer> -> <port> <process>()
For better understanding, the whole RegEx used for definition examination is:
((?P<inport>[a-zA-Z_]+(\[(?P<inport_no>[0-9]+)\])?)\s)?((?P<process>[\w\/]+)(\((?P<component>[\w\/\\\.]+)?\))?)(\s(?P<outport>[a-zA-Z_]+(\[(?P<outport_no>[0-9]+)\])?))?
Comments: You can add comments and empty lines for better readability and documentation. If you have a comment in the first line, it will be used as name of the definition.
# this definition reads files and counts their lines
ReadFile() OUT -> IN SplitbyLines()
ReadFile() out -> In SplitbyLines()
# some comment
# and for readability :-)
ReadFile(ReadFile) OUT -> IN SplitbyLines(SplitStr)
Initializer: You can have initial values for a graph:
'test.file' -> IN ReadFile()
Multiple definitions: You can have a complete chain of definitions in one line to enhance visibility of a chain of events:
GreetUser() DATA -> OPTIONS Render() OUT -> STRING WriteResponse()
Installation
Regular install via composer:
composer require phpflo/phpflo-fbp