@@ -106,8 +106,8 @@ public function run(){
106
106
$ safeEnv = $ this ->env ;
107
107
unset($ safeEnv ['Strategy ' ]);
108
108
109
- require $ this ->env [ ' strategy_dir ' ]. $ class. ' / ' . $ class . ' .php ' ;
110
- $ this ->Strategy = new $ class ($ strategy , $ safeEnv );
109
+ $ actualClass = $ this ->requireStrategy ( $ class) ;
110
+ $ this ->Strategy = new $ actualClass ($ strategy , $ safeEnv );
111
111
$ this ->Strategy ->callAction ($ this ->env ['params ' ]['action ' ]);
112
112
}
113
113
else {
@@ -258,6 +258,33 @@ public function callback(){
258
258
echo "</pre> " ;
259
259
}
260
260
261
+ /**
262
+ * Loads a strategy, firstly check if the strategy's class already exists, especially for users of Composer;
263
+ * If it isn't, attempts to load it from $this->env['strategy_dir']
264
+ *
265
+ * @param string $strategy Name of a strategy
266
+ * @return string Class name of the strategy, usually StrategyStrategy
267
+ */
268
+ private function requireStrategy ($ strategy ){
269
+ if (!class_exists ($ strategy .'Strategy ' )){
270
+ if (file_exists ($ this ->env ['strategy_dir ' ].$ strategy .'/ ' .$ strategy .'Strategy.php ' )){
271
+ require $ this ->env ['strategy_dir ' ].$ strategy .'/ ' .$ strategy .'Strategy.php ' ;
272
+ return $ strategy .'Strategy ' ;
273
+ }
274
+
275
+ // Deprecated support for strategies without Strategy postfix as class name or filename
276
+ elseif (file_exists ($ this ->env ['strategy_dir ' ].$ strategy .'/ ' .$ strategy .'.php ' )){
277
+ require $ this ->env ['strategy_dir ' ].$ strategy .'/ ' .$ strategy .'.php ' ;
278
+ return $ strategy ;
279
+ }
280
+
281
+ else {
282
+ trigger_error ('Strategy class file ( ' .$ this ->env ['strategy_dir ' ].$ strategy .'/ ' .$ strategy .'Strategy.php ' .') is missing ' , E_USER_ERROR );
283
+ exit ();
284
+ }
285
+ }
286
+ return $ strategy .'Strategy ' ;
287
+ }
261
288
262
289
/**
263
290
* Prints out variable with <pre> tags
0 commit comments