| 
									
										
										
										
											2019-10-17 17:22:43 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace App\Console\Commands; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-19 21:44:26 -05:00
										 |  |  | use App\Console\Commands\Traits\CompletesConfigArgument; | 
					
						
							| 
									
										
										
										
											2019-10-17 17:22:43 +00:00
										 |  |  | use App\Console\LnmsCommand; | 
					
						
							|  |  |  | use LibreNMS\Config; | 
					
						
							|  |  |  | use Symfony\Component\Console\Input\InputArgument; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class GetConfigCommand extends LnmsCommand | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-04-19 21:44:26 -05:00
										 |  |  |     use CompletesConfigArgument; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-17 17:22:43 +00:00
										 |  |  |     protected $name = 'config:get'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Create a new command instance. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return void | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function __construct() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         parent::__construct(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->addArgument('setting', InputArgument::OPTIONAL); | 
					
						
							|  |  |  |         $this->addOption('json'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Execute the console command. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return mixed | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function handle() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $setting = $this->argument('setting'); | 
					
						
							|  |  |  |         if ($this->option('json')) { | 
					
						
							|  |  |  |             $this->line($setting ? json_encode(Config::get($setting)) : Config::toJson()); | 
					
						
							| 
									
										
										
										
											2020-09-21 14:54:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-17 17:22:43 +00:00
										 |  |  |             return 0; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-21 14:54:51 +02:00
										 |  |  |         if (! $setting) { | 
					
						
							| 
									
										
										
										
											2019-10-17 17:22:43 +00:00
										 |  |  |             throw new \RuntimeException('Not enough arguments (missing: "setting").'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (Config::has($setting)) { | 
					
						
							|  |  |  |             $output = Config::get($setting); | 
					
						
							| 
									
										
										
										
											2020-09-21 14:54:51 +02:00
										 |  |  |             if (! is_string($output)) { | 
					
						
							| 
									
										
										
										
											2021-03-30 00:43:05 +02:00
										 |  |  |                 $output = var_export($output, true); | 
					
						
							| 
									
										
										
										
											2019-10-17 17:22:43 +00:00
										 |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $this->line($output); | 
					
						
							| 
									
										
										
										
											2020-09-21 14:54:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-17 17:22:43 +00:00
										 |  |  |             return 0; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-09-21 14:54:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-17 17:22:43 +00:00
										 |  |  |         return 1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |