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