reset() public static method

Initializes the list of default validation rules.
public static reset ( )
Esempio n. 1
0
 /**
  * Tests that the rules state is reset when calling `Validator::reset()`.
  */
 public function testStateReset()
 {
     $this->assertNull(Validator::rules('foo'));
     Validator::add('foo', '/foo/');
     $this->assertEqual('/foo/', Validator::rules('foo'));
     Validator::reset();
     $this->assertNull(Validator::rules('foo'));
 }
 public function tearDown()
 {
     Catalog::reset();
     Validator::reset();
     Catalog::config($this->_backup['catalogConfig']);
 }
Esempio n. 3
0
     * and an array specifying which formats within the rule to use.
     *
     * @param array $rules All available rules.
     * @return \Closure Function returning boolean `true` if validation succeeded, `false` otherwise.
     */
    protected static function _checkFormats($rules)
    {
        return function ($self, $params, $chain) use($rules) {
            $value = $params['value'];
            $format = $params['format'];
            $options = $params['options'];
            $defaults = array('all' => true);
            $options += $defaults;
            $formats = (array) $format;
            $options['all'] = $format === 'any';
            foreach ($rules as $index => $check) {
                if (!$options['all'] && !(in_array($index, $formats) || isset($formats[$index]))) {
                    continue;
                }
                $regexPassed = is_string($check) && preg_match($check, $value);
                $closurePassed = is_object($check) && $check($value, $format, $options);
                if ($regexPassed || $closurePassed) {
                    return true;
                }
            }
            return false;
        };
    }
}
Validator::reset();