<?php

namespace Shopping\Feed;

class FeedWriter {
    private $fh;
    private string $path;
    private int $count = 0;

    public function __construct(string $path) {
        $this->path = $path;
    }

    public function open(): void {
        $this->fh = fopen($this->path, 'w');
    }

    public function write(array $row): void {
        fwrite($this->fh, json_encode($row, JSON_UNESCAPED_SLASHES) . "\n");
        $this->count++;
    }

    public function getCount(): int {
        return $this->count;
    }

    public function close(): void {
        fclose($this->fh);
    }
}
