<?php
/**
* User friendly errors while validation
*/
class ValidatorError
{
/**
* which error
* @var
*/
private $errType;
/**
* current error data
* @var array
*/
private $data;
/**
* validator type error occurred to
* @var
*/
private $validatorType;
/**
* error types
* @var array
*/
static $errorTypeArray = array();
public function __construct($errType, ValidatorAnyType $validatorType, array $additionalData = array()){
$this->errType = $errType;
$this->data = $additionalData;
$this->validatorType = $validatorType;
}
/**
* Form standard errors in a user friendly view
* @return string
*/
public function ToString(){
$this->_ProcessFieldName();
return ValidatorLocalization::GetField($this->errType, $this->data);
}
/**
* getter for error type
* @return mixed
*/
public function GetErrType(){
return $this->errType;
}
/**
* getter for current error data
* @return array
*/
public function GetErrData(){
return $this->data;
}
/**
* getter for name of field current error belongs to
*/
public function GetFieldName(){
return $this->validatorType->GetName();
}
/**
* if field name is set get it either from user-friendly name or from field name
*/
private function _ProcessFieldName(){
if(!isset($this->data['fieldName'])){
$ufName = $this->validatorType->GetUserFriendlyName() ;
$this->data['fieldName'] = !empty($ufName) ? $ufName : $this->validatorType->GetName();
}
}
}
?>