Validate options are allowed

@param   array   $options    array of options

@throws FilestackException   e.g. policy option not allowed

@return bool
184432
protected function validateOptions($options)
    {
        foreach ($options as $key => $value) {
            if (!in_array($key, $this->allowed_options)) {
                throw new FilestackException("Invalid policy option: $key:$value", 400);
            }
        }

        return true;
    }
1323283
private function validateOptions(array $options, $type)
    {
        if (!isset(self::$requiredOptions[$type])) {
            return;
        }
        foreach (self::$requiredOptions[$type] as $requiredOption) {
            if (!array_key_exists($requiredOption, $options)) {
                throw new ConfigurationException(
                    sprintf('Option "%s" must be provided for "%s" type parameters.', $requiredOption, $type)
                );
            }
        }
    }
829869
public function saveIfExistsOrFail(array $options = []): bool
    {
        if ($this->exists === false) {
            return false;
        }

        return $this->saveOrFail($options);
    }
313957
public function deleteFile(array $options)
    {
        if (!isset($options['FileName'])) {
            $file = $this->getFile($options);

            $options['FileName'] = $file->getName();
        }

        if (!isset($options['FileId']) && isset($options['BucketName']) && isset($options['FileName'])) {
            $file = $this->getFile($options);

            $options['FileId'] = $file->getId();
        }

        $this->client->request('POST', $this->apiUrl.'/b2_delete_file_version', [
            'headers' => [
                'Authorization' => $this->authToken
            ],
            'json' => [
                'fileName' => $options['FileName'],
                'fileId' => $options['FileId']
            ]
        ]);

        return true;
    }
364316
protected function validate($entity, array &$options)
    {
        $allowedEntityClasses = $this->getAllowedEntityClasses();

        if (!empty($allowedEntityClasses)) {
            $entityClassAllowed = false;

            foreach ($allowedEntityClasses as $allowedEntityClass) {
                if ($entity instanceof $allowedEntityClass) {
                    $entityClassAllowed = true;

                    break;
                }
            }
            if (!$entityClassAllowed) {
                $message = sprintf(
                    'View widget "%s" requires entity to be instance of one of "%s" classes.',
                    $this->getAlias(),
                    implode('", "', $allowedEntityClasses)
                );

                throw new WidgetException($message);
            }
        }
        try {
            $options = $this->optionsResolver->resolve($options);
        } catch (ExceptionInterface $ex) {
            throw new WidgetException(
                sprintf('View widget "%s" options are invalid: "%s".', $this->getAlias(), $ex->getMessage())
            );
        }
    }
310919
protected function validateOptions(array $options, FieldTypeInterface $field)
    {
        $parsed = [];

        foreach ($options as $key => $value) {
            if (! in_array($key, $field->getAllowedOptions(), true)) {
                throw new \DomainException('The "'.$key.'" option is not allowed on the provided field.');
            }

            $parsed[$key] = $value;
        }

        return $parsed;
    }
364445
public function checkLimit(array $options)
    {
        $options['limit'] = (int)$options['limit'];
        if (empty($options['limit']) || $options['limit'] < 1) {
            $options['limit'] = 1;
        }
        $options['limit'] = max(min($options['limit'], $options['maxLimit']), 1);

        return $options;
    }
1190738
private function sanitizeOptions(array $options)
    {
        $booleanOptions = [
            Option::TRANSACTIONAL,
            Option::OPEN_TRACKING,
            Option::CLICK_TRACKING,
            Option::SANDBOX,
            Option::SKIP_SUPPRESSION,
            Option::INLINE_CSS,
        ];
        $stringOptions  = [
            Option::IP_POOL,
        ];

        $sanitized = [];

        foreach ($options as $option => $value) {
            if (in_array($option, $stringOptions, true)) {
                if ($value) {
                    $sanitized[$option] = (string) $value;
                }
                continue;
            }

            if (in_array($option, $booleanOptions, true)) {
                $sanitized[$option] = (bool) $value;
                continue;
            }

            throw new Exception(sprintf('Unknown SparkPost option "%s"', $option));
        }

        return $sanitized;
    }
820229
public function fromArray($options)
    {
        if (isset($options['Id'])) {
            Validate::isString($options['Id'], 'options[Id]');
            $this->_id = $options['Id'];
        }

        if (isset($options['Name'])) {
            Validate::isString($options['Name'], 'options[Name]');
            $this->_name = $options['Name'];
        }

        if (isset($options['AssetDeliveryProtocol'])) {
            Validate::isInteger($options['AssetDeliveryProtocol'], 'options[AssetDeliveryProtocol]');
            $this->_protocol = $options['AssetDeliveryProtocol'];
        }

        if (isset($options['AssetDeliveryPolicyType'])) {
            Validate::isInteger($options['AssetDeliveryPolicyType'], 'options[AssetDeliveryPolicyType]');
            $this->_policyType = $options['AssetDeliveryPolicyType'];
        }

        if (isset($options['AssetDeliveryConfiguration'])) {
            Validate::isString($options['AssetDeliveryConfiguration'], 'options[AssetDeliveryConfiguration]');
            $this->_configuration = $options['AssetDeliveryConfiguration'];
        }

        if (isset($options['Created'])) {
            Validate::isDateString($options['Created'], 'options[Created]');
            $this->_created = new \DateTime($options['Created']);
        }

        if (isset($options['LastModified'])) {
            Validate::isDateString(
                $options['LastModified'],
                'options[LastModified]'
            );
            $this->_lastModified = new \DateTime($options['LastModified']);
        }
    }
676749
final public function check(array $options) {
        foreach ($options as $property => $value) {
            if ((is_array($value) && !in_array($this->$property, $value)) ||
                    (!is_array($value) && $this->$property !== $value))
                return false;
        }

        return true;
    }
576653
private function validateAggregationOptions(array $options)
    {
        // get db version
        $client = $this->getDatabase()->getClient();
        $dbVersion = $client->getDbVersion();

        // check options for db < 2.6
        if (version_compare($dbVersion, '2.6.0', '<')) {
            if (!empty($options['explain'])) {
                throw new FeatureNotSupportedException(
                    'Explain of aggregation implemented only from 2.6.0'
                );
            }

            if (!empty($options['allowDiskUse'])) {
                throw new FeatureNotSupportedException(
                    'Option allowDiskUse of aggregation implemented only from 2.6.0'
                );
            }

            if (!empty($options['cursor'])) {
                throw new FeatureNotSupportedException(
                    'Option cursor of aggregation implemented only from 2.6.0'
                );
            }
        }

        // check options for db < 3.2
        if (version_compare($dbVersion, '3.2.0', '<')) {
            if (!empty($options['bypassDocumentValidation'])) {
                throw new FeatureNotSupportedException(
                    'Option bypassDocumentValidation of aggregation implemented only from 3.2.0'
                );
            }

            if (!empty($options['readConcern'])) {
                throw new FeatureNotSupportedException(
                    'Option readConcern of aggregation implemented only from 3.2.0'
                );
            }
        }
    }
82508
public function permitted($options = []) : bool {
		// authorized
		if (\User::authorized()) {
			// see if controller is for authorized
			if (empty($this->acl['authorized'])) return false;
			// permissions
			if (!empty($this->acl['permission'])) {
				// determine action
				switch ($this->method_code) {
					case 'Edit': $action = 'Record_View'; break;
					case 'Index': $action = 'List_View'; break;
					case 'Activate': $action = 'Activate_Data'; break;
					// if we need to alter menu name
					case 'JsonMenuName':
					case 'JsonMenuName2':
					case 'JsonMenuName3':
					case 'JsonMenuName4':
					case 'JsonMenuName5':
						foreach (['Edit' => 'Record_View', 'Index' => 'List_View', 'Activate' => 'Activate_Data'] as $k => $v) {
							if ($this->can($v, $k)) {
								return true;
							}
						}
						return false;
						break;
				}
				return $this->can($action);
			}
		} else {
			// we need to redirect to login controller if not authorized
			if (($options['redirect'] ?? false) && !empty($this->acl['authorized']) && empty($this->acl['public']) && !\Application::get('flag.global.__skip_session')) {
				\Request::redirect(\Object\ACL\Resources::getStatic('authorization', 'login', 'url'));
			}
			// public permission
			if (empty($this->acl['public'])) {
				return false;
			}
		}
		return true;
	}
