Validates and normalizes connection parameters

@param array $params
@param string $error
@return array
normalized parameters or FALSE if parameters is invalid
507979
public function checkParams(array $params, &$error = null)
    {
        $result = array();
        foreach ($this->paramsReq as $param) {
            if (!array_key_exists($param, $params)) {
                $error = 'required '.$param;
                return false;
            }
            $result[$param] = $params[$param];
        }
        foreach ($this->paramsDefault as $param => $default) {
            if (array_key_exists($param, $params)) {
                $result[$param] = $params[$param];
            } else {
                $result[$param] = $default;
            }
        }
        return $result;
    }
893762
private function validate($value, $rule, $param)
    {
        if (in_array($rule, $this->reserved)) {
            return array($value, null);
        }
        if (is_array($value) && !in_array($rule, array('minLength', 'maxLength', 'rangeLength'))) {
            $values = $value;
            $errors = array();
            foreach ($values as $key => $value) {
                list($value, $error) = $this->validate($value, $rule, $param);
                $values[$key] = $value;
                if ($error) {
                    $errors[$key] = $error;
                }
            }

            return array($values, !empty($errors) ? array_shift($errors) : null);
        }
        $error = null;
        if ($rule == 'remote') {
            if ('true' != $result = $this->remote($value, $param)) {
                $error = ($result == 'false') ? $this->errorMessage($rule, $param) : $result;
            }
        } elseif (isset($this->rules[$rule]) && is_callable($this->rules[$rule])) {
            if (!is_bool($result = $this->rules[$rule]($value, $param))) {
                $value = $result;
            }
            if ($result === false) {
                $error = $this->errorMessage($rule, $param);
            }
        } elseif (in_array($rule, $this->methods)) {
            if (!is_bool($result = self::$rule($value, $param))) {
                $value = $result;
            }
            if ($result === false) {
                $error = $this->errorMessage($rule, $param);
            }
        }

        return array($value, $error);
    }
688390
private function setSecureConnection(array $params)
    {
        if (! isset($params['ssl_key']) &&
            ! isset($params['ssl_cert']) &&
            ! isset($params['ssl_ca']) &&
            ! isset($params['ssl_capath']) &&
            ! isset($params['ssl_cipher'])
        ) {
            return;
        }

        $this->conn->ssl_set(
            $params['ssl_key']    ?? null,
            $params['ssl_cert']   ?? null,
            $params['ssl_ca']     ?? null,
            $params['ssl_capath'] ?? null,
            $params['ssl_cipher'] ?? null
        );
    }
952256
public function validateParam($param, $err = null)
    {
        return $this->validate($this->request->param($param), $err);
    }
94638
private function check($value, $params) {

		if(true === is_string($value)) {
			return true === in_array($value, $params[0]);
		}

		return false;
	}
