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