master

laravel/framework

Last updated at: 29/12/2023 09:21

Filesystem.php

TLDR

The Filesystem interface defines a set of methods for handling files, directories, and file operations in the Illuminate framework. It includes methods for creating, deleting, moving, copying, and reading files, as well as retrieving file sizes and modification times.

Methods

exists($path)

Determines if a file exists at the specified path.

get($path)

Retrieves the contents of a file at the specified path.

readStream($path)

Retrieves a resource to read the specified file.

put($path, $contents, $options = [])

Writes the contents to a file at the specified path. The $contents parameter can accept various types, including strings, resources, and objects implementing the StreamInterface interface.

writeStream($path, $resource, array $options = [])

Writes a new file using a stream. The stream is provided as a resource, and additional options can be specified.

getVisibility($path)

Retrieves the visibility (permission) settings for the specified path.

setVisibility($path, $visibility)

Sets the visibility (permission) for the specified path.

prepend($path, $data)

Prepends the specified data to a file at the specified path.

append($path, $data)

Appends the specified data to a file at the specified path.

delete($paths)

Deletes the file(s) specified by the $paths parameter. Multiple files can be deleted by providing an array of paths.

copy($from, $to)

Copies a file from the source path $from to the destination path $to.

move($from, $to)

Moves a file from the source path $from to the destination path $to.

size($path)

Retrieves the file size of the file at the specified path.

lastModified($path)

Retrieves the last modification time of the file at the specified path.

files($directory = null, $recursive = false)

Retrieves an array of all the files in the specified directory. If no directory is provided, it retrieves files from the root directory. The $recursive parameter indicates whether to include files from subdirectories.

allFiles($directory = null)

Retrieves all the files (including subdirectories) in the specified directory.

directories($directory = null, $recursive = false)

Retrieves an array of all the directories in the specified directory. If no directory is provided, it retrieves directories from the root directory. The $recursive parameter indicates whether to include directories from subdirectories.

allDirectories($directory = null)

Retrieves all the directories (including subdirectories) in the specified directory.

makeDirectory($path)

Creates a new directory at the specified path.

deleteDirectory($directory)

Recursively deletes the directory at the specified path.

<?php

namespace Illuminate\Contracts\Filesystem;

interface Filesystem
{
    /**
     * The public visibility setting.
     *
     * @var string
     */
    const VISIBILITY_PUBLIC = 'public';

    /**
     * The private visibility setting.
     *
     * @var string
     */
    const VISIBILITY_PRIVATE = 'private';

    /**
     * Determine if a file exists.
     *
     * @param  string  $path
     * @return bool
     */
    public function exists($path);

    /**
     * Get the contents of a file.
     *
     * @param  string  $path
     * @return string|null
     */
    public function get($path);

    /**
     * Get a resource to read the file.
     *
     * @param  string  $path
     * @return resource|null The path resource or null on failure.
     */
    public function readStream($path);

    /**
     * Write the contents of a file.
     *
     * @param  string  $path
     * @param  \Psr\Http\Message\StreamInterface|\Illuminate\Http\File|\Illuminate\Http\UploadedFile|string|resource  $contents
     * @param  mixed  $options
     * @return bool
     */
    public function put($path, $contents, $options = []);

    /**
     * Write a new file using a stream.
     *
     * @param  string  $path
     * @param  resource  $resource
     * @param  array  $options
     * @return bool
     */
    public function writeStream($path, $resource, array $options = []);

    /**
     * Get the visibility for the given path.
     *
     * @param  string  $path
     * @return string
     */
    public function getVisibility($path);

    /**
     * Set the visibility for the given path.
     *
     * @param  string  $path
     * @param  string  $visibility
     * @return bool
     */
    public function setVisibility($path, $visibility);

    /**
     * Prepend to a file.
     *
     * @param  string  $path
     * @param  string  $data
     * @return bool
     */
    public function prepend($path, $data);

    /**
     * Append to a file.
     *
     * @param  string  $path
     * @param  string  $data
     * @return bool
     */
    public function append($path, $data);

    /**
     * Delete the file at a given path.
     *
     * @param  string|array  $paths
     * @return bool
     */
    public function delete($paths);

    /**
     * Copy a file to a new location.
     *
     * @param  string  $from
     * @param  string  $to
     * @return bool
     */
    public function copy($from, $to);

    /**
     * Move a file to a new location.
     *
     * @param  string  $from
     * @param  string  $to
     * @return bool
     */
    public function move($from, $to);

    /**
     * Get the file size of a given file.
     *
     * @param  string  $path
     * @return int
     */
    public function size($path);

    /**
     * Get the file's last modification time.
     *
     * @param  string  $path
     * @return int
     */
    public function lastModified($path);

    /**
     * Get an array of all files in a directory.
     *
     * @param  string|null  $directory
     * @param  bool  $recursive
     * @return array
     */
    public function files($directory = null, $recursive = false);

    /**
     * Get all of the files from the given directory (recursive).
     *
     * @param  string|null  $directory
     * @return array
     */
    public function allFiles($directory = null);

    /**
     * Get all of the directories within a given directory.
     *
     * @param  string|null  $directory
     * @param  bool  $recursive
     * @return array
     */
    public function directories($directory = null, $recursive = false);

    /**
     * Get all (recursive) of the directories within a given directory.
     *
     * @param  string|null  $directory
     * @return array
     */
    public function allDirectories($directory = null);

    /**
     * Create a directory.
     *
     * @param  string  $path
     * @return bool
     */
    public function makeDirectory($path);

    /**
     * Recursively delete a directory.
     *
     * @param  string  $directory
     * @return bool
     */
    public function deleteDirectory($directory);
}