Get the data we're going to validate

@param bool $trimStrings

@return array
@throws Config\Exception
@throws Exception
195627
public function getData(bool $trimStrings = null): array
    {
        $trimStrings = ($trimStrings === null) ? true : $trimStrings;
        $data = $this->data;

        foreach ($data as $key => $value) {
            if (array_key_exists($key, $this->rules)) {
                if ($value === '') {
                    // convert empty strings into nulls
                    $data[$key] = null;
                }
            }

            if ($trimStrings && is_string($data[$key])) {
                $data[$key] = trim($data[$key]);
            }
        }

        $csrfParameterName = Csrf::getParameterName();

        foreach ($this->rules as $field => $rules) {
            if ($field != $csrfParameterName && !array_key_exists($field, $data)) {
                $data[$field] = null;
            }

            if (isset($data[$field]) && is_string($data[$field]) && $rules !== null) {
	            $rules = explode('|', is_object($rules) && method_exists($rules, '__toString') ? $rules->__toString() : $rules);

                // case booleans
                if (in_array('bool', $rules) || in_array('boolean', $rules)) {
                    if ($data[$field] === 'true') {
                        $data[$field] = true;
                    } else if ($data[$field] === 'false') {
                        $data[$field] = false;
                    } else {
                        $data[$field] = (bool)$data[$field];
                    }
                } else if (in_array('integer', $rules)) {
                    $data[$field] = (int)$data[$field];
                }
            }
        }

        if ($this->isCsrfEnabled() && isset($data[$csrfParameterName])) {
            unset($data[$csrfParameterName]);
        }

        return $data;
    }
44890
public function validate()
    {
        $result = parent::validate();
        $checkEmail = [
            'EmailAddress' => 'EMAILADDRESSINVALID',
            'EmailFrom' => 'EMAILFROMINVALID',
            'EmailReplyTo' => 'EMAILREPLYTOINVALID',
        ];
        foreach ($checkEmail as $check => $translation) {
            if ($this->$check) {
                //may be a comma separated list of emails
                $addresses = explode(',', $this->$check);
                foreach ($addresses as $address) {
                    $trimAddress = trim($address);
                    if ($trimAddress && !Email::is_valid_address($trimAddress)) {
                        $error = _t(
                            __CLASS__.".$translation",
                            "Invalid email address $trimAddress"
                        );
                        $result->addError($error . " ($trimAddress)");
                    }
                }
            }
        }

        // if there is no from address and no fallback, you'll have errors if this isn't defined
        if (!$this->EmailFrom && empty(Email::getSendAllEmailsFrom()) && empty(Email::config()->get('admin_email'))) {
            $result->addError(_t(__CLASS__.".EMAILFROMREQUIRED", '"Email From" address is required'));
        }
        return $result;
    }
270320
protected function getValidatorData($validatorClassName)
    {
        if (false === isset($this->validatorsData[$validatorClassName])) {
            $this->validatorsData[$validatorClassName] = [];

            if (in_array(AbstractValidator::class, class_parents($validatorClassName))) {
                $validatorReflection = new \ReflectionClass($validatorClassName);
                $validatorProperties = $validatorReflection->getDefaultProperties();
                unset($validatorReflection);

                $validatorData = [
                    'supportedOptions'   => $validatorProperties['supportedOptions'],
                    'acceptsEmptyValues' => $validatorProperties['acceptsEmptyValues']
                ];

                if (in_array(FormzAbstractValidator::class, class_parents($validatorClassName))) {
                    $validatorData['formzValidator'] = true;
                    $validatorData['supportedMessages'] = $validatorProperties['supportedMessages'];
                    $validatorData['supportsAllMessages'] = $validatorProperties['supportsAllMessages'];
                }

                $this->validatorsData[$validatorClassName] = $validatorData;
            }
        }

        return $this->validatorsData[$validatorClassName];
    }
379996
public function getParams(&$errors = null) {
		$ary    = [];
		$fields = $this->__vars;
		foreach ($fields as $field => $v) {
			$value = $this->{$field};
			if (is_null($value)) {
				continue;
			}
			$ary[ $field ] = $value;
		}
		unset($obj, $vars, $var);
		if ($fields) {
			try {
				$this->validateNewData($ary);
			} catch (ValidateException $e) {
				$errors = $e->getErrors();

				return null;
			}
		}

		return $ary;
	}
