ImportPipeline.php 716 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace App\Domain\Import;
  3. use Illuminate\Pipeline\Pipeline;
  4. class ImportPipeline
  5. {
  6. public function __construct(private readonly Pipeline $pipeline)
  7. {
  8. }
  9. public function run(string $type, array $payload): array
  10. {
  11. $stages = match ($type) {
  12. 'markdown' => [
  13. \App\Domain\Import\Stages\NormalizeMarkdown::class,
  14. \App\Domain\Import\Stages\SplitMarkdown::class,
  15. ],
  16. 'pdf' => [
  17. \App\Domain\Import\Stages\SplitPdf::class,
  18. ],
  19. default => [],
  20. };
  21. return $this->pipeline
  22. ->send($payload)
  23. ->through($stages)
  24. ->thenReturn();
  25. }
  26. }