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
d5d241e8
Commit
d5d241e8
authored
Feb 01, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of git.yiisoft.com:yii2
parents
25e82b3d
da0ef127
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
109 additions
and
102 deletions
+109
-102
Component.md
docs/api/base/Component.md
+2
-2
Object.md
docs/api/base/Object.md
+0
-3
ActiveRecord.md
docs/api/db/ActiveRecord.md
+7
-7
model.md
docs/model.md
+2
-2
View.php
framework/console/View.php
+88
-78
ActiveRecord.php
framework/db/ActiveRecord.php
+10
-10
No files found.
docs/api/base/Component.md
View file @
d5d241e8
...
...
@@ -7,7 +7,7 @@ is triggered (i.e. comment will be added), our custom code will be executed.
An event is identified by a name that should be unique within the class it is defined at. Event names are
*case-sensitive*
.
One or multiple PHP callbacks, called
*event handlers*
, could be attached to event. You can call
[
[trigger()
]
] to
One or multiple PHP callbacks, called
*event handlers*
, could be attached to
an
event. You can call
[
[trigger()
]
] to
raise an event. When an event is raised, the event handlers will be invoked automatically in the order they were
attached.
...
...
@@ -24,7 +24,7 @@ Valid event handlers include:
-
anonymous function:
`function($event) { ... }`
-
object method:
`array($object, 'handleAdd')`
-
static method:
`array('Page', 'handleAdd')`
-
static
class
method:
`array('Page', 'handleAdd')`
-
global function:
`'handleAdd'`
The signature of an event handler should be like the following:
...
...
docs/api/base/Object.md
View file @
d5d241e8
...
...
@@ -31,6 +31,3 @@ If a property has only a getter method and has no setter method, it is considere
to modify the property value will cause an exception.
One can call
[
[hasProperty
]
],
[
[canGetProperty
]
] and/or
[
[canSetProperty
]
] to check the existence of a property.
Besides the property feature, the Object class defines a static method
[
[create
]
] which provides a convenient
alternative way of creating a new object instance.
docs/api/db/ActiveRecord.md
View file @
d5d241e8
ActiveRecord implements the
[
Active Record design pattern
](
http://en.wikipedia.org/wiki/Active_record
)
.
The idea is that ActiveRecord object is associated with a row in a database table
The idea is that
an
ActiveRecord object is associated with a row in a database table
so object properties are mapped to colums of the corresponding database row.
For example, a
`Customer`
object is associated with a row in the
`tbl_customer`
table. Instead of writing raw SQL statements to access the data in the table,
...
...
@@ -62,7 +62,7 @@ There are two ActiveRecord methods for getting data:
-
[
[find()
]
]
-
[
[findBySql()
]
]
They
all
return an
[
[ActiveQuery
]
] instance. Coupled with the various customization and query methods
They
both
return an
[
[ActiveQuery
]
] instance. Coupled with the various customization and query methods
provided by
[
[ActiveQuery
]
], ActiveRecord supports very flexible and powerful data retrieval approaches.
The followings are some examples,
...
...
@@ -158,7 +158,7 @@ $customer = Customer::find($id);
$customer->delete();
// to increment the age of all customers by 1
Customer::updateAllCounters(array('age' =>
+
1));
Customer::updateAllCounters(array('age' => 1));
~~~
...
...
@@ -386,10 +386,10 @@ When getting an ActiveRecord instance through the [[find()]] method, we will hav
When calling
[
[save()
]
] to insert or update an ActiveRecord, we will have the following life cycles:
1.
[
[beforeValidate()
]
]: will trigger an
[
[EVENT_BEFORE_VALIDATE
]
] event
2.
[
[
beforeSave()
]
]: will trigger an
[
[EVENT_BEFORE_INSERT
]
] or
[
[EVENT_BEFORE_UP
DATE
]
] event
3.
perform the actual data insertion or updating
4.
[
[afterSave()
]
]: will trigger an
[
[EVENT_AFTER_INSERT
]
] or
[
[EVENT_AFTER_UPDATE
]
] event
5.
[
[after
Validate()
]
]: will trigger an
[
[EVENT_AFTER_VALI
DATE
]
] event
2.
[
[
afterValidate()
]
]: will trigger an
[
[EVENT_AFTER_VALI
DATE
]
] event
3.
[
[beforeSave()
]
]: will trigger an
[
[EVENT_BEFORE_INSERT
]
] or
[
[EVENT_BEFORE_UPDATE
]
] event
4.
perform the actual data insertion or updating
5.
[
[after
Save()
]
]: will trigger an
[
[EVENT_AFTER_INSERT
]
] or
[
[EVENT_AFTER_UP
DATE
]
] event
Finally when calling
[
[delete()
]
] to delete an ActiveRecord, we will have the following life cycles:
...
...
docs/model.md
View file @
d5d241e8
...
...
@@ -7,7 +7,7 @@ Attributes
Attributes store the actual data represented by a model and can
be accessed like object member variables. For example, a
`Post`
model
may contain a
`title`
attribute and a
`content`
attribute which may be
accessed as follows
,
accessed as follows
:
~~~
php
$post
->
title
=
'Hello, world'
;
...
...
@@ -51,7 +51,7 @@ Scenarios
A model may be used in different scenarios. For example, a
`User`
model may be
used to collect user login inputs, and it may also be used for user registration
purpose. For this reason, each model has a property named
`scenario`
which stores
the name of the scenario that the model is currently being used. As we will explain
the name of the scenario that the model is currently being used
in
. As we will explain
in the next few sections, the concept of scenario is mainly used in validation and
massive attribute assignment.
...
...
framework/
util/ConsoleHelper
.php
→
framework/
console/View
.php
View file @
d5d241e8
<?php
/**
*
ConsoleHelper
class file.
*
View
class file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\util
;
namespace
yii\console
;
// todo define how subclassing will work
// todo add a run() or render() method
// todo test this on all kinds of terminals, especially windows (check out lib ncurses)
// todo not sure if all methods should be static
// todo subclass DetailView
// todo subclass GridView
// todo more subclasses
/**
* Console
Helper provides additional utility functions for console applications.
* Console
View is the base class for console view components
*
*
@author Carsten Brandt <mail@cebe.cc>
*
@author Alexander Makarov <sam@rmcreative.ru>
*
A console view provides functionality to create rich console application by allowing to format output
*
by adding color and font style to it.
*
* @author Carsten Brandt <mail@cebe.cc>
* @since 2.0
*/
class
ConsoleColor
class
View
extends
\yii\base\Component
{
const
FG_
COLOR_
BLACK
=
30
;
const
FG_
COLOR_
RED
=
31
;
const
FG_
COLOR_
GREEN
=
32
;
const
FG_
COLOR_
YELLOW
=
33
;
const
FG_
COLOR_
BLUE
=
34
;
const
FG_
COLOR_
PURPLE
=
35
;
const
FG_C
OLOR_C
YAN
=
36
;
const
FG_
COLOR_
GREY
=
37
;
const
BG_
COLOR_
BLACK
=
40
;
const
BG_
COLOR_
RED
=
41
;
const
BG_
COLOR_
GREEN
=
42
;
const
BG_
COLOR_
YELLOW
=
43
;
const
BG_
COLOR_
BLUE
=
44
;
const
BG_
COLOR_
PURPLE
=
45
;
const
BG_C
OLOR_C
YAN
=
46
;
const
BG_
COLOR_
GREY
=
47
;
const
TEXT_
BOLD
=
1
;
const
TEXT_
ITALIC
=
3
;
const
TEXT_
UNDERLINE
=
4
;
const
TEXT_
BLINK
=
5
;
const
TEXT_
NEGATIVE
=
7
;
const
TEXT_
CONCEALED
=
8
;
const
TEXT_
CROSSED_OUT
=
9
;
const
TEXT_
FRAMED
=
51
;
const
TEXT_
ENCIRCLED
=
52
;
const
TEXT_
OVERLINED
=
53
;
const
FG_BLACK
=
30
;
const
FG_RED
=
31
;
const
FG_GREEN
=
32
;
const
FG_YELLOW
=
33
;
const
FG_BLUE
=
34
;
const
FG_PURPLE
=
35
;
const
FG_CYAN
=
36
;
const
FG_GREY
=
37
;
const
BG_BLACK
=
40
;
const
BG_RED
=
41
;
const
BG_GREEN
=
42
;
const
BG_YELLOW
=
43
;
const
BG_BLUE
=
44
;
const
BG_PURPLE
=
45
;
const
BG_CYAN
=
46
;
const
BG_GREY
=
47
;
const
BOLD
=
1
;
const
ITALIC
=
3
;
const
UNDERLINE
=
4
;
const
BLINK
=
5
;
const
NEGATIVE
=
7
;
const
CONCEALED
=
8
;
const
CROSSED_OUT
=
9
;
const
FRAMED
=
51
;
const
ENCIRCLED
=
52
;
const
OVERLINED
=
53
;
/**
* Moves the terminal cursor up by sending ANSI code CUU to the terminal.
* Moves the terminal cursor up by sending ANSI co
ntrol co
de CUU to the terminal.
* If the cursor is already at the edge of the screen, this has no effect.
* @param integer $rows number of rows the cursor should be moved up
*/
...
...
@@ -59,7 +70,7 @@ class ConsoleColor
}
/**
* Moves the terminal cursor down by sending ANSI code CUD to the terminal.
* Moves the terminal cursor down by sending ANSI co
ntrol co
de CUD to the terminal.
* If the cursor is already at the edge of the screen, this has no effect.
* @param integer $rows number of rows the cursor should be moved down
*/
...
...
@@ -69,7 +80,7 @@ class ConsoleColor
}
/**
* Moves the terminal cursor forward by sending ANSI code CUF to the terminal.
* Moves the terminal cursor forward by sending ANSI co
ntrol co
de CUF to the terminal.
* If the cursor is already at the edge of the screen, this has no effect.
* @param integer $steps number of steps the cursor should be moved forward
*/
...
...
@@ -79,7 +90,7 @@ class ConsoleColor
}
/**
* Moves the terminal cursor backward by sending ANSI code CUB to the terminal.
* Moves the terminal cursor backward by sending ANSI co
ntrol co
de CUB to the terminal.
* If the cursor is already at the edge of the screen, this has no effect.
* @param integer $steps number of steps the cursor should be moved backward
*/
...
...
@@ -89,7 +100,7 @@ class ConsoleColor
}
/**
* Moves the terminal cursor to the beginning of the next line by sending ANSI code CNL to the terminal.
* Moves the terminal cursor to the beginning of the next line by sending ANSI co
ntrol co
de CNL to the terminal.
* @param integer $lines number of lines the cursor should be moved down
*/
public
static
function
moveCursorNextLine
(
$lines
=
1
)
...
...
@@ -98,7 +109,7 @@ class ConsoleColor
}
/**
* Moves the terminal cursor to the beginning of the previous line by sending ANSI code CPL to the terminal.
* Moves the terminal cursor to the beginning of the previous line by sending ANSI co
ntrol co
de CPL to the terminal.
* @param integer $lines number of lines the cursor should be moved up
*/
public
static
function
moveCursorPrevLine
(
$lines
=
1
)
...
...
@@ -107,7 +118,7 @@ class ConsoleColor
}
/**
* Moves the cursor to an absolute position given as column and row by sending ANSI code CUP or CHA to the terminal.
* Moves the cursor to an absolute position given as column and row by sending ANSI co
ntrol co
de CUP or CHA to the terminal.
* @param integer $column 1-based column number, 1 is the left edge of the screen.
* @param integer|null $row 1-based row number, 1 is the top edge of the screen. if not set, will move cursor only in current line.
*/
...
...
@@ -121,7 +132,7 @@ class ConsoleColor
}
/**
* Scrolls whole page up by sending ANSI code SU to the terminal.
* Scrolls whole page up by sending ANSI co
ntrol co
de SU to the terminal.
* New lines are added at the bottom. This is not supported by ANSI.SYS used in windows.
* @param int $lines number of lines to scroll up
*/
...
...
@@ -131,7 +142,7 @@ class ConsoleColor
}
/**
* Scrolls whole page down by sending ANSI code SD to the terminal.
* Scrolls whole page down by sending ANSI co
ntrol co
de SD to the terminal.
* New lines are added at the top. This is not supported by ANSI.SYS used in windows.
* @param int $lines number of lines to scroll down
*/
...
...
@@ -141,7 +152,7 @@ class ConsoleColor
}
/**
* Saves the current cursor position by sending ANSI code SCP to the terminal.
* Saves the current cursor position by sending ANSI co
ntrol co
de SCP to the terminal.
* Position can then be restored with {@link restoreCursorPosition}.
*/
public
static
function
saveCursorPosition
()
...
...
@@ -150,7 +161,7 @@ class ConsoleColor
}
/**
* Restores the cursor position saved with {@link saveCursorPosition} by sending ANSI code RCP to the terminal.
* Restores the cursor position saved with {@link saveCursorPosition} by sending ANSI co
ntrol co
de RCP to the terminal.
*/
public
static
function
restoreCursorPosition
()
{
...
...
@@ -176,7 +187,7 @@ class ConsoleColor
}
/**
* Clears entire screen content by sending ANSI code ED with argument 2 to the terminal.
* Clears entire screen content by sending ANSI co
ntrol co
de ED with argument 2 to the terminal.
* Cursor position will not be changed.
* **Note:** ANSI.SYS implementation used in windows will reset cursor position to upper left corner of the screen.
*/
...
...
@@ -186,7 +197,7 @@ class ConsoleColor
}
/**
* Clears text from cursor to the beginning of the screen by sending ANSI code ED with argument 1 to the terminal.
* Clears text from cursor to the beginning of the screen by sending ANSI co
ntrol co
de ED with argument 1 to the terminal.
* Cursor position will not be changed.
*/
public
static
function
clearScreenBeforeCursor
()
...
...
@@ -195,7 +206,7 @@ class ConsoleColor
}
/**
* Clears text from cursor to the end of the screen by sending ANSI code ED with argument 0 to the terminal.
* Clears text from cursor to the end of the screen by sending ANSI co
ntrol co
de ED with argument 0 to the terminal.
* Cursor position will not be changed.
*/
public
static
function
clearScreenAfterCursor
()
...
...
@@ -203,9 +214,8 @@ class ConsoleColor
echo
"
\033
[0J"
;
}
/**
* Clears the line, the cursor is currently on by sending ANSI code EL with argument 2 to the terminal.
* Clears the line, the cursor is currently on by sending ANSI co
ntrol co
de EL with argument 2 to the terminal.
* Cursor position will not be changed.
*/
public
static
function
clearLine
()
...
...
@@ -214,7 +224,7 @@ class ConsoleColor
}
/**
* Clears text from cursor position to the beginning of the line by sending ANSI code EL with argument 1 to the terminal.
* Clears text from cursor position to the beginning of the line by sending ANSI co
ntrol co
de EL with argument 1 to the terminal.
* Cursor position will not be changed.
*/
public
static
function
clearLineBeforeCursor
()
...
...
@@ -223,7 +233,7 @@ class ConsoleColor
}
/**
* Clears text from cursor position to the end of the line by sending ANSI code EL with argument 0 to the terminal.
* Clears text from cursor position to the end of the line by sending ANSI co
ntrol co
de EL with argument 0 to the terminal.
* Cursor position will not be changed.
*/
public
static
function
clearLineAfterCursor
()
...
...
@@ -309,32 +319,32 @@ class ConsoleColor
{
switch
(
$controlCode
)
{
case
static
::
FG_
COLOR_
BLACK
:
$style
=
array
(
'color'
=>
'#000000'
);
break
;
case
static
::
FG_
COLOR_
BLUE
:
$style
=
array
(
'color'
=>
'#000078'
);
break
;
case
static
::
FG_C
OLOR_C
YAN
:
$style
=
array
(
'color'
=>
'#007878'
);
break
;
case
static
::
FG_
COLOR_
GREEN
:
$style
=
array
(
'color'
=>
'#007800'
);
break
;
case
static
::
FG_
COLOR_
GREY
:
$style
=
array
(
'color'
=>
'#787878'
);
break
;
case
static
::
FG_
COLOR_
PURPLE
:
$style
=
array
(
'color'
=>
'#780078'
);
break
;
case
static
::
FG_
COLOR_
RED
:
$style
=
array
(
'color'
=>
'#780000'
);
break
;
case
static
::
FG_
COLOR_
YELLOW
:
$style
=
array
(
'color'
=>
'#787800'
);
break
;
case
static
::
BG_
COLOR_
BLACK
:
$style
=
array
(
'background-color'
=>
'#000000'
);
break
;
case
static
::
BG_
COLOR_
BLUE
:
$style
=
array
(
'background-color'
=>
'#000078'
);
break
;
case
static
::
BG_C
OLOR_C
YAN
:
$style
=
array
(
'background-color'
=>
'#007878'
);
break
;
case
static
::
BG_
COLOR_
GREEN
:
$style
=
array
(
'background-color'
=>
'#007800'
);
break
;
case
static
::
BG_
COLOR_
GREY
:
$style
=
array
(
'background-color'
=>
'#787878'
);
break
;
case
static
::
BG_
COLOR_
PURPLE
:
$style
=
array
(
'background-color'
=>
'#780078'
);
break
;
case
static
::
BG_
COLOR_
RED
:
$style
=
array
(
'background-color'
=>
'#780000'
);
break
;
case
static
::
BG_
COLOR_
YELLOW
:
$style
=
array
(
'background-color'
=>
'#787800'
);
break
;
case
static
::
TEXT_
BOLD
:
$style
=
array
(
'font-weight'
=>
'bold'
);
break
;
case
static
::
TEXT_
ITALIC
:
$style
=
array
(
'font-style'
=>
'italic'
);
break
;
case
static
::
TEXT_
UNDERLINE
:
$style
=
array
(
'text-decoration'
=>
array
(
'underline'
));
break
;
case
static
::
TEXT_
OVERLINED
:
$style
=
array
(
'text-decoration'
=>
array
(
'overline'
));
break
;
case
static
::
TEXT_
CROSSED_OUT
:
$style
=
array
(
'text-decoration'
=>
array
(
'line-through'
));
break
;
case
static
::
TEXT_
BLINK
:
$style
=
array
(
'text-decoration'
=>
array
(
'blink'
));
break
;
case
static
::
TEXT_
NEGATIVE
:
// ???
case
static
::
TEXT_
CONCEALED
:
case
static
::
TEXT_
ENCIRCLED
:
case
static
::
TEXT_
FRAMED
:
case
static
::
FG_BLACK
:
$style
=
array
(
'color'
=>
'#000000'
);
break
;
case
static
::
FG_BLUE
:
$style
=
array
(
'color'
=>
'#000078'
);
break
;
case
static
::
FG_CYAN
:
$style
=
array
(
'color'
=>
'#007878'
);
break
;
case
static
::
FG_GREEN
:
$style
=
array
(
'color'
=>
'#007800'
);
break
;
case
static
::
FG_GREY
:
$style
=
array
(
'color'
=>
'#787878'
);
break
;
case
static
::
FG_PURPLE
:
$style
=
array
(
'color'
=>
'#780078'
);
break
;
case
static
::
FG_RED
:
$style
=
array
(
'color'
=>
'#780000'
);
break
;
case
static
::
FG_YELLOW
:
$style
=
array
(
'color'
=>
'#787800'
);
break
;
case
static
::
BG_BLACK
:
$style
=
array
(
'background-color'
=>
'#000000'
);
break
;
case
static
::
BG_BLUE
:
$style
=
array
(
'background-color'
=>
'#000078'
);
break
;
case
static
::
BG_CYAN
:
$style
=
array
(
'background-color'
=>
'#007878'
);
break
;
case
static
::
BG_GREEN
:
$style
=
array
(
'background-color'
=>
'#007800'
);
break
;
case
static
::
BG_GREY
:
$style
=
array
(
'background-color'
=>
'#787878'
);
break
;
case
static
::
BG_PURPLE
:
$style
=
array
(
'background-color'
=>
'#780078'
);
break
;
case
static
::
BG_RED
:
$style
=
array
(
'background-color'
=>
'#780000'
);
break
;
case
static
::
BG_YELLOW
:
$style
=
array
(
'background-color'
=>
'#787800'
);
break
;
case
static
::
BOLD
:
$style
=
array
(
'font-weight'
=>
'bold'
);
break
;
case
static
::
ITALIC
:
$style
=
array
(
'font-style'
=>
'italic'
);
break
;
case
static
::
UNDERLINE
:
$style
=
array
(
'text-decoration'
=>
array
(
'underline'
));
break
;
case
static
::
OVERLINED
:
$style
=
array
(
'text-decoration'
=>
array
(
'overline'
));
break
;
case
static
::
CROSSED_OUT
:
$style
=
array
(
'text-decoration'
=>
array
(
'line-through'
));
break
;
case
static
::
BLINK
:
$style
=
array
(
'text-decoration'
=>
array
(
'blink'
));
break
;
case
static
::
NEGATIVE
:
// ???
case
static
::
CONCEALED
:
case
static
::
ENCIRCLED
:
case
static
::
FRAMED
:
// TODO allow resetting codes
break
;
case
0
:
// ansi reset
...
...
framework/db/ActiveRecord.php
View file @
d5d241e8
...
...
@@ -602,13 +602,13 @@ class ActiveRecord extends Model
*
* 1. call [[beforeValidate()]] when `$runValidation` is true. If validation
* fails, it will skip the rest of the steps;
* 2. call [[beforeSave()]]. If the method returns false, it will skip the
* 2. call [[afterValidate()]] when `$runValidation` is true.
* 3. call [[beforeSave()]]. If the method returns false, it will skip the
* rest of the steps;
* 3. insert the record into database. If this fails, it will skip the rest of the steps;
* 4. call [[afterSave()]];
* 5. call [[afterValidate()]] when `$runValidation` is true.
* 4. insert the record into database. If this fails, it will skip the rest of the steps;
* 5. call [[afterSave()]];
*
* In the above step 1, 2,
4
and 5, events [[EVENT_BEFORE_VALIDATE]],
* In the above step 1, 2,
3
and 5, events [[EVENT_BEFORE_VALIDATE]],
* [[EVENT_BEFORE_INSERT]], [[EVENT_AFTER_INSERT]] and [[EVENT_AFTER_VALIDATE]]
* will be raised by the corresponding methods.
*
...
...
@@ -673,13 +673,13 @@ class ActiveRecord extends Model
*
* 1. call [[beforeValidate()]] when `$runValidation` is true. If validation
* fails, it will skip the rest of the steps;
* 2. call [[beforeSave()]]. If the method returns false, it will skip the
* 2. call [[afterValidate()]] when `$runValidation` is true.
* 3. call [[beforeSave()]]. If the method returns false, it will skip the
* rest of the steps;
* 3. save the record into database. If this fails, it will skip the rest of the steps;
* 4. call [[afterSave()]];
* 5. call [[afterValidate()]] when `$runValidation` is true.
* 4. save the record into database. If this fails, it will skip the rest of the steps;
* 5. call [[afterSave()]];
*
* In the above step 1, 2,
4
and 5, events [[EVENT_BEFORE_VALIDATE]],
* In the above step 1, 2,
3
and 5, events [[EVENT_BEFORE_VALIDATE]],
* [[EVENT_BEFORE_UPDATE]], [[EVENT_AFTER_UPDATE]] and [[EVENT_AFTER_VALIDATE]]
* will be raised by the corresponding methods.
*
...
...
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