26 lines
585 B
PHP
26 lines
585 B
PHP
<?php
|
|
|
|
namespace Toolbox;
|
|
|
|
/**
|
|
* Fuente de paquetes en disco: `packages/<pkg>/<archivo>`.
|
|
*/
|
|
final class DirectorySource implements PackageSource
|
|
{
|
|
public function __construct(private readonly string $packagesDir)
|
|
{
|
|
}
|
|
|
|
public function baseDir(string $package): string
|
|
{
|
|
return rtrim($this->packagesDir, '/') . '/' . $package;
|
|
}
|
|
|
|
public function read(string $package, string $file): ?string
|
|
{
|
|
$path = $this->baseDir($package) . '/' . ltrim($file, '/');
|
|
|
|
return is_file($path) ? (string) file_get_contents($path) : null;
|
|
}
|
|
}
|