1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LeadThread\Sms\Search; |
4
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Support\Arrayable; |
6
|
|
|
use LeadThread\Sms\Interfaces\PhoneSearchParams; |
7
|
|
|
|
8
|
|
|
abstract class Search implements Arrayable, PhoneSearchParams |
9
|
|
|
{ |
10
|
|
|
protected $params = [ |
11
|
|
|
"state", |
12
|
|
|
"areacode", |
13
|
|
|
"country", |
14
|
|
|
]; |
15
|
|
|
|
16
|
|
|
protected $state; |
17
|
|
|
protected $areacode; |
18
|
|
|
protected $country = "US"; |
19
|
|
|
|
20
|
21 |
|
public function __construct($opts) |
21
|
|
|
{ |
22
|
21 |
|
foreach ($opts as $key => $value) { |
23
|
3 |
|
if (in_array($key, $this->params)) { |
24
|
3 |
|
$this->{$key} = $value; |
25
|
3 |
|
} |
26
|
21 |
|
} |
27
|
21 |
|
} |
28
|
|
|
|
29
|
12 |
|
public function toArray() |
30
|
|
|
{ |
31
|
12 |
|
$arr = $this->getBaseArray(); |
32
|
12 |
|
foreach ($this->params as $key) { |
33
|
12 |
|
if (!empty($this->{$key})) { |
34
|
12 |
|
$this->handleParamKey($key, $arr); |
35
|
12 |
|
} |
36
|
12 |
|
} |
37
|
12 |
|
return $arr; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
abstract protected function getBaseArray(); |
41
|
|
|
abstract protected function handleParamKey($key, &$arr); |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Gets the value of areacode. |
45
|
|
|
* |
46
|
|
|
* @return mixed |
47
|
|
|
*/ |
48
|
|
|
public function getAreaCode() |
49
|
|
|
{ |
50
|
|
|
return $this->areacode; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Sets the value of areacode. |
55
|
|
|
* |
56
|
|
|
* @param mixed $areacode the areacode |
57
|
|
|
* |
58
|
|
|
* @return self |
59
|
|
|
*/ |
60
|
|
|
public function setAreaCode($areacode) |
61
|
|
|
{ |
62
|
|
|
$this->areacode = $areacode; |
63
|
|
|
|
64
|
|
|
return $this; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Gets the value of country. |
69
|
|
|
* |
70
|
|
|
* @return mixed |
71
|
|
|
*/ |
72
|
|
|
public function getCountry() |
73
|
|
|
{ |
74
|
|
|
return $this->country; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Sets the value of country. |
79
|
|
|
* |
80
|
|
|
* @param mixed $country the country |
81
|
|
|
* |
82
|
|
|
* @return self |
83
|
|
|
*/ |
84
|
|
|
public function setCountry($country) |
85
|
|
|
{ |
86
|
|
|
$this->country = $country; |
87
|
|
|
|
88
|
|
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Gets the value of state. |
93
|
|
|
* |
94
|
|
|
* @return mixed |
95
|
|
|
*/ |
96
|
|
|
public function getState() |
97
|
|
|
{ |
98
|
|
|
return $this->state; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Sets the value of state. |
103
|
|
|
* |
104
|
|
|
* @param mixed $state the state |
105
|
|
|
* |
106
|
|
|
* @return self |
107
|
|
|
*/ |
108
|
|
|
protected function setState($state) |
109
|
|
|
{ |
110
|
|
|
$this->state = $state; |
111
|
|
|
|
112
|
|
|
return $this; |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|