BraintreeErrorValidationErrorCollection

Collection of errors enumerating all validation errors for a given request.

Defined (1)

The class is defined in the following location(s).

/includes/lib/Braintree/lib/Braintree/Error/ValidationErrorCollection.php  
  1. class ValidationErrorCollection extends Collection 
  2. private $_errors = []; 
  3. private $_nested = []; 
  4.  
  5. /** 
  6. * @ignore 
  7. */ 
  8. public function __construct($data) 
  9. foreach($data AS $key => $errorData) 
  10. // map errors to new collections recursively 
  11. if ($key == 'errors') { 
  12. foreach ($errorData AS $error) { 
  13. $this->_errors[] = new Validation($error); 
  14. } else { 
  15. $this->_nested[$key] = new ValidationErrorCollection($errorData); 
  16.  
  17.  
  18. public function deepAll() 
  19. $validationErrors = array_merge([], $this->_errors); 
  20. foreach($this->_nested as $nestedErrors) 
  21. $validationErrors = array_merge($validationErrors, $nestedErrors->deepAll()); 
  22. return $validationErrors; 
  23.  
  24. public function deepSize() 
  25. $total = sizeof($this->_errors); 
  26. foreach($this->_nested as $_nestedErrors) 
  27. $total = $total + $_nestedErrors->deepSize(); 
  28. return $total; 
  29.  
  30. public function forIndex($index) 
  31. return $this->forKey("index" . $index); 
  32.  
  33. public function forKey($key) 
  34. return isset($this->_nested[$key]) ? $this->_nested[$key] : null; 
  35.  
  36. public function onAttribute($attribute) 
  37. $matches = []; 
  38. foreach ($this->_errors AS $key => $error) { 
  39. if($error->attribute == $attribute) { 
  40. $matches[] = $error; 
  41. return $matches; 
  42.  
  43.  
  44. public function shallowAll() 
  45. return $this->_errors; 
  46.  
  47. /** 
  48. * @ignore 
  49. */ 
  50. public function __get($name) 
  51. $varName = "_$name"; 
  52. return isset($this->$varName) ? $this->$varName : null; 
  53.  
  54. /** 
  55. * @ignore 
  56. */ 
  57. public function __toString() 
  58. $output = []; 
  59.  
  60. // TODO: implement scope 
  61. if (!empty($this->_errors)) { 
  62. $output[] = $this->_inspect($this->_errors); 
  63. if (!empty($this->_nested)) { 
  64. foreach ($this->_nested AS $key => $values) { 
  65. $output[] = $this->_inspect($this->_nested); 
  66. return join(', ', $output); 
  67.  
  68. /** 
  69. * @ignore 
  70. */ 
  71. private function _inspect($errors, $scope = null) 
  72. $eOutput = '[' . __CLASS__ . '/errors:['; 
  73. foreach($errors AS $error => $errorObj) { 
  74. $outputErrs[] = "({$errorObj->error['code']} {$errorObj->error['message']})"; 
  75. $eOutput .= join(', ', $outputErrs) . ']]'; 
  76.  
  77. return $eOutput;