40 lines
758 B
PHP
40 lines
758 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KupShop\FeedsBundle\Formatter;
|
|
|
|
use KupShop\FeedsBundle\Dto\FeedItem;
|
|
|
|
class StreamedJSONFormatter implements StreamedFormatterInterface
|
|
{
|
|
public static function getType(): string
|
|
{
|
|
return 'json';
|
|
}
|
|
|
|
public static function getContentType(): string
|
|
{
|
|
return 'application/json';
|
|
}
|
|
|
|
/**
|
|
* @param \Generator<int, FeedItem> $data
|
|
*/
|
|
public function process(array $configuration, \Generator $data): void
|
|
{
|
|
echo '[';
|
|
|
|
/** @var FeedItem $item */
|
|
foreach ($data as $key => $item) {
|
|
if ($key !== 0) {
|
|
echo ',';
|
|
}
|
|
|
|
echo json_encode($item->asArray());
|
|
}
|
|
|
|
echo ']';
|
|
}
|
|
}
|