-
Notifications
You must be signed in to change notification settings - Fork 0
/
Seed.php
47 lines (43 loc) · 1.2 KB
/
Seed.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/**
* OriginPHP Framework
* Copyright 2018 - 2021 Jamiel Sharief.
*
* Licensed under The MIT License
* The above copyright notice and this permission notice shall be included in all copies or substantial
* portions of the Software.
*
* @copyright Copyright (c) Jamiel Sharief
* @link https://www.originphp.com
* @license https://opensource.org/licenses/mit-license.php MIT License
*/
declare(strict_types = 1);
namespace Origin\Model;
use Origin\Core\HookTrait;
class Seed
{
use HookTrait;
public function __construct()
{
$this->executeHook('initialize');
}
/**
* Creates the SQL statements for inserting
*
* @param \Origin\Model\Connection $connection
* @return array
*/
public function insertSql(Connection $connection): array
{
$out = [];
$properties = get_object_vars($this);
foreach (array_keys($properties) as $table) {
foreach ($this->$table as $record) {
$builder = $connection->queryBuilder($table);
$sql = $builder->insert($record)->write();
$out[] = [$sql,$builder->getValues()];
}
}
return $out;
}
}