diff --git a/framework/yii/helpers/StringHelperBase.php b/framework/yii/helpers/StringHelperBase.php index 54dabda..cbb696e 100644 --- a/framework/yii/helpers/StringHelperBase.php +++ b/framework/yii/helpers/StringHelperBase.php @@ -47,8 +47,8 @@ class StringHelperBase /** * Returns the trailing name component of a path. - * This method does the same as the php function `basename()` except that it will - * always use \ and / as directory separators, independent of the operating system. + * This method is similar to the php function `basename()` except that it will + * treat both \ and / as directory separators, independent of the operating system. * This method was mainly created to work on php namespaces. When working with real * file paths, php's `basename()` should work fine for you. * Note: this method is not aware of the actual filesystem, or path components such as "..". @@ -70,6 +70,24 @@ class StringHelperBase } /** + * Returns parent directory's path. + * This method is similar to `dirname()` except that it will treat + * both \ and / as directory separators, independent of the operating system. + * @param string $path A path string. + * @return string the parent directory's path. + * @see http://www.php.net/manual/en/function.basename.php + */ + public static function dirname($path) + { + $pos = mb_strrpos(str_replace('\\', '/', $path), '/'); + if ($pos !== false) { + return mb_substr($path, 0, $pos); + } else { + return $path; + } + } + + /** * Compares two strings or string arrays, and return their differences. * This is a wrapper of the [phpspec/php-diff](https://packagist.org/packages/phpspec/php-diff) package. * @param string|array $lines1 the first string or string array to be compared. If it is a string,