Skip to content

Commit

Permalink
Extend validator interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ilijastuden committed Dec 3, 2015
1 parent fe575fb commit ae4019e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
18 changes: 5 additions & 13 deletions src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,41 +288,33 @@ public function url($field_name, $allow_null = false)
}

/**
* Return array of validation messages, indexed by field name
*
* @return array
* {@inheritdoc}
*/
public function getErrors()
{
return $this->errors;
}

/**
* @return bool
* {@inheritdoc}
*/
public function hasErrors()
{
return count($this->errors) > 0;
}

/**
* Return field errors
*
* @param string $field_name
* @return array
* {@inheritdoc}
*/
public function getFieldErrors($field_name)
{
return isset($this->errors[$field_name]) ? $this->errors[$field_name] : [];
}

/**
* Report an error for the given field
*
* @param string $field_name
* @param string $error_message
* {@inheritdoc}
*/
private function addFieldError($field_name, $error_message)
public function addFieldError($field_name, $error_message)
{
if (empty($this->errors[$field_name])) {
$this->errors[$field_name] = [];
Expand Down
25 changes: 25 additions & 0 deletions src/ValidatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,35 @@ public function presentAndUniqueWhere($field_name, $where, ...$context);
public function email($field_name, $allow_null = false);

/**
* Return array of validation messages, indexed by field name
*
* @return array
*/
public function getErrors();

/**
* Return true if there are error
*
* @return bool
*/
public function hasErrors();

/**
* Return field errors
*
* @param string $field_name
* @return array
*/
public function getFieldErrors($field_name);

/**
* Report an error for the given field
*
* @param string $field_name
* @param string $error_message
*/
public function addFieldError($field_name, $error_message);

/**
* @return ValidationException
*/
Expand Down

0 comments on commit ae4019e

Please sign in to comment.