Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
4df9b6cb
Commit
4df9b6cb
authored
Dec 04, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1416 from yiisoft/helpers-renames
Helpers refactoring
parents
9bd89ef7
51592f17
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
32 additions
and
38 deletions
+32
-38
ActiveRecord.php
extensions/elasticsearch/ActiveRecord.php
+0
-2
Generator.php
extensions/gii/generators/module/Generator.php
+1
-1
ActiveRecord.php
extensions/redis/ActiveRecord.php
+1
-2
ActiveRecord.php
extensions/sphinx/ActiveRecord.php
+2
-2
Cache.php
framework/yii/caching/Cache.php
+1
-1
ActiveRecord.php
framework/yii/db/ActiveRecord.php
+1
-6
BaseFileHelper.php
framework/yii/helpers/BaseFileHelper.php
+3
-3
BaseSecurity.php
framework/yii/helpers/BaseSecurity.php
+11
-11
BaseStringHelper.php
framework/yii/helpers/BaseStringHelper.php
+4
-2
Response.php
framework/yii/web/Response.php
+3
-3
StringHelperTest.php
tests/unit/framework/helpers/StringHelperTest.php
+4
-4
ResponseTest.php
tests/unit/framework/web/ResponseTest.php
+1
-1
No files found.
extensions/elasticsearch/ActiveRecord.php
View file @
4df9b6cb
...
...
@@ -9,8 +9,6 @@ namespace yii\elasticsearch;
use
yii\base\InvalidCallException
;
use
yii\base\InvalidConfigException
;
use
yii\base\NotSupportedException
;
use
yii\db\ActiveRecordInterface
;
use
yii\db\BaseActiveRecord
;
use
yii\helpers\Inflector
;
use
yii\helpers\Json
;
...
...
extensions/gii/generators/module/Generator.php
View file @
4df9b6cb
...
...
@@ -7,9 +7,9 @@
namespace
yii\gii\generators\module
;
use
Yii
;
use
yii\gii\CodeFile
;
use
yii\helpers\Html
;
use
Yii
;
use
yii\helpers\StringHelper
;
/**
...
...
extensions/redis/ActiveRecord.php
View file @
4df9b6cb
...
...
@@ -8,7 +8,6 @@
namespace
yii\redis
;
use
yii\base\InvalidConfigException
;
use
yii\base\NotSupportedException
;
use
yii\db\BaseActiveRecord
;
use
yii\helpers\Inflector
;
use
yii\helpers\StringHelper
;
...
...
@@ -288,7 +287,7 @@ class ActiveRecord extends BaseActiveRecord
if
(
is_numeric
(
$key
))
{
return
$key
;
}
elseif
(
is_string
(
$key
))
{
return
ctype_alnum
(
$key
)
&&
StringHelper
::
strlen
(
$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
));
...
...
extensions/sphinx/ActiveRecord.php
View file @
4df9b6cb
...
...
@@ -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\Inflector
;
use
yii\helpers\StringHelper
;
use
Yii
;
use
yii\helpers\StringHelper
;
/**
* ActiveRecord is the base class for classes representing relational data in terms of objects.
...
...
framework/yii/caching/Cache.php
View file @
4df9b6cb
...
...
@@ -100,7 +100,7 @@ abstract class Cache extends Component implements \ArrayAccess
protected
function
buildKey
(
$key
)
{
if
(
is_string
(
$key
))
{
$key
=
ctype_alnum
(
$key
)
&&
StringHelper
::
strlen
(
$key
)
<=
32
?
$key
:
md5
(
$key
);
$key
=
ctype_alnum
(
$key
)
&&
StringHelper
::
byteLength
(
$key
)
<=
32
?
$key
:
md5
(
$key
);
}
else
{
$key
=
md5
(
json_encode
(
$key
));
}
...
...
framework/yii/db/ActiveRecord.php
View file @
4df9b6cb
...
...
@@ -9,13 +9,8 @@
namespace
yii\db
;
use
yii\base\InvalidConfigException
;
use
yii\base\Model
;
use
yii\base\InvalidParamException
;
use
yii\base\ModelEvent
;
use
yii\base\UnknownMethodException
;
use
yii\base\InvalidCallException
;
use
yii\helpers\StringHelper
;
use
yii\helpers\Inflector
;
use
yii\helpers\StringHelper
;
/**
* ActiveRecord is the base class for classes representing relational data in terms of objects.
...
...
framework/yii/helpers/BaseFileHelper.php
View file @
4df9b6cb
...
...
@@ -292,11 +292,11 @@ class BaseFileHelper
if
(
$isDir
=
is_dir
(
$path
))
{
$path
.=
'/'
;
}
$n
=
StringHelper
::
strlen
(
$path
);
$n
=
StringHelper
::
byteLength
(
$path
);
if
(
!
empty
(
$options
[
'except'
]))
{
foreach
(
$options
[
'except'
]
as
$name
)
{
if
(
StringHelper
::
substr
(
$path
,
-
StringHelper
::
strlen
(
$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
::
substr
(
$path
,
-
StringHelper
::
strlen
(
$name
),
$n
)
===
$name
)
{
if
(
StringHelper
::
byteSubstr
(
$path
,
-
StringHelper
::
byteLength
(
$name
),
$n
)
===
$name
)
{
return
true
;
}
}
...
...
framework/yii/helpers/BaseSecurity.php
View file @
4df9b6cb
...
...
@@ -80,10 +80,10 @@ class BaseSecurity
}
$module
=
static
::
openCryptModule
();
$ivSize
=
mcrypt_enc_get_iv_size
(
$module
);
$iv
=
StringHelper
::
s
ubstr
(
$data
,
0
,
$ivSize
);
$iv
=
StringHelper
::
byteS
ubstr
(
$data
,
0
,
$ivSize
);
$key
=
static
::
deriveKey
(
$password
,
$iv
);
mcrypt_generic_init
(
$module
,
$key
,
$iv
);
$decrypted
=
mdecrypt_generic
(
$module
,
StringHelper
::
substr
(
$data
,
$ivSize
,
StringHelper
::
strlen
(
$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
::
strlen
(
$data
)
%
self
::
CRYPT_BLOCK_SIZE
);
$pad
=
self
::
CRYPT_BLOCK_SIZE
-
(
StringHelper
::
byteLength
(
$data
)
%
self
::
CRYPT_BLOCK_SIZE
);
return
$data
.
str_repeat
(
chr
(
$pad
),
$pad
);
}
...
...
@@ -107,11 +107,11 @@ class BaseSecurity
*/
protected
static
function
stripPadding
(
$data
)
{
$end
=
StringHelper
::
s
ubstr
(
$data
,
-
1
,
NULL
);
$end
=
StringHelper
::
byteS
ubstr
(
$data
,
-
1
,
NULL
);
$last
=
ord
(
$end
);
$n
=
StringHelper
::
strlen
(
$data
)
-
$last
;
if
(
StringHelper
::
s
ubstr
(
$data
,
$n
,
NULL
)
==
str_repeat
(
$end
,
$last
))
{
return
StringHelper
::
s
ubstr
(
$data
,
0
,
$n
);
$n
=
StringHelper
::
byteLength
(
$data
)
-
$last
;
if
(
StringHelper
::
byteS
ubstr
(
$data
,
$n
,
NULL
)
==
str_repeat
(
$end
,
$last
))
{
return
StringHelper
::
byteS
ubstr
(
$data
,
0
,
$n
);
}
return
false
;
}
...
...
@@ -164,11 +164,11 @@ class BaseSecurity
*/
public
static
function
validateData
(
$data
,
$key
,
$algorithm
=
'sha256'
)
{
$hashSize
=
StringHelper
::
strlen
(
hash_hmac
(
$algorithm
,
'test'
,
$key
));
$n
=
StringHelper
::
strlen
(
$data
);
$hashSize
=
StringHelper
::
byteLength
(
hash_hmac
(
$algorithm
,
'test'
,
$key
));
$n
=
StringHelper
::
byteLength
(
$data
);
if
(
$n
>=
$hashSize
)
{
$hash
=
StringHelper
::
s
ubstr
(
$data
,
0
,
$hashSize
);
$data2
=
StringHelper
::
s
ubstr
(
$data
,
$hashSize
,
$n
-
$hashSize
);
$hash
=
StringHelper
::
byteS
ubstr
(
$data
,
0
,
$hashSize
);
$data2
=
StringHelper
::
byteS
ubstr
(
$data
,
$hashSize
,
$n
-
$hashSize
);
return
$hash
===
hash_hmac
(
$algorithm
,
$data2
,
$key
)
?
$data2
:
false
;
}
else
{
return
false
;
...
...
framework/yii/helpers/BaseStringHelper.php
View file @
4df9b6cb
...
...
@@ -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
strlen
(
$string
)
public
static
function
byteLength
(
$string
)
{
return
mb_strlen
(
$string
,
'8bit'
);
}
...
...
@@ -40,7 +40,7 @@ class BaseStringHelper
* @return string the extracted part of string, or FALSE on failure or an empty string.
* @see http://www.php.net/manual/en/function.substr.php
*/
public
static
function
s
ubstr
(
$string
,
$start
,
$length
)
public
static
function
byteS
ubstr
(
$string
,
$start
,
$length
)
{
return
mb_substr
(
$string
,
$start
,
$length
,
'8bit'
);
}
...
...
@@ -52,6 +52,7 @@ class BaseStringHelper
* 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.
...
...
@@ -73,6 +74,7 @@ class BaseStringHelper
* 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
...
...
framework/yii/web/Response.php
View file @
4df9b6cb
...
...
@@ -382,7 +382,7 @@ class Response extends \yii\base\Response
public
function
sendContentAsFile
(
$content
,
$attachmentName
,
$mimeType
=
'application/octet-stream'
)
{
$headers
=
$this
->
getHeaders
();
$contentLength
=
StringHelper
::
strlen
(
$content
);
$contentLength
=
StringHelper
::
byteLength
(
$content
);
$range
=
$this
->
getHttpRange
(
$contentLength
);
if
(
$range
===
false
)
{
$headers
->
set
(
'Content-Range'
,
"bytes */
$contentLength
"
);
...
...
@@ -395,14 +395,14 @@ 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
::
strlen
(
$content
))
->
setDefault
(
'Content-Length'
,
StringHelper
::
byteLength
(
$content
))
->
setDefault
(
'Content-Disposition'
,
"attachment; filename=
\"
$attachmentName
\"
"
);
list
(
$begin
,
$end
)
=
$range
;
if
(
$begin
!=
0
||
$end
!=
$contentLength
-
1
)
{
$this
->
setStatusCode
(
206
);
$headers
->
set
(
'Content-Range'
,
"bytes
$begin
-
$end
/
$contentLength
"
);
$this
->
content
=
StringHelper
::
s
ubstr
(
$content
,
$begin
,
$end
-
$begin
+
1
);
$this
->
content
=
StringHelper
::
byteS
ubstr
(
$content
,
$begin
,
$end
-
$begin
+
1
);
}
else
{
$this
->
setStatusCode
(
200
);
$this
->
content
=
$content
;
...
...
tests/unit/framework/helpers/StringHelperTest.php
View file @
4df9b6cb
...
...
@@ -12,14 +12,14 @@ class StringHelperTest extends TestCase
{
public
function
testStrlen
()
{
$this
->
assertEquals
(
4
,
StringHelper
::
strlen
(
'this'
));
$this
->
assertEquals
(
6
,
StringHelper
::
strlen
(
'это'
));
$this
->
assertEquals
(
4
,
StringHelper
::
byteLength
(
'this'
));
$this
->
assertEquals
(
6
,
StringHelper
::
byteLength
(
'это'
));
}
public
function
testSubstr
()
{
$this
->
assertEquals
(
'th'
,
StringHelper
::
s
ubstr
(
'this'
,
0
,
2
));
$this
->
assertEquals
(
'э'
,
StringHelper
::
s
ubstr
(
'это'
,
0
,
2
));
$this
->
assertEquals
(
'th'
,
StringHelper
::
byteS
ubstr
(
'this'
,
0
,
2
));
$this
->
assertEquals
(
'э'
,
StringHelper
::
byteS
ubstr
(
'это'
,
0
,
2
));
}
public
function
testBasename
()
...
...
tests/unit/framework/web/ResponseTest.php
View file @
4df9b6cb
...
...
@@ -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
::
strlen
(
$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'
));
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment