76 $root = is_link($root) ? realpath($root) : $root;
77 $this->permissionMap = array_replace_recursive(static::$permissions,
$permissions);
80 if ( ! is_dir($root) || ! is_readable($root)) {
81 throw new LogicException(
'The root path ' . $root .
' is not readable.');
100 if ( ! is_dir($root)) {
102 @mkdir($root, $this->permissionMap[
'dir'][
'public'],
true);
105 if ( ! is_dir($root)) {
106 throw new Exception(sprintf(
'Impossible to create the root directory "%s".', $root));
134 $result = compact(
'contents',
'type',
'size',
'path');
136 if ($visibility = $config->
get(
'visibility')) {
137 $result[
'visibility'] = $visibility;
157 stream_copy_to_stream($resource,
$stream);
163 if ($visibility = $config->
get(
'visibility')) {
169 return compact(
'type',
'path',
'visibility');
180 return [
'type' =>
'file',
'path' =>
$path,
'stream' =>
$stream];
200 if (
$size ===
false) {
206 return compact(
'type',
'path',
'size',
'contents',
'mimetype');
221 return [
'type' =>
'file',
'path' =>
$path,
'contents' =>
$contents];
273 foreach ($iterator as
$file) {
276 if (preg_match(
'#(^|/|\\\\)\.{1,2}$#',
$path)) {
311 $finfo =
new Finfo(FILEINFO_MIME_TYPE);
314 if (in_array($mimetype, [
'application/octet-stream',
'inode/x-empty'])) {
318 return [
'path' =>
$path,
'type' =>
'file',
'mimetype' => $mimetype];
339 return compact(
'path',
'visibility');
355 return compact(
'path',
'visibility');
365 $visibility = $config->
get(
'visibility',
'public');
367 if ( ! is_dir(
$location) && ! mkdir(
$location, $this->permissionMap[
'dir'][$visibility],
true)) {
370 $return = [
'path' => $dirname,
'type' =>
'dir'];
405 switch ($file->getType()) {
407 rmdir($file->getRealPath());
410 unlink($file->getPathname());
413 unlink($file->getRealPath());
428 if ( ! $file->isLink()) {
432 if ($this->linkHandling & self::DISALLOW_LINKS) {
449 return trim(str_replace(
'\\',
'/',
$path),
'/');
486 'type' => $file->getType(),
490 $normalized[
'timestamp'] = $file->getMTime();
492 if ($normalized[
'type'] ===
'file') {
493 $normalized[
'size'] = $file->getSize();
506 if ( ! $file->isReadable()) {
getMetadata($path)
Get all the meta data of a file or directory.array|false
const VISIBILITY_PUBLIC
VISIBILITY_PUBLIC public visibility
getTimestamp($path)
Get the timestamp of a file.array|false
static detectByFilename($filename)
getDirectoryIterator($path)
static dirname($path)
Get a normalized dirname from a path.
writeStream($path, $resource, Config $config)
Write a new file using a stream.Config objectarray|false false on failure file meta data on success ...
mapFileInfo(SplFileInfo $file)
deleteFileInfoObject(SplFileInfo $file)
static guessMimeType($path, $content)
Guess MIME Type based on the path of the file and it's content.
normalizeFileInfo(SplFileInfo $file)
Normalize the file info.
setVisibility($path, $visibility)
Set the visibility for a file.array|false file meta data
updateStream($path, $resource, Config $config)
Update a file using a stream.Config objectarray|false false on failure file meta data on success ...
has($path)
Check whether a file exists.array|bool|null
getRecursiveDirectoryIterator($path, $mode=RecursiveIteratorIterator::SELF_FIRST)
setPathPrefix($prefix)
Set the path prefix.
listContents($directory='', $recursive=false)
List contents of a directory.array
$stream
PHP stream implementation.
__construct($root, $writeFlags=LOCK_EX, $linkHandling=self::DISALLOW_LINKS, array $permissions=[])
Constructor.
getMimetype($path)
Get the mimetype of a file.array|false
const VISIBILITY_PRIVATE
VISIBILITY_PRIVATE private visibility
deleteDir($dirname)
Delete a directory.
read($path)
Read a file.array|false
createDir($dirname, Config $config)
Create a directory.directory name array|false
guardAgainstUnreadableFileInfo(SplFileInfo $file)
static forFileInfo(SplFileInfo $fileInfo)
rename($path, $newpath)
Rename a file.bool
applyPathPrefix($path)
Prefix a path.
getSize($path)
Get the size of a file.array|false
Create styles array
The data for the language used.
ensureDirectory($root)
Ensure the root directory exists.
getFilePath(SplFileInfo $file)
Get the normalized path from a SplFileInfo object.
copy($path, $newpath)
Copy a file.bool
update($path, $contents, Config $config)
Update a file.Config objectarray|false false on failure file meta data on success ...
write($path, $contents, Config $config)
Write a new file.Config objectarray|false false on failure file meta data on success ...
static forLink(SplFileInfo $file)
Create a new exception for a link.
readStream($path)
Read a file as a stream.array|false
getVisibility($path)
Get the visibility of a file.array|false
removePathPrefix($path)
Remove a path prefix.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
get($key, $default=null)
Get a setting.