Assert that key configuration is valid.

@param KeyConfiguration $keyConfig

@throws InvalidKeyConfigurationException
@throws UnknownHashAlgorithmException
484052
private function assertValidKeyConfiguration(KeyConfiguration $keyConfig)
    {
        if (empty($keyConfig->getHashAlgorithm()) || empty($keyConfig->getSalt()) || empty($keyConfig->getCost())) {
            throw new InvalidKeyConfigurationException();
        }

        $this->assertValidHashAlgorithm($keyConfig);
    }
641358
private function hasValidMasterSlaveConfig(array $driverConfig)
    {
        if (!isset($driverConfig['read'])) {
            throw new \InvalidArgumentException("Parameter 'read' must be set for read/write config.");
        }

        $slaves = $driverConfig['read'];

        if (!is_array($slaves) || in_array(false, array_map('is_array', $slaves))) {
            throw new \InvalidArgumentException("Parameter 'read' must be an array containing multiple arrays.");
        }

        if (($key = array_search(0, array_map('count', $slaves))) !== false) {
            throw new \InvalidArgumentException("Parameter 'read' config no. {$key} is empty.");
        }
    }
573014
private function checkConfigOptions($config)
    {
        if (!isset($config['cas_host'])) {
            throw new Exception("CAS host required!", 500);
        }
        if (!isset($config['cas_port'])) {
            throw new Exception("CAS port required!", 500);
        }
        if (!isset($config['cas_context'])) {
            throw new Exception("CAS path required!", 500);
        }
        if (!isset($config['ca_cert_path'])) {
            throw new Exception("CA cert path for CAS server required!", 500);
        }
    }
180635
protected function isParsedConfigValid(array $config, array $required)
    {
        $inConfig = count(array_intersect_key(array_flip($required), array_filter($config)));

        return $inConfig === count($required);
    }
952189
private function validateConstructorArgs($apiKey, $domain)
    {
        if (!isset($apiKey)) {
            throw new Exceptions\InvalidConfigurationException("API key is empty.");
        }

        if (!isset($domain)) {
            throw new Exceptions\InvalidConfigurationException("Domain is empty.");
        }
    }
932570
public function validate($configuration, $required)
    {
        // search for any null or empty field to throw an exception
        $missing = '';
        foreach ($configuration as $key => $value) {
            if (in_array($key, $required) &&
                (empty($value) || $value == null || $value == '')
            ) {
                $missing .= ' '.$key;
            }
        }

        if ($missing) {
            throw new MissingConfigurationException('Missed Configuration:'.$missing);
        }
    }
1124346
public static function get($key, $config = null)
    {
        if ($key === '') {
            throw new \InvalidArgumentException("Key cannot be an empty string");
        }

        if (!is_string($key)) {
            throw new \InvalidArgumentException("Parameter of type string is expected, \"".gettype($key)."\" given");
        }

        self::initConfig();

        $config = ($config === null) ? self::$config : $config;
        try {
            if (self::isComplexKey($key)) {
                $keys = explode('.', $key);
                $childKey = array_shift($keys);
                if (self::has($childKey, $config)) {
                    $config = self::get($childKey, $config);
                    $key = implode(".", $keys);
                } else {
                    throw new ConfigNotFoundException("Config key \"{$key}\" was not found in config");
                }
            }

            if (!self::has($key, $config)) {
                throw new ConfigNotFoundException("Config key \"{$key}\" was not found in config");
            }

            return $config[$key];
        } catch (ConfigNotFoundException $e) {
            return array();
        }
    }
227561
protected function validateConfig()
    {
        $defaults = [
            'tpl_folder',
            'cache_folder',
            'tpl_file_format',
            //'compress',
            //'event_emitter',
        ];

        foreach ($defaults as $key) {
            if (! isset($this->config[$key])) {
                throw new InvalidConfigException(sprintf("Missing a configuration key (%s)", $key));
            }
        }
    }
1360026
private function verifyConfig()
    {
        foreach (Config::KEYS as $key) {
            if (!isset(Config::get()[$key])) {
                throw new OrmException('Key "'.$key.'" is not given.');
            }
        }
    }
1032549
protected function resolveValue(Config $config, $key)
    {
        $value = $config->getRequired($key);
        if (is_array($value)) {
            throw new KeyException(sprintf('Referenced configuration key "%s" must not be an array.', $key));
        }

        if (in_array($key, $this->referenceStack)) {
            throw new KeyException(sprintf('Circular reference detected resolving configuration key "%s"', $key));
        }
        $this->referenceStack[] = $key;

        preg_match_all('/%([^%]+)%/', $value, $matches);
        if (!$matches) {
            return;
        }

        foreach ($matches[1] as $referenceKey) {
            $replacement = $this->resolveValue($config, $referenceKey);
            $value = str_replace('%'.$referenceKey.'%', $replacement, $value);
        }
        array_pop($this->referenceStack);

        return $value;
    }
