1 | <?php |
||
56 | class DynamicModel extends Model |
||
57 | { |
||
58 | private $_attributes = []; |
||
59 | |||
60 | |||
61 | /** |
||
62 | * Constructors. |
||
63 | * @param array $attributes the dynamic attributes (name-value pairs, or names) being defined |
||
64 | * @param array $config the configuration array to be applied to this object. |
||
65 | */ |
||
66 | 47 | public function __construct(array $attributes = [], $config = []) |
|
77 | |||
78 | /** |
||
79 | * @inheritdoc |
||
80 | */ |
||
81 | 32 | public function __get($name) |
|
89 | |||
90 | /** |
||
91 | * @inheritdoc |
||
92 | */ |
||
93 | 19 | public function __set($name, $value) |
|
101 | |||
102 | /** |
||
103 | * @inheritdoc |
||
104 | */ |
||
105 | public function __isset($name) |
||
113 | |||
114 | /** |
||
115 | * @inheritdoc |
||
116 | */ |
||
117 | public function __unset($name) |
||
125 | |||
126 | /** |
||
127 | * Defines an attribute. |
||
128 | * @param string $name the attribute name |
||
129 | * @param mixed $value the attribute value |
||
130 | */ |
||
131 | 17 | public function defineAttribute($name, $value = null) |
|
132 | { |
||
133 | 17 | $this->_attributes[$name] = $value; |
|
134 | 17 | } |
|
135 | |||
136 | /** |
||
137 | * Undefines an attribute. |
||
138 | * @param string $name the attribute name |
||
139 | */ |
||
140 | public function undefineAttribute($name) |
||
144 | |||
145 | /** |
||
146 | * Adds a validation rule to this model. |
||
147 | * You can also directly manipulate [[validators]] to add or remove validation rules. |
||
148 | * This method provides a shortcut. |
||
149 | * @param string|array $attributes the attribute(s) to be validated by the rule |
||
150 | * @param mixed $validator the validator for the rule.This can be a built-in validator name, |
||
151 | * a method name of the model class, an anonymous function, or a validator class name. |
||
152 | * @param array $options the options (name-value pairs) to be applied to the validator |
||
153 | * @return $this the model itself |
||
154 | */ |
||
155 | 8 | public function addRule($attributes, $validator, $options = []) |
|
162 | |||
163 | /** |
||
164 | * Validates the given data with the specified validation rules. |
||
165 | * This method will create a DynamicModel instance, populate it with the data to be validated, |
||
166 | * create the specified validation rules, and then validate the data using these rules. |
||
167 | * @param array $data the data (name-value pairs) to be validated |
||
168 | * @param array $rules the validation rules. Please refer to [[Model::rules()]] on the format of this parameter. |
||
169 | * @return static the model instance that contains the data being validated |
||
170 | * @throws InvalidConfigException if a validation rule is not specified correctly. |
||
171 | */ |
||
172 | 1 | public static function validateData(array $data, $rules = []) |
|
194 | |||
195 | /** |
||
196 | * @inheritdoc |
||
197 | */ |
||
198 | public function attributes() |
||
202 | } |
||
203 |