Skip to content

Commit 8dcbb72

Browse files
committed
Types
1 parent 0815510 commit 8dcbb72

29 files changed

Lines changed: 414 additions & 497 deletions

composer.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
{
22
"name": "ether/simplemap",
3-
"description": "A beautifully simple Map field type for Craft CMS 3",
4-
"version": "3.9.3",
3+
"description": "A beautifully simple Map field type for Craft CMS",
4+
"version": "4.0.0",
55
"type": "craft-plugin",
66
"license": "proprietary",
77
"minimum-stability": "dev",
88
"require": {
9-
"craftcms/cms": "^3.2.1",
9+
"craftcms/cms": "^4.0.0",
1010
"mapkit/jwt": "^1.1.2",
1111
"geoip2/geoip2": "~2.0",
1212
"guzzlehttp/guzzle": "^6.3.3|^7.2.0",
1313
"what3words/w3w-php-wrapper": "3.*",
1414
"ext-openssl": "*",
1515
"ext-json": "*",
16-
"ext-zlib": "*"
16+
"ext-zlib": "*",
17+
"php": "^8.0"
1718
},
1819
"autoload": {
1920
"psr-4": {
@@ -34,5 +35,11 @@
3435

3536
"class": "ether\\simplemap\\SimpleMap",
3637
"schemaVersion": "3.4.2"
38+
},
39+
"config": {
40+
"allow-plugins": {
41+
"yiisoft/yii2-composer": true,
42+
"craftcms/plugin-installer": true
43+
}
3744
}
3845
}

src/SimpleMap.php

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
namespace ether\simplemap;
1010

1111
use Craft;
12+
use craft\base\Model;
1213
use craft\base\Plugin;
1314
use craft\events\RegisterComponentTypesEvent;
14-
use craft\events\RegisterGqlQueriesEvent;
1515
use craft\events\RegisterGqlTypesEvent;
1616
use craft\events\RegisterUrlRulesEvent;
1717
use craft\helpers\UrlHelper;
@@ -21,7 +21,6 @@
2121
use craft\web\twig\variables\CraftVariable;
2222
use craft\web\UrlManager;
2323
use ether\simplemap\fields\MapField as MapField;
24-
use ether\simplemap\integrations\craftql\GetCraftQLSchema;
2524
use ether\simplemap\integrations\feedme\FeedMeMaps;
2625
use ether\simplemap\integrations\graphql\MapPartsType;
2726
use ether\simplemap\integrations\graphql\MapType;
@@ -31,7 +30,9 @@
3130
use ether\simplemap\services\MapService;
3231
use ether\simplemap\services\StaticService;
3332
use ether\simplemap\web\Variable;
33+
use Exception;
3434
use yii\base\Event;
35+
use yii\base\InvalidConfigException;
3536

3637
/**
3738
* Class SimpleMap
@@ -52,7 +53,7 @@ class SimpleMap extends Plugin
5253
// Properties
5354
// =========================================================================
5455

55-
public $hasCpSettings = true;
56+
public bool $hasCpSettings = true;
5657

5758
// Static
5859
// =========================================================================
@@ -116,15 +117,6 @@ public function init ()
116117
);
117118
}
118119

119-
if (class_exists(\markhuot\CraftQL\CraftQL::class))
120-
{
121-
Event::on(
122-
MapField::class,
123-
'craftQlGetFieldSchema',
124-
[new GetCraftQLSchema, 'handle']
125-
);
126-
}
127-
128120
if (class_exists(\craft\feedme\Plugin::class))
129121
{
130122
Event::on(
@@ -150,39 +142,39 @@ public function init ()
150142
}
151143
}
152144

153-
protected function beforeUninstall (): bool
145+
protected function beforeUninstall (): void
154146
{
155147
if ($this->getSettings()->geoLocationService === GeoLocationService::MaxMindLite)
156148
GeoLocationService::purgeDb();
157-
158-
return parent::beforeUninstall();
159149
}
160150

161151
// Settings
162152
// =========================================================================
163153

164-
protected function createSettingsModel ()
154+
protected function createSettingsModel (): Model
165155
{
166156
return new Settings();
167157
}
168158

169159
/**
170-
* @return bool|\craft\base\Model|Settings
160+
* @return Model
171161
*/
172-
public function getSettings ()
162+
public function getSettings (): Model
173163
{
174164
return parent::getSettings();
175165
}
176166

177-
protected function settingsHtml ()
167+
protected function settingsHtml (): ?string
178168
{
179169
// Redirect to our settings page
180170
Craft::$app->controller->redirect(
181171
UrlHelper::cpUrl('maps/settings')
182172
);
173+
174+
return null;
183175
}
184176

185-
public function afterSaveSettings ()
177+
public function afterSaveSettings (): void
186178
{
187179
parent::afterSaveSettings();
188180

@@ -210,7 +202,7 @@ public function onRegisterFieldTypes (RegisterComponentTypesEvent $event)
210202
/**
211203
* @param Event $event
212204
*
213-
* @throws \yii\base\InvalidConfigException
205+
* @throws InvalidConfigException
214206
*/
215207
public function onRegisterVariable (Event $event)
216208
{
@@ -232,7 +224,7 @@ public function onRegisterGqlTypes (RegisterGqlTypesEvent $event)
232224
}
233225

234226
/**
235-
* @throws \Exception
227+
* @throws Exception
236228
*/
237229
public function onApplicationInit ()
238230
{
@@ -243,12 +235,12 @@ public function onApplicationInit ()
243235
// Helpers
244236
// =========================================================================
245237

246-
public static function t ($message, $params = [])
238+
public static function t ($message, $params = []): string
247239
{
248240
return Craft::t('simplemap', $message, $params);
249241
}
250242

251-
public static function v ($version, $operator = '=')
243+
public static function v ($version, $operator = '='): bool
252244
{
253245
return SimpleMap::getInstance()->is($version, $operator);
254246
}

src/controllers/SettingsController.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use ether\simplemap\enums\MapTiles;
1414
use ether\simplemap\services\GeoLocationService;
1515
use ether\simplemap\SimpleMap;
16+
use yii\web\Response as YiiResponse;
1617

1718
/**
1819
* Class SettingsController
@@ -23,10 +24,7 @@
2324
class SettingsController extends Controller
2425
{
2526

26-
/**
27-
* @return string
28-
*/
29-
public function actionIndex ()
27+
public function actionIndex (): YiiResponse
3028
{
3129
return $this->renderTemplate(
3230
'simplemap/settings',

src/controllers/StaticController.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88

99
namespace ether\simplemap\controllers;
1010

11+
use Craft;
1112
use craft\web\Controller;
1213
use ether\simplemap\utilities\StaticMap;
14+
use Exception;
1315
use Yii;
1416
use yii\web\BadRequestHttpException;
1517

@@ -22,15 +24,15 @@
2224
class StaticController extends Controller
2325
{
2426

25-
protected $allowAnonymous = true;
27+
protected int|bool|array $allowAnonymous = true;
2628

2729
/**
2830
* @throws BadRequestHttpException
29-
* @throws \Exception
31+
* @throws Exception
3032
*/
3133
public function actionIndex ()
3234
{
33-
$request = \Craft::$app->getRequest();
35+
$request = Craft::$app->getRequest();
3436

3537
if (!$request->validateCsrfToken($request->getRequiredQueryParam('csrf')))
3638
throw new BadRequestHttpException(Yii::t('yii', 'Unable to verify your data submission.'));

src/enums/GeoService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ abstract class GeoService
4242
// Helpers
4343
// =========================================================================
4444

45-
public static function getSelectOptions ()
45+
public static function getSelectOptions (): array
4646
{
4747
$isLite = SimpleMap::v(SimpleMap::EDITION_LITE);
4848

src/enums/MapTiles.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use ether\simplemap\models\Settings;
1212
use ether\simplemap\SimpleMap;
1313
use ether\simplemap\services\GeoService;
14+
use Exception;
1415

1516
/**
1617
* Class MapTiles
@@ -74,7 +75,7 @@ abstract class MapTiles
7475
// Methods
7576
// =========================================================================
7677

77-
public static function getSelectOptions ()
78+
public static function getSelectOptions (): array
7879
{
7980
$isLite = SimpleMap::v(SimpleMap::EDITION_LITE);
8081

@@ -120,15 +121,15 @@ public static function getSelectOptions ()
120121
* Get the tiles url for the given type and scale
121122
*
122123
* @param string $type
123-
* @param int $scale
124+
* @param int $scale
124125
*
125126
* @return array
126-
* @throws \Exception
127+
* @throws Exception
127128
*/
128-
public static function getTiles ($type, $scale = 1)
129+
public static function getTiles (string $type, int $scale = 1): array
129130
{
130131
$scale = $scale == 1 ? '.png' : '@2x.png';
131-
$style = strpos($type, '.') !== false ? explode('.', $type, 2)[1] : '';
132+
$style = str_contains($type, '.') ? explode('.', $type, 2)[1] : '';
132133

133134
switch ($type)
134135
{
@@ -151,13 +152,13 @@ public static function getTiles ($type, $scale = 1)
151152
];
152153
}
153154

154-
throw new \Exception('Unknown tile type "' . $type . '"');
155+
throw new Exception('Unknown tile type "' . $type . '"');
155156
}
156157

157158
// Helpers
158159
// =========================================================================
159160

160-
public static function pro ($label, $isLite)
161+
public static function pro ($label, $isLite): array
161162
{
162163
return [
163164
'label' => SimpleMap::t($label) . ($isLite ? ' (Pro)' : ''),

0 commit comments

Comments
 (0)