/** * {@inheritDoc} * @see CRegularExpressionValidator::validateAttribute() */ protected function validateAttribute($object, $attribute) { $value = $object->{$attribute}; if ($this->allowEmpty && $this->isEmpty($value)) { return; } // trigger the make up to verify that the version is correctly set $this->makeupPattern(); if ($this->useFilterVar) { $flags = array(); if ($this->version === self::IPV4 || $this->version === self::BOTH) { $flags[] = FILTER_FLAG_IPV4; } if ($this->version === self::IPV6 || $this->version === self::BOTH) { $flags[] = FILTER_FLAG_IPV6; } $isValid = (bool) filter_var($value, FILTER_VALIDATE_IP, array('flags' => $flags)); if (!$this->not && !$isValid || $this->not && $isValid) { $message = $this->message !== null ? $this->message : Yii::t('yiiext.validator', '{attribute} is not a valid IP adress.'); $this->addError($object, $attribute, $message); } } else { parent::validateAttribute($object, $attribute); } }
/** * Validates the attribute of the object. * If there is any error, the error message is added to the object. * @param CModel $object the object being validated * @param string $attribute the attribute being validated */ protected function validateAttribute($object, $attribute) { switch ($this->formatName) { case RussianNamingValidator::FORMAT_ANY: $this->pattern = $this->patternAny; break; default: $this->pattern = $this->patternAny; } return parent::validateAttribute($object, $attribute); }
protected function validateAttribute($object, $attribute) { switch ($object->auth) { case SBAdmin::AUTH_STEAM: $this->pattern = SourceBans::PATTERN_STEAM; break; case SBAdmin::AUTH_IP: $this->pattern = SourceBans::PATTERN_IP; break; default: return; } parent::validateAttribute($object, $attribute); }
protected function validateAttribute($object, $attribute) { switch ($attribute) { case 'ip': $this->allowEmpty = $object->type != SBBan::TYPE_IP; $this->pattern = SourceBans::PATTERN_IP; break; case 'steam': $this->allowEmpty = $object->type != SBBan::TYPE_STEAM; $this->pattern = SourceBans::PATTERN_STEAM; break; } parent::validateAttribute($object, $attribute); }
/** * (non-PHPdoc) * @see CValidator::validateAttribute() */ protected function validateAttribute($object, $attribute) { $this->not = false; parent::validateAttribute($object, $attribute); if ($object->hasErrors($attribute)) { return; } $value = $object->{$attribute}; $matches = array(); preg_match($this->pattern, $value, $matches); if (!isset($matches[1])) { throw new CException(Yii::t('validator', 'The "pattern" property must be specified with an unique capture group.')); } $luhnNumber = $matches[1]; $message = $this->getMessage(); $luhn = new PhpExtended\Luhn\Luhn(); if (!$luhn->validate($luhnNumber)) { $this->addError($object, $attribute, $message); } // special supplementary validation for siret with inner siren if ($this->pattern === self::PATTERN_SIRET) { $subpattern = substr($luhnNumber, 0, 9); if (!$luhn->validate($subpattern)) { $this->addError($object, $attribute, $message); } } }