Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update comments in BaseFileHelper #18928

Merged
merged 1 commit into from
Oct 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions framework/helpers/BaseFileHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,12 @@ public static function normalizePath($path, $ds = DIRECTORY_SEPARATOR)
* "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.
* If the target and the source language codes are the same, the original file will be returned.
*
* @param string $file the original file
* @param string $language the target language that the file should be localized to.
* @param string|null $language the target language that the file should be localized to.
* If not set, the value of [[\yii\base\Application::language]] will be used.
* @param string $sourceLanguage the language that the original file is in.
* @param string|null $sourceLanguage 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.
Expand Down Expand Up @@ -141,7 +140,7 @@ public static function localize($file, $language = null, $sourceLanguage = null)
* [finfo_open](https://secure.php.net/manual/en/function.finfo-open.php). If the `fileinfo` extension is not installed,
* it will fall back to [[getMimeTypeByExtension()]] when `$checkExtension` is true.
* @param string $file the file name.
* @param string $magicFile name of the optional magic database file (or alias), usually something like `/path/to/magic.mime`.
* @param string|null $magicFile name of the optional magic database file (or alias), usually something like `/path/to/magic.mime`.
* This will be passed as the second parameter to [finfo_open()](https://secure.php.net/manual/en/function.finfo-open.php)
* when the `fileinfo` extension is installed. If the MIME type is being determined based via [[getMimeTypeByExtension()]]
* and this is null, it will use the file specified by [[mimeMagicFile]].
Expand Down Expand Up @@ -180,7 +179,7 @@ public static function getMimeType($file, $magicFile = null, $checkExtension = t
* 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.
* @param string $file the file name.
* @param string $magicFile the path (or alias) of the file that contains all available MIME type information.
* @param string|null $magicFile 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.
*/
Expand All @@ -202,7 +201,7 @@ public static function getMimeTypeByExtension($file, $magicFile = null)
* Determines the extensions by given MIME type.
* This method will use a local map between extension names and MIME types.
* @param string $mimeType file MIME type.
* @param string $magicFile the path (or alias) of the file that contains all available MIME type information.
* @param string|null $magicFile 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
*/
Expand Down Expand Up @@ -503,13 +502,14 @@ public static function findFiles($dir, $options = [])
* @param array $options options for directory searching. Valid options are:
*
* - `filter`: callback, a PHP callback that is called for each directory or file.
* The signature of the callback should be: `function ($path)`, where `$path` refers the full path to be filtered.
* The callback can return one of the following values:
* The signature of the callback should be: `function (string $path): bool`, where `$path` refers
* the full path to be filtered. The callback can return one of the following values:
*
* * `true`: the directory will be returned
* * `false`: the directory will NOT be returned
*
* - `recursive`: boolean, whether the files under the subdirectories should also be looked for. Defaults to `true`.
* See [[findFiles()]] for more options.
* @return array directories found under the directory, in no particular order. Ordering depends on the files system used.
* @throws InvalidArgumentException if the dir is invalid.
* @since 2.0.14
Expand Down Expand Up @@ -539,6 +539,8 @@ public static function findDirectories($dir, $options = [])

/**
* @param string $dir
* @param array $options
* @return array
*/
private static function setBasePath($dir, $options)
{
Expand All @@ -553,6 +555,8 @@ private static function setBasePath($dir, $options)

/**
* @param string $dir
* @return resource
* @throws InvalidArgumentException if unable to open directory
*/
private static function openDir($dir)
{
Expand All @@ -565,13 +569,15 @@ private static function openDir($dir)

/**
* @param string $dir
* @return string
* @throws InvalidArgumentException if directory not exists
*/
private static function clearDir($dir)
{
if (!is_dir($dir)) {
throw new InvalidArgumentException("The dir argument must be a directory: $dir");
}
return rtrim($dir, DIRECTORY_SEPARATOR);
return rtrim($dir, '\/');
}

/**
Expand Down