7 use League\Flysystem\Adapter\Local as LocalAdapter;
36 public function __construct(Filesystem $filesystem, $local_path =
'', $chroot =
'') {
37 $this->fs = $filesystem;
38 $this->local_path = rtrim(strtr($local_path,
'\\',
'/'),
"/\\");
39 $this->
chroot = $this->normalize($chroot);
44 return new self($this->fs, $this->local_path,
$path);
54 private function isDirectory(
$path) {
56 return $this->fs->has(
$path) && $this->fs->get(
$path)->isDir();
62 return $this->fs->has(
$path) && $this->fs->get(
$path)->isFile();
67 return (
string)$this->fs->read($this->getInternalPath(
$path));
72 if ($this->isDirectory(
$path)) {
73 throw new \RuntimeException(
"There is already a directory at that location: $path");
100 protected function getEntries(
$path =
'', $recursive =
true, $types = [
'file',
'dir']) {
101 $contents = $this->fs->listContents($this->getInternalPath(
$path), $recursive);
107 return in_array(
$metadata[
'type'], $types);
110 return Collection\InMemory::fromArray(array_map(
function (
$metadata) {
115 return new self($this->fs, $this->local_path,
$metadata[
'path']);
121 $path = $this->normalize($this->getInternalPath(
$path));
122 return "{$this->local_path}/$path";
134 private function getInternalPath(
$path) {
136 return $this->normalize(
"{$this->chroot}/$path");
157 $fs =
new Filesystem(
new LocalAdapter(
$path));
158 return new self($fs,
$path);
167 $fs =
new Filesystem(
new MemoryAdapter());
168 return new self($fs);
180 private function normalize(
$path) {
182 $test_path =
"/$path/";
183 if (strpos($test_path,
'/./') !==
false || strpos($test_path,
'/../') !==
false) {
184 throw new \InvalidArgumentException(
'Paths cannot contain "." or ".."');
187 return trim(strtr(
$path,
'\\',
'/'),
"/");
A simple directory abstraction.
putContents($path, $content)
static createInMemory()
Shorthand for generating a new in-memory-only filesystem.
A wrapper around Flysystem that implements Elgg's filesystem API.
__construct(Filesystem $filesystem, $local_path= '', $chroot= '')
Use one of the static factory functions to create an instance.
getDirectories($path= '', $recursive=true)
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.
$content
Set robots.txt action.
static createLocal($path)
Shorthand for generating a new local filesystem.
http free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
getFiles($path= '', $recursive=true)