소스 검색

dev 2020-10

Max F 5 년 전
부모
커밋
d94fddc395
6개의 변경된 파일89개의 추가작업 그리고 6개의 파일을 삭제
  1. 0 1
      bin/console.php
  2. 1 3
      src/App.php
  3. 17 1
      src/App/Middlewares/CommandRouter.php
  4. 42 0
      src/Commands/HelpCommand.php
  5. 29 0
      src/Commands/TestCommand.php
  6. 0 1
      www/index.php

+ 0 - 1
bin/console.php

@@ -31,7 +31,6 @@ $app = new App([
     //new KarmaMiddlewares\ForceHttps,
     //new KarmaMiddlewares\GzipEncoding,
     //new KarmaMiddlewares\MaintenanceMode,
-    new KarmaMiddlewares\LoadHelpers,
     new KarmaMiddlewares\SessionHandler,
     //'handle404',
     //'Authentification',

+ 1 - 3
src/App.php

@@ -54,7 +54,7 @@ class App
 			}
 			exit;
 		}
-		
+
 	}
 
 
@@ -235,13 +235,11 @@ class App
 
 	protected static function loadHelpersDirs()
 	{
-		//echo 'avant';
 		if (is_array(self::$helpers_dirs)) {
 			foreach (self::$helpers_dirs as $helpers_dir) {
 				self::loadHelpers($helpers_dir);
 			}
 		}
-		//pre('apres');
 	}
 
 	protected static function loadHelpers($dir)

+ 17 - 1
src/App/Middlewares/CommandRouter.php

@@ -23,10 +23,14 @@ class CommandRouter
 	{
 		$arguments = array_slice($this->argv, 0);
 		$script_name = array_shift($arguments);
+
 		$command_name = array_shift($arguments);
+		if (in_array($command_name, ['-h', '--help', '-help'])) {
+			$command_name = 'help';
+		}
+		
 		$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;
@@ -36,11 +40,23 @@ class CommandRouter
 				$command = new $class_user($request, $response);
 				$command->execute($arguments);
 
+			} else if (class_exists($class_user . "Command")) {
+				// User command
+				$class_user .= "Command";
+				$command = new $class_user($request, $response);
+				$command->execute($arguments);
+
 			} else if (class_exists($class_fw)) {
 				// Framework command
 				$command = new $class_fw($request, $response);
 				$command->execute($arguments);
 
+			} else if (class_exists($class_fw . "Command")) {
+				// Framework command
+				$class_fw .= "Command";
+				$command = new $class_fw($request, $response);
+				$command->execute($arguments);
+
 			} else {
 				$this->usage("invalid command : " . $command_name);
 			}

+ 42 - 0
src/Commands/HelpCommand.php

@@ -0,0 +1,42 @@
+<?php
+
+namespace KarmaFW\Commands;
+
+//use \KarmaFW\App;
+use \KarmaFW\App\Request;
+use \KarmaFW\App\Response;
+
+
+class HelpCommand
+{
+	protected $request;
+	protected $response;
+
+
+	public function __construct(Request $request, Response $response) 
+	{
+		$this->request = $request;
+		$this->response = $response;
+	}
+
+
+	public function execute($arguments=[]) 
+	{
+		echo "PHP Console script" . PHP_EOL;
+		echo PHP_EOL;
+		echo "Usage: php console.php <command> [arguments]" . PHP_EOL;
+		echo PHP_EOL;
+		echo "Example: php console.php test param1 param2" . PHP_EOL;
+		echo PHP_EOL;
+		echo "Example: php console.php MonScript param1 param2" . PHP_EOL;
+		echo "Example: php console.php mon_script param1 param2" . PHP_EOL;
+		echo PHP_EOL;
+		echo " => execute \\App\\Commands\\MonScript.php" . PHP_EOL;
+		echo "         or \\App\\Commands\\MonScriptCommand.php" . PHP_EOL;
+		echo "         or \\KarmaFW\\Commands\\MonScript.php" . PHP_EOL;
+		echo "         or \\KarmaFW\\Commands\\MonScriptCommand.php" . PHP_EOL;
+		echo PHP_EOL;
+		
+	}
+	
+}

+ 29 - 0
src/Commands/TestCommand.php

@@ -0,0 +1,29 @@
+<?php
+
+namespace KarmaFW\Commands;
+
+//use \KarmaFW\App;
+use \KarmaFW\App\Request;
+use \KarmaFW\App\Response;
+
+
+class TestCommand
+{
+	protected $request;
+	protected $response;
+
+
+	public function __construct(Request $request, Response $response) 
+	{
+		$this->request = $request;
+		$this->response = $response;
+	}
+
+
+	public function execute($arguments=[]) 
+	{
+		print_r($arguments);
+		
+	}
+	
+}

+ 0 - 1
www/index.php

@@ -30,7 +30,6 @@ $app = new App([
     new KarmaMiddlewares\ForceHttps,
     //new KarmaMiddlewares\GzipEncoding,
     //new KarmaMiddlewares\MaintenanceMode,
-    new KarmaMiddlewares\LoadHelpers,
     new KarmaMiddlewares\SessionHandler,
     //'handle404',
     //'Authentification',