public function validate($value, &$filtered = null)
    {
        $this->error = null;

        if ($value === null)
            return $this->options['nullable'] ?? false;
        
        $filtered = $value;
        if ($this->type === Validator::EXISTS)
            return true;
        
        $o = $this->options;
        if ($this->type !== Validator::VALIDATE_CUSTOM && !$this->matchType($value, $filtered))
            return false;

        if (isset($o['custom']) && is_callable($o['custom']))
        {
            try
            {
                $valid = $o['custom']($value);
                if (!is_bool($valid))
                    throw new \RuntimeException("Validator did not return boolean: " . WF::str($valid));
            }
            catch (ValidationException $e)
            {
                $this->error = $e->getError();
                $valid = false;
            }
            return $valid;
        }

        return true;
    }
public function validate($value, &$filtered = null)
    {
        $this->error = null;

        if ($value === null)
            return $this->options['nullable'] ?? false;
        
        $filtered = $value;
        if ($this->type === Validator::EXISTS)
            return true;
        
        $o = $this->options;
        if ($this->type !== Validator::VALIDATE_CUSTOM && !$this->matchType($value, $filtered))
            return false;

        if (isset($o['custom']) && is_callable($o['custom']))
        {
            try
            {
                $valid = $o['custom']($value);
                if (!is_bool($valid))
                    throw new \RuntimeException("Validator did not return boolean: " . WF::str($valid));
            }
            catch (ValidationException $e)
            {
                $this->error = $e->getError();
                $valid = false;
            }
            return $valid;
        }

        return true;
    }
public function validate ( $ value , & $ filtered = null ) { $ this -> error = null ; if ( $ value === null ) return $ this -> options [ 'nullable' ] ?? false ; $ filtered = $ value ; if ( $ this -> type === Validator :: EXISTS ) return true ; $ o = $ this -> options ; if ( $ this -> type !== Validator :: VALIDATE_CUSTOM && ! $ this -> matchType ( $ value , $ filtered ) ) return false ; if ( isset ( $ o [ 'custom' ] ) && is_callable ( $ o [ 'custom' ] ) ) { try { $ valid = $ o [ 'custom' ] ( $ value ) ; if ( ! is_bool ( $ valid ) ) throw new \ RuntimeException ( "Validator did not return boolean: " . WF :: str ( $ valid ) ) ; } catch ( ValidationException $ e ) { $ this -> error = $ e -> getError ( ) ; $ valid = false ; } return $ valid ; } return true ; }
Check if the value matches the expected value
@param mixed $value
@return bool True if the value matches all constraints, false if it does not
Check if the value matches the expected value