Skip to content

Commit 3c26700

Browse files
authored
Merge pull request #442 from Gman98ish/geoip
Added GeoIps to loadbalancers
2 parents b3b1035 + 9c8c539 commit 3c26700

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

src/Client.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ public function apiToFriendly($item, $map)
267267
$item = $item->toArray();
268268
}
269269
foreach ($item as $key => $value) {
270+
if ($value instanceof Entity) {
271+
$value = $value->toArray();
272+
}
270273
$keyParts = explode(':', $key);
271274
$key = array_shift($keyParts);
272275
$filter = array_shift($keyParts);

src/Loadbalancers/Entities/GeoIp.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace UKFast\SDK\Loadbalancers\Entities;
4+
5+
use UKFast\SDK\Entity;
6+
7+
/**
8+
* @property string $restriction
9+
* @property array $countries
10+
* @property array $continents
11+
* @property boolean $europeanUnion
12+
*/
13+
class GeoIp extends Entity
14+
{
15+
}

src/Loadbalancers/Entities/Listener.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* @property bool $http2Only
2323
* @property string $customCiphers
2424
* @property int $timeoutsClient
25+
* @property GeoIp $geoip
2526
*/
2627
class Listener extends Entity
2728
{

src/Loadbalancers/ListenerClient.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use UKFast\SDK\Client as BaseClient;
77
use UKFast\SDK\Loadbalancers\Entities\Bind;
88
use UKFast\SDK\Loadbalancers\Entities\Cert;
9+
use UKFast\SDK\Loadbalancers\Entities\GeoIp;
910
use UKFast\SDK\Loadbalancers\Entities\Listener;
1011
use UKFast\SDK\SelfResponse;
1112
use UKFast\SDK\Traits\PageItems;
@@ -42,11 +43,27 @@ class ListenerClient extends BaseClient implements ClientEntityInterface
4243
'ca_bundle' => 'caBundle'
4344
];
4445

46+
47+
const GEOIP_MAP = [
48+
'european_union' => 'europeanUnion'
49+
];
50+
4551
protected $collectionPath = 'v2/listeners';
4652

4753
public function getEntityMap()
4854
{
49-
return static::MAP;
55+
return []; // needs to be empty so we can do custom hydration logic
56+
}
57+
58+
public function friendlyToApi($item, $map)
59+
{
60+
$raw = parent::friendlyToApi($item, $map);
61+
if (isset($item['geoip'])) {
62+
$rawGeoIp = $this->friendlyToApi($item['geoip'], self::GEOIP_MAP);
63+
$raw['geoip'] = $rawGeoIp;
64+
}
65+
66+
return $raw;
5067
}
5168

5269
/**
@@ -202,6 +219,11 @@ public function deleteBindById($id, $bindId)
202219
*/
203220
public function loadEntity($data)
204221
{
205-
return new Listener($this->apiToFriendly($data, $this->getEntityMap()));
222+
$listener = new Listener($this->apiToFriendly($data, self::MAP));
223+
if (isset($data->geoip)) {
224+
$listener->geoip = new GeoIp($this->apiToFriendly($data->geoip, self::GEOIP_MAP));
225+
}
226+
227+
return $listener;
206228
}
207229
}

0 commit comments

Comments
 (0)