552139
protected static function __match(array $patterns)
    {
        return function (...$args) use ($patterns) {
            $parameterTypes = array_map(self::getType(), $args);

            try {
                $keysToValues = Arrays::zip(array_keys($patterns), array_values($patterns));

                list($key, $matchingPattern) = Arrays::first(
                    Pattern::patternApplies($parameterTypes, $args),
                    $keysToValues
                );
            } catch (ElementNotFoundException $e) {
                throw new IncompletePatternMatchException(
                    'Incomplete pattern match expression. (missing ' . implode(', ', $parameterTypes) . ')'
                );
            }


            /**
             * Upcoming Feature, Array DSL for matching via `x::xs` etc.
             */
//            // if key is a string, manually match
//            if (is_string($key)) {
//
//                throw new \Exception('Array DSL not available.');
//            }

            list($hasExtractable, $unwrappedArgs) = self::unwrapArgs($args);

            $value = $matchingPattern(...$args);
            $isCallable = is_callable($value);

            if ($hasExtractable && ! $isCallable) {
                throw new InvalidPatternMatchException(
                    'Invalid pattern match expression. (one of ' . implode(', ', $parameterTypes)
                    . ' requires a callback to unwrap)'
                );
            }

            /**
             * Extractable requires a callback to feed args into.
             */
            if ($hasExtractable && $isCallable) {
                return $matchingPattern(...$args)(...$unwrappedArgs);
            }

            /**
             * No extractable so we can just return the value directly.
             */
            return $value;
        };
    }
940794
private function validateData($rules, $data) {
		$errors = [];
		foreach ($rules as $field => $rule) {
			$valid = $this->validateField($field, $data, $rule);
			if ($valid !== true) {
				$errors[ $field ] = $valid;
			}
		}
		if (!empty($errors)) {
			throw new ValidateException($errors);
		}

		return true;
	}
185854
public function getLine( $trim = false )
    {
        $data = '';
        $line = '';

        if ( is_resource( $this->connection ) )
        {
            // in case there is a problem with the connection fgets() returns false
            while ( strpos( $data, self::CRLF ) === false )
            {
                $line = fgets( $this->connection, 512 );

                /* If the mail server aborts the connection, fgets() will
                 * return false. We need to throw an exception here to prevent
                 * the calling code from looping indefinitely. */
                if ( $line === false )
                {
                    $this->connection = null;
                    throw new ezcMailTransportException( 'Could not read from the stream. It was probably terminated by the host.' );
                }

                $data .= $line;
            }

            if ( $trim == false )
            {
                return $data;
            }
            else
            {
                return rtrim( $data, "\r\n" );
            }
        }
        throw new ezcMailTransportException( 'Could not read from the stream. It was probably terminated by the host.' );
    }
118498
public static function parseHeaders($headerstr=false) {
        if ( $headerstr === false ) $headerstr = self::getLastHeadersReceived();
        $lines = explode("\n",$headerstr);
        $headermap = array();

        foreach ($lines as $line) {
            $pos = strpos($line, ':');
            if ( $pos < 1 ) continue;
            $key = substr($line,0,$pos);
            $value = trim(substr($line, $pos+1));
            if ( strlen($key) < 1 || strlen($value) < 1 ) continue;
            $headermap[$key] = $value;
        }
        return $headermap;
    }
1208166
public function laravel($value, $validationString, $messages = [])
    {
        //create validator
        $validator = \Validator::make(['laravel' => $value], ['laravel' => $validationString]);
        $validator->setCustomMessages($this->getMessages());

        // error message management
        if ($validator->fails() && !$this->hasMessage('laravel')) {
            $message = '';
            foreach ( $validator->errors()->get('laravel') as $m) {
                $message .= $m . ' ';
            }
            $this->addMessage('laravel', $message);
        }

        // return validation
        return $validator->valid();
    }
