Validate input as string

@param mixed $input
@return string
12293
public function validate( $input )
    {
        // Check if we received a unix timestamp, in this case we can just
        // directly convert and return it.
        if ( is_numeric( $input ) )
        {
            $date = new DateTime( '@' . $input );
        }
        // Otherwise we received most presumably some phpillowrary string, which
        // we first just try to parse with datetime (strtotime).
        else if ( ( $date = new DateTime( $input ) ) !== false )
        {
            // Already converted
        }
        // If IndexableDateTime could not parse the string, we got a problem. Maybe
        // handle more datetime formats here manually, but now we just fail.
        //
        // Since PHP 5.3 datetime seems to accept everything and just returns
        // NOW, if it fails to parse. So this seems untestable for now.
        else {
            throw new phpillowValidationException( 
                'Error parsing the date: %date', 
                array(
                    'date' => $input,
                )
            );
        }

        // Convert date to an array of ints, which is easily indexable inside
        // CouchDB views.
        return array(
            (int) $date->format( 'Y' ),
            (int) $date->format( 'm' ),
            (int) $date->format( 'd' ),
            (int) $date->format( 'H' ),
            (int) $date->format( 'i' ),
            (int) $date->format( 's' ),
        );
    }
870509
public function validate( $input )
    {
        $uuidv4Pattern = '(^([0-9a-fA-F]{8})-?([0-9a-fA-F]{4})-?(4[0-9a-fA-F]{3})-?([89abAB][0-9a-fA-F]{3})-?([0-9a-fA-F]{12})$)';
        if ( preg_match( $uuidv4Pattern, $input, $matches ) !== 1 ) 
        {
            throw new phpillowValidationException( 
                'A uuid version 4 is required. Something else has been given.',
                array()
            );
        }

        return strtolower( 
            $matches[1] . '-' . $matches[2] . '-' . $matches[3] . '-' . $matches[4] . '-' . $matches[5]
        );
    }
473800
private function checkValidStructure($input)
    {
        $mirror = ($input) ? (array)$input : [];

        foreach ($this->getRules() as $attributeRule) {
            if (array_key_exists($attributeRule->reference, $mirror)) {
                unset($mirror[$attributeRule->reference]);
            }
        }

        return array_keys($mirror);
    }
560484
public function serialise($input)
    {
        $writer = Writer::createFromString('');

        if (is_array(reset($input))) {
            $writer->insertOne(array_keys(reset($input)));
        } else {
            $writer->insertOne(array_keys($input));
        }

        if (is_array(reset($input))) {
            $writer->insertAll($input);
        } else {
            $writer->insertOne($input);
        }

        return $writer->__toString();
    }
1246629
public function validate($input)
    {
        $this->errors = [];

        foreach($this->rawRules as $rules){

            list($ruleName, $rule) = $rules;

            // notOf or oneOf
            if ($rule instanceof Validate) {
                $rule->validate($input);
                $this->errors = array_merge($this->errors, $rule->getErrors());
                continue;
            }

            if ($rule instanceof When) {
                $rule->invert = $this->invert;
                $rule->validate($input);
                $this->errors = array_merge($this->errors, $rule->getErrors());
                continue;
            }

            if ($rule instanceof Attributes) {
                $config = [
                    'one' => $this->one,
                    'invert' => $this->invert,
                    'remainder' =>  $this->remainder
                ];
                Instance::configure($rule, $config);
                $rule->validate($input);
                $this->errors = $rule->getErrors();
                break;
            }

            if ($this->skipEmpty && $rule->skipEmpty && $this->isEmpty($input, $rule)) {
                continue;
            }

            if ($rule->validate($input) === !$this->invert) {
                continue;
            }
            $this->errors[$ruleName] = $this->error($ruleName, $rule);
            if ($this->one === true) {
                break;
            }
        }
        return empty($this->errors);
    }
