fibable/lib/TagManager.php

30 lines
635 B
PHP

<?php
final class TagManager
{
const BASE_PATH = "./data/tags";
public static function getTags(): array
{
$tags = [];
foreach (array_diff(scandir(self::BASE_PATH), [".", ".."]) as $file) {
$tags[] = $file;
}
return $tags;
}
public static function getFromTag(string $tag): array
{
return file(self::BASE_PATH . "/$tag", FILE_IGNORE_NEW_LINES);
}
public static function add(array $tags, string $fullref)
{
foreach ($tags as $tag) {
file_put_contents(self::BASE_PATH . "/$tag", "$fullref\n", FILE_APPEND);
}
}
}