Class yii\helpers\BaseFileHelper
Inheritance | yii\helpers\BaseFileHelper |
---|---|
Subclasses | yii\helpers\FileHelper |
Available since version | 2.0 |
Source Code | https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseFileHelper.php |
BaseFileHelper provides concrete implementation for yii\helpers\FileHelper.
Do not use BaseFileHelper. Use yii\helpers\FileHelper instead.
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$mimeAliasesFile | string | The path (or alias) of a PHP file containing MIME aliases. | yii\helpers\BaseFileHelper |
$mimeMagicFile | string | The path (or alias) of a PHP file containing MIME type information. | yii\helpers\BaseFileHelper |
Public Methods
Method | Description | Defined By |
---|---|---|
copyDirectory() | Copies a whole directory as another one. | yii\helpers\BaseFileHelper |
createDirectory() | Creates a new directory. | yii\helpers\BaseFileHelper |
filterPath() | Checks if the given file path satisfies the filtering options. | yii\helpers\BaseFileHelper |
findDirectories() | Returns the directories found under the specified directory and subdirectories. | yii\helpers\BaseFileHelper |
findFiles() | Returns the files found under the specified directory and subdirectories. | yii\helpers\BaseFileHelper |
getExtensionsByMimeType() | Determines the extensions by given MIME type. | yii\helpers\BaseFileHelper |
getMimeType() | Determines the MIME type of the specified file. | yii\helpers\BaseFileHelper |
getMimeTypeByExtension() | Determines the MIME type based on the extension name of the specified file. | yii\helpers\BaseFileHelper |
localize() | Returns the localized version of a specified file. | yii\helpers\BaseFileHelper |
normalizePath() | Normalizes a file/directory path. | yii\helpers\BaseFileHelper |
removeDirectory() | Removes a directory (and all its content) recursively. | yii\helpers\BaseFileHelper |
unlink() | Removes a file or symlink in a cross-platform way | yii\helpers\BaseFileHelper |
Protected Methods
Method | Description | Defined By |
---|---|---|
loadMimeAliases() | Loads MIME aliases from the specified file. | yii\helpers\BaseFileHelper |
loadMimeTypes() | Loads MIME types from the specified file. | yii\helpers\BaseFileHelper |
normalizeOptions() | yii\helpers\BaseFileHelper |
Constants
Constant | Value | Description | Defined By |
---|---|---|---|
PATTERN_CASE_INSENSITIVE | 32 | yii\helpers\BaseFileHelper | |
PATTERN_ENDSWITH | 4 | yii\helpers\BaseFileHelper | |
PATTERN_MUSTBEDIR | 8 | yii\helpers\BaseFileHelper | |
PATTERN_NEGATIVE | 16 | yii\helpers\BaseFileHelper | |
PATTERN_NODIR | 1 | yii\helpers\BaseFileHelper |
Property Details
The path (or alias) of a PHP file containing MIME aliases.
The path (or alias) of a PHP file containing MIME type information.
Method Details
Copies a whole directory as another one.
The files and sub-directories will also be copied over.
public static void copyDirectory ( $src, $dst, $options = [] ) | ||
$src | string | The source directory |
$dst | string | The destination directory |
$options | array | Options for directory copy. Valid options are:
|
throws | yii\base\InvalidArgumentException | if unable to open directory |
---|
Creates a new directory.
This method is similar to the PHP mkdir()
function except that
it uses chmod()
to set the permission of the created directory
in order to avoid the impact of the umask
setting.
public static boolean createDirectory ( $path, $mode = 0775, $recursive = true ) | ||
$path | string | Path of the directory to be created. |
$mode | integer | The permission to be set for the created directory. |
$recursive | boolean | Whether to create parent directories if they do not exist. |
return | boolean | Whether the directory is created successfully |
---|---|---|
throws | yii\base\Exception | if the directory could not be created (i.e. php error due to parallel changes) |
Checks if the given file path satisfies the filtering options.
public static boolean filterPath ( $path, $options ) | ||
$path | string | The path of the file or directory to be checked |
$options | array | The filtering options. See findFiles() for explanations of the supported options. |
return | boolean | Whether the file or directory satisfies the filtering options. |
---|
Returns the directories found under the specified directory and subdirectories.
public static array findDirectories ( $dir, $options = [] ) | ||
$dir | string | The directory under which the files will be looked for. |
$options | array | Options for directory searching. Valid options are:
|
return | array | Directories found under the directory, in no particular order. Ordering depends on the files system used. |
---|---|---|
throws | yii\base\InvalidArgumentException | if the dir is invalid. |
Returns the files found under the specified directory and subdirectories.
public static array findFiles ( $dir, $options = [] ) | ||
$dir | string | The directory under which the files will be looked for. |
$options | array | Options for file searching. Valid options are:
|
return | array | Files found under the directory, in no particular order. Ordering depends on the files system used. |
---|---|---|
throws | yii\base\InvalidArgumentException | if the dir is invalid. |
Determines the extensions by given MIME type.
This method will use a local map between extension names and MIME types.
public static array getExtensionsByMimeType ( $mimeType, $magicFile = null ) | ||
$mimeType | string | File MIME type. |
$magicFile | string | The path (or alias) of the file that contains all available MIME type information. If this is not set, the file specified by $mimeMagicFile will be used. |
return | array | The extensions corresponding to the specified MIME type |
---|
Determines the MIME type of the specified file.
This method will first try to determine the MIME type based on
finfo_open. If the fileinfo
extension is not installed,
it will fall back to getMimeTypeByExtension() when $checkExtension
is true.
public static string|null getMimeType ( $file, $magicFile = null, $checkExtension = true ) | ||
$file | string | The file name. |
$magicFile | string | Name of the optional magic database file (or alias), usually something like |
$checkExtension | boolean | Whether to use the file extension to determine the MIME type in case
|
return | string|null | The MIME type (e.g. |
---|---|---|
throws | yii\base\InvalidConfigException | when the |
Determines the MIME type based on the extension name of the specified file.
This method will use a local map between extension names and MIME types.
public static string|null getMimeTypeByExtension ( $file, $magicFile = null ) | ||
$file | string | The file name. |
$magicFile | string | The path (or alias) of the file that contains all available MIME type information. If this is not set, the file specified by $mimeMagicFile will be used. |
return | string|null | The MIME type. Null is returned if the MIME type cannot be determined. |
---|
Loads MIME aliases from the specified file.
protected static array loadMimeAliases ( $aliasesFile ) | ||
$aliasesFile | string | The path (or alias) of the file that contains MIME type aliases. If this is not set, the file specified by $mimeAliasesFile will be used. |
return | array | The mapping from file extensions to MIME types |
---|
Loads MIME types from the specified file.
protected static array loadMimeTypes ( $magicFile ) | ||
$magicFile | string | The path (or alias) of the file that contains all available MIME type information. If this is not set, the file specified by $mimeMagicFile will be used. |
return | array | The mapping from file extensions to MIME types |
---|
Returns the localized version of a specified file.
The searching is based on the specified language code. In particular, a file with the same name will be looked for under the subdirectory whose name is the same as the language code. For example, given the file "path/to/view.php" and language code "zh-CN", the localized file will be looked for as "path/to/zh-CN/view.php". If the file is not found, it will try a fallback with just a language code that is "zh" i.e. "path/to/zh/view.php". If it is not found as well the original file will be returned.
If the target and the source language codes are the same, the original file will be returned.
public static string localize ( $file, $language = null, $sourceLanguage = null ) | ||
$file | string | The original file |
$language | string | The target language that the file should be localized to. If not set, the value of yii\base\Application::$language will be used. |
$sourceLanguage | string | The language that the original file is in. If not set, the value of yii\base\Application::$sourceLanguage will be used. |
return | string | The matching localized file, or the original file if the localized version is not found. If the target and the source language codes are the same, the original file will be returned. |
---|
protected static array normalizeOptions ( array $options ) | ||
$options | array | Raw options |
return | array | Normalized options |
---|
Normalizes a file/directory path.
The normalization does the following work:
- Convert all directory separators into
DIRECTORY_SEPARATOR
(e.g. "\a/b\c" becomes "/a/b/c") - Remove trailing directory separators (e.g. "/a/b/c/" becomes "/a/b/c")
- Turn multiple consecutive slashes into a single one (e.g. "/a///b/c" becomes "/a/b/c")
- Remove ".." and "." based on their meanings (e.g. "/a/./b/../c" becomes "/a/c")
Note: For registered stream wrappers, the consecutive slashes rule and ".."/"." translations are skipped.
public static string normalizePath ( $path, $ds = DIRECTORY_SEPARATOR ) | ||
$path | string | The file/directory path to be normalized |
$ds | string | The directory separator to be used in the normalized result. Defaults to |
return | string | The normalized file/directory path |
---|
Removes a directory (and all its content) recursively.
public static void removeDirectory ( $dir, $options = [] ) | ||
$dir | string | The directory to be deleted recursively. |
$options | array | Options for directory remove. Valid options are:
|
throws | yii\base\ErrorException | in case of failure |
---|
Removes a file or symlink in a cross-platform way
public static boolean unlink ( $path ) | ||
$path | string |