API / Minn\Runtime / FileNames

FileNames final class

Minn\Runtime\FileNames · public/minn/src/Minn/Runtime/FileNames.php · 119 lines

Files as WordPress's file functions name and remove them: a name made safe to store, a name no file in the folder has, a file's type from its content as much as its name, and a file deleted (only inside the folder it should be in).

Constants and properties

privateSPECIAL_CHARACTERS = array ( 0 => '?', 1 => '[', 2 => ']', 3 => '/', 4 => '\\', 5 => '=', 6 => '<', 7 => '>', 8 => ':', 9 => ';', 10 => ',', 11 => '\'', 12 => '"', 13 => '&', 14 => '$', 15 => '#', 16 => '*', 17 => '(', 18 => ')', 19 => '|', 20 => '~', 21 => '`', 22 => '!', 23 => '{', 24 => '}', 25 => '%', 26 => '+', 27 => '’', 28 => '«', 29 => '»', 30 => '”', 31 => '“', 32 => '' . "\0" . '', )

The characters a file name loses, handed to sanitize_file_name_chars in this order.

Public

staticsanitize(mixed $filename): mixed#

A file name safe to store (sanitize_file_name): accents transliterated, the special characters out, spaces and runs of dashes as one dash, no dots or dashes at the ends; an inner part that looks like an extension but is no type the site allows gets an underscore; a name that is only an extension becomes unnamed-file.{ext}; as sanitize_file_name leaves it.

staticneutralizeInnerExtensions(string $filename): string#

An inner part of a file name that looks like an extension (two to five letters, maybe a digit) and is no allowed type, given an underscore.

staticunique(mixed $dir, mixed $filename, mixed $callback = NULL): mixed#

A clean name no file in the folder has (wp_unique_filename): the name sanitized, its extension lowercased, a callback's name when one is given, else -1, -2... before the extension; as wp_unique_filename leaves it.

staticcheckUpload(mixed $file, mixed $filename, mixed $mimes = NULL): mixed#

A file's extension and type from its content as much as its name (wp_check_filetype_and_ext), with a corrected name when an image carried the wrong extension; as wp_check_filetype_and_ext leaves them.

staticdelete(mixed $file): bool#

A file deleted (wp_delete_file), as wp_delete_file names it; whether it went.

staticdeleteFromDirectory(mixed $file, mixed $directory): bool#

A file deleted only when it is inside the folder (wp_delete_file_from_directory); false when it is not, or not there.