@@ 70-92 (lines=23) @@ | ||
67 | * @throws InvalidConfigException |
|
68 | * @return BaseModel |
|
69 | */ |
|
70 | public function create($config = [], string $toScenario = null): BaseModel |
|
71 | { |
|
72 | ||
73 | // Treat records as known data and set via config |
|
74 | if ($config instanceof Record) { |
|
75 | return $this->createFromRecord($config, $toScenario); |
|
76 | } |
|
77 | ||
78 | // Force Array |
|
79 | if (!is_array($config)) { |
|
80 | $config = ArrayHelper::toArray($config, [], false); |
|
81 | } |
|
82 | ||
83 | // Set the model class |
|
84 | $config['class'] = static::modelClass(); |
|
85 | ||
86 | return ModelHelper::create( |
|
87 | $config, |
|
88 | static::modelClassInstance(), |
|
89 | $toScenario |
|
90 | ); |
|
91 | ||
92 | } |
|
93 | ||
94 | /** |
|
95 | * @param Record $record |
@@ 68-91 (lines=24) @@ | ||
65 | * @throws InvalidConfigException |
|
66 | * @return BaseObject |
|
67 | */ |
|
68 | public function create($config = []): BaseObject |
|
69 | { |
|
70 | ||
71 | // Treat records as known data and set via config |
|
72 | if ($config instanceof Record) { |
|
73 | return $this->createFromRecord($config); |
|
74 | } |
|
75 | ||
76 | // Force Array |
|
77 | if (!is_array($config)) { |
|
78 | $config = ArrayHelper::toArray($config, [], false); |
|
79 | } |
|
80 | ||
81 | // Auto-set the class |
|
82 | if ($class = static::objectClass()) { |
|
83 | $config['class'] = $class; |
|
84 | } |
|
85 | ||
86 | return ObjectHelper::create( |
|
87 | $config, |
|
88 | static::objectClassInstance() |
|
89 | ); |
|
90 | ||
91 | } |
|
92 | ||
93 | /** |
|
94 | * @param Record $record |