237295
public function configure($config)
    {
        foreach ((array)$config as $key => $value) {
            $this->setConfig($key, $value);
        }
    }
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);
	}
709982
public function validate($data)
    {
        $this->validator->reset();
        $this->validator->check($data, $this->schema());

        if (!$this->validator->isValid()) {
            throw new InvalidConfigurationException(
                $this->validator->getErrors()
            );
        }
    }
1142485
public function setConfig(array $config)
    {
        if (!isset($config['thumbnailer'])) {
            $this->_thumbnailer = new Thumbnailer();
        } elseif (class_exists($config['thumbnailer'])) {
            $this->_thumbnailer = new $config['thumbnailer'];
        } else {
            throw new ConfigurationException('Class ' . $config['thumbnailer'] . ' does not exist.');
        }

        if (!($this->_thumbnailer instanceof ThumbnailerInterface)) {
            throw new ConfigurationException('Class ' . get_class($this->_thumbnailer) . ' must implement the interface \ysaroka\autothumb\ThumbnailerInterface.');
        }

        if (!isset($config['document_root'])) {
            throw new ConfigurationException('"document_root" key is required.');
        }

        if (!is_dir(realpath($config['document_root']))) {
            throw new ConfigurationException('"document_root": directory "' . $config['document_root'] . '" does not exist.');
        }

        if (!isset($config['types']) || count($config['types']) == 0) {
            throw new ConfigurationException('"types" key is required and should not be empty.');
        }

        foreach ($config['types'] as $type => $params) {
            if (!preg_match('#^[\w\d]+$#', $type)) {
                throw new ConfigurationException('"type": type name "' . $type . '" must contain only words and numbers.');
            }

            if (!isset($params['width'])) {
                $config['types'][$type]['width'] = 100;
            }

            if (!isset($params['height'])) {
                $config['types'][$type]['height'] = 100;
            }

            if (!isset($params['crop'])) {
                $config['types'][$type]['crop'] = true;
            }

            if (!isset($params['stretch'])) {
                $config['types'][$type]['stretch'] = false;
            }

            if (!isset($params['watermark'])) {
                $config['types'][$type]['watermark'] = false;
            } elseif (file_exists($params['watermark']) && !is_dir($params['watermark'])) {
                $config['types'][$type]['watermark'] = realpath($params['watermark']);
                if (isset($params['watermark_pos']) && defined('\ysaroka\autothumb\ThumbnailerInterface::POS_' . strtoupper($params['watermark_pos']))) {
                    $config['types'][$type]['watermark_pos'] = constant('\ysaroka\autothumb\ThumbnailerInterface::POS_' . strtoupper($params['watermark_pos']));
                } else {
                    $config['types'][$type]['watermark_pos'] = ThumbnailerInterface::POS_BOTTOM_RIGHT;
                }
            } else {
                throw new ConfigurationException('Image file "watermark": "' . $params['watermark'] . '" for type "' . $type . '" does not exist.');
            }
        }

        if (isset($config['allowed_extensions']) && is_array($config['allowed_extensions']) && count($config['allowed_extensions']) > 0) {
            $this->_allowedExtensions = $config['allowed_extensions'];
        }

        $this->_documentRoot = realpath($config['document_root']);
        $this->_types = $config['types'];

        return $this;
    }
1288009
private function validateEachCanonicalLocaleExists(array $config)
    {
        $canonicals = $config['canonicals'] ?? [];
        foreach ($canonicals as $locale => $canonical) {
            if (!$this->existsAsLocale($config['locales'], $locale)) {
                throw new InvalidConfig('Canonical key '.$locale.' is not present as locale.');
            }
        }
    }
122846
private function validateTypeAndService(array $config, $path)
    {
        if (!isset($config['type']) && !isset($config['service'])) {
            throw new InvalidConfigurationException(sprintf('You must set one of "type" or "service" for "%s"', $path));
        }
        if (isset($config['type']) && isset($config['service'])) {
            throw new InvalidConfigurationException(sprintf('You cannot set both "type" and "service" for "%s" - please choose one.', $path));
        }
    }
1275937
public function authenticate(array $config)
    {
        if (!$this->client) {
            throw new InvalidArgumentException('The client instance was not given to the token authenticator.');
        }

        if (!array_key_exists('token', $config)) {
            throw new InvalidArgumentException('The token authenticator requires a token.');
        }

        $this->client->authenticate($config['token'], Client::AUTH_HTTP_TOKEN);

        return $this->client;
    }