Skip to content

Commit f3141ad

Browse files
JoMessinasebprt
authored andcommitted
Add extractor/transformer/loader examples to the custom plugin page
1 parent 3088582 commit f3141ad

File tree

1 file changed

+132
-1
lines changed

1 file changed

+132
-1
lines changed

content/connectivity/custom/_index.en.md

Lines changed: 132 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ description: "Read transform and write files in any format"
88
weight: 3
99
---
1010

11-
- [What is it ?](#what-is-it-)
11+
- [What is it ?](#definition)
1212
- [Installation](#installation)
1313
- [Usage](#usage)
1414
- [Building an extractor](#building-an-extractor)
1515
- [Building a transformer](#building-a-transformer)
1616
- [Building a loader](#building-a-loader)
17+
- [Usage examples](#usage-examples)
18+
- [Example of an extractor](#example-of-an-extractor)
19+
- [Example of a transformer](#example-of-a-transformer)
20+
- [Example of a loader](#example-of-a-loader)
1721
---
1822

1923
## Definition
@@ -68,3 +72,130 @@ custom:
6872
calls:
6973
- withUsername: [ 'admin' ]
7074
```
75+
76+
## Usage examples
77+
78+
Some examples of pipeline with Magento to extract, FastMap to transform and ZohoCRM to load data
79+
80+
### Example of an extractor
81+
82+
```yaml
83+
custom:
84+
extractor:
85+
use: 'App\Component\Flow\Magento2\CustomerExtractor'
86+
services:
87+
App\Component\Flow\Magento2\CustomerExtractor:
88+
arguments:
89+
- '@Monolog\Logger'
90+
- ['@firstname_filter_group_1', '@firstname_filter_group_2']
91+
public: true
92+
firstname_filter_group_1:
93+
class: App\Component\Flow\Magento2\FilterGroup
94+
calls:
95+
- withFilter: [ '@firstname_filter_1' ]
96+
firstname_filter_1:
97+
class: App\Component\Flow\Magento2\Filter
98+
arguments:
99+
- 'firstname'
100+
- 'nlike'
101+
- '%bm01.cc'
102+
firstname_filter_group_2:
103+
class: App\Component\Flow\Magento2\FilterGroup
104+
calls:
105+
- withFilter: [ '@firstname_filter_2' ]
106+
firstname_filter_2:
107+
class: App\Component\Flow\Magento2\Filter
108+
arguments:
109+
$field: 'firstname'
110+
$conditionType: 'nlike'
111+
$value: '%.xyz'
112+
Monolog\Logger:
113+
arguments:
114+
- 'app'
115+
- [ '@Monolog\Handler\StreamHandler' ]
116+
Monolog\Handler\StreamHandler:
117+
arguments:
118+
- 'var/dev.log'
119+
- 300
120+
```
121+
122+
You can write the arguments of your service in 2 different ways.
123+
You can list them with a '-' but you need to respect the order of the arguments in the constructor,
124+
or you can simply name the arguments by their variable name in the constructor.
125+
126+
#### Filter class constructor :
127+
```php
128+
class Filter
129+
{
130+
public function __construct(
131+
public string $field,
132+
public string $conditionType,
133+
public string $value,
134+
) {
135+
}
136+
}
137+
```
138+
139+
### Example of a transformer
140+
```yaml
141+
custom:
142+
transformer:
143+
use: 'App\CachedAttributeLookup'
144+
services:
145+
PDO:
146+
arguments:
147+
- 'mysql:host=127.0.0.1;port=3306;dbname=lacelier'
148+
- 'user'
149+
- 'password'
150+
App\CachedAttributeLookup:
151+
arguments:
152+
- '@PDO'
153+
- 'SELECT * FROM color WHERE region=:region AND code=:code'
154+
- '@Cache\Adapter\Apcu\ApcuCachePool'
155+
- 'color'
156+
- '@App\ColorLookupMapper'
157+
public: true
158+
App\ColorLookupMapper: ~
159+
Cache\Adapter\Apcu\ApcuCachePool: ~
160+
Symfony\Component\Cache\Adapter\ApcuAdapter: ~
161+
```
162+
163+
### Example of a loader
164+
```yaml
165+
custom:
166+
loader:
167+
use: 'App\Component\Flow\ZohoCRM\ContactLoader'
168+
services:
169+
App\Component\Flow\ZohoCRM\ContactLoader:
170+
arguments:
171+
- '@App\Component\Flow\ZohoCRM\Client\Client'
172+
- '@Monolog\Logger'
173+
public: true
174+
GuzzleHttp\Client: ~
175+
GuzzleHttp\Psr7\HttpFactory: ~
176+
App\Component\Flow\ZohoCRM\Client\AuthenticationMiddleware:
177+
arguments:
178+
- '@GuzzleHttp\Client'
179+
- '@GuzzleHttp\Psr7\HttpFactory'
180+
- '@GuzzleHttp\Psr7\HttpFactory'
181+
- '%env(ZOHO_OAUTH_HOST)%'
182+
- '%env(ZOHO_CLIENT_ID)%'
183+
- '%env(ZOHO_CLIENT_SECRET)%'
184+
- '%env(ZOHO_ACCESS_TOKEN)%'
185+
- '%env(ZOHO_REFRESH_TOKEN)%'
186+
App\Component\Flow\ZohoCRM\Client\Client:
187+
arguments:
188+
- '%env(ZOHO_BASE_HOST)%'
189+
- '@App\Component\Flow\ZohoCRM\Client\AuthenticationMiddleware'
190+
- '@GuzzleHttp\Psr7\HttpFactory'
191+
- '@GuzzleHttp\Psr7\HttpFactory'
192+
- '@GuzzleHttp\Psr7\HttpFactory'
193+
Monolog\Logger:
194+
arguments:
195+
- 'app'
196+
- [ '@Monolog\Handler\StreamHandler' ]
197+
Monolog\Handler\StreamHandler:
198+
arguments:
199+
- 'var/dev.log'
200+
- 300
201+
```

0 commit comments

Comments
 (0)