Validation.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Braintree\Error;
  3. use Braintree\Util;
  4. /**
  5. * error object returned as part of a validation error collection
  6. * provides read-only access to $attribute, $code, and $message
  7. *
  8. * <b>== More information ==</b>
  9. *
  10. * For more detailed information on Validation errors, see {@link https://developers.braintreepayments.com/reference/general/validation-errors/overview/php https://developers.braintreepayments.com/reference/general/validation-errors/overview/php}
  11. *
  12. * @package Braintree
  13. * @subpackage Error
  14. *
  15. * @property-read string $attribute
  16. * @property-read string $code
  17. * @property-read string $message
  18. */
  19. class Validation
  20. {
  21. private $_attribute;
  22. private $_code;
  23. private $_message;
  24. /**
  25. * @ignore
  26. * @param array $attributes
  27. */
  28. public function __construct($attributes)
  29. {
  30. $this->_initializeFromArray($attributes);
  31. }
  32. /**
  33. * initializes instance properties from the keys/values of an array
  34. * @ignore
  35. * @access protected
  36. * @param array $attributes array of properties to set - single level
  37. * @return void
  38. */
  39. private function _initializeFromArray($attributes)
  40. {
  41. foreach($attributes AS $name => $value) {
  42. $varName = "_$name";
  43. $this->$varName = Util::delimiterToCamelCase($value, '_');
  44. }
  45. }
  46. /**
  47. *
  48. * @ignore
  49. */
  50. public function __get($name)
  51. {
  52. $varName = "_$name";
  53. return isset($this->$varName) ? $this->$varName : null;
  54. }
  55. }
  56. class_alias('Braintree\Error\Validation', 'Braintree_Error_Validation');