Skip to content

Commit a0c0007

Browse files
authored
Document dataProcessors
1 parent 641bb1c commit a0c0007

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,51 @@ Wwwision:
4242
./flow import:import some-prefix:some-name
4343
```
4444

45+
## Pre-process data
46+
47+
Sometimes the data has to be processed before it is mapped to. This can be done with a `dataProcessor`.
48+
49+
### Example:
50+
51+
#### Implementation
52+
53+
A processor is any *public* method of any class that can be instantiated by Flow without additional arguments:
54+
55+
```php
56+
<?php
57+
declare(strict_types=1);
58+
namespace Some\Package;
59+
60+
use Wwwision\ImportService\ValueObject\DataRecord;
61+
use Wwwision\ImportService\ValueObject\DataRecords;
62+
63+
final class SomeProcessor
64+
{
65+
66+
public function someMethod(DataRecords $records): DataRecords
67+
{
68+
return $records->map(static fn (DataRecord $record) => $record->withAttribute('title', 'overridden'));
69+
}
70+
}
71+
```
72+
73+
*Note:* The processor class _can_ have dependencies, but it should be possible to create a new instance via `ObjectMananger::get($processorClassname)` without further arguments, i.e. the class should behave like a singleton (see https://flowframework.readthedocs.io/en/stable/TheDefinitiveGuide/PartIII/ObjectManagement.html)
74+
75+
#### Configuration
76+
77+
```yaml
78+
Wwwision:
79+
ImportService:
80+
presets:
81+
'<preset-name>':
82+
# ...
83+
options:
84+
dataProcessor: 'Some\Package\SomeProcessor::someMethod'
85+
```
86+
87+
*Note:* The syntax looks like the method has to be static, but that's not the case. It just has to satisfy PHPs `is_callable()` function
88+
89+
4590
## Validate configuration
4691

4792
Configuration for this package is verbose and thus error prone.

0 commit comments

Comments
 (0)