50 lines
		
	
	
		
			877 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			877 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| 
 | |
| namespace kernel\console;
 | |
| 
 | |
| 
 | |
| use kernel\App;
 | |
| use Phroute\Phroute\Dispatcher;
 | |
| 
 | |
| class ConsoleApp extends App
 | |
| {
 | |
|     public array $argv;
 | |
| 
 | |
|     public function run(): void
 | |
|     {
 | |
|         if(!$rout = $this->getRout()){
 | |
|             echo "Not found \n";
 | |
|             exit();
 | |
|         }
 | |
|         $dispatcher = new Dispatcher(App::$collector->getData());
 | |
|         $response = $dispatcher->dispatch('GET', $rout);
 | |
|         echo $response;
 | |
|     }
 | |
| 
 | |
|     public function setArgv($argv): static
 | |
|     {
 | |
|         $this->argv = $argv;
 | |
|         return $this;
 | |
|     }
 | |
| 
 | |
|     public function setRouting(): void
 | |
|     {
 | |
|         include CONSOLE_DIR . "/routs/cli.php";
 | |
|     }
 | |
| 
 | |
|     private function getRout()
 | |
|     {
 | |
|         if(isset($this->argv[1])){
 | |
|             return $this->argv[1];
 | |
|         }
 | |
|         return null;
 | |
|     }
 | |
| 
 | |
|     public static function create(): ConsoleApp
 | |
|     {
 | |
|         return new self();
 | |
|     }
 | |
| 
 | |
| 
 | |
| } |