You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+8-36Lines changed: 8 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -174,12 +174,12 @@ Porter includes one transformer, `FilterTransformer`, that removes records from
174
174
Transformers implement the `Transformer` interface that defines one method with the following signature.
175
175
176
176
```php
177
-
public function transform(RecordCollection $records, $context): RecordCollection;
177
+
public function transform(RecordCollection $records, $context): RecordCollection;
178
178
```
179
179
180
180
When `transform()` is called the transformer may iterate each record and change it in any way, including removing or inserting additional records. The record collection must be returned by the method, whether or not changes were made.
181
181
182
-
Transformers should also implement the `__clone` magic method if the they store any object state in order to facilitate deep copy when Porter clones the owning `ImportSpecification` during an import.
182
+
Transformers should also implement the `__clone` magic method if the they store any object state, in order to facilitate deep copy when Porter clones the owning `ImportSpecification` during import.
183
183
184
184
Filtering
185
185
---------
@@ -188,7 +188,7 @@ Filtering provides a way to remove some records. For each record, if the specifi
188
188
189
189
In general we would like to avoid filtering because it is inefficient to import data and then immediately remove some of it, but some immature APIs do not provide a way to reduce the data set on the server, so filtering on the client is the only alternative. Filtering also invalidates the record count reported by some resources, meaning we no longer know how many records are in the collection before iteration.
190
190
191
-
####Example
191
+
### Example
192
192
193
193
The following example filters out any records that do not have an *id* field present.
194
194
@@ -225,7 +225,7 @@ Any connector can be wrapped in a `CachingConnector` to provide [PSR-6][PSR-6] c
225
225
226
226
Remember that whilst using a `CachingConnector` enables caching, caching must also be enabled on a per-import basis by calling `ImportSpecification::enableCache()`.
227
227
228
-
####Example
228
+
### Example
229
229
230
230
The follow example enables connector caching.
231
231
@@ -236,34 +236,6 @@ $records = $porter->import(
236
236
);
237
237
```
238
238
239
-
### Cache keys
240
-
241
-
The cache key is generated by a `CacheKeyGenerator` that encodes the source and connector options to produce a unique cache key for each distinct `Connector::fetch` request. The default `JsonCacheKeyGenerator` simply JSON-encodes the parameters to create a cache key. The cache key generation strategy may be changed by calling `CachingConnector::setCacheKeyGenerator`.
242
-
243
-
#### Writing a cache key generator
244
-
245
-
The `CacheKeyGenerator` interface defines one method with the following interface.
246
-
247
-
```php
248
-
public function generateCacheKey(string $source, array $sortedOptions) : string;
249
-
```
250
-
251
-
Implementations receive the source of the fetch request and an array and sorted options, so that options originally specified in a different order still result in the same cache key. The method must return a [PSR-6][PSR-6] compatible cache key.
252
-
253
-
##### Implementation example
254
-
255
-
The following example demonstrates cache key generation using a hash of JSON-encoded parameters.
256
-
257
-
```php
258
-
class MyCacheKeyGenerator implements CacheKeyGenerator
259
-
{
260
-
public function generateCacheKey($source, array $sortedOptions)
Congratulations! We have covered everything needed to use Porter.
275
247
276
-
The rest of this readme is for those wishing to go deeper. Continue when you're ready to learn how to write [providers](#providers), [resources](#resources) and [connectors](#connectors).
248
+
The rest of this readme is for those wishing to go deeper. Continue when you're ready to learn how to write [providers](#providers), [resources](#resources) and [connectors](#connectors). ☕️
277
249
278
250
</div>
279
251
@@ -328,8 +300,8 @@ Resources
328
300
Resources fetch data using the supplied connector and format it as a collection of arrays. A resource implements `ProviderResource` that defines the following three methods.
329
301
330
302
```php
331
-
public function getProviderClassName(): string;
332
-
public function fetch(ImportConnector $connector): Iterator;
303
+
public function getProviderClassName(): string;
304
+
public function fetch(ImportConnector $connector): Iterator;
333
305
```
334
306
335
307
A resource supplies the class name of the provider it expects a connector from when `getProviderClassName()` is called.
@@ -447,7 +419,7 @@ Connectors fetch remote data from a source specified at fetch time. Connectors f
447
419
Writing providers and resources is a common task that should be fairly easy but writing a connector is slightly less common and has some specific technical considerations that must be carefully considered. A connector implements the `Connector` interface that defines one method with the following signature.
448
420
449
421
```php
450
-
public function fetch(ConnectionContext $context, $source): mixed;
422
+
public function fetch(ConnectionContext $context, $source): mixed;
451
423
```
452
424
453
425
When `fetch()` is called the connector fetches data from the specified source. Connectors may return data in any format that's convenient for resources to consume, but in general, such data should be as raw as possible and without modification. If multiple pieces of information are returned it is recommended to use a specialized response class, like the HTTP connector that returns the response body and headers together in an `HttpResponse`.
Copy file name to clipboardExpand all lines: docs/Quickstart.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,6 @@
1
+
Porter Quick Start Guide
2
+
========================
3
+
1
4
This quick start guide will walk through getting up and running with Porter from scratch and assumes you already have a PHP environment set up with Composer. Let's start by initializing our Composer file by running `composer init` in our project's root directory and accepting the defaults. We can skip defining dependencies interactively because we'll issue separate commands in a moment.
2
5
3
6
Let's start with the [European Central Bank][ECB provider] (ECB) provider by including it in our `composer.json` with the following command.
0 commit comments