1239528
public function valid($options = array())
    {
        $options && $this->setOption($options);

        // Initialize the validation result to be true
        $this->result = true;

        $this->beforeValidate && call_user_func($this->beforeValidate, $this, $this->wei);

        foreach ($this->rules as $field => $rules) {
            $data = $this->getFieldData($field);

            /**
             * Process simple rule
             * FROM
             * 'username' => 'required'
             * TO
             * 'username' => array(
             *     'required' => true
             * )
             */
            if (is_string($rules)) {
                $rules = array($rules => true);
            } elseif ($rules instanceof BaseValidator) {
                $rules = array($rules);
            } elseif (!is_array($rules)) {
                throw new \InvalidArgumentException(sprintf(
                    'Expected argument of type array, string or instance of Wei\Validator\BaseValidator, "%s" given',
                    is_object($rules) ? get_class($rules) : gettype($rules)
                ));
            }

            // Make sure the "required" rule at first
            if (!isset($rules['required'])) {
                $isRequired = true;
            } else {
                $isRequired = (bool) $rules['required'];
                unset($rules['required']);
            }
            $rules = array('required' => $isRequired) + $rules;

            // Start validation
            foreach ($rules as $rule => $params) {
                // Prepare property options for validator
                $props = $this->prepareProps($field, $rule);

                // The current rule validation result
                /* @var $validator Validator\BaseValidator */
                $validator = null;
                $result = $this->validateOne($rule, $data, $params, $validator, $props);

                if (is_object($params)) {
                    $rule = get_class($params);
                }

                // Record the rule validators
                $this->ruleValidators[$field][$rule] = $validator;

                // If any rule is invalid, the result would always be false in the whole validation flow
                if (false === $result) {
                    $this->result = false;
                }

                // Record the valid/invalid rule
                $method = $result ? 'addValidRule' : 'addInvalidRule';
                $this->$method($field, $rule);

                // Trigger the ruleValid/ruleInvalid callback
                $callback = $result ? 'ruleValid' : 'ruleInvalid';
                if ($this->$callback && false === call_user_func($this->$callback, $rule, $field, $this, $this->wei)) {
                    return $this->result;
                }

                if ($result) {
                    // The field data is empty and optional, skip the remaining validation rules
                    /** @var $validator Validator\Required */
                    if ('required' === $rule && $validator->isInvalid($data)) {
                        break;
                    }
                } else {
                    // Break the validation flow when any field's rule is invalid
                    if ('required' === $rule || $this->breakRule || $this->skip) {
                        break;
                    }
                }
            }

            // Trigger the fieldValid/fieldInvalid callback
            $callback = $this->isFieldValid($field) ? 'fieldValid' : 'fieldInvalid';
            if ($this->$callback && false === call_user_func($this->$callback, $field, $this, $this->wei)) {
                return $this->result;
            }

            if (!$this->result && $this->skip) {
                continue;
            }

            // Break the validation flow when any field is invalid
            if (!$this->result && ($this->breakRule || $this->breakField)) {
                break;
            }
        }

        // Trigger the success/failure callback
        $callback = $this->result ? 'success' : 'failure';
        $this->$callback && call_user_func($this->$callback, $this, $this->wei);

        return $this->result;
    }
507753
protected static function checkOptions(array $options)
    {
        if (isset($options['value'])) {
            $value = $options['value'];
            unset($options['value']);
            $options['value'] = $value;
        }

        return $options;
    }
334830
public function saveOrFail(array $options = [])
    {
        if ($this->isInvalid()) {
            return $this->throwValidationException();
        }

        return $this->getModel()->parentSaveOrFail($options);
    }
376219
public function validate($value, $options)
	{
		$this->value = $value;
		$this->options = $options;
		$this->errors = [];

		return $this->checkIt();
	}
767296
protected function validate(array $options)
    {
        if (! isset($options['method'])) {
            throw new \InvalidArgumentException('method property is missing');
        } elseif (! in_array($options['method'], ['GET', 'POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE', 'HEAD'])) {
            throw new \InvalidArgumentException('method property is not valid');
        } elseif (! isset($options['path'])) {
            throw new \InvalidArgumentException('path property is missing');
        } elseif (isset($options['since'])
            && ! preg_match('#^' . Application::API_VERSION_REG_EXP . '$#', $options['since'])) {
            throw new \InvalidArgumentException('since property is not valid');
        } elseif (isset($options['until'])
            && ! preg_match('#^' . Application::API_VERSION_REG_EXP . '$#', $options['until'])) {
            throw new \InvalidArgumentException('until property is not valid');
        }
    }