Base.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace Braintree;
  3. use JsonSerializable;
  4. /**
  5. * Braintree PHP Library.
  6. *
  7. * Braintree base class and initialization
  8. * Provides methods to child classes. This class cannot be instantiated.
  9. *
  10. * PHP version 5
  11. */
  12. abstract class Base implements JsonSerializable
  13. {
  14. protected $_attributes = [];
  15. /**
  16. * @ignore
  17. * don't permit an explicit call of the constructor!
  18. * (like $t = new Transaction())
  19. */
  20. protected function __construct()
  21. {
  22. }
  23. /**
  24. * Disable cloning of objects
  25. *
  26. * @ignore
  27. */
  28. protected function __clone()
  29. {
  30. }
  31. /**
  32. * Accessor for instance properties stored in the private $_attributes property
  33. *
  34. * @ignore
  35. * @param string $name
  36. * @return mixed
  37. */
  38. public function __get($name)
  39. {
  40. if (array_key_exists($name, $this->_attributes)) {
  41. return $this->_attributes[$name];
  42. }
  43. else {
  44. trigger_error('Undefined property on ' . get_class($this) . ': ' . $name, E_USER_NOTICE);
  45. return null;
  46. }
  47. }
  48. /**
  49. * Checks for the existance of a property stored in the private $_attributes property
  50. *
  51. * @ignore
  52. * @param string $name
  53. * @return boolean
  54. */
  55. public function __isset($name)
  56. {
  57. return array_key_exists($name, $this->_attributes);
  58. }
  59. /**
  60. * Mutator for instance properties stored in the private $_attributes property
  61. *
  62. * @ignore
  63. * @param string $key
  64. * @param mixed $value
  65. */
  66. public function _set($key, $value)
  67. {
  68. $this->_attributes[$key] = $value;
  69. }
  70. /**
  71. * Implementation of JsonSerializable
  72. *
  73. * @ignore
  74. * @return array
  75. */
  76. public function jsonSerialize()
  77. {
  78. return $this->_attributes;
  79. }
  80. }