/** * Create a ValidationError error that is associated with a form field. * * @param string $failureCode The code or slug that identifies this error's failure cause * @param string $fieldResolved The machine-readable error code that uniquely identifies the error * @param string $fieldType Can be 'field', 'meta', or 'tag' to determine the type of error field * @param string $fieldTitle The title or human readable name for the failing field * @param string $value The value that was invalid * @param string $defaultErrorMessage A default error message to display if we can't * Lookup another one using the failureCode */ public function __construct($failureCode, $fieldResolved, $fieldType, $fieldTitle, $value, $defaultErrorMessage) { $errorCode = $fieldResolved . '.' . $failureCode; parent::__construct($errorCode, $defaultErrorMessage); $this->failureCode = $failureCode; $this->fieldResolved = $fieldResolved; $this->fieldTitle = $fieldTitle; $this->fieldType = $fieldType; $this->value = $value; }
static function password($password1, $password2, $rules = []) { $error = new ValidationError(); if ($password1 != $password2) { $error->add('Wachtwoorden komen niet overeen'); } if (!empty($rules)) { if (isset($rules['min_length'])) { if (strlen($password1) < $rules['min_length']) { $error->add('Wachtwoord moet langer zijn dan ' . $rules['min_length']); } } if (isset($rules['special_chars'])) { if (!preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $password1)) { $error->add('Wachtwoord moet speciaale karakters hebben'); } } } if (count($error->errors) == 0) { return true; } else { return $error; } }
/** * Adds a single ValidationError. * * @since 0.4 * * @param string $errorMessage * @param integer $severity */ public static function addError(ValidationError $error) { self::$errors[$error->getElement()][] = $error; }
/** * Creates and returns the output when a fatal error prevent regular rendering. * * @since 0.4 * * @param ValidationError $error * * @return string */ protected function renderFatalError(ValidationError $error) { return '<div><span class="errorbox">' . htmlspecialchars(wfMsgExt('validator-fatal-error', 'parsemag', $error->getMessage())) . '</span></div><br /><br />'; }
/** * @param string $field * @param string $msg * @return Hypercharge\Errors\ValidationError */ static function create($field, $msg) { $e = new ValidationError(); $e->add($field, $msg); $e->flush(); return $e; }
function testValidationErrorToStringEquality() { // same property $this->assertEqual(ValidationError::create('equal', 'equal info') . '', ValidationError::create('equal', 'equal info') . ''); // same property, message ignored in __toString() $this->assertEqual(ValidationError::create('equal', 'bbb') . '', ValidationError::create('equal', 'different') . ''); // different properties $this->assertNotEqual(ValidationError::create('a', 'equal info') . '', ValidationError::create('different', 'equal info') . ''); }