Process and validate config

@param mixed[] $config
185215
public function setupPlugin(array $config = []): void
	{
		if (!$this->defaults) return;
		$this->setupConfig($this->defaults, $config);
	}
310220
public function _validate_config($config)
	{
		$validated = array();

		foreach ($config as $name => $item)
		{
			if ($name == 'memcached' and is_array($item))
			{
				foreach ($item as $name => $value)
				{
					switch ($name)
					{
						case 'cookie_name':
							if ( empty($value) or ! is_string($value))
							{
								$value = 'fuelmid';
							}
						break;

						case 'servers':
							// do we have a servers config
							if ( empty($value) or ! is_array($value))
							{
								$value = array('default' => array('host' => '127.0.0.1', 'port' => '11211'));
							}

							// validate the servers
							foreach ($value as $key => $server)
							{
								// do we have a host?
								if ( ! isset($server['host']) or ! is_string($server['host']))
								{
									throw new \FuelException('Invalid Memcached server definition in the session configuration.');
								}
								// do we have a port number?
								if ( ! isset($server['port']) or ! is_numeric($server['port']) or $server['port'] < 1025 or $server['port'] > 65535)
								{
									throw new \FuelException('Invalid Memcached server definition in the session configuration.');
								}
								// do we have a relative server weight?
								if ( ! isset($server['weight']) or ! is_numeric($server['weight']) or $server['weight'] < 0)
								{
									// set a default
									$value[$key]['weight'] = 0;
								}
							}
						break;

						default:
							// unknown property
							continue;
					}

					$validated[$name] = $value;
				}
			}
			else
			{
				// skip all config array properties
				if (is_array($item))
				{
					continue;
				}

				// global config, was validated in the driver
				$validated[$name] = $item;
			}

		}

		// validate all global settings as well
		return parent::_validate_config($validated);
	}
1180954
protected function processSassConfiguration(array $config)
    {
        // changed from css_preprocessor to css_preprocessor for 3.0
        if (in_array($config['css_preprocessor'], array('sass', 'scssphp'))) {
            if ($config['assets_dir'] === Configuration::DEFAULT_ASSETS_DIR) {
                $config['assets_dir'] = Configuration::DEFAULT_ASSETS_DIR_SASS;
            }
            if ($config['customize']['bootstrap_output'] === Configuration::DEFAULT_BOOTSTRAP_OUTPUT) {
                $config['customize']['bootstrap_output'] = Configuration::DEFAULT_BOOTSTRAP_OUTPUT_SASS;
            }
            if ($config['customize']['bootstrap_template'] === Configuration::DEFAULT_BOOTSTRAP_TEMPLATE) {
                $config['customize']['bootstrap_template'] = Configuration::DEFAULT_BOOTSTRAP_TEMPLATE_SASS;
            }
        }

        return $config;
    }
671965
public function validator($config = array())
    {
        $config = new KObjectConfigJson($config);
        $config->append(array(
            'debug' => false,
            'selector' => '.k-js-form-controller',
            'options_callback' => null,
            'options'  => array(
                'ignoreTitle' => true,
                'onsubmit'    => false // We run the validation ourselves
            )
        ));

        $html = '';

        if(!static::isLoaded('validator'))
        {
            $html .= $this->koowa();
            $html .= '<ktml:script src="assets://js/'.($config->debug ? 'build/' : 'min/').'jquery.validate.js" />';

            static::setLoaded('validator');
        }

        $options   = (string) $config->options;
        $signature = md5('validator-'.$config->selector.$config->options_callback.$options);

        if (!static::isLoaded($signature))
        {
            if ($config->options_callback) {
                $options = $config->options_callback.'('.$options.')';
            }

            $html .= "<script>
            kQuery(function($){
                $('$config->selector').on('k:validate', function(event){
                    if(!$(this).valid() || $(this).validate().pendingRequest !== 0) {
                        event.preventDefault();
                    }
                }).validate($options);
            });
            </script>";

            static::setLoaded($signature);
        }

        return $html;
    }
231214
private function setConfig($config)
    {
        $allowedConfigKeys = [
            'host',
            'port',
            'sasl_user',
            'sasl_password',
        ];

        foreach ($config as $key => $server) {
            (false === is_array($server)) ? $this->checkSimpleConfigArray($key, $allowedConfigKeys) : $this->checkMultidimensionalConfigArray($server, $allowedConfigKeys);
        }

        $this->config = $config;
    }
