1 | <?php namespace Limoncello\Data\Seeds; |
||
32 | trait SeedTrait |
||
33 | { |
||
34 | /** |
||
35 | * @var ContainerInterface |
||
36 | */ |
||
37 | private $container; |
||
38 | |||
39 | /** |
||
40 | * @inheritdoc |
||
41 | */ |
||
42 | 1 | public function init(ContainerInterface $container): SeedInterface |
|
51 | |||
52 | /** |
||
53 | * @return ContainerInterface |
||
54 | */ |
||
55 | 1 | protected function getContainer(): ContainerInterface |
|
59 | |||
60 | /** |
||
61 | * @return Connection |
||
62 | */ |
||
63 | 1 | protected function getConnection(): Connection |
|
69 | |||
70 | /** |
||
71 | * @return ModelSchemaInfoInterface |
||
72 | */ |
||
73 | 1 | protected function getModelSchemas(): ModelSchemaInfoInterface |
|
74 | { |
||
75 | 1 | assert($this->getContainer()->has(ModelSchemaInfoInterface::class) === true); |
|
76 | |||
77 | 1 | return $this->getContainer()->get(ModelSchemaInfoInterface::class); |
|
78 | } |
||
79 | |||
80 | /** |
||
81 | * @return AbstractSchemaManager |
||
82 | */ |
||
83 | 1 | protected function getSchemaManager(): AbstractSchemaManager |
|
87 | |||
88 | /** |
||
89 | * @return string |
||
90 | */ |
||
91 | 1 | protected function now(): string |
|
98 | |||
99 | /** |
||
100 | * @param string $tableName |
||
101 | * @param null|int $limit |
||
102 | * |
||
103 | * @return array |
||
104 | */ |
||
105 | 1 | protected function readTableData(string $tableName, int $limit = null): array |
|
120 | |||
121 | /** |
||
122 | * @param string $modelClass |
||
123 | * @param null|int $limit |
||
124 | * |
||
125 | * @return array |
||
126 | */ |
||
127 | 1 | protected function readModelsData(string $modelClass, int $limit = null): array |
|
131 | |||
132 | /** |
||
133 | * @param int $records |
||
134 | * @param string $tableName |
||
135 | * @param Closure $dataClosure |
||
136 | * |
||
137 | * @return void |
||
138 | */ |
||
139 | 1 | protected function seedTableData(int $records, $tableName, Closure $dataClosure): void |
|
146 | |||
147 | /** |
||
148 | * @param int $records |
||
149 | * @param string $modelClass |
||
150 | * @param Closure $dataClosure |
||
151 | * |
||
152 | * @return void |
||
153 | */ |
||
154 | 1 | protected function seedModelsData(int $records, string $modelClass, Closure $dataClosure): void |
|
158 | |||
159 | /** |
||
160 | * @param string $tableName |
||
161 | * @param array $data |
||
162 | * |
||
163 | * @return string|null |
||
164 | */ |
||
165 | 1 | protected function seedRowData(string $tableName, array $data): ?string |
|
169 | |||
170 | /** |
||
171 | * @param string $modelClass |
||
172 | * @param array $data |
||
173 | * |
||
174 | * @return string|null |
||
175 | */ |
||
176 | 1 | protected function seedModelData(string $modelClass, array $data): ?string |
|
180 | |||
181 | /** |
||
182 | * @return string |
||
183 | */ |
||
184 | 1 | protected function getLastInsertId(): string |
|
188 | |||
189 | /** |
||
190 | * @param string $tableName |
||
191 | * @param Connection $connection |
||
192 | * @param array $data |
||
193 | * |
||
194 | * @return string|null |
||
195 | */ |
||
196 | 1 | private function insertRow($tableName, Connection $connection, array $data): ?string |
|
214 | } |
||
215 |