776839
public function validate($params)
    {
        $params = $this->boolParams($params);

        if (!empty($params['html']) && (!empty($params['url']) || !empty($params['file'])))
            throw new InvalidParameterException("Only one of [html, url, file] parameters can be set!");

        if (!empty($params['url']) && !empty($params['file']))
            throw new InvalidParameterException("Only one of [html, url, file] parameters can be set!");

        if ((!empty($params['page_width']) && empty($params['page_height']))
            ||(empty($params['page_width']) && !empty($params['page_height'])))
        {
            throw new InvalidParameterException('Page width and page height must both be set or unset!');
        }
        if (!empty($params['filename']) && !is_string($params['filename']))
            throw new InvalidParameterException('Filename must be a string.');

        if (!empty($params['footer']) && !is_string($params['footer']))
            throw new InvalidParameterException('Footer must be a string.');

        if (!empty($params['header']) && !is_string($params['header']))
            throw new InvalidParameterException('Header must be a string.');

        if (!empty($params['header_spacing']) && !is_int($params['header_spacing']))
            throw new InvalidParameterException('Header spacing parameter must be an integer.');

        if (!empty($params['footer_spacing']) && !is_int($params['footer_spacing']))
            throw new InvalidParameterException('Footer spacing parameter must be an integer.');

        if (!empty($params['page_size']) && !is_string($params['page_size']))
            throw new InvalidParameterException('Page size must be a string of some standard page size.');

        if (!empty($params['dpi']) && (!is_int($params['dpi']) || $params['dpi']<75))
            throw new InvalidParameterException('DPI must be an integer larger than 75.');

        if (!empty($params['image_dpi']) && !is_int($params['image_dpi']))
            throw new InvalidParameterException('Image DPI must be an integer.');

        if (!empty($params['lowquality']) && (!is_int($params['lowquality']) || !in_array($params['lowquality'], array(
                    0, 1 ) )))
            throw new InvalidParameterException(
                'Lowquality must be either 0 or 1 (alternative: use bool values');

        if (!empty($params['orientation']) && (!is_string($params['orientation']) || !in_array($params['orientation'],
                array("landscape", "portrait"))))
            throw new InvalidParameterException('Orientation must be set to either "landscape" or "portrait"');

        if (!empty($params['margin_top']) && !is_int($params['margin_top']))
            throw new InvalidParameterException('Margin top must be an integer.');

        if (!empty($params['margin_bottom']) && !is_int($params['margin_bottom']))
            throw new InvalidParameterException('Margin top must be an integer.');

        if (!empty($params['margin_left']) && !is_int($params['margin_left']))
            throw new InvalidParameterException('Margin top must be an integer.');

        if (!empty($params['margin_right']) && !is_int($params['margin_right']))
            throw new InvalidParameterException('Margin top must be an integer.');

        if (!empty($params['background']) && (!is_int($params['background']) || !in_array($params['background'], array(
                    0, 1 ) )))
            throw new InvalidParameterException(
                'Background must be either 0 or 1 (alternative: use bool values');

        if (!empty($params['images']) && (!is_int($params['images']) || !in_array($params['images'], array(
                    0, 1 ) )))
            throw new InvalidParameterException(
                'Images must be either 0 or 1 (alternative: use bool values');

        if (!empty($params['page_width']) && !is_int($params['page_width']))
            throw new InvalidParameterException('Page width must be an integer.');

        if (!empty($params['page_height']) && !is_int($params['page_height']))
            throw new InvalidParameterException('Page height must be an integer.');

        if (!empty($params['disposition']) && (!is_string($params['disposition']) || !in_array($params['disposition'],
                    array("attachment", "inline"))))
            throw new InvalidParameterException('Disposition can only be "attachment or "inline"');

        if (!empty($params['group']) && !is_string($params['group']))
            throw new InvalidParameterException('Group must be a string.');

        if (!empty($params['engine_version']) && (!is_int($params['engine_version']) || !in_array($params['engine_version'],
        array( 11, 12 ) )))
            throw new InvalidParameterException(
                'Engine version can be integer 11 or 12');

        if (!empty($params['title']) && !is_string($params['title']))
            throw new InvalidParameterException('Title must be a string.');

        if (!empty($params['outline']) && (!is_int($params['outline']) || !in_array($params['outline'], array(
                    0, 1 ) )))
            throw new InvalidParameterException(
                'Outline must be either 0 or 1 (alternative: use bool values');

        if (!empty($params['outline_depth']) && !is_int($params['outline_depth']))
            throw new InvalidParameterException('Outline depth must be an integer.');

        if (!empty($params['encoding']) && !is_string($params['encoding']))
            throw new InvalidParameterException('Encoding must be a string.');

        if (!empty($params['javascript']) && (!is_int($params['javascript']) || !in_array($params['javascript'], array(
                    0, 1 ) )))
            throw new InvalidParameterException(
                'Javascript must be either 0 or 1 (alternative: use bool values');

        if (!empty($params['javascript_delay']) &&
            (!is_int($params['javascript_delay']) || $params['javascript_delay']<1 || $params['javascript_delay']>800))
            throw new InvalidParameterException('Javascript delay must be an integer larger than 1, but smaller than 800.');

        if (!empty($params['internal_links']) &&
            (!is_int($params['internal_links']) || !in_array($params['internal_links'], array( 0, 1 ) )))
            throw new InvalidParameterException(
                'Internal links must be either 0 or 1 (alternative: use bool values');

        if (!empty($params['external_links']) &&
            (!is_int($params['external_links']) || !in_array($params['external_links'], array( 0, 1 ) )))
            throw new InvalidParameterException(
                'External links must be either 0 or 1 (alternative: use bool values');

        if (!empty($params['page_offset']) && !is_int($params['page_offset']))
            throw new InvalidParameterException('Page offset must be an integer.');

        if (!empty($params['username']) && !is_string($params['username']))
            throw new InvalidParameterException('Username must be a string.');

        if (!empty($params['password']) && !is_string($params['password']))
            throw new InvalidParameterException('Password must be a string.');

        if (!empty($params['use_print_media']) &&
            (!is_int($params['use_print_media']) || !in_array($params['use_print_media'], array(
                    0, 1 ) )))
            throw new InvalidParameterException(
                'Use print media must be either 0 or 1 (alternative: use bool values');

        if (!empty($params['zoom']) && !is_numeric($params['zoom']))
            throw new InvalidParameterException('Zoom must be an integer.');

        if (!empty($params['viewport_size']) &&
            (!is_string($params['viewport_size'] || preg_match("^\\d+x\\d+$", $params['viewport_size']))))
            throw new InvalidParameterException('Viewport must be a string of a following format: [width]x[height].');

        if (!empty($params['id']) && !is_string($params['id']))
            throw new InvalidParameterException('ID must be a string.');

        /*if (!empty($params['file']))
            $this->validateFile($params['file']);*/

        return $params;
    }
