32 lines
848 B
PHP
32 lines
848 B
PHP
<?php
|
|
|
|
final class EntryParser
|
|
{
|
|
|
|
const BASE_PATH = "./data/cache/uuids/";
|
|
|
|
public static function parse(Post $post, string $link): Entry
|
|
{
|
|
$entry = new Entry();
|
|
$entry->title = $post->title;
|
|
$entry->content = $post->content;
|
|
$entry->date = date("c", $post->date);
|
|
$entry->url = $link .
|
|
"/?view=single&date=" . date("Y-m-d", $post->date) .
|
|
"&ref=" . $post->id;
|
|
$entry->id = self::getEntryUUID($post);
|
|
return $entry;
|
|
}
|
|
|
|
private static function getEntryUUID(Post $post): string
|
|
{
|
|
$ref = date("Ymd", $post->date) . $post->id;
|
|
$file = self::BASE_PATH . $ref;
|
|
if (!is_file($file)) {
|
|
file_put_contents($file, UUIDGenerator::generate(), LOCK_EX);
|
|
}
|
|
return file_get_contents($file);
|
|
}
|
|
|
|
}
|