Normalizes value as per context and runs thorugh filter if possible.

@param Parameter   $parameter
@param string|null $value

@return mixed
559586
public function normalizeValue(Parameter $parameter, string $value = null)
    {
        if (\is_bool($default = $parameter->default())) {
            return !$default;
        }

        if ($parameter->variadic()) {
            return (array) $value;
        }

        if (null === $value) {
            return $parameter->required() ? null : true;
        }

        return $parameter->filter($value);
    }
801201
public function addParameter($parameter, $value)
    {
        if (isset($this->parameters[$parameter])) {
            return;
        }

        $this->parameters[$parameter] = $value;
    }
270849
public function filterByParameter($parameter)
    {
        $callback = function (BindingInterface $binding, $key) use ($parameter) {
            return $binding->getParameter() == $parameter;
        };

        return $this->filter($callback);
    }
1169997
protected function format($parameter, $value)
    {
        if ($value) {
            if (is_bool($value)) {
                return strlen($parameter) === 1 ? '-'.$parameter : '--'.$parameter;
            }
            return strlen($parameter) === 1 ? '-'.$parameter.$value : '--'.$parameter.'='.$value;
        }
        return '';
    }
108035
public function setParam($param, $value = null)
    {
        if (is_string($param)) {
            $this->_params[$param] = $value;

            return $this;
        }

        if (is_array($param)) {
            foreach ($param as $key => $value) {
                $this->_params[$key] = $value;
            }
        }

        return $this;
    }
1004631
public function bindValue($parameter = null, $value = null, $type = null)
    {
        parent::bindValue($parameter, $value, $type);
        
        return $this;
    }
505159
public function whereHas($parameter, $value)
    {
        if (! $this->verify($parameter, $value)) {
            return true;
        }

        $this->search = $this->search
            ->whereHas($parameter, function ($query) use ($value) {
                $query->where('rbac_roles.id', $value);
            });
    }
171456
protected function _validate_ext($value, $parameter)
    {
        if ($value === '') {
            return '';
        }

        $ext = pathinfo($value, PATHINFO_EXTENSION);
        return in_array(strtolower($ext), preg_split('#[\s,]+#', $parameter, -1, PREG_SPLIT_NO_EMPTY), true) ? $value : null;
    }
1247406
protected function adjustCaseInsensitive(&$value, &$parameters) {
        $parameterAmount = count($parameters);
        if ($parameterAmount == 1 || $parameterAmount > 1 && $parameters[1]) {
            $parameters[0] = strtolower($parameters[0]);
            $value         = strtolower($value);
        }
    }
678647
public function toParameterValue($value)
    {
        foreach ($this->getTransformers() as $transformer) {
            $value = $transformer->toParameterValue($value);
        }

        return $value;
    }
496762
public function isLength($value, $parameter)
    {
        $min = $parameter[0];
        $max = $parameter[1];
        if ($min != 0 && strlen($value) < $min) {
            return false;
        }
        if ($max != 0 && strlen($value) > $max) {
            return false;
        }

        return true;
    }
1279722
public function set(string $parameter, $value, int $typeConstant = null): string
	{
		$this->bindings[$parameter] = new Bind($parameter, $value, $typeConstant);
		return $parameter;
	}
329146
public function normalizeValue($value)
	{
		if (is_string($value) && preg_match('(^#\\w+$)', $value))
		{
			$value = AttributeFilterCollection::getDefaultFilter(substr($value, 1));
		}

		return parent::normalizeValue($value);
	}
715556
public function normalize($value)
    {
        if ($value instanceof Expression ||
            $value instanceof Expressionable) {
            return $value;
        }

        return parent::normalize($value);
    }
371240
private static function matchType(\ReflectionParameter $parameter, $value) : bool
    {
        if ($class = $parameter->getClass()) {
            return \is_object($value) && $class->isInstance($value);
        }

        if ($parameter->isArray()) {
            return \is_array($value);
        }

        if ($parameter->isCallable()) {
            return \is_callable($value);
        }

        if (!$type = $parameter->getType()) {
            return true;
        }

        switch ($type->getName()) {
            case 'bool': return \is_bool($value);
            case 'float': return \is_float($value);
            case 'int': return \is_int($value);
            case 'string': return \is_string($value);
            case 'iterable': return \is_iterable($value);
        }

        return true;
    }
362000
protected function filterValue($value)
    {
        $filter = new Filter();

        call_user_func($this->callable, $filter);

        return $filter->filter($value);
    }
933940
protected function _validate_exists($value, $parameter = null)
    {
        $context = $this->_context;

        if (!$value) {
            return $value;
        }
        $field = $context->field;
        if ($parameter) {
            $className = $parameter;
        } else {
            $modelName = get_class($context->model);
            if (preg_match('#^(.*)_id$#', $field, $match)) {
                $className = substr($modelName, 0, strrpos($modelName, '\\') + 1) . Text::camelize($match[1]);
                if (!class_exists($className)) {
                    $className = $this->alias->get('@ns.app') . '\\Models\\' . Text::camelize($match[1]);
                }
            } else {
                throw new InvalidValueException(['validate `:field` field failed: related model class name is not provided', 'field' => $field]);
            }
        }

        if (!class_exists($className)) {
            throw new InvalidValueException(['validate `:1` field failed: related `:2` model class is not exists.', $field, $className]);
        }

        /**
         * @var \ManaPHP\Model $model
         * @var \ManaPHP\Model $className
         */
        $model = new $className;
        return $className::exists([$model->getPrimaryKey() => $value]) ? $value : null;
    }