-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed Caching Pipeline & Build (#958)
* Fixed phar build * Fixed caching pipeline * Fixed failing tests
- Loading branch information
1 parent
e68f94a
commit ee7bfa1
Showing
9 changed files
with
121 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use function Flow\ETL\DSL\config_builder; | ||
use function Flow\ETL\DSL\df; | ||
use function Flow\ETL\DSL\from_cache; | ||
use function Flow\ETL\DSL\ref; | ||
use function Flow\ETL\DSL\to_output; | ||
use Flow\ETL\Adapter\Http\DynamicExtractor\NextRequestFactory; | ||
use Flow\ETL\Adapter\Http\PsrHttpClientDynamicExtractor; | ||
use Flow\ETL\Cache\PSRSimpleCache; | ||
use Http\Client\Curl\Client; | ||
use Nyholm\Psr7\Factory\Psr17Factory; | ||
use Psr\Http\Message\RequestInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Symfony\Component\Cache\Adapter\FilesystemAdapter; | ||
use Symfony\Component\Cache\Psr16Cache; | ||
|
||
require __DIR__ . '/../../../autoload.php'; | ||
|
||
$factory = new Psr17Factory(); | ||
$client = new Client($factory, $factory); | ||
|
||
$from_github_api = new PsrHttpClientDynamicExtractor($client, new class implements NextRequestFactory { | ||
public function create(?ResponseInterface $previousResponse = null) : ?RequestInterface | ||
{ | ||
$factory = new Psr17Factory(); | ||
|
||
if ($previousResponse === null) { | ||
return $factory | ||
->createRequest('GET', 'https://api.github.com/orgs/flow-php') | ||
->withHeader('Accept', 'application/vnd.github.v3+json') | ||
->withHeader('User-Agent', 'flow-php/etl'); | ||
} | ||
|
||
return null; | ||
} | ||
}); | ||
|
||
$adapter = new PSRSimpleCache( | ||
new Psr16Cache( | ||
new FilesystemAdapter( | ||
directory: __DIR__ . '/output/cache' | ||
) | ||
) | ||
); | ||
|
||
df(config_builder()->cache($adapter)) | ||
->read( | ||
from_cache( | ||
id: 'github_api', | ||
fallback_extractor: $from_github_api | ||
) | ||
) | ||
->cache('github_api') | ||
->withEntry('unpacked', ref('response_body')->jsonDecode()) | ||
->select('unpacked') | ||
->withEntry('unpacked', ref('unpacked')->unpack()) | ||
->renameAll('unpacked.', '') | ||
->drop('unpacked') | ||
->select('name', 'html_url', 'blog', 'login', 'public_repos', 'followers', 'created_at') | ||
->write(to_output(false)) | ||
->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use function Flow\ETL\DSL\array_entry; | ||
use function Flow\ETL\DSL\array_expand; | ||
use function Flow\ETL\DSL\df; | ||
use function Flow\ETL\DSL\from_rows; | ||
use function Flow\ETL\DSL\int_entry; | ||
use function Flow\ETL\DSL\ref; | ||
use function Flow\ETL\DSL\row; | ||
use function Flow\ETL\DSL\rows; | ||
use function Flow\ETL\DSL\to_output; | ||
|
||
// flow.phar run examples/topics/phar/data_frame/code.php | ||
|
||
return df() | ||
->read(from_rows(rows( | ||
row(int_entry('id', 1), array_entry('array', ['a' => 1, 'b' => 2, 'c' => 3])), | ||
))) | ||
->write(to_output(false)) | ||
->withEntry('expanded', array_expand(ref('array'))) | ||
->write(to_output(false)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters