@@ -30,6 +30,8 @@ class License
3030
3131 protected const SALT = 'kwAHMLyLPBnHEskzH9pPbJsBxQhKXZnX ' ;
3232
33+ protected App $ kirby ;
34+
3335 // cache
3436 protected LicenseStatus $ status ;
3537 protected LicenseType $ type ;
@@ -50,6 +52,8 @@ public function __construct(
5052 if ($ email !== null ) {
5153 $ this ->email = $ this ->normalizeEmail ($ email );
5254 }
55+
56+ $ this ->kirby = App::instance ();
5357 }
5458
5559 /**
@@ -100,6 +104,15 @@ public function date(
100104 return $ this ->date !== null ? Str::date (strtotime ($ this ->date ), $ format , $ handler ) : null ;
101105 }
102106
107+ /**
108+ * Deletes the license file if it exists
109+ * @since 5.0.0
110+ */
111+ public function delete (): bool
112+ {
113+ return F::remove ($ this ->root ());
114+ }
115+
103116 /**
104117 * Returns the activation domain if available
105118 */
@@ -179,7 +192,7 @@ public function isLegacy(): bool
179192 }
180193
181194 // get release date of current major version
182- $ major = Str::before (App:: instance () ->version (), '. ' );
195+ $ major = Str::before ($ this -> kirby ->version (), '. ' );
183196 $ release = strtotime (static ::HISTORY [$ major ] ?? '' );
184197
185198 // if there's no matching version in the history
@@ -219,7 +232,7 @@ public function isOnCorrectDomain(): bool
219232 }
220233
221234 // compare domains
222- if ($ this ->normalizeDomain (App:: instance () ->system ()->indexUrl ()) !== $ this ->normalizeDomain ($ this ->domain )) {
235+ if ($ this ->normalizeDomain ($ this -> kirby ->system ()->indexUrl ()) !== $ this ->normalizeDomain ($ this ->domain )) {
223236 return false ;
224237 }
225238
@@ -236,7 +249,7 @@ public function isSigned(): bool
236249 }
237250
238251 // get the public key
239- $ pubKey = F::read (App:: instance () ->root ('kirby ' ) . '/kirby.pub ' );
252+ $ pubKey = F::read ($ this -> kirby ->root ('kirby ' ) . '/kirby.pub ' );
240253
241254 // verify the license signature
242255 $ data = json_encode ($ this ->signatureData ());
@@ -328,7 +341,7 @@ public static function polyfill(array $license): array
328341 public static function read (): static
329342 {
330343 try {
331- $ license = Json::read (App:: instance ()-> root (' license ' ));
344+ $ license = Json::read (static :: root ());
332345 } catch (Throwable ) {
333346 return new static ();
334347 }
@@ -409,6 +422,15 @@ public function request(string $path, array $data): array
409422 // @codeCoverageIgnoreEnd
410423 }
411424
425+ /**
426+ * Returns the root path to the license file
427+ * @since 5.0.0
428+ */
429+ public static function root (): string
430+ {
431+ return App::instance ()->root ('license ' );
432+ }
433+
412434 /**
413435 * Saves the license in the config folder
414436 */
@@ -420,11 +442,11 @@ public function save(): bool
420442 );
421443 }
422444
423- // where to store the license file
424- $ file = App::instance ()->root ('license ' );
425-
426445 // save the license information
427- return Json::write ($ file , $ this ->content ());
446+ return Json::write (
447+ file: $ this ->root (),
448+ data: $ this ->content ()
449+ );
428450 }
429451
430452 /**
0 commit comments