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