1 | <?php |
||
21 | trait SubsidiaryTrait |
||
22 | { |
||
23 | /** |
||
24 | * @var string[] Subsidiary map. |
||
25 | * Array key represents class alias, |
||
26 | * array value represents the full qualified class name corresponds to the alias. |
||
27 | * |
||
28 | * For example: |
||
29 | ```php |
||
30 | public $subsidiaryMap = [ |
||
31 | 'Profile' => [ |
||
32 | 'class' => 'app\models\user\Profile', |
||
33 | ], |
||
34 | ]; |
||
35 | ``` |
||
36 | * |
||
37 | * The other elements will be taken if subsidiary configuration does not specify. |
||
38 | * If you want to create subsidiary model and the class is not found, the array elements will be taken. |
||
39 | */ |
||
40 | public $subsidiaryMap = []; |
||
41 | |||
42 | /** |
||
43 | * Add subsidiary class to map. |
||
44 | * @param string $name Subsidiary name, case insensitive. |
||
45 | * @param string|array $config If this parameter is string, it will regarded as class name. |
||
46 | * If this parameter is array, you should specify `class`, and the class should be existed. |
||
47 | * @return boolean True if the class added. |
||
48 | * @throws InvalidConfigException throws if subsidiary name is not specified or class is not |
||
49 | * specified. |
||
50 | */ |
||
51 | 8 | public function addSubsidiaryClass($name, $config) |
|
72 | |||
73 | /** |
||
74 | * Remove subsidiary. |
||
75 | * @param string $name |
||
76 | * @return boolean |
||
77 | */ |
||
78 | 1 | public function removeSubsidiary($name) |
|
87 | |||
88 | /** |
||
89 | * Get subsidiary class. |
||
90 | * @param string $name |
||
91 | * @return string |
||
92 | */ |
||
93 | 8 | public function getSubsidiaryClass($name) |
|
101 | |||
102 | /** |
||
103 | * @param $name |
||
104 | * @return bool |
||
105 | */ |
||
106 | public function hasSubsidiary($name) |
||
118 | |||
119 | /** |
||
120 | * Get subsidiaries. |
||
121 | * @param $name |
||
122 | * @param string $limit |
||
123 | * @param int $page |
||
124 | * @return null |
||
125 | */ |
||
126 | 2 | public function getSubsidiaries($name, $limit = 'all', $page = 0) |
|
138 | |||
139 | /** |
||
140 | * @param $name |
||
141 | * @param $arguments |
||
142 | * @return mixed |
||
143 | */ |
||
144 | 8 | public function __call($name, $arguments) |
|
153 | |||
154 | /** |
||
155 | * Find existed, or create new model. |
||
156 | * If model to be found doesn't exist, and $config is null, the parameter |
||
157 | * `$condition` will be regarded as properties of new model. |
||
158 | * If you want to know whether the returned model is new model, please check |
||
159 | * the return value of `getIsNewRecord()` method. |
||
160 | * @param string $className Full qualified class name. |
||
161 | * @param array $condition Search condition, or properties if not found and |
||
162 | * $config is null. |
||
163 | * @param array $config new model's configuration array. If you specify this |
||
164 | * parameter, the $condition will be skipped when created one. |
||
165 | * @return [[$className]] the existed model, or new model created by specified |
||
|
|||
166 | * condition or configuration. |
||
167 | */ |
||
168 | 1 | public function findOneOrCreate($className, $condition = [], $config = null) |
|
183 | |||
184 | /** |
||
185 | * Create new entity model associated with current user. The model to be created |
||
186 | * must be extended from [[BaseBlameableModel]], [[BaseMongoBlameableModel]], |
||
187 | * [[BaseRedisBlameableModel]], or any other classes used [[BlameableTrait]]. |
||
188 | * if $config does not specify `hostClass` property, self will be assigned to. |
||
189 | * @param string $className Full qualified class name. |
||
190 | * @param array $config name-value pairs that will be used to initialize |
||
191 | * the object properties. |
||
192 | * @param boolean $loadDefault Determines whether loading default values |
||
193 | * after entity model created. |
||
194 | * Notice! The [[\yii\mongodb\ActiveRecord]] and [[\yii\redis\ActiveRecord]] |
||
195 | * does not support loading default value. If you want to assign properties |
||
196 | * with default values, please define the `default` rule(s) for properties in |
||
197 | * `rules()` method and return them by yourself if you don't specified them in config param. |
||
198 | * @param boolean $skipIfSet whether existing value should be preserved. |
||
199 | * This will only set defaults for attributes that are `null`. |
||
200 | * @return [[$className]] new model created with specified configuration. |
||
201 | */ |
||
202 | 169 | public function create($className, $config = [], $loadDefault = true, $skipIfSet = true) |
|
217 | |||
218 | /** |
||
219 | * |
||
220 | * @param string $name |
||
221 | * @param array $config |
||
222 | * @return mixed |
||
223 | */ |
||
224 | 8 | public function createSubsidiary($name, $config) |
|
239 | } |
||
240 |
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.