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

52 lines
1.2 KiB
PHP
Raw Normal View History

2023-10-02 23:10:49 +03:00
<?php namespace Lucent\StaticGenerator;
2023-10-04 23:48:12 +03:00
use Illuminate\Contracts\View\View;
2023-10-02 23:10:49 +03:00
class StaticGenerator
{
2023-10-04 23:48:12 +03:00
public function __construct(
)
2023-10-02 23:10:49 +03:00
{
}
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 23:48:12 +03:00
public function createRedirect(string $from, string $to, string $title = "Redirecting", string $message = "Redirecting Soon..."): void
{
$html = view("lucent::redirect", [
"to" => $to,
"title" => $title,
"message" => $message,
])->render();
$this->save($from, $html);
}
2023-10-02 23:10:49 +03:00
}