@@ -79,6 +79,8 @@ public function run(Input\InputInterface $input = null, Output\OutputInterface $
7979
8080 $ this ->_loadPlugins ();
8181
82+ $ this ->_loadExtraCommands ();
83+
8284 parent ::run ($ this ->_input , $ this ->_output );
8385 }
8486
@@ -204,6 +206,51 @@ public function getPlugins()
204206 return $ this ->_plugins ;
205207 }
206208
209+ /**
210+ * Loads extra commands from the ~/.joomlatools/console/commands/ folder
211+ *
212+ * Each PHP file in the folder is included and if the class in the file extends the base Symfony command
213+ * it's instantiated and added to the app.
214+ *
215+ * @return void
216+ */
217+ protected function _loadExtraCommands ()
218+ {
219+ $ path = $ this ->getConsoleHome ().'/commands ' ;
220+
221+ if (\is_dir ($ path ))
222+ {
223+ $ iterator = new \DirectoryIterator ($ path );
224+
225+ foreach ($ iterator as $ file )
226+ {
227+ if ($ file ->getExtension () == 'php ' )
228+ {
229+ require $ file ->getPathname ();
230+
231+ $ className = $ file ->getBasename ('.php ' );
232+
233+ if (\class_exists ($ className ))
234+ {
235+ $ reflection = new \ReflectionClass ($ className );
236+
237+ if (!$ reflection ->isSubclassOf ('\Symfony\Component\Console\Command\Command ' )) {
238+ continue ;
239+ }
240+
241+ $ command = new $ className ();
242+
243+ if (!$ command instanceof \Symfony \Component \Console \Command \Command) {
244+ continue ;
245+ }
246+
247+ $ this ->add ($ command );
248+ }
249+ }
250+ }
251+ }
252+ }
253+
207254 /**
208255 * Set up environment
209256 */
@@ -227,7 +274,7 @@ protected function _setup()
227274
228275 if (file_exists ($ old ))
229276 {
230- $ this ->_output ->writeln ('<comment>Moving legacy plugin directory to ~/.joomlatools- console/plugins.</comment> ' );
277+ $ this ->_output ->writeln ('<comment>Moving legacy plugin directory to ~/.joomlatools/ console/plugins.</comment> ' );
231278
232279 $ cmd = sprintf ('mv %s %s ' , escapeshellarg ($ old ), escapeshellarg ($ this ->getPluginPath ()));
233280 exec ($ cmd );
0 commit comments