@@ -31,6 +31,8 @@ class License
31
31
32
32
protected const SALT = 'kwAHMLyLPBnHEskzH9pPbJsBxQhKXZnX ' ;
33
33
34
+ protected App $ kirby ;
35
+
34
36
// cache
35
37
protected LicenseStatus $ status ;
36
38
protected LicenseType $ type ;
@@ -51,6 +53,8 @@ public function __construct(
51
53
if ($ email !== null ) {
52
54
$ this ->email = $ this ->normalizeEmail ($ email );
53
55
}
56
+
57
+ $ this ->kirby = App::instance ();
54
58
}
55
59
56
60
/**
@@ -101,6 +105,15 @@ public function date(
101
105
return $ this ->date !== null ? Str::date (strtotime ($ this ->date ), $ format , $ handler ) : null ;
102
106
}
103
107
108
+ /**
109
+ * Deletes the license file if it exists
110
+ * @since 5.0.0
111
+ */
112
+ public function delete (): bool
113
+ {
114
+ return F::remove ($ this ->root ());
115
+ }
116
+
104
117
/**
105
118
* Returns the activation domain if available
106
119
*/
@@ -180,7 +193,7 @@ public function isLegacy(): bool
180
193
}
181
194
182
195
// get release date of current major version
183
- $ major = Str::before (App:: instance () ->version (), '. ' );
196
+ $ major = Str::before ($ this -> kirby ->version (), '. ' );
184
197
$ release = strtotime (static ::HISTORY [$ major ] ?? '' );
185
198
186
199
// if there's no matching version in the history
@@ -220,7 +233,7 @@ public function isOnCorrectDomain(): bool
220
233
}
221
234
222
235
// compare domains
223
- if ($ this ->normalizeDomain (App:: instance () ->system ()->indexUrl ()) !== $ this ->normalizeDomain ($ this ->domain )) {
236
+ if ($ this ->normalizeDomain ($ this -> kirby ->system ()->indexUrl ()) !== $ this ->normalizeDomain ($ this ->domain )) {
224
237
return false ;
225
238
}
226
239
@@ -237,7 +250,7 @@ public function isSigned(): bool
237
250
}
238
251
239
252
// get the public key
240
- $ pubKey = F::read (App:: instance () ->root ('kirby ' ) . '/kirby.pub ' );
253
+ $ pubKey = F::read ($ this -> kirby ->root ('kirby ' ) . '/kirby.pub ' );
241
254
242
255
// verify the license signature
243
256
$ data = json_encode ($ this ->signatureData ());
@@ -329,7 +342,7 @@ public static function polyfill(array $license): array
329
342
public static function read (): static
330
343
{
331
344
try {
332
- $ license = Json::read (App:: instance ()-> root (' license ' ));
345
+ $ license = Json::read (static :: root ());
333
346
} catch (Throwable ) {
334
347
return new static ();
335
348
}
@@ -410,6 +423,15 @@ public function request(string $path, array $data): array
410
423
// @codeCoverageIgnoreEnd
411
424
}
412
425
426
+ /**
427
+ * Returns the root path to the license file
428
+ * @since 5.0.0
429
+ */
430
+ public static function root (): string
431
+ {
432
+ return App::instance ()->root ('license ' );
433
+ }
434
+
413
435
/**
414
436
* Saves the license in the config folder
415
437
*/
@@ -421,11 +443,11 @@ public function save(): bool
421
443
);
422
444
}
423
445
424
- // where to store the license file
425
- $ file = App::instance ()->root ('license ' );
426
-
427
446
// save the license information
428
- return Json::write ($ file , $ this ->content ());
447
+ return Json::write (
448
+ file: $ this ->root (),
449
+ data: $ this ->content ()
450
+ );
429
451
}
430
452
431
453
/**
0 commit comments