Validate the data using the given rule and parameter.

@param string $keyword
@param mixed  $parameter

@return null|ValidationError|ValidationError[]
164047
private function validateRule($keyword, $parameter)
    {
        if (!$this->ruleSet->has($keyword)) {
            return null;
        }

        return $this->ruleSet->get($keyword)->validate($this->data, $parameter, $this);
    }
1067036
public static function invalidParameter($actualParameter, array $allowedParameter, $keyword, $pointer)
    {
        $message = sprintf(
            'Value is "%s" but must be one of: "%s"',
            $actualParameter,
            implode(', ', $allowedParameter)
        );

        return new self($message, $keyword, $pointer);
    }
840041
public function validator($resource=null)
    {

        $resource = $this->passedOrCurrent($resource);

        if ($class = $this->mapper->validatorClass($resource)) {
            return $this->makeValidator($resource, $class);
        }

        $modelClass = class_basename($this->modelClass($resource));

        if ($class = $this->finder->validatorClass($resource, $modelClass)) {
            return $this->makeValidator($resource, $class);;
        }

        $class = 'Cmsable\Resource\GenericResourceValidator';

        if ($rules = $this->getManualRules($resource)) {
            $validator = $this->makeValidator($resource, $class);
            return $validator->setRules($rules);
        }

        // Support for rules inside forms
        if (!$this->hasForm($resource)) {
            throw new RuntimeException('No validator for resource $resource found');
        }


        if ($rules = $this->formRules($this->form(null, $resource))) {
             $validator = $this->makeValidator($resource, $class);
             return $validator->setRules($rules);

        }

        throw new RuntimeException('No validator for resource $resource found');

    }
1217316
public function validateReservedWord($attribute,$params)
	{
		$value=$this->$attribute;
		if(in_array(strtolower($value),self::$keywords))
			$this->addError($attribute, $this->getAttributeLabel($attribute).' cannot take a reserved PHP keyword.');
	}
487136
protected function extractParameter(string $parameter, array $variables): array
    {
        $result = preg_match(
            '/^\s*' . self::REGEX_VARIABLE . '(\s*,\s*(?<next>.+))?\s*$/is',
            $parameter,
            $matches
        );

        if ($result === 0) {
            throw new SyntaxErrorException("Invalid parameter list $parameter");
        }

        return empty($matches['next'])
            ? [$this->getValue($matches, $variables)]
            : array_merge(
                [$this->getValue($matches, $variables)],
                $this->extractParameter($matches['next'], $variables)
            );
    }
611361
private function extractRequiredParameter(string $parameter, array $data)
    {
        if (!isset($data[$parameter])) {
            throw new InvalidAudioFormatParameterException(
                sprintf("Parameter \"%s\" is required", $parameter)
            );
        }

        return $data[$parameter];
    }
748882
public function get_param_validation() {
        switch ($this->vtype) {
            case self::IS_BOOLEAN:
                return PARAM_BOOL;
            case self::IS_INTEGER:
                return PARAM_INT;
            case self::IS_FILENAME:
                return PARAM_FILE;
            case self::IS_PATH:
                return PARAM_PATH;
            case self::IS_TEXT:
                return PARAM_TEXT;
        }
        return null;
    }
