2023-10-02 23:10:49 +03:00
|
|
|
<?php namespace Lucent\StaticGenerator;
|
|
|
|
|
|
|
|
|
|
class StaticGenerator
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public function construct()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function save(string $path, string $html): void
|
|
|
|
|
{
|
|
|
|
|
$path = trim($path, "/");
|
|
|
|
|
|
|
|
|
|
$filepath = public_path($path . "/index.html");
|
|
|
|
|
|
|
|
|
|
if (!file_exists(pathinfo($filepath, PATHINFO_DIRNAME))) {
|
2023-10-04 13:32:30 +03:00
|
|
|
make_dir_r(pathinfo($filepath, PATHINFO_DIRNAME));
|
2023-10-02 23:10:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
file_put_contents($filepath, $html);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function recordIterator(callable $query, callable $parser, int $skip = 0): int
|
|
|
|
|
{
|
|
|
|
|
$limit = 100;
|
2023-10-02 23:47:01 +03:00
|
|
|
// logger("fetching $skip");
|
2023-10-02 23:10:49 +03:00
|
|
|
|
|
|
|
|
$records = $query($limit, $skip);
|
|
|
|
|
$parser($records);
|
|
|
|
|
|
|
|
|
|
if ($records->hasResults()) {
|
|
|
|
|
return $this->recordIterator($query, $parser, $skip + $limit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-04 13:32:30 +03:00
|
|
|
|
2023-10-02 23:10:49 +03:00
|
|
|
}
|