535326
private function initializeConfig($config)
    {

        if (isset($config[self::ASSERT_VALID_IP_CONFIG])) {
            $this->assertValidIp = $config[self::ASSERT_VALID_IP_CONFIG];
        }

        // If we don't need to validate the service Ip, we're done here
        if ( ! $this->assertValidIp) {
            return;
        }

        /*
         *  If we should validate the service IP but there aren't
         *  any trusted IPs, throw an exception
         */
        if (empty($config[self::TRUSTED_IPS_CONFIG])) {
            throw new EmailServiceClientException(
                'The config entry for ' . self::TRUSTED_IPS_CONFIG .
                ' must be set (as an array) when ' .
                self::ASSERT_VALID_IP_CONFIG .
                ' is not set or is set to True.',
                1503511658
            );
        }

        /*
         * At this point, we need to validate the service Ip and we know
         * that the TRUSTED_IPS_CONFIG is not empty
         */
        $newTrustedIpRanges = $config[self::TRUSTED_IPS_CONFIG];
        if ( ! is_array($newTrustedIpRanges)) {
            throw new EmailServiceClientException(
                'The config entry for ' . self::TRUSTED_IPS_CONFIG .
                ' must be an array.',
                1503511659
            );
        }

        foreach ($newTrustedIpRanges as $nextIpRange) {
            $ipBlock = IPBlock::create($nextIpRange);
            $this->trustedIpRanges[] = $ipBlock;
        }

        $this->assertTrustedIp();
    }
149421
private function validateDirs($config): void
    {
        // Check that dirs key exists
        if (! Validator::key('dirs')->validate($config)) {
            throw new InvalidConfigException('"dirs" parameter is not an array.');
        }
        // Clean dirs value
        if ($config['dirs'] === null) {
            $this->config['dirs'] = $config['dirs'] = [];
        }
        // Validate each dirs
        if (! Validator::arrayVal()
            ->each(Validator::stringType(), Validator::stringType())->validate($config['dirs'])
        ) {
            throw new InvalidConfigException('Some directories in "dirs" parameter are not strings.');
        }
    }
1029621
public function validate(array $data)
    {
        $processor = new Processor();
        self::setData($data);
        $configuration = $processor->processConfiguration($this, $data);
    }
1243221
public function setConfig(&$config)
    {
        $this->_checkConfig($config);

        $this->config = $config;
        $this->init();
    }
1041236
protected function checkConfig($config)
    {
        $required_fields = ['namespace', 'table', 'path', 'mapping', 'import_keys'];

        foreach ($required_fields as $key) {
            if (!array_has($config, $key)) {
                $this->error(sprintf('Missing \'%s\' from the dataset configuration file.', $key));
                $this->line('');
                $this->line('');

                exit(1);
            }
        }
    }
1084323
protected function validate($config): void
    {
        // Check that $config is an array
        if (! Validator::arrayType()->validate($config)) {
            throw new InvalidConfigException('The config must be an array.');
        }

        // Check boolean parameters
        if (! Validator::key('interface', Validator::boolType())->validate($config)) {
            throw new InvalidConfigException('"interface" parameter must be set as a boolean.');
        }
        if (! Validator::key('private', Validator::boolType())->validate($config)) {
            throw new InvalidConfigException('"private" parameter must be set as a boolean.');
        }
        if (! Validator::key('auto', Validator::boolType())->validate($config)) {
            throw new InvalidConfigException('"auto" parameter must be set as a boolean.');
        }

        $this->validatePhpdoc($config);
    }
734991
protected function parseConfig(array $config)
    {
        $config = $this->setHost($config);
        $config = $this->setPort($config);
        $config = $this->setProtocol($config);
        $config = $this->setServiceId($config);
        $config = $this->setTNS($config);
        $config = $this->setCharset($config);

        return $config;
    }
917050
private function checkConfig($config){
		$config = Hash::merge($this->configDef,$config);
		$this->include = $config['include'];
		unset($config['include']);
    	$this->config= $config;
	}
1194492
public static function initModelsValidators(&$config) {
		$models = CacheManager::getModels ( $config, true );
		foreach ( $models as $model ) {
			self::initClassValidators ( $model );
		}
	}
672666
protected function validateConfiguration(array $config) : bool
    {
        if (!is_array($config)) {
            throw new DatabaseConnectionException('Could not load LDAP configuration settings.');
        }
        $config_keys = array_keys($config);
        $missing = array_diff(['server', 'port', 'domain', 'base_dn', 'username', 'password'], $config_keys);
        if (count($missing) > 0) {
            throw new DatabaseConnectionException('LDAP configuration missing ' . implode(', ', $missing));
        }
        return true;
    }
902029
public function configure(array $config)
    {
        if (isset($config['services'])) {
            foreach ($config['services'] as $service) {
                $this->validate($service);
            }
        }

        parent::configure($config);

        return $this;
    }
1017491
protected function isValidData($config)
    {
        $valid = true;
        foreach ($config as $k => $v) {
            if (!($this->isValidKey($k) && $this->isValidValue($v))) {
                $valid = false;
                break;
            }
        }
        return $valid;
    }