Matches a string against current filter

Matches given string against the filter rule the specific object of this
class represents

@param string $input the string input to match

@throws \InvalidArgumentException if argument is no string
@return boolean
178827
public function match($input)
    {
        if (!is_string($input)) {
            throw new \InvalidArgumentException(
                'Invalid argument. Expected a string, received ' . gettype($input)
            );
        }

        return (bool) preg_match('/' . $this->getRule() . '/ms', strtolower($input));
    }
1015145
protected function validate_contains($field, $input, $param = null)
    {
        if (!isset($input[$field])) {
            return;
        }

        $param = trim(strtolower($param));

        $value = trim(strtolower($input[$field]));

        if (preg_match_all('#\'(.+?)\'#', $param, $matches, PREG_PATTERN_ORDER)) {
            $param = $matches[1];
        } else {
            $param = explode(chr(32), $param);
        }

        if (in_array($value, $param)) { // valid, return nothing
            return;
        }

        return array(
            'field' => $field,
            'value' => $value,
            'rule' => __FUNCTION__,
            'param' => $param,
        );
    }
716323
public function verifySalt($input)
    {
        $regex = '/^\$sha1\$(\d{1,10})\$([\.\/0-9A-Za-z]{0,64})\$?$/';
        $matches = array ();

        $appearsValid = (1 === preg_match($regex, $input, $matches));
        if ($appearsValid) {
            $rounds = (int) $matches[1];
            $salt = $matches[2];

            if (!empty ($matches[1]) && ($rounds < 1 || $rounds > 4294967295)) {
                $appearsValid = false;
            }
        }

        return $appearsValid;
    }
1147174
public function matches(array &$input, array &$output)
    {
        if ($this->token === null || $this->token->matches($input, $output)) {
            // excessive arguments should fail, make sure input is now empty
            // single remaining `--` to separate options from arguments is also accepted
            if (!$input || (count($input) === 1 && reset($input) === '--')) {
                return true;
            }
        }

        return false;
    }
240413
public function sanitize(array $input)
    {
        if (!isset($input['text'])) {
            throw new InvalidArgumentException('A \'text\' entry should have been given in the input array');
        }
        if (!is_object($input['text']) || !($input['text'] instanceof Text)) {
            throw new InvalidArgumentException('The \'text\' entry should be an instance of Text');
        }

        return $input['text'];
    }
223271
protected function getNodesMatchingInput($input, bool $matchType = true): NodeList {
        if ($input instanceof NodeList || $input instanceof \DOMNode) {
            $inputNodes = $this->inputAsNodeList($input, false);

            $fn = function($node) use ($inputNodes) {
                return $inputNodes->exists($node);
            };


        } elseif (is_callable($input)) {
            // Since we're at the behest of the input callable, the 'matched'
            //  return value is always true.
            $matchType = true;

            $fn = $input;

        } elseif (is_string($input)) {
            $fn = function($node) use ($input) {
                return $node->find($input, 'self::')->count() != 0;
            };

        } else {
            throw new \InvalidArgumentException('Unexpected input value of type "' . gettype($input) . '"');
        }

        // Build a list of matching nodes.
        return $this->collection()->map(function($node) use ($fn, $matchType) {
            if ($fn($node) !== $matchType) {
                return null;
            }

            return $node;
        });
    }
144402
private function getIdFromInput( $input ) {
		if( is_string( $input ) ) {
			return $input;
		} elseif( $input instanceof ItemId ) {
			return $input->getSerialization();
		} elseif( $input instanceof Item ) {
			return $input->getId()->getSerialization();
		} else {
			throw new InvalidArgumentException( 'Merge target should be either string, Item or ItemId' );
		}
	}
681859
public function applyFilter($position, $input)
    {
        // oops, invalid position
        if (!in_array($position, array('pre', 'post'))) {
            throw new \InvalidArgumentException("Cannot add filters to '$position'. Use 'pre' or 'post'");
        }

        // determine accessor
        $var = $position. 'Filters';

        if (!$this->$var) {
            return $input;
        }

        foreach ($this->$var as $filter) {
            $input = $filter($input);
        }
        return $input;
    }
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);
    }
87701
public function validate($input) {
        if (is_null($input)) {
            return false;
        }
        if (is_string($input)) {
            return trim($input) !== '';
        }
        if (!is_array($input)) {
            return true;
        }
        foreach ($input as $item) {
            if ($this->validate($item)) {
                return true;
            }
        }
        return false;
    }
80886
public function validate($input): bool
    {
        if (\is_string($input) && filter_var($input, FILTER_VALIDATE_EMAIL)) {
            [, $domain] = explode('@', $input, 2);
            if ($this->checkDns) {
                return checkdnsrr($domain, 'MX') || checkdnsrr($domain, 'A');
            }
            return true;
        }
        return false;
    }
1158627
public static function isUrl($input = false) {

        if ($input && !filter_var($input, FILTER_VALIDATE_URL) === false) {

            return true;
        }

        return false;
    }
1257308
public function match($string, array &$matches = null)
    {
        return $this->filter === false || (\preg_match($this->pattern, $string, $matches) xor $this->invert);
    }
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);
    }
256420
public function parse($input, $allowedTokenType = null)
    {
        if (null !== $allowedTokenType && !is_integer($allowedTokenType)) {
            throw new \InvalidArgumentException('Allowed operator must be an integer.');
        }

        $this->allowedTokenType = $allowedTokenType ?: Lexer::T_ALL;
        $this->supportedTokenType = $this->expressionBuilder->getSupportedTokenType();

        try {
            $this->lexer->setInput($input);
            $this->lexer->moveNext();

            return $this->getExpression();
        } catch (LexerException $exception) {
            throw new InvalidExpressionException($input, '', 0, $exception);
        } catch (ParserException $exception) {
            throw new InvalidExpressionException($input, '', 0, $exception);
        }
    }
1058244
public function validate($input): bool
    {
        $input = (string)$input;
        // check by regular expression
        if (preg_match("/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i", $input)
            && preg_match("/^.{1,253}$/", $input)
            && preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $input)
        ) {
            // check by DNS record
            if ($this->checkDns) {
                return checkdnsrr($input, 'A');
            }
            return true;
        }
        return false;
    }
164990
public function match($string)
    {
        if (!is_string($string)) {
            throw new InvalidArgumentException('
                Invalid argument. Expected a string, received ' . gettype($string)
            );
        }

        return (bool) preg_match(
            '/' . $this->getRule() . '/ms', strtolower($string)
        );
    }