Browse Source

dev 2020-09

Max F 5 years ago
parent
commit
646d0f8af7
3 changed files with 30 additions and 2 deletions
  1. 10 1
      src/ConsoleApp.md
  2. 17 1
      src/ConsoleApp.php
  3. 3 0
      src/Routing/Readme.md

+ 10 - 1
src/ConsoleApp.md

@@ -9,6 +9,8 @@ bin
 config
     config.php
 src
+	scripts
+    	my_test_script.php
     Models
     helpers
 vendor
@@ -51,4 +53,11 @@ $loader->setPsr4('MyApp\\', __DIR__ . '/../src');
 // APP ROUTE
 \KarmaFW\ConsoleApp::routeFromArgs($argv);
 
-```
+```
+
+
+## Exécution d'un script
+
+```
+$ php bin/app_console.php my_test_script [arguments]
+```

+ 17 - 1
src/ConsoleApp.php

@@ -40,7 +40,23 @@ class ConsoleApp extends App
 
 		$bin_path = array_shift($argv);
 
-		print_r($argv); // TODO: call defined class/method
+		if ( ($command = array_shift($argv)) === null ) {
+			// error: missing command parameter
+			throw new Exception("Command not specified", 1);
+		
+		} else {
+			$scripts_dir = APP_DIR . "/src/scripts";
+			$script_filepath = $scripts_dir . '/' . $command . '.php';
+
+			if (is_file($script_filepath)) {
+				require $script_filepath;
+
+			} else {
+				throw new Exception("Script file not found", 1);
+			}
+
+		}
+
 
 
 		if (defined('USE_HOOKS') && USE_HOOKS) {

+ 3 - 0
src/Routing/Readme.md

@@ -1,4 +1,7 @@
 
+
+Exemple de fichier de routes ( ./config/routes.php )
+
 ```
 use \KarmaFW\Routing\Router;