Skip to content

Commit 3b7d2da

Browse files
authored
Improved remote filesystem code samples (#1295)
1 parent 7a592e0 commit 3b7d2da

File tree

11 files changed

+117
-12
lines changed

11 files changed

+117
-12
lines changed

documentation/_navigation.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,5 @@
5353
## Bridges
5454
- [Filesystem Azure](/documentation/components/bridges/filesystem-azure-bridge.md)
5555
- [Filesystem Async AWS](/documentation/components/bridges/filesystem-async-aws-bridge.md)
56+
- [Symfony Http Foundation](/documentation/components/bridges/symfony-http-foundation-bridge.md)
5657
- [Monolog Http](/documentation/components/bridges/monolog-http-bridge.md)

documentation/components/bridges/filesystem-async-aws-bridge.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,28 @@ $aws = aws_s3_filesystem(
2222
);
2323
2424
$fstab = fstab($aws);
25+
```
26+
27+
## Usage with Flow
28+
29+
To use the AWS S3 filesystem with Flow, you need to mount the filesystem to the configuration.
30+
This operation will mount the S3 filesystem to fstab instance available in the DataFrame runtime.
31+
32+
```php
33+
$config = config_builder()
34+
->mount(
35+
aws_s3_filesystem(
36+
$_ENV['AWS_S3_BUCKET'],
37+
aws_s3_client([
38+
'region' => $_ENV['AWS_S3_REGION'],
39+
'accessKeyId' => $_ENV['AWS_S3_KEY'],
40+
'accessKeySecret' => $_ENV['AWS_S3_SECRET'],
41+
])
42+
)
43+
);
44+
45+
data_frame($config)
46+
->read(from_csv(path('aws-s3://test.csv')))
47+
->write(to_stream(__DIR__ . '/output.txt', truncate: false))
48+
->run();
2549
```

documentation/components/bridges/filesystem-azure-bridge.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,32 @@ $sdk = azure_blob_service(
4040
azure_shared_key_authorization_factory($config, $accountKey),
4141
$logger
4242
);
43+
```
44+
45+
## Usage with Flow
46+
47+
To use the Azure Blob filesystem with Flow, you need to mount the filesystem to the configuration.
48+
This operation will mount the Azure Blob filesystem to fstab instance available in the DataFrame runtime.
49+
50+
```php
51+
$config = config_builder()
52+
->mount(
53+
azure_filesystem(
54+
azure_blob_service(
55+
azure_blob_service_config(
56+
$_ENV['AZURE_ACCOUNT'],
57+
$_ENV['AZURE_CONTAINER']
58+
),
59+
azure_shared_key_authorization_factory(
60+
$_ENV['AZURE_ACCOUNT'],
61+
$_ENV['AZURE_ACCOUNT_KEY']
62+
),
63+
)
64+
)
65+
);
66+
67+
data_frame($config)
68+
->read(from_csv(path('azure-blob://test.csv')))
69+
->write(to_stream(__DIR__ . '/output.txt', truncate: false))
70+
->run();
4371
```
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
+----------+-----------------------------+---------------------+----------+--------------+-----------+----------------------+
22
| name | html_url | blog | login | public_repos | followers | created_at |
33
+----------+-----------------------------+---------------------+----------+--------------+-----------+----------------------+
4-
| Flow PHP | https://github.com/flow-php | http://flow-php.com | flow-php | 36 | 106 | 2020-10-26T18:40:27Z |
4+
| Flow PHP | https://github.com/flow-php | http://flow-php.com | flow-php | 37 | 106 | 2020-10-26T18:40:27Z |
55
+----------+-----------------------------+---------------------+----------+--------------+-----------+----------------------+
66
1 rows

examples/topics/filesystem/azure/code.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
declare(strict_types=1);
44

55
use function Flow\Azure\SDK\DSL\{azure_blob_service, azure_blob_service_config, azure_shared_key_authorization_factory};
6-
use function Flow\ETL\Adapter\CSV\to_csv;
7-
use function Flow\ETL\DSL\{config_builder, data_frame, from_array, overwrite};
6+
use function Flow\ETL\Adapter\CSV\{from_csv, to_csv};
7+
use function Flow\ETL\DSL\{config_builder, data_frame, from_array, overwrite, to_stream};
88
use function Flow\Filesystem\Bridge\Azure\DSL\azure_filesystem;
99
use function Flow\Filesystem\DSL\path;
1010
use Symfony\Component\Dotenv\Dotenv;
@@ -46,3 +46,8 @@
4646
->saveMode(overwrite())
4747
->write(to_csv(path('azure-blob://test.csv')))
4848
->run();
49+
50+
data_frame($config)
51+
->read(from_csv(path('azure-blob://test.csv')))
52+
->write(to_stream(__DIR__ . '/output.txt', truncate: false))
53+
->run();
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
+----+------+
2+
| id | name |
3+
+----+------+
4+
| 1 | test |
5+
+----+------+
6+
1 rows
7+
+----+------+
8+
| id | name |
9+
+----+------+
10+
| 2 | test |
11+
+----+------+
12+
1 rows
13+
+----+------+
14+
| id | name |
15+
+----+------+
16+
| 3 | test |
17+
+----+------+
18+
1 rows
19+
+----+------+
20+
| id | name |
21+
+----+------+
22+
| 4 | test |
23+
+----+------+
24+
1 rows

examples/topics/filesystem/s3/code.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
declare(strict_types=1);
44

5-
use function Flow\ETL\Adapter\CSV\to_csv;
6-
use function Flow\ETL\DSL\{config_builder, data_frame, from_array, overwrite};
5+
use function Flow\ETL\Adapter\CSV\{from_csv, to_csv};
6+
use function Flow\ETL\DSL\{config_builder, data_frame, from_array, overwrite, to_stream};
77
use function Flow\Filesystem\Bridge\AsyncAWS\DSL\{aws_s3_client, aws_s3_filesystem};
88
use function Flow\Filesystem\DSL\path;
99
use Symfony\Component\Dotenv\Dotenv;
@@ -41,3 +41,8 @@
4141
->saveMode(overwrite())
4242
->write(to_csv(path('aws-s3://test.csv')))
4343
->run();
44+
45+
data_frame($config)
46+
->read(from_csv(path('aws-s3://test.csv')))
47+
->write(to_stream(__DIR__ . '/output.txt', truncate: false))
48+
->run();

examples/topics/filesystem/s3/description.md

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
+----+------+
2+
| id | name |
3+
+----+------+
4+
| 1 | test |
5+
+----+------+
6+
1 rows
7+
+----+------+
8+
| id | name |
9+
+----+------+
10+
| 2 | test |
11+
+----+------+
12+
1 rows
13+
+----+------+
14+
| id | name |
15+
+----+------+
16+
| 3 | test |
17+
+----+------+
18+
1 rows
19+
+----+------+
20+
| id | name |
21+
+----+------+
22+
| 4 | test |
23+
+----+------+
24+
1 rows

examples/topics/filesystem/stdout/description.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ write straight to stdout of the process.
33

44
`Stdout is a write-only filesystem. It is not possible to read from it.`
55

6-
Its main purpose is to allow to allow web servers to stream
7-
data to the client without buffering it in memory.
6+
Its main purpose is to allow web servers to stream data to the client without buffering it in memory.

0 commit comments

Comments
 (0)