1: <?php
2:
3: /**
4: * Base class for entities
5: */
6: abstract class Syspay_Merchant_Entity
7: {
8:
9: /**
10: * An stdClass object representing the raw object returned by the API
11: *
12: * @var stdClass
13: */
14: public $raw;
15:
16: /**
17: * Get an array representation of the object to build the request.
18: * It will collect all protected properties.
19: *
20: * @return array An array to be used in the request
21: */
22: public function toArray()
23: {
24: $data = array();
25:
26: $r = new ReflectionClass($this);
27: $properties = $r->getProperties(ReflectionProperty::IS_PROTECTED);
28: foreach ($properties as $property) {
29: $name = $property->getName();
30:
31: if (true === isset($this->$name)) {
32: $data[$name] = $this->$name;
33: }
34: }
35: return $data;
36: }
37:
38: /**
39: * Get the entity type
40: * @return string Entity type (as seen in the API)
41: */
42: public function getType()
43: {
44: // static:: has only been introduced as of PHP 5.3.
45: return constant(get_class($this) . '::TYPE');
46: }
47: }
48: