diff --git a/extensions/gii/generators/crud/templates/views/view.php b/extensions/gii/generators/crud/templates/views/view.php
index 7087d48..9e74aff 100644
--- a/extensions/gii/generators/crud/templates/views/view.php
+++ b/extensions/gii/generators/crud/templates/views/view.php
@@ -1,7 +1,7 @@
title = $model->= $generator->getNameAttribute() ?>;
-$this->params['breadcrumbs'][] = ['label' => '= Inflector::pluralize(Inflector::camel2words(FileHelper::basename($generator->modelClass))) ?>', 'url' => ['index']];
+$this->params['breadcrumbs'][] = ['label' => '= Inflector::pluralize(Inflector::camel2words(StringHelper::basename($generator->modelClass))) ?>', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
-
+
= "= " ?>Html::encode($this->title) ?>
diff --git a/extensions/gii/generators/module/Generator.php b/extensions/gii/generators/module/Generator.php
index 2209ace..a97aa20 100644
--- a/extensions/gii/generators/module/Generator.php
+++ b/extensions/gii/generators/module/Generator.php
@@ -7,10 +7,10 @@
namespace yii\gii\generators\module;
-use Yii;
use yii\gii\CodeFile;
use yii\helpers\Html;
-use yii\helpers\FileHelper;
+use Yii;
+use yii\helpers\StringHelper;
/**
* This generator will generate the skeleton code needed by a module.
@@ -119,7 +119,7 @@ EOD;
$files = [];
$modulePath = $this->getModulePath();
$files[] = new CodeFile(
- $modulePath . '/' . FileHelper::basename($this->moduleClass) . '.php',
+ $modulePath . '/' . StringHelper::basename($this->moduleClass) . '.php',
$this->render("module.php")
);
$files[] = new CodeFile(
diff --git a/extensions/redis/ActiveRecord.php b/extensions/redis/ActiveRecord.php
index 9de9f6c..a308a32 100644
--- a/extensions/redis/ActiveRecord.php
+++ b/extensions/redis/ActiveRecord.php
@@ -9,7 +9,6 @@ namespace yii\redis;
use yii\base\InvalidConfigException;
use yii\db\BaseActiveRecord;
-use yii\helpers\FileHelper;
use yii\helpers\Inflector;
use yii\helpers\StringHelper;
@@ -97,7 +96,7 @@ class ActiveRecord extends BaseActiveRecord
*/
public static function keyPrefix()
{
- return Inflector::camel2id(FileHelper::basename(get_called_class()), '_');
+ return Inflector::camel2id(StringHelper::basename(get_called_class()), '_');
}
/**
@@ -288,7 +287,7 @@ class ActiveRecord extends BaseActiveRecord
if (is_numeric($key)) {
return $key;
} elseif (is_string($key)) {
- return ctype_alnum($key) && StringHelper::byteLen($key) <= 32 ? $key : md5($key);
+ return ctype_alnum($key) && StringHelper::byteLength($key) <= 32 ? $key : md5($key);
} elseif (is_array($key)) {
if (count($key) == 1) {
return self::buildKey(reset($key));
diff --git a/extensions/sphinx/ActiveRecord.php b/extensions/sphinx/ActiveRecord.php
index 9831cbd..e7bda34 100644
--- a/extensions/sphinx/ActiveRecord.php
+++ b/extensions/sphinx/ActiveRecord.php
@@ -8,13 +8,13 @@
namespace yii\sphinx;
use yii\base\InvalidConfigException;
-use yii\db\BaseActiveRecord;
use yii\base\NotSupportedException;
use yii\db\ActiveRelationInterface;
+use yii\db\BaseActiveRecord;
use yii\db\StaleObjectException;
-use yii\helpers\FileHelper;
use yii\helpers\Inflector;
use Yii;
+use yii\helpers\StringHelper;
/**
* ActiveRecord is the base class for classes representing relational data in terms of objects.
@@ -166,7 +166,7 @@ abstract class ActiveRecord extends BaseActiveRecord
*/
public static function indexName()
{
- return Inflector::camel2id(FileHelper::basename(get_called_class()), '_');
+ return Inflector::camel2id(StringHelper::basename(get_called_class()), '_');
}
/**
diff --git a/framework/yii/caching/Cache.php b/framework/yii/caching/Cache.php
index ee471b3..31d1e2d 100644
--- a/framework/yii/caching/Cache.php
+++ b/framework/yii/caching/Cache.php
@@ -100,7 +100,7 @@ abstract class Cache extends Component implements \ArrayAccess
protected function buildKey($key)
{
if (is_string($key)) {
- $key = ctype_alnum($key) && StringHelper::byteLen($key) <= 32 ? $key : md5($key);
+ $key = ctype_alnum($key) && StringHelper::byteLength($key) <= 32 ? $key : md5($key);
} else {
$key = md5(json_encode($key));
}
diff --git a/framework/yii/db/ActiveRecord.php b/framework/yii/db/ActiveRecord.php
index ada79b6..7f7e6f3 100644
--- a/framework/yii/db/ActiveRecord.php
+++ b/framework/yii/db/ActiveRecord.php
@@ -9,8 +9,8 @@
namespace yii\db;
use yii\base\InvalidConfigException;
-use yii\helpers\FileHelper;
use yii\helpers\Inflector;
+use yii\helpers\StringHelper;
/**
* ActiveRecord is the base class for classes representing relational data in terms of objects.
@@ -169,7 +169,7 @@ class ActiveRecord extends BaseActiveRecord
*/
public static function tableName()
{
- return 'tbl_' . Inflector::camel2id(FileHelper::basename(get_called_class()), '_');
+ return 'tbl_' . Inflector::camel2id(StringHelper::basename(get_called_class()), '_');
}
/**
diff --git a/framework/yii/helpers/BaseFileHelper.php b/framework/yii/helpers/BaseFileHelper.php
index 7994773..90d6117 100644
--- a/framework/yii/helpers/BaseFileHelper.php
+++ b/framework/yii/helpers/BaseFileHelper.php
@@ -292,11 +292,11 @@ class BaseFileHelper
if ($isDir = is_dir($path)) {
$path .= '/';
}
- $n = StringHelper::byteLen($path);
+ $n = StringHelper::byteLength($path);
if (!empty($options['except'])) {
foreach ($options['except'] as $name) {
- if (StringHelper::byteSubstr($path, -StringHelper::byteLen($name), $n) === $name) {
+ if (StringHelper::byteSubstr($path, -StringHelper::byteLength($name), $n) === $name) {
return false;
}
}
@@ -304,7 +304,7 @@ class BaseFileHelper
if (!$isDir && !empty($options['only'])) {
foreach ($options['only'] as $name) {
- if (StringHelper::byteSubstr($path, -StringHelper::byteLen($name), $n) === $name) {
+ if (StringHelper::byteSubstr($path, -StringHelper::byteLength($name), $n) === $name) {
return true;
}
}
@@ -338,48 +338,4 @@ class BaseFileHelper
chmod($path, $mode);
return $result;
}
-
- /**
- * Returns the trailing name component of a path.
- * 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 "..".
- *
- * @param string $path A path string.
- * @param string $suffix If the name component ends in suffix this will also be cut off.
- * @return string the trailing name component of the given path.
- * @see http://www.php.net/manual/en/function.basename.php
- */
- public static function basename($path, $suffix = '')
- {
- if (($len = mb_strlen($suffix)) > 0 && mb_substr($path, -$len) == $suffix) {
- $path = mb_substr($path, 0, -$len);
- }
- $path = rtrim(str_replace('\\', '/', $path), '/\\');
- if (($pos = mb_strrpos($path, '/')) !== false) {
- return mb_substr($path, $pos + 1);
- }
- return $path;
- }
-
- /**
- * 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;
- }
- }
}
diff --git a/framework/yii/helpers/BaseSecurity.php b/framework/yii/helpers/BaseSecurity.php
index 6abdd04..a49dd78 100644
--- a/framework/yii/helpers/BaseSecurity.php
+++ b/framework/yii/helpers/BaseSecurity.php
@@ -83,7 +83,7 @@ class BaseSecurity
$iv = StringHelper::byteSubstr($data, 0, $ivSize);
$key = static::deriveKey($password, $iv);
mcrypt_generic_init($module, $key, $iv);
- $decrypted = mdecrypt_generic($module, StringHelper::byteSubstr($data, $ivSize, StringHelper::byteLen($data)));
+ $decrypted = mdecrypt_generic($module, StringHelper::byteSubstr($data, $ivSize, StringHelper::byteLength($data)));
mcrypt_generic_deinit($module);
mcrypt_module_close($module);
return static::stripPadding($decrypted);
@@ -96,7 +96,7 @@ class BaseSecurity
*/
protected static function addPadding($data)
{
- $pad = self::CRYPT_BLOCK_SIZE - (StringHelper::byteLen($data) % self::CRYPT_BLOCK_SIZE);
+ $pad = self::CRYPT_BLOCK_SIZE - (StringHelper::byteLength($data) % self::CRYPT_BLOCK_SIZE);
return $data . str_repeat(chr($pad), $pad);
}
@@ -109,7 +109,7 @@ class BaseSecurity
{
$end = StringHelper::byteSubstr($data, -1, NULL);
$last = ord($end);
- $n = StringHelper::byteLen($data) - $last;
+ $n = StringHelper::byteLength($data) - $last;
if (StringHelper::byteSubstr($data, $n, NULL) == str_repeat($end, $last)) {
return StringHelper::byteSubstr($data, 0, $n);
}
@@ -164,8 +164,8 @@ class BaseSecurity
*/
public static function validateData($data, $key, $algorithm = 'sha256')
{
- $hashSize = StringHelper::byteLen(hash_hmac($algorithm, 'test', $key));
- $n = StringHelper::byteLen($data);
+ $hashSize = StringHelper::byteLength(hash_hmac($algorithm, 'test', $key));
+ $n = StringHelper::byteLength($data);
if ($n >= $hashSize) {
$hash = StringHelper::byteSubstr($data, 0, $hashSize);
$data2 = StringHelper::byteSubstr($data, $hashSize, $n - $hashSize);
diff --git a/framework/yii/helpers/BaseStringHelper.php b/framework/yii/helpers/BaseStringHelper.php
index 8f6c002..8db4f98 100644
--- a/framework/yii/helpers/BaseStringHelper.php
+++ b/framework/yii/helpers/BaseStringHelper.php
@@ -26,7 +26,7 @@ class BaseStringHelper
* @param string $string the string being measured for length
* @return integer the number of bytes in the given string.
*/
- public static function byteLen($string)
+ public static function byteLength($string)
{
return mb_strlen($string, '8bit');
}
@@ -94,4 +94,48 @@ class BaseStringHelper
$diff = new \Diff($lines1, $lines2);
return $diff->render($renderer);
}
+
+ /**
+ * Returns the trailing name component of a path.
+ * 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 "..".
+ *
+ * @param string $path A path string.
+ * @param string $suffix If the name component ends in suffix this will also be cut off.
+ * @return string the trailing name component of the given path.
+ * @see http://www.php.net/manual/en/function.basename.php
+ */
+ public static function basename($path, $suffix = '')
+ {
+ if (($len = mb_strlen($suffix)) > 0 && mb_substr($path, -$len) == $suffix) {
+ $path = mb_substr($path, 0, -$len);
+ }
+ $path = rtrim(str_replace('\\', '/', $path), '/\\');
+ if (($pos = mb_strrpos($path, '/')) !== false) {
+ return mb_substr($path, $pos + 1);
+ }
+ return $path;
+ }
+
+ /**
+ * 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;
+ }
+ }
}
diff --git a/framework/yii/web/Response.php b/framework/yii/web/Response.php
index 9fe8ed4..1c0fb18 100644
--- a/framework/yii/web/Response.php
+++ b/framework/yii/web/Response.php
@@ -382,7 +382,7 @@ class Response extends \yii\base\Response
public function sendContentAsFile($content, $attachmentName, $mimeType = 'application/octet-stream')
{
$headers = $this->getHeaders();
- $contentLength = StringHelper::byteLen($content);
+ $contentLength = StringHelper::byteLength($content);
$range = $this->getHttpRange($contentLength);
if ($range === false) {
$headers->set('Content-Range', "bytes */$contentLength");
@@ -395,7 +395,7 @@ class Response extends \yii\base\Response
->setDefault('Content-Type', $mimeType)
->setDefault('Cache-Control', 'must-revalidate, post-check=0, pre-check=0')
->setDefault('Content-Transfer-Encoding', 'binary')
- ->setDefault('Content-Length', StringHelper::byteLen($content))
+ ->setDefault('Content-Length', StringHelper::byteLength($content))
->setDefault('Content-Disposition', "attachment; filename=\"$attachmentName\"");
list($begin, $end) = $range;
diff --git a/framework/yii/web/XmlResponseFormatter.php b/framework/yii/web/XmlResponseFormatter.php
index c072ee6..292424a 100644
--- a/framework/yii/web/XmlResponseFormatter.php
+++ b/framework/yii/web/XmlResponseFormatter.php
@@ -12,7 +12,7 @@ use DOMElement;
use DOMText;
use yii\base\Arrayable;
use yii\base\Component;
-use yii\helpers\FileHelper;
+use yii\helpers\StringHelper;
/**
* XmlResponseFormatter formats the given data into an XML response content.
@@ -66,7 +66,7 @@ class XmlResponseFormatter extends Component implements ResponseFormatterInterfa
protected function buildXml($element, $data)
{
if (is_object($data)) {
- $child = new DOMElement(FileHelper::basename(get_class($data)));
+ $child = new DOMElement(StringHelper::basename(get_class($data)));
$element->appendChild($child);
if ($data instanceof Arrayable) {
$this->buildXml($child, $data->toArray());
diff --git a/tests/unit/framework/helpers/StringHelperTest.php b/tests/unit/framework/helpers/StringHelperTest.php
index 125386d..a641001 100644
--- a/tests/unit/framework/helpers/StringHelperTest.php
+++ b/tests/unit/framework/helpers/StringHelperTest.php
@@ -1,7 +1,6 @@
assertEquals(4, StringHelper::byteLen('this'));
- $this->assertEquals(6, StringHelper::byteLen('это'));
+ $this->assertEquals(4, StringHelper::byteLength('this'));
+ $this->assertEquals(6, StringHelper::byteLength('это'));
}
public function testSubstr()
@@ -25,45 +24,45 @@ class StringHelperTest extends TestCase
public function testBasename()
{
- $this->assertEquals('', FileHelper::basename(''));
+ $this->assertEquals('', StringHelper::basename(''));
- $this->assertEquals('file', FileHelper::basename('file'));
- $this->assertEquals('file.test', FileHelper::basename('file.test', '.test2'));
- $this->assertEquals('file', FileHelper::basename('file.test', '.test'));
+ $this->assertEquals('file', StringHelper::basename('file'));
+ $this->assertEquals('file.test', StringHelper::basename('file.test', '.test2'));
+ $this->assertEquals('file', StringHelper::basename('file.test', '.test'));
- $this->assertEquals('file', FileHelper::basename('/file'));
- $this->assertEquals('file.test', FileHelper::basename('/file.test', '.test2'));
- $this->assertEquals('file', FileHelper::basename('/file.test', '.test'));
+ $this->assertEquals('file', StringHelper::basename('/file'));
+ $this->assertEquals('file.test', StringHelper::basename('/file.test', '.test2'));
+ $this->assertEquals('file', StringHelper::basename('/file.test', '.test'));
- $this->assertEquals('file', FileHelper::basename('/path/to/file'));
- $this->assertEquals('file.test', FileHelper::basename('/path/to/file.test', '.test2'));
- $this->assertEquals('file', FileHelper::basename('/path/to/file.test', '.test'));
+ $this->assertEquals('file', StringHelper::basename('/path/to/file'));
+ $this->assertEquals('file.test', StringHelper::basename('/path/to/file.test', '.test2'));
+ $this->assertEquals('file', StringHelper::basename('/path/to/file.test', '.test'));
- $this->assertEquals('file', FileHelper::basename('\file'));
- $this->assertEquals('file.test', FileHelper::basename('\file.test', '.test2'));
- $this->assertEquals('file', FileHelper::basename('\file.test', '.test'));
+ $this->assertEquals('file', StringHelper::basename('\file'));
+ $this->assertEquals('file.test', StringHelper::basename('\file.test', '.test2'));
+ $this->assertEquals('file', StringHelper::basename('\file.test', '.test'));
- $this->assertEquals('file', FileHelper::basename('C:\file'));
- $this->assertEquals('file.test', FileHelper::basename('C:\file.test', '.test2'));
- $this->assertEquals('file', FileHelper::basename('C:\file.test', '.test'));
+ $this->assertEquals('file', StringHelper::basename('C:\file'));
+ $this->assertEquals('file.test', StringHelper::basename('C:\file.test', '.test2'));
+ $this->assertEquals('file', StringHelper::basename('C:\file.test', '.test'));
- $this->assertEquals('file', FileHelper::basename('C:\path\to\file'));
- $this->assertEquals('file.test', FileHelper::basename('C:\path\to\file.test', '.test2'));
- $this->assertEquals('file', FileHelper::basename('C:\path\to\file.test', '.test'));
+ $this->assertEquals('file', StringHelper::basename('C:\path\to\file'));
+ $this->assertEquals('file.test', StringHelper::basename('C:\path\to\file.test', '.test2'));
+ $this->assertEquals('file', StringHelper::basename('C:\path\to\file.test', '.test'));
// mixed paths
- $this->assertEquals('file.test', FileHelper::basename('/path\to/file.test'));
- $this->assertEquals('file.test', FileHelper::basename('/path/to\file.test'));
- $this->assertEquals('file.test', FileHelper::basename('\path/to\file.test'));
+ $this->assertEquals('file.test', StringHelper::basename('/path\to/file.test'));
+ $this->assertEquals('file.test', StringHelper::basename('/path/to\file.test'));
+ $this->assertEquals('file.test', StringHelper::basename('\path/to\file.test'));
// \ and / in suffix
- $this->assertEquals('file', FileHelper::basename('/path/to/filete/st', 'te/st'));
- $this->assertEquals('st', FileHelper::basename('/path/to/filete/st', 'te\st'));
- $this->assertEquals('file', FileHelper::basename('/path/to/filete\st', 'te\st'));
- $this->assertEquals('st', FileHelper::basename('/path/to/filete\st', 'te/st'));
+ $this->assertEquals('file', StringHelper::basename('/path/to/filete/st', 'te/st'));
+ $this->assertEquals('st', StringHelper::basename('/path/to/filete/st', 'te\st'));
+ $this->assertEquals('file', StringHelper::basename('/path/to/filete\st', 'te\st'));
+ $this->assertEquals('st', StringHelper::basename('/path/to/filete\st', 'te/st'));
// http://www.php.net/manual/en/function.basename.php#72254
- $this->assertEquals('foo', FileHelper::basename('/bar/foo/'));
- $this->assertEquals('foo', FileHelper::basename('\\bar\\foo\\'));
+ $this->assertEquals('foo', StringHelper::basename('/bar/foo/'));
+ $this->assertEquals('foo', StringHelper::basename('\\bar\\foo\\'));
}
}
diff --git a/tests/unit/framework/web/ResponseTest.php b/tests/unit/framework/web/ResponseTest.php
index 69fb60d..7883d86 100644
--- a/tests/unit/framework/web/ResponseTest.php
+++ b/tests/unit/framework/web/ResponseTest.php
@@ -57,7 +57,7 @@ class ResponseTest extends \yiiunit\TestCase
$this->assertEquals(206, $this->response->statusCode);
$headers = $this->response->headers;
$this->assertEquals("bytes", $headers->get('Accept-Ranges'));
- $this->assertEquals("bytes " . $expectedHeader . '/' . StringHelper::byteLen($fullContent), $headers->get('Content-Range'));
+ $this->assertEquals("bytes " . $expectedHeader . '/' . StringHelper::byteLength($fullContent), $headers->get('Content-Range'));
$this->assertEquals('text/plain', $headers->get('Content-Type'));
$this->assertEquals("$length", $headers->get('Content-Length'));
}