@@ -56,21 +56,12 @@ public function getLogger()
56
56
57
57
/**
58
58
* @param string $componentName
59
+ * @return Processor
59
60
*/
60
61
public function addComponent ($ componentName )
61
62
{
62
- try {
63
- if (!$ this ->isValidComponent ($ componentName )) {
64
- throw new ComponentException (
65
- sprintf ('%s component does not appear to be a valid component. ' , $ componentName )
66
- );
67
- }
68
-
69
- $ componentClass = $ this ->configInterface ->getComponentByName ($ componentName );
70
- $ this ->components [$ componentName ] = new $ componentClass ($ this ->log );
71
- } catch (ComponentException $ e ) {
72
- throw $ e ;
73
- }
63
+ $ this ->components [$ componentName ] = $ componentName ;
64
+ return $ this ;
74
65
}
75
66
76
67
/**
@@ -107,83 +98,123 @@ public function run()
107
98
// If the components list is empty, then the user would want to run all components in the master.yaml
108
99
if (empty ($ this ->components )) {
109
100
110
- try {
101
+ $ this ->runAllComponents ();
102
+ return ;
103
+ }
111
104
112
- // Read master yaml
113
- $ masterPath = BP . '/app/etc/master.yaml ' ;
114
- if (!file_exists ($ masterPath )) {
115
- throw new ComponentException ("Master YAML does not exist. Please create one in $ masterPath " );
116
- }
117
- $ this ->log ->logComment (sprintf ("Found Master YAML " ));
118
- $ yamlContents = file_get_contents ($ masterPath );
119
- $ yaml = new Parser ();
120
- $ master = $ yaml ->parse ($ yamlContents );
105
+ $ this ->runIndividualComponents ();
106
+ }
121
107
122
- //print_r($master);
108
+ private function runIndividualComponents ()
109
+ {
110
+ try {
123
111
124
- // Validate master yaml
125
- $ this ->validateMasterYaml ( $ master );
112
+ // Get the master yaml
113
+ $ master = $ this ->getMasterYaml ( );
126
114
127
- // Loop through components and run them individually in the master.yaml order
128
- foreach ($ master as $ componentAlias => $ componentConfig ) {
115
+ // Loop through the components
116
+ foreach ($ this -> components as $ componentAlias ) {
129
117
130
- $ this ->log ->logComment (sprintf ("Loading component %s " , $ componentAlias ));
118
+ // Get the config for the component from the master yaml array
119
+ $ masterConfig = $ master [$ componentAlias ];
131
120
132
- $ componentClass = $ this ->configInterface ->getComponentByName ($ componentAlias );
121
+ // Run that component
122
+ $ this ->runComponent ($ componentAlias , $ masterConfig );
123
+ }
124
+ } catch (ComponentException $ e ) {
125
+ $ this ->log ->logError ($ e ->getMessage ());
126
+ }
127
+ }
133
128
134
- /* @var ComponentAbstract $component */
135
- $ component = $ this ->objectManager ->create ($ componentClass );
136
- foreach ($ componentConfig ['sources ' ] as $ source ) {
137
- $ component ->setSource ($ source )->process ();
138
- }
129
+ private function runAllComponents ()
130
+ {
131
+ try {
139
132
140
- // Check if there are environment specific nodes placed
141
- if (! isset ( $ componentConfig [ ' env ' ])) {
133
+ // Get the master yaml
134
+ $ master = $ this -> getMasterYaml ();
142
135
143
- // If not, continue to next component
144
- $ this ->log ->logComment (
145
- sprintf ("No environment node for '%s' component " , $ component ->getComponentName ())
146
- );
147
- continue ;
148
- }
136
+ // Loop through components and run them individually in the master.yaml order
137
+ foreach ($ master as $ componentAlias => $ componentConfig ) {
149
138
150
- // Check if there is a node for this particular environment
151
- if (!isset ($ componentConfig ['env ' ][$ this ->getEnvironment ()])) {
152
-
153
- // If not, continue to next component
154
- $ this ->log ->logComment (
155
- sprintf (
156
- "No '%s' environment specific node for '%s' component " ,
157
- $ this ->getEnvironment (),
158
- $ component ->getComponentName ()
159
- )
160
- );
161
- continue ;
162
- }
139
+ // Run the component in question
140
+ $ this ->runComponent ($ componentAlias , $ componentConfig );
141
+ }
142
+ } catch (ComponentException $ e ) {
143
+ $ this ->log ->logError ($ e ->getMessage ());
144
+ }
145
+ }
163
146
164
- // Check if there are sources for the environment
165
- if (!isset ($ componentConfig ['env ' ][$ this ->getEnvironment ()]['sources ' ])) {
166
-
167
- // If not continue
168
- $ this ->log ->logComment (
169
- sprintf (
170
- "No '%s' environment specific sources for '%s' component " ,
171
- $ this ->getEnvironment (),
172
- $ component ->getComponentName ()
173
- )
174
- );
175
- continue ;
176
- }
147
+ private function runComponent ($ componentAlias , $ componentConfig )
148
+ {
149
+ $ this ->log ->logComment (sprintf ("Loading component %s " , $ componentAlias ));
177
150
151
+ $ componentClass = $ this ->configInterface ->getComponentByName ($ componentAlias );
178
152
179
- }
153
+ /* @var ComponentAbstract $component */
154
+ $ component = $ this ->objectManager ->create ($ componentClass );
155
+ foreach ($ componentConfig ['sources ' ] as $ source ) {
156
+ $ component ->setSource ($ source )->process ();
157
+ }
180
158
159
+ // Check if there are environment specific nodes placed
160
+ if (!isset ($ componentConfig ['env ' ])) {
181
161
182
- } catch (ComponentException $ e ) {
183
- $ this ->log ->logError ($ e ->getMessage ());
184
- }
162
+ // If not, continue to next component
163
+ $ this ->log ->logComment (
164
+ sprintf ("No environment node for '%s' component " , $ component ->getComponentName ())
165
+ );
166
+ return ;
167
+ }
185
168
169
+ // Check if there is a node for this particular environment
170
+ if (!isset ($ componentConfig ['env ' ][$ this ->getEnvironment ()])) {
171
+
172
+ // If not, continue to next component
173
+ $ this ->log ->logComment (
174
+ sprintf (
175
+ "No '%s' environment specific node for '%s' component " ,
176
+ $ this ->getEnvironment (),
177
+ $ component ->getComponentName ()
178
+ )
179
+ );
180
+ return ;
186
181
}
182
+
183
+ // Check if there are sources for the environment
184
+ if (!isset ($ componentConfig ['env ' ][$ this ->getEnvironment ()]['sources ' ])) {
185
+
186
+ // If not continue
187
+ $ this ->log ->logComment (
188
+ sprintf (
189
+ "No '%s' environment specific sources for '%s' component " ,
190
+ $ this ->getEnvironment (),
191
+ $ component ->getComponentName ()
192
+ )
193
+ );
194
+ return ;
195
+ }
196
+
197
+ }
198
+
199
+ /**
200
+ * @return array
201
+ */
202
+ private function getMasterYaml ()
203
+ {
204
+ // Read master yaml
205
+ $ masterPath = BP . '/app/etc/master.yaml ' ;
206
+ if (!file_exists ($ masterPath )) {
207
+ throw new ComponentException ("Master YAML does not exist. Please create one in $ masterPath " );
208
+ }
209
+ $ this ->log ->logComment (sprintf ("Found Master YAML " ));
210
+ $ yamlContents = file_get_contents ($ masterPath );
211
+ $ yaml = new Parser ();
212
+ $ master = $ yaml ->parse ($ yamlContents );
213
+
214
+ // Validate master yaml
215
+ $ this ->validateMasterYaml ($ master );
216
+
217
+ return $ master ;
187
218
}
188
219
189
220
/**
@@ -198,6 +229,12 @@ private function isValidComponent($componentName)
198
229
$ this ->log ->logQuestion (sprintf ("Does the %s component exist? " , $ componentName ));
199
230
}
200
231
$ componentClass = $ this ->configInterface ->getComponentByName ($ componentName );
232
+
233
+ if (!$ componentClass ) {
234
+ $ this ->log ->logError (sprintf ("The %s component has no class name. " , $ componentName ));
235
+ return false ;
236
+ }
237
+
201
238
$ this ->log ->logComment (sprintf ("The %s component has %s class name. " , $ componentName , $ componentClass ));
202
239
$ component = $ this ->objectManager ->create ($ componentClass );
203
240
if ($ component instanceof ComponentAbstract) {
0 commit comments