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
f8e05fbf
Commit
f8e05fbf
authored
Jun 08, 2014
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved `yii\helpers\Inflector::slug` to support more cases for Russian, Hebrew…
Improved `yii\helpers\Inflector::slug` to support more cases for Russian, Hebrew and special characters
parent
af1a2666
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
4 deletions
+17
-4
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
BaseInflector.php
framework/helpers/BaseInflector.php
+2
-2
InflectorTest.php
tests/unit/framework/helpers/InflectorTest.php
+14
-2
No files found.
framework/CHANGELOG.md
View file @
f8e05fbf
...
@@ -87,6 +87,7 @@ Yii Framework 2 Change Log
...
@@ -87,6 +87,7 @@ Yii Framework 2 Change Log
-
Enh: Added support for using path alias with
`FileDependency::fileName`
(qiangxue)
-
Enh: Added support for using path alias with
`FileDependency::fileName`
(qiangxue)
-
Enh: Added param
`hideOnSinglePage`
to
`yii\widgets\LinkPager`
(arturf)
-
Enh: Added param
`hideOnSinglePage`
to
`yii\widgets\LinkPager`
(arturf)
-
Enh: Added support for array attributes in
`in`
validator (creocoder)
-
Enh: Added support for array attributes in
`in`
validator (creocoder)
-
Enh: Improved
`yii\helpers\Inflector::slug`
to support more cases for Russian, Hebrew and special characters (samdark)
-
Chg #2898:
`yii\console\controllers\AssetController`
is now using hashes instead of timestamps (samdark)
-
Chg #2898:
`yii\console\controllers\AssetController`
is now using hashes instead of timestamps (samdark)
-
Chg #2913: RBAC
`DbManager`
is now initialized via migration (samdark)
-
Chg #2913: RBAC
`DbManager`
is now initialized via migration (samdark)
-
Chg #3036: Upgraded Twitter Bootstrap to 3.1.x (qiangxue)
-
Chg #3036: Upgraded Twitter Bootstrap to 3.1.x (qiangxue)
...
...
framework/helpers/BaseInflector.php
View file @
f8e05fbf
...
@@ -467,9 +467,9 @@ class BaseInflector
...
@@ -467,9 +467,9 @@ class BaseInflector
public
static
function
slug
(
$string
,
$replacement
=
'-'
,
$lowercase
=
true
)
public
static
function
slug
(
$string
,
$replacement
=
'-'
,
$lowercase
=
true
)
{
{
if
(
extension_loaded
(
'intl'
)
===
true
)
{
if
(
extension_loaded
(
'intl'
)
===
true
)
{
$options
=
'Any-Latin; NF
D; [:Nonspacing Mark:] Remove; NFC; [:Punctuation:] Remove;
'
;
$options
=
'Any-Latin; NF
KD; [:Punctuation:] Remove; [^\u0000-\u007E] Remove
'
;
$string
=
transliterator_transliterate
(
$options
,
$string
);
$string
=
transliterator_transliterate
(
$options
,
$string
);
$string
=
preg_replace
(
'/[-\s]+/'
,
$replacement
,
$string
);
$string
=
preg_replace
(
'/[
=
-\s]+/'
,
$replacement
,
$string
);
}
else
{
}
else
{
$string
=
str_replace
(
array_keys
(
static
::
$transliteration
),
static
::
$transliteration
,
$string
);
$string
=
str_replace
(
array_keys
(
static
::
$transliteration
),
static
::
$transliteration
,
$string
);
$string
=
preg_replace
(
'/[^\p{L}\p{Nd}]+/u'
,
$replacement
,
$string
);
$string
=
preg_replace
(
'/[^\p{L}\p{Nd}]+/u'
,
$replacement
,
$string
);
...
...
tests/unit/framework/helpers/InflectorTest.php
View file @
f8e05fbf
...
@@ -124,9 +124,21 @@ class InflectorTest extends TestCase
...
@@ -124,9 +124,21 @@ class InflectorTest extends TestCase
public
function
testSlug
()
public
function
testSlug
()
{
{
$this
->
assertEquals
(
"privet-hello-jii-framework-kak-dela-how-it-goes"
,
Inflector
::
slug
(
'Привет Hello Йии-- Framework !--- Как дела ? How it goes ?'
));
$data
=
[
'Привет. Hello, Йии-- Framework !--- Как дела ? How it goes ?'
=>
'privet-hello-jii-framework-kak-dela-how-it-goes'
,
'this is a title'
=>
'this-is-a-title'
,
'недвижимость'
=>
'nedvizimost'
,
'áàâéèêíìîóòôúùûã'
=>
'aaaeeeiiiooouuua'
,
'Ναδάλης ṃỹṛèşưḿĕ'
=>
'nadales-myresume'
,
'E=mc²'
=>
'e-mc2'
,
'è¼å¥'
=>
'e14a'
,
];
foreach
(
$data
as
$source
=>
$expected
)
{
$this
->
assertEquals
(
$expected
,
Inflector
::
slug
(
$source
));
}
$this
->
assertEquals
(
"this-is-a-title"
,
Inflector
::
slug
(
'this is a title
'
));
//$this->assertEquals('this-is-my-text-', Inflector::slug('! this is my / text $##
'));
}
}
public
function
testClassify
()
public
function
testClassify
()
...
...
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