'/var/www/html' * * Input Result * ['',''] > '' * ['','/'] > '/' * ['/','a'] > '/a' * ['/','/a'] > '/a' * ['abc','def'] > 'abc/def' * ['abc','/def'] > 'abc/def' * ['/abc','def'] > '/abc/def' * ['','foo.jpg'] > 'foo.jpg' * ['dir','0','a.jpg'] > 'dir/0/a.jpg' * * @return string */ public static function join(): string { $paths = array_filter(func_get_args(), static function ($s) { return $s !== ''; }); return preg_replace('#/+#','/',implode('/', $paths)); } /** * List the files located in the given directory * * @param string $path * @param string $glob * @return list */ public static function list(string $path, string $glob = '*'): array { return glob(self::join($path, $glob)); } public static function read(string $path): string { $content = file_get_contents($path); if ($content === false) { throw new RuntimeException("File could not be read"); } return $content; } /** * Locate a file in the given directories and return its absolute path * * @param array $directories * @param string $filename * @return string */ public static function locate(array $directories, string $filename): string { $fileLocator = new FileLocator($directories); return $fileLocator->locate($filename, null, false)[0]; } }