1 | <?php |
||
26 | trait UserTrait |
||
27 | { |
||
28 | use PasswordTrait, |
||
29 | RegistrationTrait, |
||
30 | IdentityTrait; |
||
31 | |||
32 | /** |
||
33 | * Create new entity model associated with current user. The model to be created |
||
34 | * must be extended from [[BaseBlameableModel]], [[BaseMongoBlameableModel]], |
||
35 | * [[BaseRedisBlameableModel]], or any other classes used [[BlameableTrait]]. |
||
36 | * if $config does not specify `userClass` property, self will be assigned to. |
||
37 | * @param string $className Full qualified class name. |
||
38 | * @param array $config name-value pairs that will be used to initialize |
||
39 | * the object properties. |
||
40 | * @param boolean $loadDefault Determines whether loading default values |
||
41 | * after entity model created. |
||
42 | * Notice! The [[\yii\mongodb\ActiveRecord]] and [[\yii\redis\ActiveRecord]] |
||
43 | * does not support loading default value. If you want to assign properties |
||
44 | * with default values, please define the `default` rule(s) for properties in |
||
45 | * `rules()` method and return them by yourself if you don't specified them in config param. |
||
46 | * @param boolean $skipIfSet whether existing value should be preserved. |
||
47 | * This will only set defaults for attributes that are `null`. |
||
48 | * @return [[$className]] new model created with specified configuration. |
||
49 | *//* |
||
50 | public function create($className, $config = [], $loadDefault = true, $skipIfSet = true) |
||
51 | { |
||
52 | if (!isset($config['hostClass'])) { |
||
53 | $config['hostClass'] = static::class; |
||
54 | } |
||
55 | if (isset($config['class'])) { |
||
56 | unset($config['class']); |
||
57 | } |
||
58 | $entity = new $className($config); |
||
59 | $entity->setHost($this); |
||
60 | if ($loadDefault && method_exists($entity, 'loadDefaultValues')) { |
||
61 | $entity->loadDefaultValues($skipIfSet); |
||
62 | } |
||
63 | return $entity; |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * This method is only used for overriding [[removeSelf()]] in [[TimestampTrait]]. |
||
68 | * @see deregister() |
||
69 | * @return boolean |
||
70 | */ |
||
71 | 4 | public function removeSelf() |
|
75 | |||
76 | /** |
||
77 | * Get all rules with current user properties. |
||
78 | * @return array all rules. |
||
79 | */ |
||
80 | 172 | public function rules() |
|
92 | } |
||
93 |