|
1 | 1 | # Configuration
|
2 | 2 |
|
3 |
| -The code generator CLI can be started through the `bin/ocmcg` executable. This prints the available CLI commands. |
4 |
| -The CLI command `ocmcg:workflow:run` executes the code generation depending on the configuration file. The default |
| 3 | +The code generator is shipped with a CLI which executes the code generation depending on the configuration file. The default |
5 | 4 | configuration file name is `open-code-modeling.php.dist` which should be located in the root folder of the application
|
6 | 5 | / repository.
|
7 | 6 |
|
8 | 7 | This file gets the variable `$workflowContext` provided to configure needed slot data for the code generation e. g.
|
9 | 8 | paths or global data. You have to return an instance of a class which implements `OpenCodeModeling\CodeGenerator\Config\Config`
|
10 | 9 | interface.
|
11 | 10 |
|
12 |
| -The following example add some slot data to the workflow context (`$workflowContext->put()`). |
| 11 | +The following code shows a "Hello World!" example. It prepares the `WorkflowContext` object with the first part of the |
| 12 | +greeting under slot name `part_one`. The workflow consists of two steps. Step *one* adds the second part of the greeting |
| 13 | +to the given input from slot name `part_one`. The returned value is stored under the slot name `greeting`. Step *two* |
| 14 | +prints the string of the input slot name `greeting`. It doesn't has an output slot name. |
| 15 | + |
13 | 16 | ```
|
| 17 | +use OpenCodeModeling\CodeGenerator; |
| 18 | +
|
14 | 19 | /** @var CodeGenerator\Workflow\WorkflowContext $workflowContext */
|
15 |
| -$workflowContext->put('xml_filename', 'data/domain.xml'); |
16 |
| -
|
17 |
| -$config = new CodeGenerator\Config\ComponentList( |
18 |
| - ...[ |
19 |
| - new CodeGenerator\Config\ComponentConfig( |
20 |
| - CodeGenerator\Transformator\StringToFile::workflowComponentDescription( |
21 |
| - Inspectio\WorkflowConfigFactory::SLOT_GRAPHML_XML, |
22 |
| - 'xml_filename' |
23 |
| - ) |
| 20 | +$workflowContext->put('part_one', 'Hello'); // init some data so it's available as an input slot name |
| 21 | +
|
| 22 | +$config = new CodeGenerator\Config\Workflow( |
| 23 | + // step one |
| 24 | + new CodeGenerator\Workflow\ComponentDescriptionWithSlot( |
| 25 | + function(string $inputHello) { |
| 26 | + return $inputHello . ' World!'; |
| 27 | + }, |
| 28 | + 'greeting', // output slot name |
| 29 | + 'part_one' // input slot name |
| 30 | + ), |
| 31 | + // step two |
| 32 | + new CodeGenerator\Workflow\ComponentDescriptionWithInputSlotOnly( |
| 33 | + function(string $greeting) { |
| 34 | + echo $greeting; |
| 35 | + }, |
| 36 | + 'greeting', // input slot name |
24 | 37 | ),
|
25 |
| - ] |
26 | 38 | );
|
27 | 39 |
|
28 |
| -$config->addConsoleCommands(new Inspectio\Console\XmlGenerateAllCommand()); |
29 |
| -
|
30 | 40 | return $config;
|
31 | 41 | ```
|
| 42 | + |
| 43 | +## Register additional Symfony CLI commands |
| 44 | + |
| 45 | +It is possible to add additional CLI commands to the code generator CLI. You can register additional Symfony CLI commands |
| 46 | +by adding them to the `$config` object via `$config->addConsoleCommands(new AwesomeCliCommand())`. |
| 47 | + |
| 48 | +## Register a monitor |
| 49 | + |
| 50 | +A monitor can be used to display code generation steps and progress. |
| 51 | + |
| 52 | +You can register a monitor instance of type `\OpenCodeModeling\CodeGenerator\Workflow\Monitoring\Monitoring` to the |
| 53 | +`$config` object via `$config->setMonitor(new AwesomeMonitor())`. The Code Generator is shipped with a `Psr\Log\LoggerInterface` |
| 54 | +monitor (`\OpenCodeModeling\CodeGenerator\Workflow\Monitoring\LoggerMonitor`). |
0 commit comments