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
567f81ce
Commit
567f81ce
authored
Jul 21, 2011
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
w
parent
e18dc2a1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
63 deletions
+77
-63
YiiBase.php
framework/YiiBase.php
+10
-10
Dictionary.php
framework/base/Dictionary.php
+1
-1
Model.php
framework/base/Model.php
+60
-44
ModelEvent.php
framework/base/ModelEvent.php
+6
-8
No files found.
framework/YiiBase.php
View file @
567f81ce
...
...
@@ -167,7 +167,7 @@ class YiiBase
return
self
::
$_imported
[
$alias
]
=
$className
;
}
if
((
$path
=
self
::
get
PathOf
Alias
(
dirname
(
$alias
)))
===
false
)
{
if
((
$path
=
self
::
getAlias
(
dirname
(
$alias
)))
===
false
)
{
throw
new
\yii\base\Exception
(
'Invalid path alias: '
.
$alias
);
}
...
...
@@ -189,16 +189,16 @@ class YiiBase
/**
* Translates a path alias into an actual path.
* The path alias can be either a root alias registered via [[set
PathOf
Alias]] or an
* The path alias can be either a root alias registered via [[setAlias]] or an
* alias starting with a root alias (e.g. `@yii/base/Component.php`).
* In the latter case, the root alias will be replaced by the corresponding registered path
* and the remaining part will be appended to it.
* Note, this method does not ensure the existence of the resulting path.
* @param string $alias alias
* @return mixed path corresponding to the alias, false if the root alias is not previously registered.
* @see set
PathOf
Alias
* @see setAlias
*/
public
static
function
get
PathOf
Alias
(
$alias
)
public
static
function
getAlias
(
$alias
)
{
if
(
isset
(
self
::
$aliases
[
$alias
]))
{
return
self
::
$aliases
[
$alias
];
...
...
@@ -220,9 +220,9 @@ class YiiBase
* @param string $alias alias to the path. The alias must start with '@'.
* @param string $path the path corresponding to the alias. If this is null, the corresponding
* path alias will be removed. The path can be a file path (e.g. `/tmp`) or a URL (e.g. `http://www.yiiframework.com`).
* @see get
PathOf
Alias
* @see getAlias
*/
public
static
function
set
PathOf
Alias
(
$alias
,
$path
)
public
static
function
setAlias
(
$alias
,
$path
)
{
if
(
$path
===
null
)
{
unset
(
self
::
$aliases
[
$alias
]);
...
...
@@ -261,7 +261,7 @@ class YiiBase
if
(
strpos
(
$className
,
'\\'
)
!==
false
)
{
// convert namespace to path alias, e.g. yii\base\Component to @yii/base/Component
$alias
=
'@'
.
str_replace
(
'\\'
,
'/'
,
ltrim
(
$className
,
'\\'
));
if
((
$path
=
self
::
get
PathOf
Alias
(
$alias
))
!==
false
)
{
if
((
$path
=
self
::
getAlias
(
$alias
))
!==
false
)
{
include
(
$path
.
'.php'
);
return
true
;
}
...
...
@@ -272,7 +272,7 @@ class YiiBase
if
((
$pos
=
strpos
(
$className
,
'_'
))
!==
false
)
{
// convert class name to path alias, e.g. PHPUnit_Framework_TestCase to @PHPUnit/Framework/TestCase
$alias
=
'@'
.
str_replace
(
'_'
,
'/'
,
$className
);
if
((
$path
=
self
::
get
PathOf
Alias
(
$alias
))
!==
false
)
{
if
((
$path
=
self
::
getAlias
(
$alias
))
!==
false
)
{
include
(
$path
.
'.php'
);
return
true
;
}
...
...
@@ -295,9 +295,9 @@ class YiiBase
*
* The specified configuration can be either a string or an array.
* If the former, the string is treated as the object type which can
* be either a class name or [[get
PathOf
Alias|path alias]].
* be either a class name or [[getAlias|path alias]].
* If the latter, the array must contain a `class` element which refers
* to a class name or [[get
PathOf
Alias|path alias]]. The rest of the name-value
* to a class name or [[getAlias|path alias]]. The rest of the name-value
* pairs in the array will be used to initialize the corresponding object properties.
* For example,
*
...
...
framework/base/Dictionary.php
View file @
567f81ce
...
...
@@ -274,7 +274,7 @@ class Dictionary extends Component implements \IteratorAggregate, \ArrayAccess,
* This method is required by the SPL interface `ArrayAccess`.
* It is implicitly called when you use something like `$value = $dictionary[$offset];`.
* This is equivalent to [[itemAt]].
* @param
integer
$offset the offset to retrieve element.
* @param
mixed
$offset the offset to retrieve element.
* @return mixed the element at the offset, null if no element is found at the offset
*/
public
function
offsetGet
(
$offset
)
...
...
framework/base/Model.php
View file @
567f81ce
...
...
@@ -222,8 +222,9 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
*/
public
function
afterConstruct
()
{
if
(
$this
->
hasEventHandler
(
'onAfterConstruct'
))
$this
->
onAfterConstruct
(
new
CEvent
(
$this
));
if
(
$this
->
hasEventHandler
(
'onAfterConstruct'
))
{
$this
->
onAfterConstruct
(
new
Event
(
$this
));
}
}
/**
...
...
@@ -236,9 +237,12 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
*/
public
function
beforeValidate
()
{
$event
=
new
ModelEvent
(
$this
);
$this
->
onBeforeValidate
(
$event
);
return
$event
->
isValid
;
if
(
$this
->
hasEventHandler
(
'onBeforeValidate'
))
{
$event
=
new
ModelEvent
(
$this
);
$this
->
onBeforeValidate
(
$event
);
return
$event
->
isValid
;
}
return
true
;
}
/**
...
...
@@ -249,7 +253,9 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
*/
public
function
afterValidate
()
{
$this
->
onAfterValidate
(
new
CEvent
(
$this
));
if
(
$this
->
hasEventHandler
(
'onAfterValidate'
))
{
$this
->
onAfterValidate
(
new
CEvent
(
$this
));
}
}
/**
...
...
@@ -258,7 +264,7 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
*/
public
function
onAfterConstruct
(
$event
)
{
$this
->
raiseEvent
(
'onAfterConstruct'
,
$event
);
$this
->
raiseEvent
(
__METHOD__
,
$event
);
}
/**
...
...
@@ -267,7 +273,7 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
*/
public
function
onBeforeValidate
(
$event
)
{
$this
->
raiseEvent
(
'onBeforeValidate'
,
$event
);
$this
->
raiseEvent
(
__METHOD__
,
$event
);
}
/**
...
...
@@ -276,7 +282,7 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
*/
public
function
onAfterValidate
(
$event
)
{
$this
->
raiseEvent
(
'onAfterValidate'
,
$event
);
$this
->
raiseEvent
(
__METHOD__
,
$event
);
}
/**
...
...
@@ -391,10 +397,12 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
*/
public
function
hasErrors
(
$attribute
=
null
)
{
if
(
$attribute
===
null
)
if
(
$attribute
===
null
)
{
return
$this
->
_errors
!==
array
();
else
}
else
{
return
isset
(
$this
->
_errors
[
$attribute
]);
}
}
/**
...
...
@@ -404,10 +412,12 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
*/
public
function
getErrors
(
$attribute
=
null
)
{
if
(
$attribute
===
null
)
if
(
$attribute
===
null
)
{
return
$this
->
_errors
;
else
}
else
{
return
isset
(
$this
->
_errors
[
$attribute
])
?
$this
->
_errors
[
$attribute
]
:
array
();
}
}
/**
...
...
@@ -457,10 +467,12 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
*/
public
function
clearErrors
(
$attribute
=
null
)
{
if
(
$attribute
===
null
)
if
(
$attribute
===
null
)
{
$this
->
_errors
=
array
();
else
}
else
{
unset
(
$this
->
_errors
[
$attribute
]);
}
}
/**
...
...
@@ -486,18 +498,21 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
public
function
getAttributes
(
$names
=
null
)
{
$values
=
array
();
foreach
(
$this
->
attributeNames
()
as
$name
)
$values
[
$name
]
=
$this
->
$name
;
if
(
is_array
(
$names
))
{
$values2
=
array
();
foreach
(
$names
as
$name
)
$values2
[
$name
]
=
isset
(
$values
[
$name
])
?
$values
[
$name
]
:
null
;
return
$values2
;
if
(
is_array
(
$names
))
{
foreach
(
$this
->
attributeNames
()
as
$name
)
{
if
(
in_array
(
$name
,
$names
,
true
))
{
$values
[
$name
]
=
$this
->
$name
;
}
}
}
else
return
$values
;
else
{
foreach
(
$this
->
attributeNames
()
as
$name
)
{
$values
[
$name
]
=
$this
->
$name
;
}
}
return
$values
;
}
/**
...
...
@@ -510,15 +525,16 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
*/
public
function
setAttributes
(
$values
,
$safeOnly
=
true
)
{
if
(
!
is_array
(
$values
))
return
;
$attributes
=
array_flip
(
$safeOnly
?
$this
->
getSafeAttributeNames
()
:
$this
->
attributeNames
());
foreach
(
$values
as
$name
=>
$value
)
{
if
(
isset
(
$attributes
[
$name
]))
$this
->
$name
=
$value
;
elseif
(
$safeOnly
)
$this
->
onUnsafeAttribute
(
$name
,
$value
);
if
(
is_array
(
$values
))
{
$attributes
=
array_flip
(
$safeOnly
?
$this
->
getSafeAttributeNames
()
:
$this
->
attributeNames
());
foreach
(
$values
as
$name
=>
$value
)
{
if
(
isset
(
$attributes
[
$name
]))
{
$this
->
$name
=
$value
;
}
elseif
(
$safeOnly
)
{
$this
->
onUnsafeAttribute
(
$name
,
$value
);
}
}
}
}
...
...
@@ -590,22 +606,22 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
{
$attributes
=
array
();
$unsafe
=
array
();
foreach
(
$this
->
getValidators
()
as
$validator
)
{
if
(
!
$validator
->
safe
)
{
foreach
(
$validator
->
attributes
as
$name
)
foreach
(
$this
->
getValidators
()
as
$validator
)
{
if
(
!
$validator
->
safe
)
{
foreach
(
$validator
->
attributes
as
$name
)
{
$unsafe
[]
=
$name
;
}
}
else
{
foreach
(
$validator
->
attributes
as
$name
)
else
{
foreach
(
$validator
->
attributes
as
$name
)
{
$attributes
[
$name
]
=
true
;
}
}
}
foreach
(
$unsafe
as
$name
)
foreach
(
$unsafe
as
$name
)
{
unset
(
$attributes
[
$name
]);
}
return
array_keys
(
$attributes
);
}
...
...
@@ -636,7 +652,7 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
* Returns the element at the specified offset.
* This method is required by the SPL interface `ArrayAccess`.
* It is implicitly called when you use something like `$value = $model[$offset];`.
* @param
integer
$offset the offset to retrieve element.
* @param
mixed
$offset the offset to retrieve element.
* @return mixed the element at the offset, null if no element is found at the offset
*/
public
function
offsetGet
(
$offset
)
...
...
framework/base/ModelEvent.php
View file @
567f81ce
...
...
@@ -2,24 +2,22 @@
/**
* CModelEvent class file.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\base
;
/**
*
C
ModelEvent class.
* ModelEvent class.
*
*
C
ModelEvent represents the event parameters needed by events raised by a model.
* ModelEvent represents the event parameters needed by events raised by a model.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id: CModelEvent.php 2799 2011-01-01 19:31:13Z qiang.xue $
* @package system.base
* @since 1.0
* @since 2.0
*/
class
CModelEvent
extends
C
Event
class
ModelEvent
extends
Event
{
/**
* @var boolean whether the model is in valid status and should continue its normal method execution cycles. Defaults to true.
...
...
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