master

laravel/framework

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

File.php

TLDR

This file is a part of the Illuminate\Support\Facades namespace and contains the definition of the File class. The File class is a facade for the Filesystem class and provides convenient methods for working with files.

Methods

exists

Checks if a file exists.

missing

Checks if a file is missing.

get

Reads the contents of a file.

json

Reads the JSON contents of a file and returns it as an array.

sharedGet

Reads the contents of a file that is shared between requests.

getRequire

Requires (executes) a file and returns its result.

requireOnce

Requires (executes) a file only once and returns its result.

lines

Returns an instance of the LazyCollection class that represents the lines of a file.

hash

Returns the hash value of a file using the specified algorithm (default: 'md5').

put

Writes data to a file.

replace

Replaces the contents of a file with the specified content.

replaceInFile

Replaces occurrences of search string(s) with the corresponding replace string(s) in a file.

prepend

Prepends data to the beginning of a file.

append

Appends data to the end of a file.

chmod

Changes the permissions of a file.

delete

Deletes one or more files.

move

Moves a file to a new location.

copy

Copies a file to a new location.

link

Creates a hard link from the target file to the link file.

relativeLink

Creates a symbolic link from the target file to the link file.

name

Returns the name (without extension) of a file.

basename

Returns the base name (file name with extension) of a file.

dirname

Returns the directory name of a file.

extension

Returns the extension of a file.

guessExtension

Returns the extension of a file based on the file's content.

type

Returns the file type (MIME type) of a file.

mimeType

Returns the MIME type of a file.

size

Returns the file size in bytes.

lastModified

Returns the last modified timestamp of a file.

isDirectory

Checks if a path is a directory.

isEmptyDirectory

Checks if a directory is empty.

isReadable

Checks if a file is readable.

isWritable

Checks if a file is writable.

hasSameHash

Checks if two files have the same hash.

isFile

Checks if a path is a file.

glob

Finds pathnames matching a specified pattern.

files

Returns an array of SplFileInfo objects representing the files in a directory.

allFiles

Returns an array of SplFileInfo objects representing all the files in a directory (including subdirectories).

directories

Returns an array of directories in a directory.

ensureDirectoryExists

Ensures that a directory exists by creating it if necessary.

makeDirectory

Creates a new directory.

moveDirectory

Moves a directory to a new location.

copyDirectory

Copies a directory to a new location.

deleteDirectory

Deletes a directory.

deleteDirectories

Deletes one or more directories.

cleanDirectory

Deletes all the files in a directory, but not the directory itself.

when

Conditionally executes a callback based on a value.

unless

Conditionally executes a callback based on a value.

macro

Adds a new macro method.

mixin

Adds a mixin to the File class.

hasMacro

Checks if a macro method exists.

flushMacros

Resets all registered macros.

Classes

<?php

namespace Illuminate\Support\Facades;

/**
 * @method static bool exists(string $path)
 * @method static bool missing(string $path)
 * @method static string get(string $path, bool $lock = false)
 * @method static array json(string $path, int $flags = 0, bool $lock = false)
 * @method static string sharedGet(string $path)
 * @method static mixed getRequire(string $path, array $data = [])
 * @method static mixed requireOnce(string $path, array $data = [])
 * @method static \Illuminate\Support\LazyCollection lines(string $path)
 * @method static string hash(string $path, string $algorithm = 'md5')
 * @method static int|bool put(string $path, string $contents, bool $lock = false)
 * @method static void replace(string $path, string $content, int|null $mode = null)
 * @method static void replaceInFile(array|string $search, array|string $replace, string $path)
 * @method static int prepend(string $path, string $data)
 * @method static int append(string $path, string $data, bool $lock = false)
 * @method static mixed chmod(string $path, int|null $mode = null)
 * @method static bool delete(string|array $paths)
 * @method static bool move(string $path, string $target)
 * @method static bool copy(string $path, string $target)
 * @method static void link(string $target, string $link)
 * @method static void relativeLink(string $target, string $link)
 * @method static string name(string $path)
 * @method static string basename(string $path)
 * @method static string dirname(string $path)
 * @method static string extension(string $path)
 * @method static string|null guessExtension(string $path)
 * @method static string type(string $path)
 * @method static string|false mimeType(string $path)
 * @method static int size(string $path)
 * @method static int lastModified(string $path)
 * @method static bool isDirectory(string $directory)
 * @method static bool isEmptyDirectory(string $directory, bool $ignoreDotFiles = false)
 * @method static bool isReadable(string $path)
 * @method static bool isWritable(string $path)
 * @method static bool hasSameHash(string $firstFile, string $secondFile)
 * @method static bool isFile(string $file)
 * @method static array glob(string $pattern, int $flags = 0)
 * @method static \Symfony\Component\Finder\SplFileInfo[] files(string $directory, bool $hidden = false)
 * @method static \Symfony\Component\Finder\SplFileInfo[] allFiles(string $directory, bool $hidden = false)
 * @method static array directories(string $directory)
 * @method static void ensureDirectoryExists(string $path, int $mode = 0755, bool $recursive = true)
 * @method static bool makeDirectory(string $path, int $mode = 0755, bool $recursive = false, bool $force = false)
 * @method static bool moveDirectory(string $from, string $to, bool $overwrite = false)
 * @method static bool copyDirectory(string $directory, string $destination, int|null $options = null)
 * @method static bool deleteDirectory(string $directory, bool $preserve = false)
 * @method static bool deleteDirectories(string $directory)
 * @method static bool cleanDirectory(string $directory)
 * @method static \Illuminate\Filesystem\Filesystem|mixed when(\Closure|mixed|null $value = null, callable|null $callback = null, callable|null $default = null)
 * @method static \Illuminate\Filesystem\Filesystem|mixed unless(\Closure|mixed|null $value = null, callable|null $callback = null, callable|null $default = null)
 * @method static void macro(string $name, object|callable $macro)
 * @method static void mixin(object $mixin, bool $replace = true)
 * @method static bool hasMacro(string $name)
 * @method static void flushMacros()
 *
 * @see \Illuminate\Filesystem\Filesystem
 */
class File extends Facade
{
    /**
     * Get the registered name of the component.
     *
     * @return string
     */
    protected static function getFacadeAccessor()
    {
        return 'files';
    }
}