Braintree_Error_ErrorCollection

Handles validation errors.

Defined (1)

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

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