586736
protected function _parse_string($string, $single_trim = false) {
    if ($single_trim) {
      $string = preg_replace("/^[\"\']/", "", $string);
      $string = preg_replace("/[\"\']$/", "", $string);
    }
    else {
      $string = trim($string, "'\"");
    }
    
    $string = str_replace(array("\\\n",'\\"',"\\'"),
                          array("",'"',"'"), $string);

    // Convert escaped hex characters into ascii characters (e.g. \A => newline)
    $string = preg_replace_callback("/\\\\([0-9a-fA-F]{0,6})(\s)?(?(2)|(?=[^0-9a-fA-F]))/",
                                    create_function('$matches',
                                                    'return chr(hexdec($matches[1]));'),
                                    $string);
    return $string;
  }
695113
protected function validate($params)
    {
        if (array_get($params, 'data.dispatchable') === false) {
            return false;
        }
        if (is_null($classname = array_get($params, 'data.classname'))) {
            return false;
        }
        try {
            if (!class_exists($classname)) {
                return false;
            }
        } catch (Exception $ex) {
            return false;
        }

        return $classname;
    }
1028124
public function getValidData()
    {
        return array_combine(
            array_keys($this->validAttribs),
            array_map(function ($ref) {
                return $ref['value'];
            }, array_values($this->validAttribs))
        );
    }
684071
public static function getMatches(string $branchString)
    {
        $branchString = trim($branchString);

        $regexList = [
            '/^\*?\ *?(\S+)\ +(\S{40})\ +(.+)$/',
            '/^\*?\ *?\(.*(detached).*\)\ +(\S{40})\ +(.+)$/',
        ];

        $matches = [];
        while (empty($matches) and $regex = array_pop($regexList)) {
            preg_match($regex, trim($branchString), $matches);
        }

        if (empty($matches)) {
            throw new \InvalidArgumentException(sprintf('the branch string is not valid: %s', $branchString));
        }

        return array_map('trim', $matches);
    }
720374
public function validated()
    {
        if ($this->invalid()) {
            throw new ValidationException($this);
        }

        $results = [];

        $missingValue = Str::random(10);

        foreach (array_keys($this->getRules()) as $key) {
            $value = data_get($this->getData(), $key, $missingValue);

            if ($value !== $missingValue) {
                Arr::set($results, $key, $value);
            }
        }

        return $results;
    }
329464
public function getHttpHost($trimPort = true) {
        if ( ! isset($this->SERVER['HTTP_HOST'])) {
            return false;
        }
        if ($trimPort) {
            $host = explode(':', $this->SERVER['HTTP_HOST']);
            return $host[0];
        }
        return $this->SERVER['HTTP_HOST'];
    }
1110249
public function get_errors_array($convert_to_string = null)
    {
        if (empty($this->errors)) {
            return ($convert_to_string) ? null : array();
        }

        $resp = array();

        // Error messages
        $messages = $this->get_messages();

        foreach ($this->errors as $e)
        {
            $field = ucwords(str_replace(array('_', '-'), chr(32), $e['field']));
            $param = $e['param'];

            // Let's fetch explicitly if the field names exist
            if (array_key_exists($e['field'], self::$fields)) {
                $field = self::$fields[$e['field']];

                // If param is a field (i.e. equalsfield validator)
                if (array_key_exists($param, self::$fields)) {
                    $param = self::$fields[$e['param']];
                }
            }

            // Messages
            if (isset($messages[$e['rule']])) {
                // Show first validation error and don't allow to be overwritten
                if (!isset($resp[$e['field']])) {
                    if (is_array($param)) {
                        $param = implode(', ', $param);
                    }
                    $message = str_replace('{param}', $param, str_replace('{field}', $field, $messages[$e['rule']]));
                    $resp[$e['field']] = $message;
                }
            } else {
                throw new \Exception ('Rule "'.$e['rule'].'" does not have an error message');
            }
        }

        return $resp;
    }
523115
public static function parseAttrsString($attrs,$excludeAttrs = array())
	{
		$result = '';
		if(is_array($attrs))
		{
			if(isset($attrs['disabled']) && 0==$attrs['disabled'])
			{
				unset($attrs['disabled']);
			}
			if(isset($attrs['readonly']) && 0==$attrs['readonly'])
			{
				unset($attrs['readonly']);
			}
			foreach($attrs as $key=>$attr)
			{
				if(false===in_array($key,$excludeAttrs))
				{
					$result .= " {$key}=\"{$attr}\"";
				}
			}
		}
		return $result;
	}