2015-04-05
Пока никем извне класса не используется, но будет.
@used-by checkProperty()
@param mixed $value
@param \Zend_Validate_Interface $validator
@throws \Df\Core\Exception
@return bool
337795
static function validate($value, \Zend_Validate_Interface $validator) {
		return
			is_null($value)
			&& isset($validator->{self::$SKIP_ON_NULL})
			&& $validator->{self::$SKIP_ON_NULL}
			|| $validator->isValid($value)
		;
	}
1345915
public function validate($attribute, $value, $parameters, $validator)
    {
        list ($name, $locale) = $this->getAttributeNameAndLocale($attribute);

        if ($this->isUnique($value, $name, $locale, $parameters)) {
            return true;
        }

        $this->addErrorsToValidator($validator, $parameters, $name, $locale);

        return false;
    }
314791
protected function hasValidator(Validator $validator) : bool
    {
        $hash = spl_object_hash($validator);

        return isset($this->validators[$hash]);
    }
56101
public function withValidator($validator)
    {
        if ($validator->passes()) {
            $validator->after(function ($validator) {

                try {
                    // get validated data
                    $data = $this->validated();

                    // Set temporary DB connection
                    config(['database.connections.mysql' => [
                        'driver' => 'mysql',
                        'host' =>  $data['DB_HOST'],
                        'database' => $data['DB_DATABASE'],
                        'prefix' => $data['DB_PREFIX'],
                        'username' => $data['DB_USERNAME'],
                        'password' => $data['DB_PASSWORD'],
                        'charset' => 'utf8',
                        'collation' => 'utf8_unicode_ci',
                        'strict' => true,
                        'engine' => 'InnoDB',
                    ]]);

                    // Check DB connection and exists table
                    \DB::purge('mysql');
                    \DB::reconnect('mysql');
                    \DB::setTablePrefix($data['DB_PREFIX']);
                    \DB::connection()->getPdo();
                    if (is_null(\DB::connection('mysql')->getDatabaseName())) {
                        throw new InstallerFailed(__('msg.not_dbconnect'));
                    }

                    // 3 Manipulation of the database
                    \DB::beginTransaction();

                    // Make migrate
                    $exitCode = \Artisan::call('migrate', ['--force' => true]);
                    $outputMigrate = \Artisan::output();
                    session()->flash('flash_output_migrate', $outputMigrate);

                    \DB::commit();
                } catch (\InstallerFailed $e) {
                    $validator->errors()->add('database', $e->getMessage());
                } catch (\PDOException $e) {
                    $validator->errors()->add('database', $e->getMessage());
                } finally {
                    \DB::rollback();
                }

            });
        }

        return $validator;
    }
283189
protected function validate($name, $value, $validators = null)
    {
        if (empty($validators)) {
            $validators = @$this->fieldValidators[$name];
        }
        $failedValidations = array();

        if (!empty($validators)) {
            foreach ($validators as $type) {
                Logger::get()->debug("Validating $name with $type...");
                $validator = Validators::get($type);
                if (!$validator->isValid($value)) {
                    Logger::get()->debug('Failed!');
                    // The validation has failed, report its data.
                    $failedValidations[] = $validator->getFailMessage();
                }
            }
        }

        return $failedValidations;
    }
466001
public function validate($validator)
    {
        $valid = true;
        foreach ($this->children as $child) {
            /** @var FormField $child */
            $valid = ($child && $child->validate($validator) && $valid);
        }
        return $valid;
    }
703573
public function validationDefault(Validator $validator) {
		if (!empty($this->validate)) {
			foreach ($this->validate as $field => $rules) {
				if (is_int($field)) {
					$field = $rules;
					$rules = [];
				}
				if (!$rules) {
					continue;

				}
				$rules = (array)$rules;

				foreach ($rules as $key => $rule) {
					if (is_string($rule)) {
						$ruleArray = ['rule' => $rule];
						$rules[$rule] = $ruleArray;
						unset($rules[$key]);
						$key = $rule;
						$rule = $ruleArray;
					}

					if (isset($rule['required'])) {
						$validator->requirePresence($field, $rule['required']);
						unset($rules[$key]['required']);
					}
					if (isset($rule['allowEmpty'])) {
						$validator->allowEmpty($field, $rule['allowEmpty']);
						unset($rules[$key]['allowEmpty']);
					}
					if (isset($rule['message'])) {
						if (is_array($rule['message'])) {
							$name = array_shift($rule['message']);
							//$args = array_slice($rule['message'], 1);
							$args = $this->_translateArgs($rule['message']);
							$message = __d($this->validationDomain, $name, $args);
						} else {
							$message = __d($this->validationDomain, $rule['message']);
						}
						$rules[$key]['message'] = $message;
					}

					if (!empty($rules[$key]['rule']) && ($rules[$key]['rule'] === 'notEmpty' || $rules[$key]['rule'] === ['notEmpty'])) {
						$rules[$key]['rule'] = 'notBlank';
					}

					if (!empty($rules[$key]['rule']) && ($rules[$key]['rule'] === 'isUnique' || $rules[$key]['rule'] === ['isUnique'])) {
						$rules[$key]['rule'] = 'validateUnique';
						$rules[$key]['provider'] = 'table';
					}
				}

				$validator->add($field, $rules);
			}
		}

		return $validator;
	}
