Skip to content

Commit 74d70ba

Browse files
committed
add function that will display as many SQL parameters as there are values under "$path"
1 parent 7188513 commit 74d70ba

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

src/Console/Command/PipelineRunCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4242
$dotenv = new Dotenv();
4343
$dotenv->usePutenv();
4444

45-
if (file_exists($file = $cwd . '/.env')) {
45+
if (file_exists($file = $cwd.'/.env')) {
4646
$dotenv->loadEnv($file);
4747
}
48-
if (file_exists($file = $cwd . '/' . $input->getArgument('path') . '/.env')) {
48+
if (file_exists($file = $cwd.'/'.$input->getArgument('path').'/.env')) {
4949
$dotenv->loadEnv($file);
5050
}
5151

src/ExpressionLanguage/InSql.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Kiboko\Component\Satellite\ExpressionLanguage;
6+
7+
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
8+
9+
final class InSql extends ExpressionFunction
10+
{
11+
public function __construct(string $name)
12+
{
13+
parent::__construct(
14+
$name,
15+
function (string $path, string $name): string {
16+
$pattern = <<<'PHP'
17+
(function () use ($input) {
18+
$parameters = [];
19+
foreach (%s as $key => $value) {
20+
$parameters[] = ':' . %s . '_' . $key;
21+
}
22+
23+
return 'IN (' . implode(', ', $parameters) . ')';
24+
})()
25+
PHP;
26+
27+
return sprintf($pattern, $path, $name);
28+
},
29+
function (array $path, string $name) {
30+
$parameters = [];
31+
foreach ($path as $key => $value) {
32+
$parameters[] = ':'.$name.'_'.$key;
33+
}
34+
35+
return 'IN ('.implode(', ', $parameters).')';
36+
},
37+
);
38+
}
39+
}

src/ExpressionLanguage/Provider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public function getFunctions(): array
1616
new File('file'),
1717
new Base64Decode('base64Decode'),
1818
new TemporaryFile('temporaryFile'),
19+
new InSql('inSql'),
1920
];
2021
}
2122
}

0 commit comments

Comments
 (0)