Skip to content

Commit 51196f4

Browse files
committed
feat: added support for php-etl v1.2
1 parent 20600f6 commit 51196f4

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

Command/ExecuteCommand.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@
22

33
namespace Oliverde8\PhpEtlBundle\Command;
44

5+
use Oliverde8\Component\PhpEtl\Output\SymfonyConsoleOutput;
56
use Oliverde8\PhpEtlBundle\Services\ChainProcessorsManager;
67
use Symfony\Component\Console\Command\Command;
78
use Symfony\Component\Console\Input\InputArgument;
89
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Console\Input\InputOption;
911
use Symfony\Component\Console\Output\OutputInterface;
1012

1113
class ExecuteCommand extends Command
1214
{
1315
const ARGUMENT_NAME = "name";
1416
const ARGUMENT_DATA = "data";
1517
const ARGUMENT_PARAMS = "params";
18+
const OPTION_PRETTY = "pretty";
1619

1720
protected ChainProcessorsManager $chainProcessorsManager;
1821

@@ -32,6 +35,7 @@ protected function configure()
3235
$this->addArgument(self::ARGUMENT_NAME, InputArgument::REQUIRED);
3336
$this->addArgument(self::ARGUMENT_DATA, InputArgument::OPTIONAL, "json with the input array");
3437
$this->addArgument(self::ARGUMENT_PARAMS, InputArgument::OPTIONAL, "json with all the additional parameters");
38+
$this->addOption(self::OPTION_PRETTY, "p", InputOption::VALUE_NONE, "Disables pretty output");
3539
}
3640

3741
/**
@@ -43,7 +47,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
4347
$options = json_decode($input->getArgument(self::ARGUMENT_PARAMS) ?? '[]', true);
4448
$data = json_decode($input->getArgument(self::ARGUMENT_DATA) ?? '[]', true);
4549

46-
$this->chainProcessorsManager->execute($chainName, $data, $options);
50+
$processorOutput = new SymfonyConsoleOutput($output, 0);
51+
$observation = function (array $operationStates) use ($processorOutput) {
52+
$processorOutput->output($operationStates);
53+
};
54+
if ($input->getOption(self::OPTION_PRETTY)) {
55+
$observation = function (array $operationStates) {};
56+
}
57+
58+
$this->chainProcessorsManager->execute($chainName, $data, $options, $observation);
4759
return 0;
4860
}
4961
}

Services/ChainProcessorsManager.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function getProcessor(string $chainName, array $options): ChainProcessor
7777
*
7878
* @throws \Exception
7979
*/
80-
public function execute(string $chainName, iterable $iterator, array $params)
80+
public function execute(string $chainName, iterable $iterator, array $params, ?callable $observerCallback = null)
8181
{
8282
$definition = $this->getRawDefinition($chainName);
8383

@@ -91,14 +91,14 @@ public function execute(string $chainName, iterable $iterator, array $params)
9191
$execution->setStatus(EtlExecution::STATUS_RUNNING);
9292
$this->etlExecutionRepository->save($execution);
9393

94-
$this->executeFromEtlEntity($execution, $iterator);
94+
$this->executeFromEtlEntity($execution, $iterator, $observerCallback);
9595
}
9696

9797
/**
9898
* Execute a chain from it's entity.
9999
*
100100
*/
101-
public function executeFromEtlEntity(EtlExecution $execution, iterable $iterator = null): void
101+
public function executeFromEtlEntity(EtlExecution $execution, iterable $iterator = null, ?callable $observerCallback = null): void
102102
{
103103
$chainName = $execution->getName();
104104
$logger = $this->loggerFactory->get($execution);
@@ -124,7 +124,7 @@ public function executeFromEtlEntity(EtlExecution $execution, iterable $iterator
124124
];
125125

126126
// Start the process.
127-
$processor->process($iterator, $params);
127+
$processor->process($iterator, $params, $observerCallback);
128128
$execution = $this->etlExecutionRepository->find($execution->getId());
129129
$execution->setStatus(EtlExecution::STATUS_SUCCESS);
130130
} catch (\Throwable $exception) {

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
],
1212
"require": {
1313
"php": ">=8.0",
14-
"oliverde8/php-etl": "^v1.1.0-alpha1",
15-
"symfony/framework-bundle": "^5.4|^6.0",
16-
"symfony/messenger": "^5.4|^6.0",
14+
"oliverde8/php-etl": "^v1.2.0-alpha1",
15+
"symfony/framework-bundle": "^5.4|^6.0|^7.0",
16+
"symfony/messenger": "^5.4|^6.0|^7.0",
1717
"ext-json": "*"
1818
},
1919
"autoload": {
@@ -23,6 +23,6 @@
2323
},
2424
"require-dev": {
2525
"symfony/monolog-bundle": "^3.7",
26-
"symfony/console": "^5.4|^6.0"
26+
"symfony/console": "^6.0|^7.0"
2727
}
2828
}

0 commit comments

Comments
 (0)