forked from sendgrid/sendgrid-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrefactoring.php
51 lines (43 loc) · 1011 Bytes
/
refactoring.php
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
<?php
class Setting implements \JsonSerializable
{
protected $attributes;
public function __get($prop)
{
return $this->attributes[$prop];
}
public function __set($prop, $value)
{
$this->attributes[$prop] = $value;
}
public function __construct($availableAttributes)
{
// initialize the avaliable attributes
foreach ($availableAttributes as $attribute) {
$this->attributes[$attribute] = null;
}
}
public function jsonSerialize()
{
return array_filter($this->attributes, function ($value) {
return $value !== null;
});
}
}
/**
* Class ClickTracking
*
* @property bool $enable
* @property bool $enable_text
*/
class ClickTracking extends Setting
{
public function __construct()
{
parent::__construct(['enable', 'enable_text']);
}
}
$click = new ClickTracking();
$click->enable = true;
$click->enable_text = false;
var_dump($click->jsonSerialize());