1 | <?php |
||
31 | class AlterInstructions |
||
32 | { |
||
33 | |||
34 | /** |
||
35 | * @var string[] The SQL snippets to be added to an ALTER instruction |
||
36 | */ |
||
37 | protected $alterParts = []; |
||
38 | |||
39 | /** |
||
40 | * @var mixed[] The SQL commands to be executed after the ALTER instruction |
||
41 | */ |
||
42 | protected $postSteps = []; |
||
43 | |||
44 | /** |
||
45 | * Constructor |
||
46 | * |
||
47 | * @param array $alterParts SQL snipets to be added to a single ALTER instruction per table |
||
48 | * @param array $postSteps SQL commands to be executed after the ALTER instruction |
||
49 | */ |
||
50 | public function __construct(array $alterParts = [], array $postSteps = []) |
||
55 | |||
56 | /** |
||
57 | * Adds another parst for the single ALTER instruction |
||
58 | * |
||
59 | * @param string $part The SQL snipped to add as part of the ALTER instruction |
||
60 | * @return void |
||
61 | */ |
||
62 | public function addAlter($part) |
||
66 | |||
67 | /** |
||
68 | * Adds a SQL command to be eecuted after the ALTER instruction. |
||
69 | * This method allows a callable, with will get an empty array as state |
||
70 | * for the first time and will pass the return value of the callable to |
||
71 | * the next callable, if present. |
||
72 | * |
||
73 | * This allows to keep a single state across callbacks. |
||
74 | * |
||
75 | * @param string|callable $sql The SQL to run after, or a callable to execute |
||
76 | * @return void |
||
77 | */ |
||
78 | public function addPostStep($sql) |
||
82 | |||
83 | /** |
||
84 | * Returns the alter SQL snippets |
||
85 | * |
||
86 | * @return string[] |
||
87 | */ |
||
88 | public function getAlterParts() |
||
92 | |||
93 | /** |
||
94 | * Returns the SQL commands to run after the ALTER instrunction |
||
95 | * |
||
96 | * @return mixed[] |
||
97 | */ |
||
98 | public function getPostSteps() |
||
102 | |||
103 | /** |
||
104 | * Merges another AlterInstructions object to this one |
||
105 | * |
||
106 | * @param AlterInstructions $other The other collection of instructions to merge in |
||
107 | * @return void |
||
108 | */ |
||
109 | public function merge(AlterInstructions $other) |
||
114 | |||
115 | /** |
||
116 | * Executes the ALTER instruction and all of the post steps. |
||
117 | * |
||
118 | * @param string $alterTemplate The template for the alter instruction |
||
119 | * @param callable $executor The function to be used to execute all instructions |
||
120 | * @return void |
||
121 | */ |
||
122 | public function execute($alterTemplate, callable $executor) |
||
140 | } |
||
141 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.