132956
public function validateValue( $value ) : bool
   {

      if ( false === $this->hasValidator() )
      {
         return true;
      }

      return (bool) ( $this->_validator )( $value );

   }
739108
public function addValidator(Validator $validator) : Component
    {
        $hash = spl_object_hash($validator);
        $this->validators[$hash] = $validator;

        return $this;
    }
721552
public function validationEnabled(Validator $validator) : Validator
    {
        $className = App::shortName(get_class($this), 'Model/Table', 'Table');
        $config = (new ModuleConfig(ConfigType::MIGRATION(), $className))->parse();
        $config = json_encode($config);
        if (false === $config) {
            return $validator;
        }
        $config = json_decode($config, true);
        $factory = new FieldHandlerFactory();

        foreach ($config as $column) {
            $validator = $factory->setValidationRules($this, $column['name'], $validator);
        }

        return $validator;
    }
890233
public function setValidator($validator, array $options = null) {
		if ($validator instanceof ZendValidatorInterface) {
			$this->validator = $validator;
		}
		else if (is_string($validator)) {
			$class = 'Zend_Validate_' . ucfirst($validator);
			
			if ($options === null) {
				$this->validator = new $class();
			} else {
				$this->validator = new $class($options);
			}
		}
		else {
			throw new ValidationFailure('Invalid Zend validator definition');
		}
	}
63540
protected function callValidator($validator)
    {
        if (is_callable($validator)) {
            try {
                call_user_func_array($validator, array($this->value));
            } catch (\Exception $ex) {
                $this->error = $ex->getMessage();
                return false;
            }
        }
    }
21154
public function validate($validator)
    {
        // Validate currency
        $currencies = $this->getAllowedCurrencies();
        $currency = $this->fieldCurrency->dataValue();
        if ($currency && $currencies && !in_array($currency, $currencies)) {
            $validator->validationError(
                $this->getName(),
                _t(
                    __CLASS__ . '.INVALID_CURRENCY',
                    'Currency {currency} is not in the list of allowed currencies',
                    ['currency' => $currency]
                )
            );
            return false;
        }

        // Field-specific validation
        return $this->fieldAmount->validate($validator) && $this->fieldCurrency->validate($validator);
    }
633819
public function validate($validator)
    {
        if (!$this->config()->get( 'enabled')) {
            return true;
        }

        if (!$this->isCorrectAnswer($this->Value())) {
            $validator->validationError(
                $this->name,
                _t(
                    'MathSpamProtectionField.INCORRECTSOLUTION',
                    "Incorrect solution to the spam protection question, please try again."
                ),
                "error"
            );

            return false;
        }

        return true;
    }
183594
public function isValid($value) {
		if ($this->validator === null) {
			throw new ValidationFailure('Zend validator wasn\'t been suplied');
		}
		
		return $this->validator->isValid($value);
	}
1368747
protected function _addValidatorProps($validator = [])
    {
        foreach ($validator as $key => $value) {
            if (!isset($value) || empty($value)) {
                continue;
            }
            if ($key === 'rule' && is_array($value) && !is_callable($value)) {
                $this->_pass = array_slice($value, 1);
                $value = array_shift($value);
            }
            if (in_array($key, ['rule', 'on', 'message', 'last', 'provider', 'pass'])) {
                $this->{"_$key"} = $value;
            }
        }
    }
423609
public function validationDefault(Validator $validator) {
		$validator
			->integer('id')
			->allowEmpty('id', 'create');

		$validator
			->requirePresence('ip', 'create')
			->notEmpty('ip');

		$validator
			->requirePresence('session_id', 'create')
			->notEmpty('session_id');

		$validator
			->allowEmpty('result');

		$validator
			->dateTime('used')
			->allowEmpty('used');

		return $validator;
	}