1136986
private function validateParameters( $taxonomy, $contextParameters, $variableSet )
	{
		$parameterArcs = $taxonomy->getGenericArc( XBRL_Constants::$arcRoleVariableSet, $variableSet->extendedLinkRoleUri, null, $variableSet->path, null, $variableSet->linkbase );

		// Get any variable sets.  These will be headed by a formula.
		$parameters = array_filter( $taxonomy->getGenericResource( 'variable',  'parameter', null, null, null /*, $variableSet->linkbase */ ),
			function( $resource ) use( $parameterArcs )
			{
				return count( array_filter( $parameterArcs, function( $arc ) use( $resource )
				{
					return $arc['tolinkbase'] == $resource['linkbase'];
				} ) ) > 0;
			}
		);

		// Check there are parameters to process
		if ( ! $parameters ) return true;

		$parameterDependencies = array();

		foreach ( $parameters as $parameterReference )
		{
			/** @var Parameter $parameter */
			$parameter = Parameter::fromArray( $parameterReference['variable'] );
			if ( ! $parameter )
			{
				$this->log->err( "Failed to create Parameter instance from an array" );
				return false;
			}

			if ( $parameter->path != $variableSet->path ) continue;

			if ( ! $parameter->validate( null, $this->nsMgr ) )
			{
				return false;
			}

			$parameterDependencies[ $parameter->getQName()->clarkNotation() ] = $parameter->getVariableRefs();

			$this->parameterQnames[ $parameter->getQName()->clarkNotation() ] = $parameter;
			$variableSet->parameters[ $parameter->getQName()->clarkNotation() ] = $parameter;
		}

		/**
		 * Examines parameter dependcies
		 * @var Function $hasCircularReference
		 */
		$parameterQnames = $this->parameterQnames;
		$hasCircularReference = function( $dependencies, $history = array() ) use( &$hasCircularReference, $parameterDependencies, $parameterQnames )
		{
			foreach ( $dependencies as /** @var QName $dependency */ $dependency )
			{
				// Check if this is a cyclic reference
				if ( in_array( $dependency, $history ) )
				{
					$this->log->formula_validation( 'Variable parameter', 'Cyclic dependencies in parameter names to names dependencies', array(
						'parameter' => end( $history ),
						'dependency' => $dependency->clarkNotation(),
						'error' => 'xbrlve:parameterCyclicDependencies'
					) );

					return true;
				}

				// The dependency MUST appear in $parameterQnames or it is undefined
				if ( ! isset( $parameterQnames[ $dependency->clarkNotation() ] ) )
				{
					$this->log->formula_validation( 'Variable parameter', 'Undefined dependencies in parameter to names dependencies', array(
						'parameter' => end( $history ),
						'dependency' => $dependency->clarkNotation(),
						'error' => 'xbrlve:unresolvedDependency'
					) );
					return true;
				}

				// Look for the dependency in $parameterDependencies
				if ( ! isset( $parameterDependencies[ $dependency->clarkNotation() ] ) )
				{
					continue;
				}

				// Check the next dependencies
				$history[] = $dependency->clarkNotation();
				if ( $hasCircularReference( $parameterDependencies[ $dependency->clarkNotation() ], $history ) )
				{
					return true;
				}
			}

			return false;
		};

		// Perform the dependency check
		foreach ( $parameterDependencies as $qname => $dependencies )
		{
			if ( $hasCircularReference( $dependencies, array( $qname ) ) )
			{
				return false;
			}
		}

		// Check there is a context parameter for each formula parameter that is marked as required
		foreach ( $this->parameterQnames as $clark => /** @var Parameter $parameter */ $parameter )
		{
			// If the parameter references a qname from the the instance then there is nothing to do here
			if ( $taxonomy->getElementByName( $parameter->getQName()->localName ) ) continue;

			try
			{
				// Check to see if the parameter is one of the context (passed in) parameters
				if ( isset( $contextParameters[ $clark ] ) )
				{
					// Test the compatibility of the context parameter type and value
					$parameter->select = $contextParameters[ $clark ]['value'];
					$expression = XPath2Expression::Compile( "{$contextParameters[ $clark ]['datatype']}({$contextParameters[ $clark ]['value']}) cast as {$contextParameters[ $clark ]['datatype']}", $this->nsMgr );
					$value = $expression->EvaluateWithVars( null, array() );
					$parameter->expression = $expression;

					// Now check the $value type is compatible with the parameter type.
					// The evaluation step will throw an exception if not
					if ( $parameter->as )
					{
						$expression = XPath2Expression::Compile( "\$value cast as {$parameter->as}", $this->nsMgr );
						$result = $expression->EvaluateWithVars( null, array( 'value' => $value ) );
						// Replace with casted expression if valid
						// $parameter->expression = $expression;
					}
				}
				else if ( $parameter->required )
				{
					$this->log->formula_validation( 'Variable parameter', 'Parameter is required but not input', array(
						'parameter' => $clark,
						'error' => 'xbrlve:missingParameterValue'
					) );

					return false;
				}
				else if ( ! isset( $parameter->select ) || ! strlen( $parameter->select ) )
				{
					$this->log->formula_validation( 'Variable parameter', 'Parameter does not have a select attribute', array(
						'parameter' => $clark,
						'error' => 'xbrlve:missingParameterValue'
					) );

					return false;
				}
			}
			catch ( Exception $ex )
			{
				$this->log->formula_validation( 'Variable parameter', 'The input parameter type is not valid', array(
					'parameter' => $clark,
					'cause' => $ex->getMessage(),
					'error' => 'xbrlve:parameterTypeMismatch'
				) );

				return false;
			}
		}

		// TODO This needs to be checked
		// There should be no dependencies so this routine should resolve all parameter expressions to result values.
		$parameters = $this->parameterQnames;
		while ( $parameters )
		{
			// Get the first parameter
			$parameter = reset( $parameters );
			unset( $parameters[ key( $parameters ) ] );

			 // Get a list of dependencies for this parameter
			$dependencies = $parameter->getVariableRefs();

			$vars = array();

			// Make sure that each dependency has been evaluated
			foreach ( $dependencies as $qname => $dependentQName )
			{
				if ( ! isset( $this->parameterQnames[ $dependentQName->clarkNotation() ] ) )
				{
					continue;
				}

				$dependentParameter = $this->parameterQnames[ $dependentQName->clarkNotation() ];
				if ( ! $dependentParameter->result ) continue;

				$vars[ $dependentParameter->name ] = $dependentParameter->result;
			}

			try
			{
				$result = $parameter->expression->EvaluateWithVars( null, $vars );
				$parameter->result = $result;
			}
			catch ( Exception $ex )
			{
				$this->log->formula_validation( 'Variable parameter', 'Parameter type is not valid', array(
					'parameter' => $parameter->getQName()->clarkNotation(),
					'select' => $parameter->getSelectAsExpression(),
					'as' => $parameter->as,
					'cause' => $ex->getMessage(),
					'error' => 'xbrlve:parameterTypeMismatch'
				) );
			}

		}

		return true;
	}
