attributes = $data['attributes']; } public function toCsv(): string { $headers = $this->getHeaders(); $f = $this->driver->fileOpen(self::FILE_PATH, 'w+'); $this->driver->filePutCsv($f, $headers); foreach ($this->items as $block) { if (!$block) { continue; } foreach ($block as $item) { $this->driver->filePutCsv($f, $this->formatLine($item, $headers)); } } rewind($f); //phpcs:disable Magento2.Functions.DiscouragedFunction.Discouraged try { $content = stream_get_contents($f); } catch (\Throwable $t) { //test } $this->driver->fileClose($f); return $content; } /** * @return string[] */ private function getHeaders(): array { $data = ['entity_id', 'store_id', 'url', 'public_url']; foreach ($this->attributes as $attribute) { $data[] = $attribute->getAttributeCode(); } return $data; } /** * @param string[] $item * @param string[] $headers * * @return string[] */ private function formatLine(array $item, array $headers): array { return [$item, $headers]; } }