Validate parameters array

@param string[] $required required properties (array keys)
@param array $params   array to check for existence of the required keys

@throws MissingArgumentException if a required parameter is missing
517449
protected function validateRequiredParameters(array $required, array $params)
    {
        foreach ($required as $param) {
            if (!isset($params[$param])) {
                throw new MissingArgumentException(sprintf('The "%s" parameter is required.', $param));
            }
        }
    }
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;
    }
861617
protected static void validateParamsPresence(Map params, String... keys) {
        for (String name : keys) {
            if (!params.containsKey(name)) {
                throw new IllegalArgumentException("parameter: '" + name + "' is missing");
            }
        }
    }
597691
private function requireParameterCount(int $count, array $parameters, string $rule): void
    {
        if (count($parameters) < $count) {
            throw new InvalidArgumentException("Validation rule {$rule} requires at least {$count} parameters.");
        }
    }
177773
protected function validateAtLeastOneOf(array $atLeastOneOf, array $params)
    {
        foreach ($atLeastOneOf as $param) {
            if (isset($params[$param])) {
                return true;
            }
        }

        throw new MissingArgumentException(sprintf(
            'You need to provide at least one of the following parameters "%s".',
            implode('", "', $atLeastOneOf)
        ));
    }
175562
protected function checkParams($params)
    {
        foreach ($params as $type) {
            if ($type instanceof Decorator) {
                $this->errors[] = "Parameter is not well instantiated [" . (string)$type . "]";
            }
        }
    }
85720
protected function validate_required($field, $input, $param = null)
    {
        if (isset($input[$field]) && ($input[$field] === false || $input[$field] === 0 || $input[$field] === 0.0 || $input[$field] === '0' || !empty($input[$field]))) {
            return;
        }

        return array(
            'field' => $field,
            'value' => null,
            'rule' => __FUNCTION__,
            'param' => $param,
        );
    }
387946
public function validate(array $params = [])
    {
        $name = array_get($params, 'name');
        if (is_null($name) or $name != config('antares/logger::operations.login')) {
            return false;
        }
        $params = array_merge($params, $this->getClientParams());
        try {
            $model = $this->model->newQuery()
                    ->where('user_id', $params['user_id'])
                    ->where('ip_address', $params['ip_address'])
                    ->where('browser', $params['browser'])
                    ->orderBy('created_at', 'desc')
                    ->firstOrFail();
            $model->touch();
        } catch (Exception $ex) {
            $this->saveNewDevice($params);
        }
        if (isset($model) and ! is_null($model) and ( $model->ip_address != $params['ip_address'] or $model->browser != $params['browser'])) {
            $this->saveNewDevice($params);
            $user = user();
            $this->dispatcher->fire('new-device-detect-notification', ['variables' => ['user' => $user, 'params' => $params, 'date' => date('Y-m-d', time()), 'time' => date("H:i", time())], 'recipients' => [$user]]);
        }
    }
1247206
protected function cleanParamWithRequirements(ParamInterface $param, $paramValue, $strict, $default)
    {
        $this->checkNotIncompatibleParams($param);
        if (null !== $default && $default === $paramValue) {
            return $paramValue;
        }

        if (null === $this->validator) {
            throw new \RuntimeException(
                'The ParamFetcher requirements feature requires the symfony/validator component.'
            );
        }

        $constraints = $param->getConstraints();
        $this->resolveConstraints($constraints);
        if (empty($constraints)) {
            return $paramValue;
        }

        try {
            $errors = $this->validator->validate($paramValue, $constraints);
        } catch (ValidatorException $e) {
            $violation = new ConstraintViolation(
                $e->getMessage(),
                $e->getMessage(),
                array(),
                $paramValue,
                '',
                null,
                null,
                $e->getCode()
            );
            $errors = new ConstraintViolationList(array($violation));
        }

        if (0 < count($errors)) {
            if ($strict) {
                throw InvalidParameterException::withViolations($param, $errors);
            }

            return null === $default ? '' : $default;
        }

        return $paramValue;
    }
804319
protected function validateParams(array &$params, $rules = null, $clean = false)
	{

		if( ! is_null($rules) )
		{
			// init laravel validator
			$validator = $this->newValidator($params, $rules, $clean);
			$this->setValidator($validator);
		}
		$validator = $this->getValidator();

		$rules = $validator->getRules();
		

		if ($validator->fails())
		{
			// params did not pass validation rules
			
			// add errors to exception
			$this->getException()->addErrors($validator->errors()->toArray());

			return false;
		}
		else
		{
			// params passed validation rules
			return true;
		}
	}
466007
private function validateAndSetBotParamsSpecial(array $params)
    {
        // Special case, where secret MUST be defined if we have a webhook.
        if (($params['webhook']['url'] ?? null) && !($params['secret'] ?? null)) {
            // This does not apply when using CLI, but make sure it gets tested for!
            if ('cli' !== PHP_SAPI || BotManager::inTest()) {
                throw new InvalidParamsException('Some vital info is missing: secret');
            }
        }
    }
701844
public static function assertNotEmpty(
        array $params,
        string $key,
        $context = null
    ) {
        self::assertHas(
            $params,
            $key,
            $context
        );

        $value = self::get(
            $params,
            $key,
            null
        );

        if (empty($value)) {
            $message = self::buildErrorMessage(
                $params,
                $key,
                "Property ({$key}) is missing and is required and can not be empty",
                $context
            );
            self::throwParamException(
                $params,
                $key,
                new ArrayPropertyMissing($message)
            );
        }
    }
42578
protected function setParams($position, $required, $param)
    {
        if (!empty($required['class']) && !is_a($param, $required['class'])) {
            $this->errors[] = sprintf("You can't put an instance of %s in the parameter #%s $%s of type %s",
                get_class($param), $position, $required['name'], $required['class']);
            return false;
        }
        $this->methodParams[$position] = $param;
    }
364418
protected function required_options($required, $options = array())
  {
      $required = explode(',', $required);
      foreach ($required as $r) {
          if (!array_key_exists(trim($r), $options)) {
              throw new Exception($r.' parameter is required!');
              break;

              return false;
          }
      }

      return true;
  }
71204
public function getMissingParameterKey(array $parameters, array $requiredKeys = [])
    {
        foreach ($requiredKeys as $key) {
            if (! isset($parameters[$key])) {
                return $key;
            }
        }
    }
924755
protected function validateS3Config(array $config, array $requiredKeys)
    {
        foreach ($requiredKeys as $requiredKey) {
            if (!array_key_exists($requiredKey, $config)) {
                throw new InvalidConfigException($requiredKey);
            }
        }
    }
684605
private function validateOptions(array $options): void
    {
        foreach ($this->requiredOptions as $name) {
            if (!array_key_exists($name, $options)) {
                throw new InvalidArgumentException(sprintf('Required parameter "%s" is missing.', $name));
            }

            $this->{$name} = $options[$name];
        }
    }