<?php
declare(strict_types=1);
namespace classes;
use classes\Donors\DonorInterface;
class Main
{
private ?array $list = [];
private ?array $images = [];
public function __construct(
protected DonorInterface $donor,
protected Storage $storage,
protected string $url)
{
}
public function list(): Main
{
$this->list = $this->donor->list($this->url);
return $this;
}
public function images(): Main
{
if (is_array($this->list) AND count($this->list)) {
foreach ($this->list AS $k => $item) {
$this->list[$k]['images'] = $this->donor->images($item['url']);
}
return $this;
}
$this->images = $this->donor->images($this->url);
return $this;
}
public function save(): void
{
$this->storage->setContent($this->list, $this->images);
}
}