10 use League\Flysystem\Local\LocalFilesystemAdapter as LocalAdapter;
44 public function __construct(Filesystem $filesystem, $local_path =
'', $chroot =
'') {
45 $this->fs = $filesystem;
46 $this->local_path =
rtrim(strtr($local_path,
'\\',
'/'),
'/\\');
47 $this->
chroot = $this->normalize($chroot);
54 return new self($this->fs, $this->local_path,
$path);
64 private function isDirectory(
$path) {
66 return !empty($this->fs->listContents(
$path)->toArray());
73 return $this->fs->fileExists($this->getInternalPath(
$path));
80 return (
string) $this->fs->read($this->getInternalPath(
$path));
89 if ($this->isDirectory(
$path)) {
90 throw new RuntimeException(
"There is already a directory at that location: {$path}");
119 protected function getEntries(
$path =
'', $recursive =
true, $types = [
'file',
'dir']) {
120 $contents = $this->fs->listContents($this->getInternalPath(
$path), $recursive)->toArray();
126 return in_array(
$metadata[
'type'], $types);
129 return Collection\InMemory::fromArray(array_map(
function (
$metadata) {
134 return new self($this->fs, $this->local_path,
$metadata[
'path']);
142 $path = $this->normalize($this->getInternalPath(
$path));
143 return "{$this->local_path}/$path";
153 private function getInternalPath(
$path) {
155 return $this->normalize(
"{$this->chroot}/$path");
180 $fs =
new Filesystem(
new LocalAdapter(
$path));
181 return new self($fs,
$path);
190 $fs =
new Filesystem(
new InMemoryFilesystemAdapter());
191 return new self($fs);
202 private function normalize(
$path) {
203 $test_path =
"/{$path}/";
204 if (str_contains($test_path,
'/./') || str_contains($test_path,
'/../')) {
208 return trim(strtr(
$path,
'\\',
'/'),
'/');
isFile($path)
Whether this directory has an existing file at the given location.The relative path within this direc...
A simple directory abstraction.
getPath($path= '')
Get the absolute path to the given directory-relative path.A file/directory path within this director...
Exception thrown if an argument is not of the expected type.
Exception thrown if an error which can only be found on runtime occurs.
putContents($path, $content)
Write a file, overwriting the contents if necessary.The path to the file. The literal text content of...
static createInMemory()
Shorthand for generating a new in-memory-only filesystem.
A wrapper around Flysystem that implements Elgg's filesystem API.
includeFile($path)
Do a PHP include of the file and return the result.NB: This only really works with local filesystems ...
__construct(Filesystem $filesystem, $local_path= '', $chroot= '')
Use one of the static factory functions to create an instance.
getContents($path)
Read the file off the filesystem.The directory-relative path to the target file.string Empty string i...
getDirectories($path= '', $recursive=true)
List the directories in the given directory path.The subdirectory path within this directory Find dir...
Represents a file that may or may not actually exist.
getEntries($path= '', $recursive=true, $types=['file', 'dir'])
List the files and directories in the given directory path.
chroot($path)
Returns a subdirectory with access limited to the given directory.The path relative to this directory...
$content
Set robots.txt action.
static createLocal($path)
Shorthand for generating a new local filesystem.
getFile($path)
A reference to the file at the given path, even if it doesn't exist yet.However, will throw an except...
if(!empty($title)&&!empty($icon_name)) if(!empty($title)) if(!empty($menu)) if(!empty($header)) if(!empty($body)) $contents
getFiles($path= '', $recursive=true)
List the files in the given directory path.The subdirectory path within this directory Find files rec...