Skip to content

Commit

Permalink
Merge pull request #123 from php-etl/feature/hook-api
Browse files Browse the repository at this point in the history
fix runtimes: http-api + hook
  • Loading branch information
clemzarch authored Aug 24, 2023
2 parents e65c423 + 2008715 commit 29c0450
Show file tree
Hide file tree
Showing 20 changed files with 1,078 additions and 323 deletions.
2 changes: 2 additions & 0 deletions bin/satellite
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ use Symfony\Component\Console\Output;
$app = new \Symfony\Component\Console\Application();

$app->addCommands([
new \Kiboko\Component\Satellite\Console\Command\ApiRunCommand(),
new \Kiboko\Component\Satellite\Console\Command\BuildCommand(),
new \Kiboko\Component\Satellite\Console\Command\HookRunCommand(),
new \Kiboko\Component\Satellite\Console\Command\ValidateCommand(),
new \Kiboko\Component\Satellite\Console\Command\PipelineRunCommand(),
new \Kiboko\Component\Satellite\Console\Command\WorkflowRunCommand(),
Expand Down
4 changes: 2 additions & 2 deletions project-fpm/caddy/Caddyfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
localhost:4000 {
reverse_proxy /foo/* satellite-1:9000 {
transport fastcgi {
root /var/www/html/index.php
root /var/www/html/main.php
}
}
reverse_proxy /bar/* satellite-2:9000 {
transport fastcgi {
root /var/www/html/index.php
root /var/www/html/main.php
}
}

Expand Down
12 changes: 6 additions & 6 deletions project-fpm/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ services:
http:
image: caddy:2-alpine
volumes:
- ./caddy/Caddyfile:/etc/caddy/Caddyfile
- ./index.html:/var/www/html/index.html
- caddy_data:/data
- ./caddy/Caddyfile:/etc/caddy/Caddyfile
- ./index.html:/var/www/html/index.html
- caddy_data:/data
ports:
- '4000:4000'
- '4000:4000'

satellite-1:
image: kiboko/satellite-1
image: kiboko/satellite:foo

satellite-2:
image: kiboko/satellite-1
image: kiboko/satellite:bar

volumes:
caddy_data:
Expand Down
15 changes: 0 additions & 15 deletions project-fpm/hello.php

This file was deleted.

42 changes: 22 additions & 20 deletions project-fpm/http-api.yaml
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
satellite:
docker:
from: php:8.0-fpm-alpine
workdir: /var/www/html
tags:
- kiboko/satellite:foo
- kiboko/satellite:bar
# filesystem:
# path: foo
# docker:
# from: php:8.0-fpm-alpine
# workdir: /var/www/html
# tags:
# - kiboko/satellite:foo
# - kiboko/satellite:bar
filesystem:
path: foo
composer:
# from_local: true
autoload:
psr4:
- namespace: "Pipeline\\"
paths: [ "" ]
require:
- "psr/http-message:^1.0@dev"
- "psr/http-factory:^1.0@dev"
- "psr/http-server-handler:^1.0@dev"
- "middlewares/uuid:dev-master"
- "middlewares/base-path:dev-master"
- "middlewares/request-handler:dev-master"
- "middlewares/fast-route:dev-master"
- "laminas/laminas-diactoros"
- "laminas/laminas-httphandlerrunner:1.2.x-dev"
- "laminas/laminas-httphandlerrunner"
- "nyholm/psr7-server"
- "nyholm/psr7"
- "php-etl/pipeline"
- "php-etl/satellite"
- "php-etl/api-runtime"
- "php-etl/mapping-contracts"
- "tuupola/slim-jwt-auth"
- "tuupola/slim-basic-auth"
http_api:
path: /foo
authorization:
jwt:
secret: 'my_secret'
routes:
- route: /hello
expression: 'input["_items"]'
pipeline:
steps:
- fastmap:
map:
- field: '[sku]'
copy: '[sku]'
- field: '[title]'
expression: 'input["sku"] ~" | "~ input["name"]'
- field: '[name]'
copy: '[name]'
- field: '[staticValue]'
Expand All @@ -48,14 +51,13 @@ satellite:
logger:
type: stderr
- route: /events/products
expression: 'input["_items"]'
pipeline:
steps:
- fastmap:
map:
- field: '[sku]'
copy: '[sku]'
- field: '[title]'
expression: 'input["sku"] ~" | "~ input["name"]'
- field: '[name]'
copy: '[name]'
- field: '[staticValue]'
Expand Down
42 changes: 24 additions & 18 deletions project-fpm/http-hook.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
satellite:
docker:
from: php:8.0-fpm-alpine
workdir: /var/www/html
tags:
- kiboko/satellite:foo
- kiboko/satellite:bar
# filesystem:
# path: foo
# docker:
# from: php:8.0-fpm-alpine
# workdir: /var/www/html
# tags:
# - kiboko/satellite:foo
# - kiboko/satellite:bar
filesystem:
path: foo
composer:
# from_local: true
autoload:
psr4:
- namespace: "Pipeline\\"
paths: [ "" ]
require:
- "psr/http-message:^1.0@dev"
- "psr/http-factory:^1.0@dev"
- "psr/http-server-handler:^1.0@dev"
- "middlewares/uuid:dev-master"
- "middlewares/base-path:dev-master"
- "middlewares/request-handler:dev-master"
- "middlewares/fast-route:dev-master"
- "laminas/laminas-diactoros"
- "laminas/laminas-httphandlerrunner:1.2.x-dev"
- "laminas/laminas-httphandlerrunner"
- "nyholm/psr7-server"
- "nyholm/psr7"
- "php-etl/hook-runtime"
- "symfony/expression-language"
- "php-etl/mapping-contracts"
- "tuupola/slim-jwt-auth"
- "tuupola/slim-basic-auth"
http_hook:
path: /bar/hello
authorization:
basic:
- user: john
password: my_password
- user: bill
password: other_password
expression: 'input["_items"]'
pipeline:
steps:
- fastmap:
Expand All @@ -36,7 +42,7 @@ satellite:
- field: '[name]'
copy: '[name]'
- field: '[staticValue]'
constant: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur mollis efficitur justo, id facilisis elit venenatis et. Sed fermentum posuere convallis. Phasellus lectus neque, bibendum sit amet enim imperdiet, dignissim blandit nisi. Donec nec neque nisi. Vivamus luctus facilisis nibh id rhoncus. Vestibulum eget facilisis tortor. Etiam at cursus enim, vitae mollis ex. Proin at velit at erat bibendum ultricies. Duis ut velit malesuada, placerat nisl a, ultrices tortor.'
constant: 'Lorem ipsum dolor sit amet'
- csv:
loader:
file_path: output.csv
Expand Down
53 changes: 47 additions & 6 deletions src/Builder/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,53 @@ final class API implements Builder
{
public function getNode(): Node
{
return new Node\Expr\Closure(subNodes: [
'params' => [
new Node\Param(
var: new Node\Expr\Variable('request')
return new Node\Stmt\Return_(
new Node\Expr\MethodCall(
new Node\Expr\MethodCall(
new Node\Expr\Variable('psr17Factory'),
'createResponse',
[
new Node\Arg(
new Node\Scalar\LNumber(200),
),
]
),
],
]);
'withBody',
[
new Node\Arg(
new Node\Expr\MethodCall(
new Node\Expr\Variable('psr17Factory'),
'createStream',
[
new Node\Arg(
new Node\Expr\FuncCall(
new Node\Name('json_encode'),
[
new Node\Arg(
new Node\Expr\Array_(
[
new Node\Expr\ArrayItem(
new Node\Expr\Variable('response'),
new Node\Scalar\String_('message')
),
new Node\Expr\ArrayItem(
new Node\Expr\FuncCall(new Node\Name('gethostname')),
new Node\Scalar\String_('server')
),
],
[
'kind' => Node\Expr\Array_::KIND_SHORT,
]
)
),
]
)
),
]
)
),
]
)
);
}
}
43 changes: 43 additions & 0 deletions src/Builder/API/APIRuntime.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace Kiboko\Component\Satellite\Builder\API;

use PhpParser\Node;

final class APIRuntime
{
public function getNode(): Node\Expr
{
return new Node\Expr\New_(
class: new Node\Name\FullyQualified('Kiboko\\Component\\Runtime\\API\\APIRuntime'),
args: [
new Node\Arg(
value: new Node\Expr\New_(
class: new Node\Name\FullyQualified(\Kiboko\Component\Pipeline\Pipeline::class),
args: [
new Node\Arg(
value: new Node\Expr\New_(
class: new Node\Name\FullyQualified(\Kiboko\Component\Pipeline\PipelineRunner::class),
args: [
new Node\Arg(
value: new Node\Expr\New_(
class: new Node\Name\FullyQualified(\Psr\Log\NullLogger::class)
)
),
]
)
),
]
),
),
new Node\Arg(
value: new Node\Expr\New_(
class: new Node\Name\FullyQualified('ProjectServiceContainer')
),
),
]
);
}
}
38 changes: 38 additions & 0 deletions src/Builder/API/PipelineBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace Kiboko\Component\Satellite\Builder\API;

use PhpParser\Builder;
use PhpParser\Node;

final readonly class PipelineBuilder
{
public function __construct(private Builder $builder)
{
}

public function getNode(): Node\Expr
{
return new Node\Expr\Closure(
subNodes: [
'static' => true,
'params' => [
new Node\Param(
var: new Node\Expr\Variable('runtime'),
type: new Node\Name\FullyQualified('Kiboko\\Component\\Runtime\\Hook\\HookRuntimeInterface'),
),
],
'stmts' => [
new Node\Stmt\Expression(
$this->builder->getNode()
),
new Node\Stmt\Return_(
expr: new Node\Expr\Variable('runtime')
),
],
]
);
}
}
Loading

0 comments on commit 29c0450

Please sign in to comment.