1 | <?php |
||
21 | trait UserTrait |
||
22 | { |
||
23 | use PasswordTrait, |
||
24 | RegistrationTrait, |
||
25 | IdentityTrait; |
||
26 | |||
27 | /** |
||
28 | * Create new entity model associated with current user. |
||
29 | * if $config does not specify `userClass` property, self will be assigned to. |
||
30 | * @param string $className Full qualified class name. |
||
31 | * @param array $config name-value pairs that will be used to initialize |
||
32 | * the object properties. |
||
33 | * @param boolean $loadDefault Determines whether loading default values |
||
34 | * after entity model created. |
||
35 | * @param boolean $skipIfSet whether existing value should be preserved. |
||
36 | * This will only set defaults for attributes that are `null`. |
||
37 | * @return $className |
||
|
|||
38 | */ |
||
39 | 20 | public function create($className, $config = [], $loadDefault = true, $skipIfSet = true) |
|
40 | { |
||
41 | 20 | if (!isset($config['userClass'])) { |
|
42 | 20 | $config['userClass'] = static::className(); |
|
43 | 20 | } |
|
44 | 20 | if (isset($config['class'])) { |
|
45 | unset($config['class']); |
||
46 | } |
||
47 | 20 | $entity = new $className($config); |
|
48 | 20 | $createdByAttribute = $entity->createdByAttribute; |
|
49 | 20 | $entity->$createdByAttribute = $this->guid; |
|
50 | 20 | if ($loadDefault && method_exists($entity, 'loadDefaultValues')) { |
|
51 | 20 | $entity->loadDefaultValues($skipIfSet); |
|
52 | 20 | } |
|
53 | 20 | return $entity; |
|
54 | } |
||
55 | |||
56 | /** |
||
57 | * Find existed or create new model. |
||
58 | * @param string $className |
||
59 | * @param array $condition |
||
60 | * @param array $config |
||
61 | * @return $className |
||
62 | */ |
||
63 | 2 | public function findOneOrCreate($className, $condition = [], $config = null) |
|
78 | |||
79 | /** |
||
80 | * Get all rules with current user properties. |
||
81 | * @return array all rules. |
||
82 | */ |
||
83 | 34 | public function rules() |
|
95 | } |
||
96 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.