222024
public static function fromString(string $input): self
    {
        $input = preg_replace('/[^\d]/', '', $input);

        if (!is_numeric($input)) {
            throw new \InvalidArgumentException("Expects \$input to be a number, \"{$input}\" given.");
        }

        // Get the last digit.
        $checkDigit = (int) $input[strlen($input) - 1];

        // Remove the last digit.
        $number = substr($input, 0, strlen($input) - 1);

        return new self($number, $checkDigit);
    }
14451
protected function validateInput($input)
    {
        // check
        $keys = [
            'form',
            'elements',
        ];

        switch (gettype($input)) {
            case 'array':
                foreach ($keys as $key) {
                    if (array_key_exists($key, $input) === false) {
                        throw new \Exception(
                            'Input invalid! Please make sure that input array contains keys (form, elements).'
                        );
                    }
                }
                break;
        }

        return true;
    }
233136
public function decode($input)
    {
        $parts = explode('.', $input);

        foreach ($parts as &$part) {
            if (strpos($part, static::PREFIX) === 0) {
                $part = $this->_decodePart(
                    substr($part, strlen(static::PREFIX))
                );
            }
        }

        return implode('.', $parts);
    }
204062
public function convert($input)
    {
        if (is_string($input) === false) {
            throw new \InvalidArgumentException('Expected a string value at Parsedown converter.');
        }

        $converter = new \ParsedownExtra();

        return $converter->text($input);
    }
1363139
public static function unpad(string $input): string
    {
        // Determine the padding size by converting the final byte of the  
        // input to its decimal value
        $padsize = \ord(Str::substr($input, -1));

        // Return string minus the padding amount
        return Str::substr($input, 0, Str::strlen($input) - $padsize);
    }
227076
public static function toString($input = false) {

        if ($input) {

            $string = (string) $input;
            if (Validate::isString($string)) {

                return $string;
            }
        }

        return false;
    }
957189
private function parseValue($input)
    {
        if (is_array($input)) {

        } elseif (substr($input, 0, 1) === '"' && substr($input, -1) === '"') {
            $input = substr($input, 1, -1);
        } elseif (strpos($input, "|") !== false) {
            $input = explode("|", $input);
            foreach ($input as $key => $value) {
                $input[$key] = $this->parseValue($value);
            }
        } elseif ($input === "false") {
            $input = false;
        } elseif ($input === "true") {
            $input = true;
        } elseif (is_numeric($input)) {
            if (strpos($input, ".") !== false) {
                $input = (float)$input;
            } else {
                $input = (int)$input;
            }
        } elseif ($input === "on") {
            $input = true;
        }

        return $input;
    }
33120
public function validate( $input )
    {
        // Check if regular expression matches the input string.
        if ( !preg_match( $this->regexp, $input ) )
        {
            throw new phpillowValidationException(
                'Input %input did not match regular expression %expression.', 
                array(
                    'input' => $input,
                    'expression' => $this->regexp,
                )
            );
        }

        return (string) $input;
    }
1282386
protected function validator($input)
    {
        $this->checkValue($input);

        if ($this->hasErrors()) {
            return '';
        }

        if (!$input) {
            if ($this->mandatory) {
                $this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['mandatory'], $this->strLabel));
            }

            return '';
        } elseif (false === strpos($input, ',')) {
            return $this->multiple ? [(int) $input] : (int) $input;
        }
        $arrValue = array_map('intval', array_filter(explode(',', $input)));

        return $this->multiple ? $arrValue : $arrValue[0];
    }
450176
public function validate($input): bool
    {
        if (!$length = $this->extractLength($input)) {
            return false;
        }

        return (null === $this->minValue || $this->less($this->minValue, $length))
            && (null === $this->maxValue || $this->less($length, $this->maxValue));
    }
793319
protected function filter($input): string
    {
        $input = parent::filter((string)$input);
        return preg_replace('/\s/', '', $input);
    }
879523
public static function pascalToSnakeCase($input)
    {
        preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $input, $matches);

        foreach ($matches[0] as &$match) {
            $match = ($match == strtoupper($match)) ? strtolower($match) : lcfirst($match);
        }

        return implode('_', $matches[0]);
    }