Instance.php
1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace Braintree;
/**
* Braintree Class Instance template
*
* @abstract
*/
abstract class Instance
{
protected $_attributes = [];
/**
*
* @param array $attributes
*/
public function __construct($attributes)
{
if (!empty($attributes)) {
$this->_initializeFromArray($attributes);
}
}
/**
* returns private/nonexistent instance properties
* @access public
* @param string $name property name
* @return mixed contents of instance properties
*/
public function __get($name)
{
if (array_key_exists($name, $this->_attributes)) {
return $this->_attributes[$name];
} else {
trigger_error('Undefined property on ' . get_class($this) . ': ' . $name, E_USER_NOTICE);
return null;
}
}
/**
* used by isset() and empty()
* @access public
* @param string $name property name
* @return boolean
*/
public function __isset($name)
{
return array_key_exists($name, $this->_attributes);
}
/**
* create a printable representation of the object as:
* ClassName[property=value, property=value]
* @return string
*/
public function __toString()
{
$objOutput = Util::implodeAssociativeArray($this->_attributes);
return get_class($this) .'[' . $objOutput . ']';
}
/**
* initializes instance properties from the keys/values of an array
* @ignore
* @access protected
* @param <type> $aAttribs array of properties to set - single level
* @return void
*/
private function _initializeFromArray($attributes)
{
$this->_attributes = $attributes;
}
}
class_alias('Braintree\Instance', 'Braintree_Instance');