diff --git a/src/CSV/FingersCrossed/Loader.php b/src/CSV/FingersCrossed/Loader.php index c08ca11..78e28fc 100644 --- a/src/CSV/FingersCrossed/Loader.php +++ b/src/CSV/FingersCrossed/Loader.php @@ -11,6 +11,7 @@ use Box\Spout\Writer\WriterInterface; use Kiboko\Component\Bucket\AcceptanceResultBucket; use Kiboko\Component\Bucket\EmptyResultBucket; +use Kiboko\Component\Bucket\RejectionResultBucket; use Kiboko\Contract\Bucket\ResultBucketInterface; use Kiboko\Contract\Pipeline\FlushableInterface; use Kiboko\Contract\Pipeline\LoaderInterface; @@ -26,24 +27,32 @@ public function __construct( public function load(): \Generator { - $line = yield new EmptyResultBucket(); + $line = yield; try { $this->writer->addRow( new Row(array_map(fn ($value) => new Cell($value), array_keys($line)), null) ); } catch (IOException|WriterNotOpenedException $exception) { $this->logger->error('Impossible to load data to the given CSV file.', ['line' => $line, 'message' => $exception->getMessage(), 'previous' => $exception->getPrevious()]); - - return; + $line = yield new RejectionResultBucket( + 'Impossible to load data to the given CSV file.', + $exception, + $line + ); } - while ($line) { + while (true) { try { $this->writer->addRow( new Row(array_map(fn ($value) => new Cell($value), $line), null) ); } catch (IOException|WriterNotOpenedException $exception) { $this->logger->error('Impossible to load data to the given CSV file.', ['line' => $line, 'message' => $exception->getMessage(), 'previous' => $exception->getPrevious()]); + $line = yield new RejectionResultBucket( + 'Impossible to load data to the given CSV file.', + $exception, + $line + ); } $line = yield new AcceptanceResultBucket($line); diff --git a/src/CSV/Safe/Loader.php b/src/CSV/Safe/Loader.php index 333c5af..29a2f16 100644 --- a/src/CSV/Safe/Loader.php +++ b/src/CSV/Safe/Loader.php @@ -11,6 +11,7 @@ use Box\Spout\Writer\WriterInterface; use Kiboko\Component\Bucket\AcceptanceResultBucket; use Kiboko\Component\Bucket\EmptyResultBucket; +use Kiboko\Component\Bucket\RejectionResultBucket; use Kiboko\Contract\Bucket\ResultBucketInterface; use Kiboko\Contract\Pipeline\FlushableInterface; use Kiboko\Contract\Pipeline\LoaderInterface; @@ -34,8 +35,11 @@ public function load(): \Generator ); } catch (IOException|WriterNotOpenedException $exception) { $this->logger->error('Impossible to load data to the given CSV file.', ['line' => $line, 'message' => $exception->getMessage(), 'previous' => $exception->getPrevious()]); - - return; + $line = yield new RejectionResultBucket( + 'Impossible to load data to the given CSV file.', + $exception, + $line + ); } while ($line) { @@ -43,6 +47,11 @@ public function load(): \Generator $this->writer->addRow($this->orderColumns($headers, $line)); } catch (IOException|WriterNotOpenedException $exception) { $this->logger->error('Impossible to load data to the given CSV file.', ['line' => $line, 'message' => $exception->getMessage(), 'previous' => $exception->getPrevious()]); + $line = yield new RejectionResultBucket( + 'Impossible to load data to the given CSV file.', + $exception, + $line + ); } $line = yield new AcceptanceResultBucket($line); diff --git a/src/Sheet/FingersCrossed/Loader.php b/src/Sheet/FingersCrossed/Loader.php index 3ce013b..255b55c 100644 --- a/src/Sheet/FingersCrossed/Loader.php +++ b/src/Sheet/FingersCrossed/Loader.php @@ -11,6 +11,7 @@ use Box\Spout\Writer\WriterInterface; use Kiboko\Component\Bucket\AcceptanceResultBucket; use Kiboko\Component\Bucket\EmptyResultBucket; +use Kiboko\Component\Bucket\RejectionResultBucket; use Kiboko\Contract\Bucket\ResultBucketInterface; use Kiboko\Contract\Pipeline\FlushableInterface; use Kiboko\Contract\Pipeline\LoaderInterface; @@ -38,8 +39,11 @@ public function load(): \Generator ); } catch (IOException|WriterNotOpenedException $exception) { $this->logger->error('Impossible to load data to the given CSV file.', ['line' => $line, 'message' => $exception->getMessage(), 'previous' => $exception->getPrevious()]); - - return; + $line = yield new RejectionResultBucket( + 'Impossible to load data to the given CSV file.', + $exception, + $line + ); } while ($line) { @@ -49,6 +53,11 @@ public function load(): \Generator ); } catch (IOException|WriterNotOpenedException $exception) { $this->logger->error('Impossible to load data to the given CSV file.', ['line' => $line, 'message' => $exception->getMessage(), 'previous' => $exception->getPrevious()]); + $line = yield new RejectionResultBucket( + 'Impossible to load data to the given CSV file.', + $exception, + $line + ); } $line = yield new AcceptanceResultBucket($line); diff --git a/src/Sheet/Safe/Loader.php b/src/Sheet/Safe/Loader.php index caf2279..16f67f4 100644 --- a/src/Sheet/Safe/Loader.php +++ b/src/Sheet/Safe/Loader.php @@ -11,6 +11,7 @@ use Box\Spout\Writer\WriterInterface; use Kiboko\Component\Bucket\AcceptanceResultBucket; use Kiboko\Component\Bucket\EmptyResultBucket; +use Kiboko\Component\Bucket\RejectionResultBucket; use Kiboko\Contract\Bucket\ResultBucketInterface; use Kiboko\Contract\Pipeline\FlushableInterface; use Kiboko\Contract\Pipeline\LoaderInterface; @@ -38,8 +39,11 @@ public function load(): \Generator ); } catch (IOException|WriterNotOpenedException $exception) { $this->logger->error('Impossible to load data to the given CSV file.', ['line' => $line, 'message' => $exception->getMessage(), 'previous' => $exception->getPrevious()]); - - return; + $line = yield new RejectionResultBucket( + 'Impossible to load data to the given CSV file.', + $exception, + $line + ); } while ($line) { @@ -47,6 +51,11 @@ public function load(): \Generator $this->writer->addRow($this->orderColumns($headers, $line)); } catch (IOException|WriterNotOpenedException $exception) { $this->logger->error('Impossible to load data to the given CSV file.', ['line' => $line, 'message' => $exception->getMessage(), 'previous' => $exception->getPrevious()]); + $line = yield new RejectionResultBucket( + 'Impossible to load data to the given CSV file.', + $exception, + $line + ); } $line = yield new AcceptanceResultBucket($line);