|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace DummyNamespace; |
| 6 | + |
| 7 | +use DragonCode\LaravelFeed\Converters\Converter; |
| 8 | +use DragonCode\LaravelFeed\Feeds\Feed; |
| 9 | +use DragonCode\LaravelFeed\Feeds\Items\FeedItem; |
| 10 | +use DragonCode\LaravelFeed\Services\TransformerService; |
| 11 | +use Illuminate\Container\Attributes\Config; |
| 12 | + |
| 13 | +use function is_array; |
| 14 | +use function json_encode; |
| 15 | + |
| 16 | +class DummyClass extends Converter |
| 17 | +{ |
| 18 | + public function __construct( |
| 19 | + #[Config('feeds.converters.jsonl.options')] |
| 20 | + protected int $options, |
| 21 | + TransformerService $transformer |
| 22 | + ) { |
| 23 | + parent::__construct(false, $transformer); |
| 24 | + } |
| 25 | + |
| 26 | + public function header(Feed $feed): string |
| 27 | + { |
| 28 | + return ''; |
| 29 | + } |
| 30 | + |
| 31 | + public function footer(Feed $feed): string |
| 32 | + { |
| 33 | + return ''; |
| 34 | + } |
| 35 | + |
| 36 | + public function root(Feed $feed): string |
| 37 | + { |
| 38 | + return ''; |
| 39 | + } |
| 40 | + |
| 41 | + public function item(FeedItem $item, bool $isLast): string |
| 42 | + { |
| 43 | + $data = $this->performItem($item->toArray()); |
| 44 | + |
| 45 | + return $this->encode($data); |
| 46 | + } |
| 47 | + |
| 48 | + public function info(array $info, bool $afterRoot): string |
| 49 | + { |
| 50 | + $data = $this->performItem($info); |
| 51 | + |
| 52 | + return $this->encode($data); |
| 53 | + } |
| 54 | + |
| 55 | + protected function performItem(array $data): array |
| 56 | + { |
| 57 | + foreach ($data as &$value) { |
| 58 | + if (is_array($value)) { |
| 59 | + $value = $this->performItem($value); |
| 60 | + |
| 61 | + continue; |
| 62 | + } |
| 63 | + |
| 64 | + $value = $this->transformValue($value); |
| 65 | + } |
| 66 | + |
| 67 | + return $data; |
| 68 | + } |
| 69 | + |
| 70 | + protected function encode(array $data): string |
| 71 | + { |
| 72 | + return json_encode($data, $this->options); |
| 73 | + } |
| 74 | +} |
0 commit comments