Skip to content

Commit b2ee529

Browse files
committed
Added composer.json to each example and make it standalone downloadable project
1 parent 447178d commit b2ee529

File tree

195 files changed

+941
-110
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

195 files changed

+941
-110
lines changed

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"coduo/php-humanizer": "^5.0",
2626
"doctrine/dbal": "^3.6 || ^4.0",
2727
"elasticsearch/elasticsearch": "^7.6|^8.0",
28+
"flow-php/etl-adapter-csv": "1.x-dev",
2829
"google/apiclient": "^2.13",
2930
"halaxa/json-machine": "^1.1",
3031
"meilisearch/meilisearch-php": "^1.11",
@@ -50,17 +51,17 @@
5051
"php-http/curl-client": "^2.2",
5152
"php-http/mock-client": "^1.5",
5253
"ramsey/uuid": "^4.5",
53-
"symfony/http-client": "^5.4.47 || ^6.4 || ^7.0",
5454
"symfony/cache": "^6.2 || ^7.0",
5555
"symfony/dotenv": "^6.2 || ^7.0",
5656
"symfony/finder": "^6.3 || ^7.0",
57+
"symfony/http-client": "^5.4.47 || ^6.4 || ^7.0",
58+
"symfony/process": "^7.2",
5759
"symfony/uid": "^6.3 || ^7.0"
5860
},
5961
"replace": {
6062
"flow-php/array-dot": "self.version",
6163
"flow-php/azure-sdk": "self.version",
6264
"flow-php/doctrine-dbal-bulk": "self.version",
63-
"flow-php/doctrine-dbal-bulk-tools": "self.version",
6465
"flow-php/dremel": "self.version",
6566
"flow-php/etl": "self.version",
6667
"flow-php/etl-adapter-avro": "self.version",

composer.lock

Lines changed: 65 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ output/*
44
compose.yml
55
var
66
.env
7+
composer.lock

examples/autoload.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

examples/clean.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
declare(strict_types=1);
5+
6+
require __DIR__ . '/../vendor/autoload.php';
7+
8+
use function Flow\Filesystem\DSL\{fstab, path, protocol};
9+
use Flow\ETL\Dataset\Statistics\HighResolutionTime;
10+
use Symfony\Component\Console\Input\{ArgvInput, InputDefinition, InputOption};
11+
use Symfony\Component\Console\Output\ConsoleOutput;
12+
use Symfony\Component\Console\Style\SymfonyStyle;
13+
use Symfony\Component\Finder\Finder;
14+
15+
if ($_ENV['FLOW_PHAR_APP'] ?? false) {
16+
print PHP_EOL . 'This script cannot be run in PHAR, please use CLI approach.' . PHP_EOL;
17+
18+
exit(1);
19+
}
20+
21+
if (false === \in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
22+
print PHP_EOL . 'This script may only be invoked from a command line, got "' . PHP_SAPI . '"' . PHP_EOL;
23+
24+
exit(1);
25+
}
26+
27+
\ini_set('memory_limit', -1);
28+
29+
$finder = new Finder();
30+
$finder->in(__DIR__ . '/topics')
31+
->files()
32+
->name('*.php');
33+
34+
$output = new ConsoleOutput();
35+
$intput = new ArgvInput(definition: new InputDefinition(
36+
[
37+
new InputOption(name: 'composer-update', shortcut: 'u', mode: InputOption::VALUE_NONE),
38+
new InputOption(name: 'composer-archive', shortcut: 'a', mode: InputOption::VALUE_NONE),
39+
]
40+
));
41+
$style = new SymfonyStyle($intput, $output);
42+
$style->setDecorated(true);
43+
44+
$style->title('Cleaning Flow PHP Examples');
45+
46+
$fs = fstab()->for(protocol('file'));
47+
48+
foreach ($finder as $file) {
49+
50+
if ($file->getBasename() !== 'code.php') {
51+
continue;
52+
}
53+
54+
$start = HighResolutionTime::now();
55+
56+
$style->info("Removing vendor folder: {$file->getRelativePathname()}");
57+
58+
$vendorPath = path($file->getPath() . '/vendor');
59+
60+
if ($fs->status($vendorPath)?->isDirectory()) {
61+
$fs->rm(path($file->getPath() . '/vendor'));
62+
}
63+
}
64+
65+
$style->success('Vendor folders remove from all examples');

examples/run.php

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
require __DIR__ . '/../vendor/autoload.php';
77

8+
use Flow\ETL\Dataset\Statistics\HighResolutionTime;
9+
use Symfony\Component\Console\Input\{ArgvInput, InputDefinition, InputOption};
10+
use Symfony\Component\Console\Output\ConsoleOutput;
11+
use Symfony\Component\Console\Style\SymfonyStyle;
812
use Symfony\Component\Finder\Finder;
913

1014
if ($_ENV['FLOW_PHAR_APP'] ?? false) {
@@ -21,23 +25,60 @@
2125

2226
\ini_set('memory_limit', -1);
2327

24-
print "Running all available examples.\n";
25-
2628
$finder = new Finder();
2729
$finder->in(__DIR__ . '/topics')
2830
->files()
2931
->name('*.php');
3032

33+
$output = new ConsoleOutput();
34+
$intput = new ArgvInput(definition: new InputDefinition(
35+
[
36+
new InputOption(name: 'composer-update', shortcut: 'u', mode: InputOption::VALUE_NONE),
37+
new InputOption(name: 'composer-archive', shortcut: 'a', mode: InputOption::VALUE_NONE),
38+
]
39+
));
40+
$style = new SymfonyStyle($intput, $output);
41+
$style->setDecorated(true);
42+
43+
$style->title('Running Flow PHP Examples');
44+
3145
foreach ($finder as $file) {
32-
print "\nExample: {$file->getRelativePathname()}\n";
3346

34-
try {
35-
if ($file->getBasename() === 'code.php') {
36-
include $file->getRealPath();
37-
}
38-
} catch (Exception $e) {
39-
print "Example failed: {$e->getMessage()}\n";
47+
if ($file->getBasename() !== 'code.php') {
48+
continue;
49+
}
50+
51+
$start = HighResolutionTime::now();
52+
53+
$style->info("Running example: {$file->getRelativePathname()}");
54+
55+
$style->note(($intput->getOption('composer-update') ? 'Updating' : 'Installing') . ' composer dependencies');
56+
$composerProcess = new Symfony\Component\Process\Process(['composer', $intput->getOption('composer-update') ? 'update' : 'install'], $file->getPath());
57+
$composerProcess->run();
58+
$style->info('Composer install finished');
59+
60+
if (!$composerProcess->isSuccessful()) {
61+
print "Composer install failed: {$composerProcess->getErrorOutput()}\n";
4062

4163
exit(1);
4264
}
65+
66+
$codeProcess = new Symfony\Component\Process\Process(['php', $file->getRealPath()]);
67+
$codeProcess->run();
68+
69+
if (!$codeProcess->isSuccessful()) {
70+
print "Example failed: {$codeProcess->getOutput()}\n";
71+
72+
exit(1);
73+
}
74+
$end = HighResolutionTime::now();
75+
76+
$style->success('Example finished in ' . $start->diff($end)->toSeconds() . ' seconds');
77+
78+
if ($intput->getOption('composer-update')) {
79+
$style->note('Generating composer archive');
80+
$composerProcess = new Symfony\Component\Process\Process(['composer', 'archive', '--format', 'zip', '--file', 'flow_php_example'], $file->getPath());
81+
$composerProcess->run();
82+
$style->info('Composer archive generated');
83+
}
4384
}

examples/topics/aggregations/average/code.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use function Flow\ETL\DSL\{average, data_frame, from_rows, int_entry, ref, row, rows, to_stream};
66

7-
require __DIR__ . '/../../../autoload.php';
7+
require __DIR__ . '/vendor/autoload.php';
88

99
data_frame()
1010
->from(from_rows(rows(
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "flow-php/examples",
3+
"description": "Flow PHP - Examples",
4+
"license": "MIT",
5+
"type": "library",
6+
"require": {
7+
"flow-php/etl": "1.x-dev"
8+
}
9+
}
Binary file not shown.

examples/topics/aggregations/first/code.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use function Flow\ETL\DSL\{data_frame, first, from_rows, int_entry, ref, row, rows, to_stream};
66

7-
require __DIR__ . '/../../../autoload.php';
7+
require __DIR__ . '/vendor/autoload.php';
88

99
data_frame()
1010
->from(from_rows(rows(
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "flow-php/examples",
3+
"description": "Flow PHP - Examples",
4+
"license": "MIT",
5+
"type": "library",
6+
"require": {
7+
"flow-php/etl": "1.x-dev"
8+
}
9+
}
Binary file not shown.

examples/topics/aggregations/group_by/code.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use function Flow\ETL\DSL\{count, data_frame, from_array, ref, to_stream};
66

7-
require __DIR__ . '/../../../autoload.php';
7+
require __DIR__ . '/vendor/autoload.php';
88

99
data_frame()
1010
->read(from_array([
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "flow-php/examples",
3+
"description": "Flow PHP - Examples",
4+
"license": "MIT",
5+
"type": "library",
6+
"require": {
7+
"flow-php/etl": "1.x-dev"
8+
}
9+
}
Binary file not shown.

examples/topics/aggregations/group_by_sum/code.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use function Flow\ETL\DSL\{data_frame, from_array, ref, sum, to_stream};
66

7-
require __DIR__ . '/../../../autoload.php';
7+
require __DIR__ . '/vendor/autoload.php';
88

99
data_frame()
1010
->read(from_array([
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "flow-php/examples",
3+
"description": "Flow PHP - Examples",
4+
"license": "MIT",
5+
"type": "library",
6+
"require": {
7+
"flow-php/etl": "1.x-dev"
8+
}
9+
}
Binary file not shown.

examples/topics/aggregations/last/code.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use function Flow\ETL\DSL\{data_frame, from_rows, int_entry, last, ref, row, rows, to_stream};
66

7-
require __DIR__ . '/../../../autoload.php';
7+
require __DIR__ . '/vendor/autoload.php';
88

99
data_frame()
1010
->from(from_rows(rows(
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "flow-php/examples",
3+
"description": "Flow PHP - Examples",
4+
"license": "MIT",
5+
"type": "library",
6+
"require": {
7+
"flow-php/etl": "1.x-dev"
8+
}
9+
}
Binary file not shown.

examples/topics/aggregations/max/code.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use function Flow\ETL\DSL\{data_frame, from_rows, int_entry, max, ref, row, rows, to_stream};
66

7-
require __DIR__ . '/../../../autoload.php';
7+
require __DIR__ . '/vendor/autoload.php';
88

99
data_frame()
1010
->from(from_rows(rows(
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "flow-php/examples",
3+
"description": "Flow PHP - Examples",
4+
"license": "MIT",
5+
"type": "library",
6+
"require": {
7+
"flow-php/etl": "1.x-dev"
8+
}
9+
}
Binary file not shown.

0 commit comments

Comments
 (0)