Gdn_Validation::defineValidationRules PHP Method

defineValidationRules() protected method

Get all of the validation rules that apply to a given set of data.
protected defineValidationRules ( array $PostedFields, boolean $Insert = false ) : array
$PostedFields array The data that will be validated.
$Insert boolean Whether or not this is an insert.
return array Returns an array of `[$Field => [$Rules, ...]`.
    protected function defineValidationRules($PostedFields, $Insert = false)
    {
        $Result = (array) $this->_FieldRules;
        // Add all of the fields from the schema.
        foreach ($this->getSchemaRules() as $Field => $Rules) {
            $FieldInfo = $this->_Schema[$Field];
            if (!array_key_exists($Field, $PostedFields)) {
                $Required = in_array('Required', $Rules);
                // Don't enforce fields that aren't required or required fields during a sparse update.
                if (!$Required || !$Insert) {
                    continue;
                }
                // Fields with a non-null default can be left out.
                if (val('Default', $FieldInfo, null) !== null || val('AutoIncrement', $FieldInfo)) {
                    continue;
                }
            }
            if (isset($Result[$Field])) {
                $Result[$Field] = array_unique(array_merge($Result[$Field], $Rules));
            } else {
                $Result[$Field] = $Rules;
            }
        }
        return $Result;
    }