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
debba898
Commit
debba898
authored
Jan 25, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of git.yiisoft.com:yii2
parents
29398f4c
c0d439ba
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
16 deletions
+18
-16
Component.md
docs/api/base/Component.md
+10
-9
StringHelper.php
framework/util/StringHelper.php
+8
-7
No files found.
docs/api/base/Component.md
View file @
debba898
...
@@ -3,15 +3,15 @@ its parent class [[Object]].
...
@@ -3,15 +3,15 @@ its parent class [[Object]].
Event is a way to "inject" custom code into existing code at certain places. For example, a comment object can trigger
Event is a way to "inject" custom code into existing code at certain places. For example, a comment object can trigger
an "add" event when the user adds a comment. We can write custom code and attach it to this event so that when the event
an "add" event when the user adds a comment. We can write custom code and attach it to this event so that when the event
is triggered, our custom code will be executed.
is triggered
(i.e. comment will be added)
, our custom code will be executed.
An event is identified by a name
(unique within the class it is defined)
. Event names are
*case-sensitive*
.
An event is identified by a name
that should be unique within the class it is defined at
. Event names are
*case-sensitive*
.
An event can be attached with one or multiple PHP callbacks, called
*event handlers*
. One
can call
[
[trigger()
]
] to
One or multiple PHP callbacks, called
*event handlers*
, could be attached to event. You
can call
[
[trigger()
]
] to
raise an event. When an event is raised, the
attached event handlers will be invoked automatically in the order they a
re
raise an event. When an event is raised, the
event handlers will be invoked automatically in the order they we
re
attached
to the event
.
attached.
To attach an event handler to an event, call
[
[on()
]
]
. For example,
To attach an event handler to an event, call
[
[on()
]
]
:
~~~
~~~
$comment->on('add', function($event) {
$comment->on('add', function($event) {
...
@@ -19,7 +19,8 @@ $comment->on('add', function($event) {
...
@@ -19,7 +19,8 @@ $comment->on('add', function($event) {
});
});
~~~
~~~
In the above, we attach an anonymous function to the "add" event of the comment. Valid event handlers include:
In the above, we attach an anonymous function to the "add" event of the comment.
Valid event handlers include:
-
anonymous function:
`function($event) { ... }`
-
anonymous function:
`function($event) { ... }`
-
object method:
`array($object, 'handleAdd')`
-
object method:
`array($object, 'handleAdd')`
...
@@ -34,7 +35,7 @@ function foo($event)
...
@@ -34,7 +35,7 @@ function foo($event)
where
`$event`
is an
[
[Event
]
] object which includes parameters associated with the event.
where
`$event`
is an
[
[Event
]
] object which includes parameters associated with the event.
One
can also attach an event handler to an event when configuring a component with a configuration array. The syntax is
You
can also attach an event handler to an event when configuring a component with a configuration array. The syntax is
like the following:
like the following:
~~~
~~~
...
@@ -45,7 +46,7 @@ array(
...
@@ -45,7 +46,7 @@ array(
where
`on add`
stands for attaching an event to the
`add`
event.
where
`on add`
stands for attaching an event to the
`add`
event.
One
can call
[
[getEventHandlers()
]
] to retrieve all event handlers that are attached to a specified event. Because this
You
can call
[
[getEventHandlers()
]
] to retrieve all event handlers that are attached to a specified event. Because this
method returns a
[
[Vector
]
] object, we can manipulate this object to attach/detach event handlers, or adjust their
method returns a
[
[Vector
]
] object, we can manipulate this object to attach/detach event handlers, or adjust their
relative orders.
relative orders.
...
...
framework/util/StringHelper.php
View file @
debba898
...
@@ -28,13 +28,14 @@ class StringHelper
...
@@ -28,13 +28,14 @@ class StringHelper
public
static
function
pluralize
(
$name
)
public
static
function
pluralize
(
$name
)
{
{
$rules
=
array
(
$rules
=
array
(
'/move$/i'
=>
'moves'
,
'/(m)ove$/i'
=>
'\1oves'
,
'/foot$/i'
=>
'feet'
,
'/(f)oot$/i'
=>
'\1eet'
,
'/child$/i'
=>
'children'
,
'/(c)hild$/i'
=>
'\1hildren'
,
'/human$/i'
=>
'humans'
,
'/(h)uman$/i'
=>
'\1umans'
,
'/man$/i'
=>
'men'
,
'/(m)an$/i'
=>
'\1en'
,
'/tooth$/i'
=>
'teeth'
,
'/(s)taff$/i'
=>
'\1taff'
,
'/person$/i'
=>
'people'
,
'/(t)ooth$/i'
=>
'\1eeth'
,
'/(p)erson$/i'
=>
'\1eople'
,
'/([m|l])ouse$/i'
=>
'\1ice'
,
'/([m|l])ouse$/i'
=>
'\1ice'
,
'/(x|ch|ss|sh|us|as|is|os)$/i'
=>
'\1es'
,
'/(x|ch|ss|sh|us|as|is|os)$/i'
=>
'\1es'
,
'/([^aeiouy]|qu)y$/i'
=>
'\1ies'
,
'/([^aeiouy]|qu)y$/i'
=>
'\1ies'
,
...
...
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