Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ConfigCommand.php

function ConfigCommand::suggestSettingKeys

Suggest setting-keys, while taking given options in account.

File

vendor/composer/composer/src/Composer/Command/ConfigCommand.php, line 1030

Class

ConfigCommand
@author Joshua Estes <Joshua.Estes@iostudio.com> @author Jordi Boggiano <j.boggiano@seld.be>

Namespace

Composer\Command

Code

private function suggestSettingKeys() : \Closure {
    return function (CompletionInput $input) : array {
        if ($input->getOption('list') || $input->getOption('editor') || $input->getOption('auth')) {
            return [];
        }
        // initialize configuration
        $config = Factory::createConfig();
        // load configuration
        $configFile = new JsonFile($this->getComposerConfigFile($input, $config));
        if ($configFile->exists()) {
            $config->merge($configFile->read(), $configFile->getPath());
        }
        // load auth-configuration
        $authConfigFile = new JsonFile($this->getAuthConfigFile($input, $config));
        if ($authConfigFile->exists()) {
            $config->merge([
                'config' => $authConfigFile->read(),
            ], $authConfigFile->getPath());
        }
        // collect all configuration setting-keys
        $rawConfig = $config->raw();
        $keys = array_merge($this->flattenSettingKeys($rawConfig['config']), $this->flattenSettingKeys($rawConfig['repositories'], 'repositories.'));
        // if unsetting …
        if ($input->getOption('unset')) {
            // … keep only the currently customized setting-keys …
            $sources = [
                $configFile->getPath(),
                $authConfigFile->getPath(),
            ];
            $keys = array_filter($keys, static function (string $key) use ($config, $sources) : bool {
                return in_array($config->getSourceOfValue($key), $sources, true);
            });
            // … else if showing or setting a value …
        }
        else {
            // … add all configurable package-properties, no matter if it exist
            $keys = array_merge($keys, self::CONFIGURABLE_PACKAGE_PROPERTIES);
            // it would be nice to distinguish between showing and setting
            // a value, but that makes the implementation much more complex
            // and partially impossible because symfony's implementation
            // does not complete arguments followed by other arguments
        }
        // add all existing configurable package-properties
        if ($configFile->exists()) {
            $properties = array_filter($configFile->read(), static function (string $key) : bool {
                return in_array($key, self::CONFIGURABLE_PACKAGE_PROPERTIES, true);
            }, ARRAY_FILTER_USE_KEY);
            $keys = array_merge($keys, $this->flattenSettingKeys($properties));
        }
        // filter settings-keys by completion value
        $completionValue = $input->getCompletionValue();
        if ($completionValue !== '') {
            $keys = array_filter($keys, static function (string $key) use ($completionValue) : bool {
                return str_starts_with($key, $completionValue);
            });
        }
        sort($keys);
        return array_unique($keys);
    };
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal