init
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user