1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2019 - present |
4
|
|
|
* updown - Node.php |
5
|
|
|
* author: Roberto Belotti - [email protected] |
6
|
|
|
* web : robertobelotti.com, github.com/biscolab |
7
|
|
|
* Initial version created on: 18/2/2019 |
8
|
|
|
* MIT license: https://github.com/biscolab/updown-php/blob/master/LICENSE |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Biscolab\UpDown\Objects; |
12
|
|
|
|
13
|
|
|
use Biscolab\UpDown\Abstracts\AbstractCollection; |
14
|
|
|
use Biscolab\UpDown\Enum\UpDownFieldType; |
15
|
|
|
use Biscolab\UpDown\Fields\NodeFields; |
16
|
|
|
use Biscolab\UpDown\Http\UpDownResponse; |
17
|
|
|
use Biscolab\UpDown\Types\Nodes; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class Node |
21
|
|
|
* @property string name |
22
|
|
|
* @property string ip |
23
|
|
|
* @property string ip6 |
24
|
|
|
* @property string city |
25
|
|
|
* @property string country |
26
|
|
|
* @property string country_code |
27
|
|
|
* @property float lat |
28
|
|
|
* @property float lng |
29
|
|
|
* @package Biscolab\UpDown\Object |
30
|
|
|
*/ |
31
|
|
|
class Node extends BaseObject |
32
|
|
|
{ |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
protected static $endpoint = 'nodes'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
protected static $collection_type = Nodes::class; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
protected static $key = NodeFields::NAME; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var array |
51
|
|
|
*/ |
52
|
|
|
protected $typeCheck = [ |
53
|
|
|
NodeFields::NAME => UpDownFieldType::STRING, |
54
|
|
|
NodeFields::IP => UpDownFieldType::STRING, |
55
|
|
|
NodeFields::IP6 => UpDownFieldType::STRING, |
56
|
|
|
NodeFields::CITY => UpDownFieldType::STRING, |
57
|
|
|
NodeFields::COUNTRY => UpDownFieldType::STRING, |
58
|
|
|
NodeFields::COUNTRY_CODE => UpDownFieldType::STRING, |
59
|
|
|
NodeFields::LAT => UpDownFieldType::FLOAT, |
60
|
|
|
NodeFields::LNG => UpDownFieldType::FLOAT |
61
|
|
|
]; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return array |
65
|
|
|
*/ |
66
|
|
|
public function getIpV4(): array |
67
|
|
|
{ |
68
|
|
|
|
69
|
|
|
$path = $this->prepareApiPath() . '/ipv4'; |
70
|
|
|
|
71
|
|
|
$response = $this->updown->get($path); |
|
|
|
|
72
|
|
|
|
73
|
|
|
$data = $response->getResult()->getData(); |
74
|
|
|
|
75
|
|
|
return $data; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return array |
80
|
|
|
*/ |
81
|
|
|
public function getIpV6(): array |
82
|
|
|
{ |
83
|
|
|
|
84
|
|
|
$path = $this->prepareApiPath() . '/ipv6'; |
85
|
|
|
|
86
|
|
|
$response = $this->updown->get($path); |
87
|
|
|
|
88
|
|
|
$data = $response->getResult()->getData(); |
89
|
|
|
|
90
|
|
|
return $data; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param UpDownResponse $response |
95
|
|
|
* |
96
|
|
|
* @return mixed |
97
|
|
|
*/ |
98
|
|
|
protected function getCollection(UpDownResponse $response): AbstractCollection |
99
|
|
|
{ |
100
|
|
|
|
101
|
|
|
$data = []; |
102
|
|
|
|
103
|
|
|
$result = $response->getResult()->getData(); |
104
|
|
|
|
105
|
|
|
foreach ($result as $k => $v) { |
106
|
|
|
|
107
|
|
|
$node_data = array_merge($v, [ |
108
|
|
|
NodeFields::NAME => $k |
109
|
|
|
]); |
110
|
|
|
array_push($data, $node_data); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
$collection_type = static::$collection_type; |
114
|
|
|
|
115
|
|
|
return new $collection_type($response->getResult()->getData()); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.