BraintreeErrorErrorCollection

Error handler Handles validation errors.

Defined (1)

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

/includes/lib/Braintree/lib/Braintree/Error/ErrorCollection.php  
  1. class ErrorCollection implements \Countable 
  2. private $_errors; 
  3.  
  4. public function __construct($errorData) 
  5. $this->_errors = 
  6. new ValidationErrorCollection($errorData); 
  7.  
  8. /** 
  9. * Return count of items in collection 
  10. * Implements countable 
  11. * @return integer 
  12. */ 
  13. public function count() 
  14. return $this->deepSize(); 
  15.  
  16. /** 
  17. * Returns all of the validation errors at all levels of nesting in a single, flat array. 
  18. */ 
  19. public function deepAll() 
  20. return $this->_errors->deepAll(); 
  21.  
  22. /** 
  23. * Returns the total number of validation errors at all levels of nesting. For example,  
  24. *if creating a customer with a credit card and a billing address, and each of the customer,  
  25. * credit card, and billing address has 1 error, this method will return 3. 
  26. * @return int size 
  27. */ 
  28. public function deepSize() 
  29. $size = $this->_errors->deepSize(); 
  30. return $size; 
  31.  
  32. /** 
  33. * return errors for the passed key name 
  34. * @param string $key 
  35. * @return mixed 
  36. */ 
  37. public function forKey($key) 
  38. return $this->_errors->forKey($key); 
  39.  
  40. /** 
  41. * return errors for the passed html field. 
  42. * For example, $result->errors->onHtmlField("transaction[customer][last_name]") 
  43. * @param string $field 
  44. * @return array 
  45. */ 
  46. public function onHtmlField($field) 
  47. $pieces = preg_split("/[\[\]]+/", $field, 0, PREG_SPLIT_NO_EMPTY); 
  48. $errors = $this; 
  49. foreach(array_slice($pieces, 0, -1) as $key) { 
  50. $errors = $errors->forKey(Util::delimiterToCamelCase($key)); 
  51. if (!isset($errors)) { return []; } 
  52. $finalKey = Util::delimiterToCamelCase(end($pieces)); 
  53. return $errors->onAttribute($finalKey); 
  54.  
  55. /** 
  56. * Returns the errors at the given nesting level (see forKey) in a single, flat array: 
  57. * <code> 
  58. * $result = Customer::create(...); 
  59. * $customerErrors = $result->errors->forKey('customer')->shallowAll(); 
  60. * </code> 
  61. */ 
  62. public function shallowAll() 
  63. return $this->_errors->shallowAll(); 
  64.  
  65. /** 
  66. * @ignore 
  67. */ 
  68. public function __get($name) 
  69. $varName = "_$name"; 
  70. return isset($this->$varName) ? $this->$varName : null; 
  71.  
  72. /** 
  73. * @ignore 
  74. */ 
  75. public function __toString() 
  76. return sprintf('%s', $this->_errors);