1036190
public function matchParams(array $params)
    {
        $result = [];
        foreach ($this->explodedParams as $name => list($default, $pattern, $patternName)) {
            if (!\array_key_exists($name, $params)) {
                if (\is_null($default)) {
                    return false;
                }
                $currentParam = $default;
            } else {
                $currentParam = $params[$name];
            }

            if (!\is_null($patternName)) {
                $patternObj = $this->patterns[$patternName];

                try {
                    $result[$name] = $patternObj->toUrl($currentParam);
                } catch (PatternException $exception) {
                    return false;
                }
            } else {
                if (\is_object($currentParam) && \method_exists($currentParam, '__toString')) {
                    $currentParam = (string) $currentParam;
                }
                if (!$this->pregMatchMultiType($pattern, $currentParam)) {
                    return false;
                }
                $result[$name] = $currentParam;
            }
        }

        return $result;
    }
385769
public function createDoctrineConnection(array $params)
	{
// 		$managed = isset($params['managed']);
		$options = !empty($params['options']) ? (array)$params['options'] : [];
		
		if(array_key_exists('encoding', $params))
		{
			$params['charset'] = $params['encoding'];
			unset($params['encoding']);
		}
		
		unset($params['managed']);
		unset($params['options']);
		
		$params = array_merge([
			'charset' => 'utf8'
		], $params);
		
		if(array_key_exists('username', $params))
		{
			if(!array_key_exists('user', $params))
			{
				$params['user'] = $params['username'];
				unset($params['username']);
			}
		}
		
		if(isset($params['dsn']))
		{
			list($type, $tmp) = explode(':', $params['dsn'], 2);
			unset($params['dsn']);
			
			$cfg = [
				'driver' => 'pdo_' . $type
			];
			
			if($cfg['driver'] == 'pdo_sqlite')
			{
				if($tmp == ':memory:')
				{
					$cfg['memory'] = true;
				}
				else
				{
					$cfg['path'] = $tmp[1];
				}
			}
			else
			{
				foreach(explode(';', $tmp) as $conf)
				{
					$parts = array_map('trim', explode('=', $conf, 2));
					$cfg[$parts[0]] = $parts[1];
				}
			}
			
			$params = array_merge($cfg, $params);
		}
		
		$conn = new Doctrine\Connection(DriverManager::getConnection($params), $options);
		$conn->setEventDispatcher($this->eventDispatcher);
		
		return $conn;
	}
249294
public function messagesFor(ParamError $error): array
    {
        return $error->fillMessages($this->properties()->section($error->id()));
    }
154822
public function error($field, $error, array $params = null)
    {
        $this->_errors[$field] = [
            $error,
            $params
        ];

        return $this;
    }
1134407
protected function validateSubset($field, $value, $params)
    {
        if (!isset($params[0])) {
            return false;
        }
        if (!\is_array($params[0])) {
            $params[0] = [$params[0]];
        }
        if (\is_scalar($value)) {
            return $this->validateIn($field, $value, $params);
        }
        $intersect = \array_intersect($value, $params[0]);

        return \array_diff($value, $intersect) === \array_diff($intersect, $value);
    }
1249147
protected function _parseApiParams($params)
  {
    $apiparams = [];
    if (count($params) === 0) {
      return $apiparams;
    }

    if (is_array($params[0])) {
      // given parameters are array
      $apiparams = $params[0];
      return $apiparams;
    }

    // user gave us query-style params
    parse_str($params[0], $apiparams);
    if (! is_array($apiparams)) {
      $apiparams = [];
    }

    return $apiparams;
  }
391411
protected function get_error_message_params( $key, $params )
	{
		// do we have a label to replace the key?
		if ( isset( $this->labels[$key] ) )
		{
			$field = $this->labels[$key];
		} else {
			$field = ucfirst( str_replace( array( '_', '-' ), ' ', $key ) );
		}

		return array_merge( array( 'field' => $field ), $params );
	}
229738
public function check($params)
	{
		$requestParams = $this->initRequestParams('check', $params);
		$this->request('check', $requestParams);

		return empty($this->error);
	}
257504
private function prepareParametersUrl(array $params, array $allowedParams)
    {
        $allowedParams = array_flip($allowedParams);
        $params = array_intersect_key($params, $allowedParams);

        $paramsUrlItems = [];
        foreach ($params as $key => $param) {
            $paramsUrlItems[] = $key . '=' . urlencode($param);
        }

        $paramsUrl = join('&', $paramsUrlItems);
        if (strlen($paramsUrl) > 0) {
            $paramsUrl = '?' . $paramsUrl;
        }

        return $paramsUrl;
    }
364840
private function normalizeError(JsonRpcExceptionInterface $error) : array
    {
        $normalizedError = [
            self::SUB_KEY_ERROR_CODE => $error->getErrorCode(),
            self::SUB_KEY_ERROR_MESSAGE => $error->getErrorMessage()
        ];

        if ($error->getErrorData()) {
            $normalizedError[self::SUB_KEY_ERROR_DATA] = $error->getErrorData();
        }

        return $normalizedError;
    }
794420
protected function validateDateFormat($field, $value, $params)
    {
        $parsed = \date_parse_from_format($params[0], $value);

        return $parsed['error_count'] === 0 && $parsed['warning_count'] === 0;
    }