15use RecursiveDirectoryIterator;
 
   16use RecursiveIteratorIterator;
 
   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));
 
  129        if ((
$size = file_put_contents(
$location, $contents, $this->writeFlags)) === 
false) {
 
  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];
 
  198        $size = file_put_contents(
$location, $contents, $this->writeFlags);
 
  200        if (
$size === 
false) {
 
  206        return compact(
'type', 
'path', 
'size', 
'contents', 
'mimetype');
 
  215        $contents = file_get_contents(
$location);
 
  217        if ($contents === 
false) {
 
  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'];
 
  392        foreach ($contents as $file) {
 
  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), 
'/');
 
  460        return new RecursiveIteratorIterator(
 
  461            new RecursiveDirectoryIterator(
$path, FilesystemIterator::SKIP_DOTS),
 
  473        $iterator = 
new DirectoryIterator(
$path);
 
  486            'type' => $file->getType(),
 
  490        $normalized[
'timestamp'] = $file->getMTime();
 
  492        if ($normalized[
'type'] === 
'file') {
 
  493            $normalized[
'size'] = $file->getSize();
 
  506        if ( ! $file->isReadable()) {
 
An exception for terminatinating execution or to throw for unit testing.
removePathPrefix($path)
Remove a path prefix.
applyPathPrefix($path)
Prefix a path.
setPathPrefix($prefix)
Set the path prefix.
mapFileInfo(SplFileInfo $file)
getVisibility($path)
Get the visibility of a file.array|false
getRecursiveDirectoryIterator($path, $mode=RecursiveIteratorIterator::SELF_FIRST)
__construct($root, $writeFlags=LOCK_EX, $linkHandling=self::DISALLOW_LINKS, array $permissions=[])
Constructor.
deleteFileInfoObject(SplFileInfo $file)
guardAgainstUnreadableFileInfo(SplFileInfo $file)
normalizeFileInfo(SplFileInfo $file)
Normalize the file info.
rename($path, $newpath)
Rename a file.bool
setVisibility($path, $visibility)
Set the visibility for a file.array|false file meta data
update($path, $contents, Config $config)
Update a file.array|false false on failure file meta data on success
updateStream($path, $resource, Config $config)
Update a file using a stream.array|false false on failure file meta data on success
write($path, $contents, Config $config)
Write a new file.array|false false on failure file meta data on success
listContents($directory='', $recursive=false)
List contents of a directory.array
getDirectoryIterator($path)
has($path)
Check whether a file exists.array|bool|null
readStream($path)
Read a file as a stream.array|false
ensureDirectory($root)
Ensure the root directory exists.
getFilePath(SplFileInfo $file)
Get the normalized path from a SplFileInfo object.
getMetadata($path)
Get all the meta data of a file or directory.array|false
createDir($dirname, Config $config)
Create a directory.array|false
writeStream($path, $resource, Config $config)
Write a new file using a stream.array|false false on failure file meta data on success
getSize($path)
Get the size of a file.array|false
getTimestamp($path)
Get the timestamp of a file.array|false
copy($path, $newpath)
Copy a file.bool
getMimetype($path)
Get the mimetype of a file.array|false
read($path)
Read a file.array|false
static forLink(SplFileInfo $file)
Create a new exception for a link.
static forFileInfo(SplFileInfo $fileInfo)
static detectByFilename($filename)
static dirname($path)
Get a normalized dirname from a path.
static guessMimeType($path, $content)
Guess MIME Type based on the path of the file and it's content.
const VISIBILITY_PUBLIC
@const VISIBILITY_PUBLIC public visibility
const VISIBILITY_PRIVATE
@const VISIBILITY_PRIVATE private visibility
deleteDir($dirname)
Delete a directory.
$stream
PHP stream implementation.