702045
public function get($parameter = null) {

        if ( empty($parameter) ) {

            $return = $this->parameters;

        } else if ( array_key_exists($parameter, $this->parameters) ) {

            $return = $this->parameters[$parameter];

        } else {

            $return = null;

        }

        return $return;

    }
1122823
protected function _validate_date($value, $parameter = null)
    {
        $context = $this->_context;

        $ts = is_numeric($value) ? (int)$value : strtotime($value);
        if ($ts === false) {
            return null;
        }

        $r = date($context->model->getDateFormat($context->field), $ts);
        return $r !== false ? $r : null;
    }
1302281
protected function _validate_in($value, $parameter)
    {
        return in_array($value, preg_split('#[\s,]+#', $parameter, -1, PREG_SPLIT_NO_EMPTY), false) ? $value : null;
    }
449003
public function getParameter($parameter)
    {
        return isset($this->getParameters()[$parameter]) ? $this->getParameters()[$parameter] : null;
    }
166369
protected function validateByOwnMethod($ruleName, array $vars, array $parameters)
    {
        $method = $this->getMethodBySnakeCaseName($ruleName);

        $methodParams = Lambda::mergeArguments([$this, $method], $vars, $parameters);

        return call_user_func_array([$this, $method], $methodParams);
    }
1173276
protected function getValidator($data = null)
    {
        if (!$this->validator) {
            if ($data) {
                // Validate without key
                if ($this->lastKey === '') {
                    $data = ['' => $data];
                }

                $this->options['data'] = $data;
            }

            $this->validator = $this->wei->validate($this->options);
        }

        return $this->validator;
    }
700362
public function validate($data = null)
    {
        if ($data !== null) {
            $this->setData($data);
        }
        // data was already validated, return the results immediately
        if ($this->wasValidated === true) {
            return $this->wasValidated && count($this->messages) === 0;
        }
        foreach ($this->rules as $selector => $valueValidator) {
            foreach ($this->getDataWrapper()->getItemsBySelector($selector) as $valueIdentifier => $value) {
                /* @var $valueValidator \Sirius\Validation\ValueValidator */
                if (!$valueValidator->validate($value, $valueIdentifier, $this->getDataWrapper())) {
                    foreach ($valueValidator->getMessages() as $message) {
                        $this->addMessage($valueIdentifier, $message);
                    }
                }
            }
        }
        $this->wasValidated = true;

        return $this->wasValidated && count($this->messages) === 0;
    }
388543
private static function getSchema($parameter, $key)
    {
        if (is_object($parameter)) {
            // list validation
            return $parameter;
        } elseif (is_array($parameter) && array_key_exists($key, $parameter)) {
            // tuple validation
            return $parameter[$key];
        }

        return null;
    }
433511
public function find($type, $method, $parameter)
    {
        if (strpos($method, '::filter_') !== false) {
            $method = substr($method, strpos($method, '::filter_') + 9);
        }
        if ($message = $this->findForMethod($method, $parameter)) {
            return $message;
        }
        // 4. use message for a specific type. 
        if (isset($this->messages['_type_'][$type])) {
            return $this->messages['_type_'][$type];
        }

        // 5. use general error message.
        return (string) Helper::arrGet($this->messages, '0', '');
    }