1
|
|
|
<?php namespace Arcanedev\GeoLocation\Entities\Measures; |
2
|
|
|
|
3
|
|
|
use Arcanedev\GeoLocation\Traits\CanBeJsonable; |
4
|
|
|
use Illuminate\Contracts\Support\Arrayable; |
5
|
|
|
use Illuminate\Contracts\Support\Jsonable; |
6
|
|
|
use JsonSerializable; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class AbstractMeasure |
10
|
|
|
* |
11
|
|
|
* @package Arcanedev\GeoLocation\Entities\Measures |
12
|
|
|
* @author ARCANEDEV <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
abstract class AbstractMeasure implements Arrayable, Jsonable, JsonSerializable |
15
|
|
|
{ |
16
|
|
|
/* ----------------------------------------------------------------- |
17
|
|
|
| Traits |
18
|
|
|
| ----------------------------------------------------------------- |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
use CanBeJsonable; |
22
|
|
|
|
23
|
|
|
/* ----------------------------------------------------------------- |
24
|
|
|
| Properties |
25
|
|
|
| ----------------------------------------------------------------- |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* The text value. |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $text; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* The numeric value. |
37
|
|
|
* |
38
|
|
|
* @var int |
39
|
|
|
*/ |
40
|
|
|
protected $value; |
41
|
|
|
|
42
|
|
|
/* ----------------------------------------------------------------- |
43
|
|
|
| Main Methods |
44
|
|
|
| ----------------------------------------------------------------- |
45
|
|
|
*/ |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* AbstractMeasure constructor. |
49
|
|
|
* |
50
|
|
|
* @param string $text |
51
|
|
|
* @param int $value |
52
|
|
|
*/ |
53
|
81 |
|
public function __construct($text, $value) |
54
|
|
|
{ |
55
|
81 |
|
$this->text = $text; |
56
|
81 |
|
$this->value = $value; |
57
|
81 |
|
} |
58
|
|
|
|
59
|
|
|
/* ----------------------------------------------------------------- |
60
|
|
|
| Getters & Setters |
61
|
|
|
| ----------------------------------------------------------------- |
62
|
|
|
*/ |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Get the text (alias). |
66
|
|
|
* |
67
|
|
|
* @see getText |
68
|
|
|
* |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
45 |
|
public function text() |
72
|
|
|
{ |
73
|
45 |
|
return $this->getText(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Get the text. |
78
|
|
|
* |
79
|
|
|
* @return string |
80
|
|
|
*/ |
81
|
45 |
|
public function getText() |
82
|
|
|
{ |
83
|
45 |
|
return $this->text; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Get the value (alias). |
88
|
|
|
* |
89
|
|
|
* @see getValue |
90
|
|
|
* |
91
|
|
|
* @return int |
92
|
|
|
*/ |
93
|
42 |
|
public function value() |
94
|
|
|
{ |
95
|
42 |
|
return $this->getValue(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Get the value. |
100
|
|
|
* |
101
|
|
|
* @return int |
102
|
|
|
*/ |
103
|
42 |
|
public function getValue() |
104
|
|
|
{ |
105
|
42 |
|
return $this->value; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/* ----------------------------------------------------------------- |
109
|
|
|
| Main Methods |
110
|
|
|
| ----------------------------------------------------------------- |
111
|
|
|
*/ |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Make a distance instance. |
115
|
|
|
* |
116
|
|
|
* @param string $text |
117
|
|
|
* @param int $value |
118
|
|
|
* |
119
|
|
|
* @return static |
120
|
|
|
*/ |
121
|
75 |
|
public static function make($text, $value) |
122
|
|
|
{ |
123
|
75 |
|
return new static($text, $value); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Make a distance instance from array. |
128
|
|
|
* |
129
|
|
|
* @param array $data |
130
|
|
|
* |
131
|
|
|
* @return static |
132
|
|
|
*/ |
133
|
57 |
|
public static function makeFromArray(array $data) |
134
|
|
|
{ |
135
|
57 |
|
return static::make($data['text'], $data['value']); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Get the instance as an array. |
140
|
|
|
* |
141
|
|
|
* @return array |
142
|
|
|
*/ |
143
|
24 |
|
public function toArray() |
144
|
|
|
{ |
145
|
|
|
return [ |
146
|
24 |
|
'text' => $this->text(), |
147
|
24 |
|
'value' => $this->value(), |
148
|
8 |
|
]; |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|