2022-09-15 07:54:28 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Data\DataPipes;
|
|
|
|
|
|
|
|
|
|
use App\Data\FileData;
|
2022-10-29 12:33:22 -05:00
|
|
|
use App\Data\WatchExport;
|
2022-09-15 07:54:28 -05:00
|
|
|
use Illuminate\Support\Collection;
|
2022-10-29 12:33:22 -05:00
|
|
|
use Spatie\LaravelData\DataCollection;
|
2022-09-15 07:54:28 -05:00
|
|
|
use Spatie\LaravelData\DataPipes\DataPipe;
|
|
|
|
|
use Spatie\LaravelData\Lazy;
|
|
|
|
|
use Spatie\LaravelData\Optional;
|
|
|
|
|
use Spatie\LaravelData\Support\DataClass;
|
|
|
|
|
use Spatie\LaravelData\Support\DataConfig;
|
|
|
|
|
use Spatie\LaravelData\Support\DataProperty;
|
|
|
|
|
|
|
|
|
|
class ReadExportFiles implements DataPipe
|
|
|
|
|
{
|
|
|
|
|
public function handle(mixed $payload, DataClass $class, Collection $properties): Collection
|
|
|
|
|
{
|
2022-10-29 12:33:22 -05:00
|
|
|
if (!$properties->has('files')) {
|
|
|
|
|
$properties['files'] = new DataCollection(WatchExport::class, []);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$properties->get('files')->count()) {
|
2022-09-15 07:54:28 -05:00
|
|
|
return $properties;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$data = [];
|
|
|
|
|
foreach ($properties->get('files') as $file)
|
|
|
|
|
{
|
|
|
|
|
$data[] = $file->rawData;
|
|
|
|
|
}
|
|
|
|
|
$properties['rawData'] = $data;
|
|
|
|
|
|
|
|
|
|
return $properties;
|
|
|
|
|
}
|
|
|
|
|
}
|