Files
lucent-laravel/src/StaticGenerator/StaticGenerator.php
T

43 lines
953 B
PHP
Raw Normal View History

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))) {
$this->make_dir(pathinfo($filepath, PATHINFO_DIRNAME));
}
file_put_contents($filepath, $html);
}
public function recordIterator(callable $query, callable $parser, int $skip = 0): int
{
$limit = 100;
logger("fetching $skip");
$records = $query($limit, $skip);
$parser($records);
if ($records->hasResults()) {
return $this->recordIterator($query, $parser, $skip + $limit);
}
return 0;
}
private function make_dir(string $path): void
{
is_dir($path) || mkdir($path, 0777, true);
}
}