1 | <?php |
||||
2 | |||||
3 | namespace App\Console\Commands; |
||||
4 | |||||
5 | use App\Console\Commands\Traits\CompletesConfigArgument; |
||||
6 | use App\Console\LnmsCommand; |
||||
7 | use LibreNMS\Config; |
||||
8 | use LibreNMS\Util\OS; |
||||
9 | use Symfony\Component\Console\Input\InputArgument; |
||||
10 | |||||
11 | class GetConfigCommand extends LnmsCommand |
||||
12 | { |
||||
13 | use CompletesConfigArgument; |
||||
14 | |||||
15 | protected $name = 'config:get'; |
||||
16 | |||||
17 | /** |
||||
18 | * Create a new command instance. |
||||
19 | * |
||||
20 | * @return void |
||||
21 | */ |
||||
22 | public function __construct() |
||||
23 | { |
||||
24 | parent::__construct(); |
||||
25 | |||||
26 | $this->addArgument('setting', InputArgument::OPTIONAL); |
||||
27 | $this->addOption('dump'); |
||||
28 | } |
||||
29 | |||||
30 | /** |
||||
31 | * Execute the console command. |
||||
32 | * |
||||
33 | * @return mixed |
||||
34 | */ |
||||
35 | public function handle() |
||||
36 | { |
||||
37 | $setting = $this->argument('setting'); |
||||
38 | |||||
39 | // load os definition if requested, and remove special definition_loaded key |
||||
40 | if (preg_match('/^os\.(?<os>[^.]+)/', $setting, $matches)) { |
||||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
41 | OS::loadDefinition($matches['os']); |
||||
42 | Config::forget("os.{$matches['os']}.definition_loaded"); |
||||
43 | } |
||||
44 | |||||
45 | if ($this->option('dump')) { |
||||
46 | $this->line($setting ? json_encode(Config::get($setting)) : Config::toJson()); |
||||
0 ignored issues
–
show
It seems like
$setting can also be of type string[] ; however, parameter $key of LibreNMS\Config::get() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
47 | |||||
48 | return 0; |
||||
49 | } |
||||
50 | |||||
51 | if (! $setting) { |
||||
52 | throw new \RuntimeException('Not enough arguments (missing: "setting").'); |
||||
53 | } |
||||
54 | |||||
55 | if (Config::has($setting)) { |
||||
0 ignored issues
–
show
It seems like
$setting can also be of type string[] ; however, parameter $key of LibreNMS\Config::has() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
56 | $output = Config::get($setting); |
||||
57 | if (! is_string($output)) { |
||||
58 | $output = json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
||||
59 | } |
||||
60 | |||||
61 | $this->line($output); |
||||
62 | |||||
63 | return 0; |
||||
64 | } |
||||
65 | |||||
66 | return 1; |
||||
67 | } |
||||
68 | } |
||||
69 |