| 1 |
<?php |
| 2 |
// @codingStandardsIgnoreFile |
| 3 |
|
| 4 |
/** |
| 5 |
* AWeberResponse |
| 6 |
* |
| 7 |
* Base class for objects that represent a response from the AWeberAPI. |
| 8 |
* Responses will exist as one of the two AWeberResponse subclasses: |
| 9 |
* - AWeberEntry - a single instance of an AWeber resource |
| 10 |
* - AWeberCollection - a collection of AWeber resources |
| 11 |
* @uses AWeberAPIBase |
| 12 |
* @package |
| 13 |
* @version $id$ |
| 14 |
*/ |
| 15 |
//260816 AWeber response objects intentionally expose dynamic API properties; opt in explicitly on PHP 8.2+. |
| 16 |
#[\AllowDynamicProperties] |
| 17 |
class AWeberResponse extends AWeberAPIBase { |
| 18 |
|
| 19 |
public $adapter = false; |
| 20 |
public $data = array(); |
| 21 |
public $_dynamicData = array(); |
| 22 |
|
| 23 |
/** |
| 24 |
* __construct |
| 25 |
* |
| 26 |
* Creates a new AWeberRespones |
| 27 |
* |
| 28 |
* @param mixed $response Data returned by the API servers |
| 29 |
* @param mixed $url URL we hit to get the data |
| 30 |
* @param mixed $adapter OAuth adapter used for future interactions |
| 31 |
* @access public |
| 32 |
* @return void |
| 33 |
*/ |
| 34 |
public function __construct($response, $url, $adapter) { |
| 35 |
$this->adapter = $adapter; |
| 36 |
$this->url = $url; |
| 37 |
$this->data = $response; |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* __set |
| 42 |
* |
| 43 |
* Manual re-implementation of __set, allows sub classes to access |
| 44 |
* the default behavior by using the parent:: format. |
| 45 |
* |
| 46 |
* @param mixed $key Key of the attr being set |
| 47 |
* @param mixed $value Value being set to the attr |
| 48 |
* @access public |
| 49 |
*/ |
| 50 |
public function __set($key, $value) { |
| 51 |
$this->{$key} = $value; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* __get |
| 56 |
* |
| 57 |
* PHP "MagicMethod" to allow for dynamic objects. Defers first to the |
| 58 |
* data in $this->data. |
| 59 |
* |
| 60 |
* @param String $value Name of the attribute requested |
| 61 |
* @access public |
| 62 |
* @return mixed |
| 63 |
*/ |
| 64 |
public function __get($value) { |
| 65 |
if (in_array($value, $this->_privateData)) { |
| 66 |
return null; |
| 67 |
} |
| 68 |
if (array_key_exists($value, $this->data)) { |
| 69 |
return $this->data[$value]; |
| 70 |
} |
| 71 |
if ($value == 'type') return $this->_type(); |
| 72 |
} |
| 73 |
|
| 74 |
} |
| 75 |
|