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
edd7ec42
Commit
edd7ec42
authored
May 20, 2013
by
Antonio Ramirez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Inflector second revision
parent
a1af54a0
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
41 deletions
+17
-41
Inflector.php
yii/helpers/base/Inflector.php
+17
-41
No files found.
yii/helpers/base/Inflector.php
View file @
edd7ec42
...
...
@@ -357,22 +357,15 @@ class Inflector
* Converts an underscored or CamelCase word into a English
* sentence.
*
* The titleize function converts text like "WelcomePage",
* "welcome_page" or "welcome page" to this "Welcome
* Page".
* If second parameter is set to 'first' it will only
* capitalize the first character of the title.
*
* @param string $word Word to format as tile
* @param string $uppercase If set to 'first' it will only uppercase the
* first character. Otherwise it will uppercase all
* the words in the title.
* @return string Text formatted as title
* @param string $words
* @param bool $ucAll whether to set all words to uppercase
* @return string
*/
public
static
function
titleize
(
$word
,
$uppercase
=
''
)
public
static
function
titleize
(
$word
s
,
$ucAll
=
false
)
{
$uppercase
=
$uppercase
==
'first'
?
'ucfirst'
:
'ucwords'
;
return
$uppercase
(
static
::
humanize
(
static
::
underscore
(
$word
)));
$words
=
static
::
humanize
(
static
::
underscore
(
$words
),
$ucAll
);
return
$ucAll
?
ucwords
(
$words
)
:
ucfirst
(
$words
);
}
/**
...
...
@@ -383,8 +376,8 @@ class Inflector
* "who's online" will be converted to "WhoSOnline"
*
* @see variablize
* @param
string $word Word to convert to camel c
ase
* @return string
UpperCamelCasedWord
* @param
string $word the word to CamelC
ase
* @return string
*/
public
static
function
camelize
(
$word
)
{
...
...
@@ -392,44 +385,27 @@ class Inflector
}
/**
* Converts a word "into_it_s_underscored_version"
*
* Convert any "CamelCased" or "ordinary Word" into an
* "underscored_word".
* Converts any "CamelCased" or "ordinary Word" into an "underscored_word".
*
* This can be really useful for creating friendly URLs.
*
* @access public
* @static
* @param string $word Word to underscore
* @return string Underscored word
* @param string $words the word(s) to underscore
* @return string
*/
public
static
function
underscore
(
$word
)
public
static
function
underscore
(
$word
s
)
{
return
strtolower
(
preg_replace
(
'/[^A-Z^a-z^0-9]+/'
,
'_'
,
preg_replace
(
'/([a-zd])([A-Z])/'
,
'1_2'
,
preg_replace
(
'/([A-Z]+)([A-Z][a-z])/'
,
'1_2'
,
$word
)
)
)
);
return
strtolower
(
preg_replace
(
'/(?<=\\w)([A-Z])/'
,
'_\\1'
,
$words
));
}
/**
* Returns a human-readable string from $word
*
* @param string $word the string to humanize
* @param bool $u
ppercase
whether to set all words to uppercase or not
* @param bool $u
cAll
whether to set all words to uppercase or not
* @return string
*/
public
static
function
humanize
(
$word
,
$u
ppercase
=
false
)
public
static
function
humanize
(
$word
,
$u
cAll
=
false
)
{
$word
=
str_replace
(
'_'
,
' '
,
preg_replace
(
'/_id$/'
,
''
,
$word
));
return
$u
ppercase
?
ucwords
(
$word
)
:
ucfirst
(
$word
);
return
$u
cAll
?
ucwords
(
$word
)
:
ucfirst
(
$word
);
}
/**
...
...
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