Browse Source

Merge branch 'master' of ssh://gogs.karmas.fr/KarmaSolutions/KarmaFW

Max F 4 years ago
parent
commit
303259d623
2 changed files with 20 additions and 51 deletions
  1. 0 51
      src/App.php
  2. 20 0
      src/App/Middlewares/CommandRouter.php

+ 0 - 51
src/App.php

@@ -210,55 +210,4 @@ class App
 		return $instances[$instance_name];
 	}
 
-
-	/*
-	public static function createOrmItem($table_name, $primary_key_values=[], $db=null)
-	{
-		return new SqlOrmModel($table_name, $primary_key_values, $db);
-	}
-	*/
-
-
-	/*
-	public static function routeCommand($argv)
-	{
-		if (! self::$booted) {
-			self::boot();
-		}
-
-		$arguments = array_slice($argv, 0);
-		$script_name = array_shift($arguments);
-		$command_name = array_shift($arguments);
-		$class_name = implode('', array_map('ucfirst', explode("_", $command_name)));
-
-		if (! empty($class_name)) {
-			$class_user = '\\App\\Commands\\' . $class_name;
-			$class_fw = '\\KarmaFW\\Commands\\' . $class_name;
-
-			if (class_exists($class_user)) {
-				$command = new $class_user;
-				$command->run($arguments);
-				exit(0);
-
-			} else if (class_exists($class_fw)) {
-				$command = new $class_fw;
-				$command->run($arguments);
-				exit(0);
-
-			} else {
-				echo "PHP Console script" . PHP_EOL . PHP_EOL; 
-				echo "Usage: php console.php <command> [arguments]" . PHP_EOL . PHP_EOL;
-				echo "Warning: invalid command" . PHP_EOL;
-			}
-
-		} else {
-			echo "PHP Console script" . PHP_EOL . PHP_EOL; 
-			echo "Usage: php console.php <command> [arguments]" . PHP_EOL . PHP_EOL;
-			echo "Warning: missing command" . PHP_EOL;
-		}
-
-		exit(1);
-	}
-	*/
-
 }

+ 20 - 0
src/App/Middlewares/CommandRouter.php

@@ -61,6 +61,26 @@ class CommandRouter
 
 		} else {
 			$this->usage("missing command");
+
+			
+			$user_commands_files = glob(APP_DIR . '/src/Commands/*.php');
+			$user_commands = array_map(function ($platform_path) {
+				$path_infos = pathinfo($platform_path);
+				return $path_infos['filename'];
+			}, $user_commands_files);
+
+			echo PHP_EOL . "Available user commands :" . PHP_EOL;
+			echo ' - ' . implode(PHP_EOL . ' - ', $user_commands) . PHP_EOL;
+
+
+			$karmafw_commands_files = glob(APP_DIR . '/vendor/karmasolutions/karmafw/src/Commands/*.php');
+			$karmafw_commands = array_map(function ($platform_path) {
+				$path_infos = pathinfo($platform_path);
+				return $path_infos['filename'];
+			}, $karmafw_commands_files);
+
+			echo PHP_EOL . "Available karmafw commands :" . PHP_EOL;
+			echo ' - ' . implode(PHP_EOL . ' - ', $karmafw_commands) . PHP_EOL;
 		}
 
 		return $response;