You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
json2db/app/Services/Chunkers/JsonChunker.php

28 lines
592 B

<?php
namespace App\Services\Chunkers;
use App\Interfaces\ChunkerInterface;
use Illuminate\Support\Facades\Storage;
use JsonMachine\Items;
class JsonChunker implements ChunkerInterface
{
public function handle(string $uuid, string $path): \Generator
{
$chunk = [];
foreach (Items::fromFile(Storage::path($path)) as $key => $value) {
$chunk[] = $value;
if (count($chunk) == 500) {
yield $chunk;
$chunk = [];
}
}
if(count($chunk) > 0){
yield $chunk;
}
}
}