merge from yiisoft/yii2

This commit is contained in:
cuileon
2018-11-14 11:57:32 +08:00
parent 47df8a8cc0
commit 489dd119a5
426 changed files with 18465 additions and 4215 deletions

View File

@@ -80,7 +80,7 @@ class DynamicModel extends Model
*/
public function __get($name)
{
if (array_key_exists($name, $this->_attributes)) {
if ($this->hasAttribute($name)) {
return $this->_attributes[$name];
}
@@ -92,7 +92,7 @@ class DynamicModel extends Model
*/
public function __set($name, $value)
{
if (array_key_exists($name, $this->_attributes)) {
if ($this->hasAttribute($name)) {
$this->_attributes[$name] = $value;
} else {
parent::__set($name, $value);
@@ -104,7 +104,7 @@ class DynamicModel extends Model
*/
public function __isset($name)
{
if (array_key_exists($name, $this->_attributes)) {
if ($this->hasAttribute($name)) {
return isset($this->_attributes[$name]);
}
@@ -116,13 +116,39 @@ class DynamicModel extends Model
*/
public function __unset($name)
{
if (array_key_exists($name, $this->_attributes)) {
if ($this->hasAttribute($name)) {
unset($this->_attributes[$name]);
} else {
parent::__unset($name);
}
}
/**
* {@inheritdoc}
*/
public function canGetProperty($name, $checkVars = true, $checkBehaviors = true)
{
return parent::canGetProperty($name, $checkVars, $checkBehaviors) || $this->hasAttribute($name);
}
/**
* {@inheritdoc}
*/
public function canSetProperty($name, $checkVars = true, $checkBehaviors = true)
{
return parent::canSetProperty($name, $checkVars, $checkBehaviors) || $this->hasAttribute($name);
}
/**
* Returns a value indicating whether the model has an attribute with the specified name.
* @param string $name the name of the attribute
* @return bool whether the model has an attribute with the specified name
*/
public function hasAttribute($name)
{
return array_key_exists($name, $this->_attributes);
}
/**
* Defines an attribute.
* @param string $name the attribute name
@@ -155,7 +181,7 @@ class DynamicModel extends Model
public function addRule($attributes, $validator, $options = [])
{
$validators = $this->getValidators();
$validators->append(Validator::createValidator($validator, $this, (array) $attributes, $options));
$validators->append(Validator::createValidator($validator, $this, (array)$attributes, $options));
return $this;
}
@@ -179,7 +205,7 @@ class DynamicModel extends Model
if ($rule instanceof Validator) {
$validators->append($rule);
} elseif (is_array($rule) && isset($rule[0], $rule[1])) { // attributes, validator type
$validator = Validator::createValidator($rule[1], $model, (array) $rule[0], array_slice($rule, 2));
$validator = Validator::createValidator($rule[1], $model, (array)$rule[0], array_slice($rule, 2));
$validators->append($validator);
} else {
throw new InvalidConfigException('Invalid validation rule: a rule must specify both attribute names and validator type.');