1
|
|
|
<?php namespace Arcanedev\GeoLocation\Entities; |
2
|
|
|
|
3
|
|
|
use Illuminate\Contracts\Support\Arrayable; |
4
|
|
|
use Illuminate\Contracts\Support\Jsonable; |
5
|
|
|
use JsonSerializable; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class Distance |
9
|
|
|
* |
10
|
|
|
* @package Arcanedev\GeoLocation\Entities |
11
|
|
|
* @author ARCANEDEV <[email protected]> |
12
|
|
|
* |
13
|
|
|
* @todo: Refactor this with Duration class ? |
14
|
|
|
*/ |
15
|
|
|
class Distance implements Arrayable, Jsonable, JsonSerializable |
16
|
|
|
{ |
17
|
|
|
/* ----------------------------------------------------------------- |
18
|
|
|
| Properties |
19
|
|
|
| ----------------------------------------------------------------- |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The text value. |
24
|
|
|
* |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $text; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* The numeric value. |
31
|
|
|
* |
32
|
|
|
* @var int |
33
|
|
|
*/ |
34
|
|
|
protected $value; |
35
|
|
|
|
36
|
|
|
/* ----------------------------------------------------------------- |
37
|
|
|
| Main Methods |
38
|
|
|
| ----------------------------------------------------------------- |
39
|
|
|
*/ |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Distance constructor. |
43
|
|
|
* |
44
|
|
|
* @param string $text |
45
|
|
|
* @param int $value |
46
|
|
|
*/ |
47
|
3 |
|
public function __construct($text, $value) |
48
|
|
|
{ |
49
|
3 |
|
$this->text = $text; |
50
|
3 |
|
$this->value = $value; |
51
|
3 |
|
} |
52
|
|
|
|
53
|
|
|
/* ----------------------------------------------------------------- |
54
|
|
|
| Getters & Setters |
55
|
|
|
| ----------------------------------------------------------------- |
56
|
|
|
*/ |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Get the text (alias). |
60
|
|
|
* |
61
|
|
|
* @see getText |
62
|
|
|
* |
63
|
|
|
* @return string |
64
|
|
|
*/ |
65
|
|
|
public function text() |
66
|
|
|
{ |
67
|
|
|
return $this->getText(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Get the text. |
72
|
|
|
* |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
|
|
public function getText() |
76
|
|
|
{ |
77
|
|
|
return $this->text; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Get the value (alias). |
82
|
|
|
* |
83
|
|
|
* @see getValue |
84
|
|
|
* |
85
|
|
|
* @return int |
86
|
|
|
*/ |
87
|
|
|
public function value() |
88
|
|
|
{ |
89
|
|
|
return $this->value; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Get the value. |
94
|
|
|
* |
95
|
|
|
* @return int |
96
|
|
|
*/ |
97
|
|
|
public function getValue() |
98
|
|
|
{ |
99
|
|
|
return $this->value; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/* ----------------------------------------------------------------- |
103
|
|
|
| Main Methods |
104
|
|
|
| ----------------------------------------------------------------- |
105
|
|
|
*/ |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Make a distance instance. |
109
|
|
|
* |
110
|
|
|
* @param string $text |
111
|
|
|
* @param int $value |
112
|
|
|
* |
113
|
|
|
* @return self |
114
|
|
|
*/ |
115
|
3 |
|
public static function make($text, $value) |
116
|
|
|
{ |
117
|
3 |
|
return new static($text, $value); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Make a distance instance from array. |
122
|
|
|
* |
123
|
|
|
* @param array $data |
124
|
|
|
* |
125
|
|
|
* @return self |
126
|
|
|
*/ |
127
|
3 |
|
public static function makeFromArray(array $data) |
128
|
|
|
{ |
129
|
3 |
|
return static::make($data['text'], $data['value']); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Get the instance as an array. |
134
|
|
|
* |
135
|
|
|
* @return array |
136
|
|
|
*/ |
137
|
|
|
public function toArray() |
138
|
|
|
{ |
139
|
|
|
// TODO: Implement toArray() method. |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Convert the object to its JSON representation. |
144
|
|
|
* |
145
|
|
|
* @param int $options |
146
|
|
|
* @return string |
147
|
|
|
*/ |
148
|
|
|
public function toJson($options = 0) |
149
|
|
|
{ |
150
|
|
|
// TODO: Implement toJson() method. |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Specify data which should be serialized to JSON |
155
|
|
|
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php |
156
|
|
|
* @return mixed data which can be serialized by <b>json_encode</b>, |
157
|
|
|
* which is a value of any type other than a resource. |
158
|
|
|
* @since 5.4.0 |
159
|
|
|
*/ |
160
|
|
|
function jsonSerialize() |
|
|
|
|
161
|
|
|
{ |
162
|
|
|
// TODO: Implement jsonSerialize() method. |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.