eee
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Di;
|
||||
|
||||
class ScanManifest
|
||||
{
|
||||
private array $entries = [];
|
||||
|
||||
public function set(string $path, int $mtime, array $classes): void
|
||||
{
|
||||
$this->entries[$path] = [
|
||||
'mtime' => $mtime,
|
||||
'classes' => array_values(array_unique($classes)),
|
||||
];
|
||||
}
|
||||
|
||||
public function has(string $path): bool
|
||||
{
|
||||
return isset($this->entries[$path]);
|
||||
}
|
||||
|
||||
public function getMtime(string $path): ?int
|
||||
{
|
||||
return $this->entries[$path]['mtime'] ?? null;
|
||||
}
|
||||
|
||||
public function getClasses(string $path): array
|
||||
{
|
||||
return $this->entries[$path]['classes'] ?? [];
|
||||
}
|
||||
|
||||
public function remove(string $path): array
|
||||
{
|
||||
$classes = $this->getClasses($path);
|
||||
unset($this->entries[$path]);
|
||||
return $classes;
|
||||
}
|
||||
|
||||
public function all(): array
|
||||
{
|
||||
return $this->entries;
|
||||
}
|
||||
|
||||
public function paths(?string $prefix = null): array
|
||||
{
|
||||
if ($prefix === null) {
|
||||
return array_keys($this->entries);
|
||||
}
|
||||
|
||||
return array_values(array_filter(array_keys($this->entries), fn(string $path) => str_starts_with($path, $prefix)));
|
||||
}
|
||||
|
||||
public function fromArray(array $entries): void
|
||||
{
|
||||
$this->entries = [];
|
||||
foreach ($entries as $path => $entry) {
|
||||
$mtime = (int)($entry['mtime'] ?? 0);
|
||||
$classes = is_array($entry['classes'] ?? null) ? $entry['classes'] : [];
|
||||
$this->set($path, $mtime, $classes);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user