0
0
Fork 0
mirror of https://github.com/nextcloud/server.git synced 2025-04-30 20:10:40 +00:00
nextcloud_server/core/Command/Config/System/GetConfig.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

81 lines
2.2 KiB
PHP
Raw Permalink Normal View History

2015-05-08 17:13:46 +02:00
<?php
2015-05-08 17:13:46 +02:00
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
2015-05-08 17:13:46 +02:00
*/
namespace OC\Core\Command\Config\System;
use OC\SystemConfig;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class GetConfig extends Base {
public function __construct(
SystemConfig $systemConfig,
) {
parent::__construct($systemConfig);
2015-05-08 17:13:46 +02:00
}
protected function configure() {
parent::configure();
$this
->setName('config:system:get')
2015-07-07 11:20:53 +02:00
->setDescription('Get a system config value')
2015-05-08 17:13:46 +02:00
->addArgument(
'name',
2015-12-09 14:47:28 +01:00
InputArgument::REQUIRED | InputArgument::IS_ARRAY,
'Name of the config to get, specify multiple for array parameter'
2015-05-08 17:13:46 +02:00
)
->addOption(
'default-value',
null,
InputOption::VALUE_OPTIONAL,
'If no default value is set and the config does not exist, the command will exit with 1'
2015-05-08 17:13:46 +02:00
)
;
}
/**
* Executes the current command.
*
* @param InputInterface $input An InputInterface instance
* @param OutputInterface $output An OutputInterface instance
* @return int 0 if everything went fine, or an error code
2015-05-08 17:13:46 +02:00
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
2015-12-09 14:47:28 +01:00
$configNames = $input->getArgument('name');
$configName = array_shift($configNames);
2015-05-08 17:13:46 +02:00
$defaultValue = $input->getOption('default-value');
if (!in_array($configName, $this->systemConfig->getKeys()) && !$input->hasParameterOption('--default-value')) {
return 1;
}
if (!in_array($configName, $this->systemConfig->getKeys())) {
$configValue = $defaultValue;
} else {
$configValue = $this->systemConfig->getValue($configName);
2015-12-09 14:47:28 +01:00
if (!empty($configNames)) {
foreach ($configNames as $configName) {
if (isset($configValue[$configName])) {
$configValue = $configValue[$configName];
} elseif (!$input->hasParameterOption('--default-value')) {
2015-12-09 14:47:28 +01:00
return 1;
} else {
$configValue = $defaultValue;
break;
}
}
}
2015-05-08 17:13:46 +02:00
}
$this->writeMixedInOutputFormat($input, $output, $configValue);
return 0;
}
}