-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathControlsWorkflow.php
128 lines (120 loc) · 3.3 KB
/
ControlsWorkflow.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/**
* @link https://github.com/illuminatech
* @copyright Copyright (c) 2022 Illuminatech
* @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php)
*/
namespace Illuminatech\EnumSeeder;
/**
* ControlsWorkflow defines common methods, which controls the seeding workflow.
* Its methods designed to be overridden at particular seeder class.
*
* @author Paul Klimov <[email protected]>
* @since 1.0
*/
trait ControlsWorkflow
{
/**
* Defines the rows, which related database entity should be synchronized with.
*
* @return array[] list of rows data.
*/
abstract protected function rows(): array;
/**
* Defines attribute values, which should be applied as defaults to each created row.
* The particular row definition may override values defined by this method.
* For example:
*
* ```
* [
* 'created_at' => now(),
* ]
* ```
*
* @return array<string, mixed> attributes specification.
*/
protected function shouldCreateWith(): array
{
return [];
}
/**
* Defines whether rows, which exist in the database, but are missing at {@see rows()} specification, should
* be deleted from database or not.
*
* @return bool whether to delete obsolete rows from database.
*/
protected function shouldDeleteObsolete(): bool
{
return false;
}
/**
* Defines the attribute values, which should be applied to the rows, which exist in the database,
* but are missing at {@see rows()} specification.
*
* For example:
*
* ```
* [
* 'deleted_at' => now(),
* ]
* ```
*
* > Note: if {@see shouldDeleteObsolete()} returns `true`, this method will be ignored.
*
* @return array<string, mixed> attributes specification.
*/
protected function shouldUpdateObsoleteWith(): array
{
return [];
}
/**
* Defines whether rows, which exist in the database, should be updated with actual {@see rows()} values or not.
*
* > Note: if {@see shouldUpdateExistingOnly()} returns not empty value, this method will be ignored.
*
* @return bool whether to always update existing rows.
*/
protected function shouldUpdateExisting(): bool
{
return true;
}
/**
* Defines the list of attributes, which should be updated for the rows, which already exist in the database.
*
* For example:
*
* ```
* [
* 'is_active',
* 'allow_purchase',
* ]
* ```
*
* > Note: this method takes precedence over {@see shouldUpdateExisting()}.
*
* @return array|string[] attributes names.
*/
protected function shouldUpdateExistingOnly(): array
{
return [];
}
/**
* Defines attribute values, which should be applied as defaults to each updated row.
* The particular row definition may override values defined by this method.
* For example:
*
* ```
* [
* 'updated_at' => now(),
* ]
* ```
*
* > Note: this method takes precedence over {@see shouldUpdateExisting()}.
*
* @return array<string, mixed> attribute values.
*/
protected function shouldUpdateExistingWith(): array
{
return [];
}
}