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
9d8a4012
Commit
9d8a4012
authored
Feb 10, 2012
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
6d6d8d95
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
85 additions
and
59 deletions
+85
-59
YiiBase.php
framework/YiiBase.php
+5
-6
Model.php
framework/base/Model.php
+4
-4
ModelBehavior.php
framework/base/ModelBehavior.php
+2
-2
ModelEvent.php
framework/base/ModelEvent.php
+6
-7
Object.php
framework/base/Object.php
+1
-1
ActiveFinder.php
framework/db/ar/ActiveFinder.php
+28
-28
ActiveMetaData.php
framework/db/ar/ActiveMetaData.php
+24
-2
ActiveRecord.php
framework/db/ar/ActiveRecord.php
+0
-0
JoinElement.php
framework/db/ar/JoinElement.php
+2
-2
Text.php
framework/util/Text.php
+13
-7
No files found.
framework/YiiBase.php
View file @
9d8a4012
...
...
@@ -75,17 +75,16 @@ class YiiBase
);
/**
* @var array initial property values that will be applied to objects newly created via [[createObject]].
* The array keys are fully qualified namespaced class names, and the array values are the corresponding
* name-value pairs for initializing the created class instances. Please make sure class names are starting
* with a backslash. For example,
* The array keys are class names without leading backslashes "\", and the array values are the corresponding
* name-value pairs for initializing the created class instances. For example,
*
* ~~~
* array(
* '
\
Bar' => array(
* 'Bar' => array(
* 'prop1' => 'value1',
* 'prop2' => 'value2',
* ),
* '
\
mycompany\foo\Car' => array(
* 'mycompany\foo\Car' => array(
* 'prop1' => 'value1',
* 'prop2' => 'value2',
* ),
...
...
@@ -375,7 +374,7 @@ class YiiBase
$object
=
new
$class
;
}
$class
=
'\\'
.
get_class
(
$object
);
$class
=
get_class
(
$object
);
if
(
isset
(
\Yii
::
$objectConfig
[
$class
]))
{
$config
=
array_merge
(
\Yii
::
$objectConfig
[
$class
],
$config
);
...
...
framework/base/Model.php
View file @
9d8a4012
...
...
@@ -207,7 +207,7 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
public
function
beforeValidate
()
{
if
(
$this
->
hasEventHandlers
(
'onBeforeValidate'
))
{
$event
=
new
Validation
Event
(
$this
);
$event
=
new
Model
Event
(
$this
);
$this
->
onBeforeValidate
(
$event
);
return
$event
->
isValid
;
}
...
...
@@ -229,7 +229,7 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
/**
* This event is raised before the validation is performed.
* @param
Validation
Event $event the event parameter
* @param
Model
Event $event the event parameter
*/
public
function
onBeforeValidate
(
$event
)
{
...
...
@@ -457,7 +457,7 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
*/
public
function
generateAttributeLabel
(
$name
)
{
return
Text
::
name
2words
(
$name
,
true
);
return
Text
::
camel
2words
(
$name
,
true
);
}
/**
...
...
@@ -583,7 +583,7 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
/**
* Returns an iterator for traversing the attributes in the model.
* This method is required by the interface IteratorAggregate.
* @return
CMap
Iterator an iterator for traversing the items in the list.
* @return
Dictionary
Iterator an iterator for traversing the items in the list.
*/
public
function
getIterator
()
{
...
...
framework/base/ModelBehavior.php
View file @
9d8a4012
...
...
@@ -52,9 +52,9 @@ class ModelBehavior extends Behavior
/**
* Responds to [[Model::onBeforeValidate]] event.
* Override this method if you want to handle the corresponding event of the [[owner]].
* You may set the [[
Validation
Event::isValid|isValid]] property of the event parameter
* You may set the [[
Model
Event::isValid|isValid]] property of the event parameter
* to be false to cancel the validation process.
* @param
Validation
Event $event event parameter
* @param
Model
Event $event event parameter
*/
public
function
beforeValidate
(
$event
)
{
...
...
framework/base/
Validation
Event.php
→
framework/base/
Model
Event.php
View file @
9d8a4012
<?php
/**
*
Validation
Event class file.
*
Model
Event class file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-2012 Yii Software LLC
...
...
@@ -10,19 +10,18 @@
namespace
yii\base
;
/**
*
Validation
Event class.
*
Model
Event class.
*
*
ValidationEvent represents the parameter needed by model validation
events.
*
ModelEvent represents the parameter needed by model
events.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class
Validation
Event
extends
Event
class
Model
Event
extends
Event
{
/**
* @var boolean whether the model passes the validation by the event handler.
* Defaults to true. If it is set false, the [[Model::validate|model validation]] will be cancelled.
* @see Model::onBeforeValidate
* @var boolean whether the model is in valid status. Defaults to true.
* A model is in valid status if it passes validation, or other checks.
*/
public
$isValid
=
true
;
}
framework/base/Object.php
View file @
9d8a4012
...
...
@@ -299,7 +299,7 @@ class Object
*/
public
static
function
newInstance
(
$config
=
array
())
{
$class
=
'\\'
.
get_called_class
();
$class
=
get_called_class
();
if
((
$n
=
func_num_args
())
>
1
)
{
$args
=
func_get_args
();
...
...
framework/db/ar/Active
Query
.php
→
framework/db/ar/Active
Finder
.php
View file @
9d8a4012
This diff is collapsed.
Click to expand it.
framework/db/ar/ActiveMetaData.php
View file @
9d8a4012
...
...
@@ -14,6 +14,10 @@ use yii\db\dao\TableSchema;
class
ActiveMetaData
{
/**
* @var ActiveMetaData[] list of ActiveMetaData instances indexed by the model class names
*/
public
static
$instances
;
/**
* @var TableSchema the table schema information
*/
public
$table
;
...
...
@@ -27,14 +31,32 @@ class ActiveMetaData
public
$relations
=
array
();
/**
* Returns an instance of ActiveMetaData for the specified model class.
* Note that each model class only has a single ActiveMetaData instance.
* This method will only create the ActiveMetaData instance if it is not previously
* done so for the specified model class.
* @param string $modelClass the model class name. Make sure the class name do NOT have a leading backslash "\".
* @param boolean $refresh whether to recreate the ActiveMetaData instance. Defaults to false.
* @return ActiveMetaData the ActiveMetaData instance for the specified model class.
*/
public
static
function
getInstance
(
$modelClass
,
$refresh
=
false
)
{
if
(
isset
(
self
::
$instances
[
$modelClass
])
&&
!
$refresh
)
{
return
self
::
$instances
[
$modelClass
];
}
else
{
return
self
::
$instances
[
$modelClass
]
=
new
self
(
$modelClass
);
}
}
/**
* Constructor.
* @param string $modelClass the model class name
*/
public
function
__construct
(
$modelClass
)
{
$this
->
modelClass
=
$modelClass
;
$tableName
=
$modelClass
::
tableName
();
$this
->
table
=
$modelClass
::
getDbConnection
()
->
getDriver
()
->
getTableSchema
(
$tableName
);
$this
->
modelClass
=
$modelClass
;
if
(
$this
->
table
===
null
)
{
throw
new
Exception
(
"Unable to find table '
$tableName
' for ActiveRecord class '
$modelClass
'."
);
}
...
...
@@ -71,7 +93,7 @@ class ActiveMetaData
$relation
->
name
=
$matches
[
1
];
$modelClass
=
$matches
[
2
];
if
(
strpos
(
$modelClass
,
'\\'
)
!==
false
)
{
$relation
->
modelClass
=
'\\'
.
ltrim
(
$modelClass
,
'\\'
);
$relation
->
modelClass
=
ltrim
(
$modelClass
,
'\\'
);
}
else
{
$relation
->
modelClass
=
dirname
(
$this
->
modelClass
)
.
'\\'
.
$modelClass
;
}
...
...
framework/db/ar/ActiveRecord.php
View file @
9d8a4012
This diff is collapsed.
Click to expand it.
framework/db/ar/JoinElement.php
View file @
9d8a4012
<?php
/**
*
ActiveQuery
class file.
*
JoinElement
class file.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
...
...
@@ -80,7 +80,7 @@ class JoinElement extends \yii\base\Object
$record
=
$modelClass
::
populateData
(
$attributes
);
foreach
(
$this
->
children
as
$child
)
{
if
(
$child
->
relation
->
select
!==
false
)
{
$record
->
initRelat
edRecord
(
$child
->
relation
);
$record
->
initRelat
ion
(
$child
->
relation
);
}
}
$this
->
records
[
$pk
]
=
$record
;
...
...
framework/util/Text.php
View file @
9d8a4012
...
...
@@ -57,26 +57,32 @@ class Text
}
/**
* Converts a
class
name into space-separated words.
* For example, 'PostTag' will be converted
as
'Post Tag'.
* Converts a
CamelCase
name into space-separated words.
* For example, 'PostTag' will be converted
to
'Post Tag'.
* @param string $name the string to be converted
* @param boolean $ucwords whether to capitalize the first letter in each word
* @return string the resulting words
*/
public
static
function
name
2words
(
$name
,
$ucwords
=
true
)
public
static
function
camel
2words
(
$name
,
$ucwords
=
true
)
{
$label
=
trim
(
strtolower
(
str_replace
(
array
(
'-'
,
'_'
,
'.'
),
' '
,
preg_replace
(
'/(?<![A-Z])[A-Z]/'
,
' \0'
,
$name
))));
return
$ucwords
?
ucwords
(
$label
)
:
$label
;
}
/**
* Converts a class name into a HTML ID.
* For example, 'PostTag' will be converted as 'post-tag'.
* Converts a CamelCase name into an ID in lowercase.
* Words in the ID may be concatenated using the specified character (defaults to '-').
* For example, 'PostTag' will be converted to 'post-tag'.
* @param string $name the string to be converted
* @param string $separator the character used to concatenate the words in the ID
* @return string the resulting ID
*/
public
static
function
name2id
(
$name
)
public
static
function
camel2id
(
$name
,
$separator
=
'-'
)
{
return
trim
(
strtolower
(
str_replace
(
'_'
,
'-'
,
preg_replace
(
'/(?<![A-Z])[A-Z]/'
,
'-\0'
,
$name
))),
'-'
);
if
(
$separator
===
'_'
)
{
return
trim
(
strtolower
(
preg_replace
(
'/(?<![A-Z])[A-Z]/'
,
'_\0'
,
$name
)),
'_'
);
}
else
{
return
trim
(
strtolower
(
str_replace
(
'_'
,
$separator
,
preg_replace
(
'/(?<![A-Z])[A-Z]/'
,
$separator
.
'\0'
,
$name
))),
$separator
);
}
}
}
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