articles[] = self::getArticle($file_path); } } } } return $dates; } private static function getArticle(string $file_path): Article { $pattern = "|(./data)/articles/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)\.txt|"; $replacement = "$1/serial/$2$3$4$5.pobj"; $serial_path = preg_replace($pattern, $replacement, $file_path); return file_exists($serial_path) ? unserialize(file_get_contents($serial_path)) : self::createArticle($file_path, $serial_path); } private static function createArticle(string $file_path, string $serial_path): Article { $parser = new ArticleParser(); $article = $parser->parse($file_path); file_put_contents($serial_path, serialize($article)); TagManager::add($article->tags, substr(basename($serial_path), 0, -5)); return $article; } }